Giter Site home page Giter Site logo

clevert-pretto / stm32-gnu-project-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from otakann/stm32-gnu-project-sample

0.0 0.0 0.0 2.8 MB

Step to show how to use GNU tools to construct stm32 MCU program develop environment

Makefile 0.31% C 98.59% Assembly 0.26% C++ 0.84%

stm32-gnu-project-sample's Introduction

Project Sample of stm32 MCU program develop

What is this

Step to show how to use free tools to code , build and debug stm32 MCU program.

Environment

SDK

Evaluation board

B-L475E-IOT01A

Example

Blink user led

Manual

Make

  • If you cannot execute the "make" command, please install the make tools.
apt install make

Toolchain

  • Download the gcc-arm-none-eabi toolchain from ARM official website. Unpack it to wherever you want. In this case I put it into "/usr/local/install".
tar -jxvf gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2 -C /usr/local/install

Debugger

  • Download the Open On-Chip Debugger binary packages from GNU MCU Eclipse Project. Unpack it to wherever you want. In this case I put it into "/usr/local/install".
tar -zxvf gnu-mcu-eclipse-openocd-0.10.0-11-20190118-1134-centos64.tgz -C /usr/local/install
  • Copy the "60-openocd.rules" file in "contrib" folder to "/etc/udev/rules.d/" directory. Then reload the udev rules.
cp /usr/local/install/gnu-mcu-eclipse/openocd/0.10.0-11-20190118-1134/contrib/60-openocd.rules /etc/udev/rules.d/
udevadm control --reload

IDE

  • Download open-jdk from oracle official website. Unpack it to wherever you want. In this case I put it into "/usr/local/install".
tar -zxvf openjdk-12.0.1_linux-x64_bin.tar.gz -C /usr/local/install
tar -zxvf eclipse-cpp-2019-03-R-linux-gtk-x86_64.tar.gz -C /usr/local/install
  • Add the jvm executable file path parameter like follows in "eclipse.ini" file. image
  • Create a new "desktop" configuration file named "eclipse.desktop" like follows in "/usr/share/applications". Then you can launch eclipse from application shortcut. image
  • Launch the eclipse IDE and click the "Help->Eclipse Marketplace" tab. Then search the "GNU MCU Eclipse" plug-in and install it. image
  • Click the "Window->Preferences" tab. Input the information in "MCU->Global OpenOCD Path" and then click the "Apply and Close" button. image

STM32Cube

  • Download STM32Cube MCU Package from ST official website. Please select the package according to your MCU model. The MCU of my board(B-L475E-IOT01A) is STM32L475VGT6. So I choose the file "en.stm32cubel4.zip".

CMSIS

  • Copy the file "stm32l4xx.h" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/CMSIS/Device/ST/STM32L4xx/Include" into "led_blink/cmsis/device/inc". And so on, if your MCU is STM32F2 series, this file maybe "stm32f2xx.h". Then uncomment the specific macro to indicate your target MCU. In my case I choose "STM32L475xx". image
  • Copy the file "stm32l475xx.h" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/CMSIS/Device/ST/STM32L4xx/Include" into "led_blink/cmsis/device/inc". And so on, this file is chosen according to your MCU model.
  • Copy the file "system_stm32l4xx.h" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/CMSIS/Device/ST/STM32L4xx/Include" into "led_blink/cmsis/device/inc". And so on, if your MCU is STM32F4 series, this file maybe "system_stm32f4xx.h".
  • Copy the file "system_stm32l4xx.c" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates" into "led_blink/cmsis/device/src". And so on, if your MCU is STM32F1 series, this file maybe "system_stm32f1xx.c". Then change HSE value and Vector table offset value in this file. HSE is the default value of external oscillator (in Hz). Please check the hardware of your board. Normally, vector table offset value will be 0. But if you do not want to put the farmware at the head of the flash (such as there is another bootloader), you may change it. image
  • Copy the file "core_cm4.h" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/CMSIS/Include" into "led_blink/cmsis/device/inc". And so on, this file is chosen according to your MCU model (STM32L4 series is cotex-M4 processor).
  • Copy the file "cmsis_gcc.h","core_cmFunc.h","core_cmInstr.h" and "core_cmSimd.h" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/CMSIS/Include" into "led_blink/cmsis/device/inc".
  • Copy the file "cmsis_os2.h" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2" into "led_blink/cmsis/rtos/inc".
  • Implement your own RTOS wrapper for CMSIS-RTOS v2 in "led_blink/cmsis/rtos/src". In this case I write a simple package for FreeRTOS. You can also copy the file "cmsis_os2.c" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2" directly.

Hardware driver

  • ST provide three forms of driver API. Standard Peripheral Library, Cube HAL APIs and Cube low layer APIs. In this case I use the low layer APIs.
  • Copy all of the files such as "stm32l4xx_ll_xxx.h" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/STM32L4xx_HAL_Driver/Inc" into "led_blink/package/ll_driver/inc".
  • Copy the file "stm32_assert_template.h" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/STM32L4xx_HAL_Driver/Inc" into "led_blink/cmsis/device/inc". Then rename it to "stm32_assert.h"
  • Copy all of the files such as "stm32l4xx_ll_xxx.c" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/STM32L4xx_HAL_Driver/Src" into "led_blink/package/ll_driver/src".

Low layer

  • Copy the file "startup_stm32l475xx.s" from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates/gcc" into "led_blink/lowlayer". And so on, this file is chosen according to your MCU model.
  • Modify the linker script file "STM32L475VGTx_FLASH.ld" in "led_blink/lowlayer". I got this file from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Projects/B-L475E-IOT01A/Templates_LL/SW4STM32/B-L475E-IOT01". So if there is no example of your MCU in STM32Cube package, you may modify this file to fit your MCU. The main points are as follows. image
  • Implement the Interrupt Handlers in "led_blink/lowlayer/stm32l4xx_it.c" and "led_blink/lowlayer/stm32l4xx_it.h". I got these two files from "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Projects/B-L475E-IOT01A/Templates_LL/Inc" and "en.stm32cubel4/STM32Cube_FW_L4_V1.13.0/Projects/B-L475E-IOT01A/Templates_LL/Src". And I comment some functions has been implemented in FreeRTOS. image
  • Modify the "SystemClock_Config" function in "led_blink/lowlayer/main.c" file to fit your hardware. You can reference the example "main.c" file in the sample project of STM32Cube package.

FreeRTOS

  • Download FreeRTOS Source code from FreeRTOS official website.
  • Copy all of the source code from "FreeRTOSv10.2.0/FreeRTOS/Source" into "led_blink/package/freertos/src".
  • Copy all of the header file from "FreeRTOSv10.2.0/FreeRTOS/Source/include" into "led_blink/package/freertos/inc".
  • Individually copy the file "portmacro.h" and "port.c" from "FreeRTOSv10.2.0/FreeRTOS/Source/portable/GCC/ARM_CM4F" into "led_blink/package/freertos/inc" and "led_blink/package/freertos/src". Please make sure your MCU model. STM32L4 series is cotex-M4 processor with FPU. So I choose the "ARM_CM4F" folder.
  • Modify the file "FreeRTOSConfig.h" in "led_blink/package/freertos/inc" to fit your own project. You can reference the meaning of each parameter from here.
  • Choose a heap implementation file from "FreeRTOSv10.2.0/FreeRTOS/Source/portable/MemMang". The diffrence of each implementation you can reference is here.

Project

  • Launch Eclipse and click "File->new->Makefile Project with Existing Code" tab. Then choose the source code folder and "Cross GCC" as toolchain. Click "finish" button. image
  • Right click the project and click the "Properties" tab. Then click "C/C++ Build->Tool Chain Editor". Select the "Current toolchain" as "no toolchain" then click "Apply and Close". Repeat this step but select the "Current toolchain" as "Cross GCC". (Perhaps CDT issue?)
  • Click the project "Properties->C/C++ Build->Settings" tab. Input the toolchain path and prefix. image
  • Click the project "Properties->C/C++ Build" tab. In the "Builder Settings" tab, set "Build Command" as follows and set "Build directory" as the top of the source code folder. In my case the top of the source code folder is "led_blink". image
  • Edit the configuration of Makefile in "led_blink" folder if you need. image
  • Try to build the project (Project->Build Project). image

Debug

  • Click the "Run->Debug Configurations..." tab. Then right click the "GDB OpenOCD Debugging" tab and choose the "New Configuration". image
  • In "Main" tab, click the "Search Project..." button to select debug file. image
  • In "Debugger" tab, input the following information and click "Apply" button. In my case, B-L475E-IOT01A already has a st-link on-board debugger. If you have a different debugger or MCU, you need change the "Config Options". You can find all of the congifuration script in your install location of openOCD. image
  • Connect the hardware and click "Debug" button then you can start to debug on-chip.

stm32-gnu-project-sample's People

Contributors

otakann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.