When developing software for STM32 microcontrollers, I usually include the following steps.
- Generation of basic project on STM32CubeMX
- Writing code in any comfortable text editor (I use Sublime Text)
- Compilation of code with use arm-none-eabi-gcc
- Firmware of microcontroller with use st-link
The whole process of installation and start-up are described below.
Stack
- STM32CubeMX
- ST-link
STM32CubeMX
I prefer to work with STM32CubeMX. It allows you to quickly generate a project with the setting of the periphery and clock frequency of the microcontroller, as well as the ability to connect such cool things as FreeRTOS or lwIP.
Installation procedure
- Download STM32CubeMX
- For installation need unzip archive and perform of command
- Add in environment variables
- Restart .bashrc
After configuring the peripherals and clock frequencies, need to generate a project. Also need to configure of the generation of the project. I set the generation Makefile and put a tick to generate *.c and *.h files for each peripheral.
You may have to wait for the required libraries to be downloaded.
ST-link
To firmware and debug the program on the microcontroller, you will need st-link. It can be cloned from repository and assemble it yourself. I recommend installing from the repository of your distribution - it’s faster.
Also will need a compiler and debugger to build:
They can also be taken from the repository.
After successful project generation, you will see a bunch of files and folders, that need to be compiled.
The first, need say Makefile is where your compiler is.
After all this, need to build a project.
And fill firmware into the microcontroller using st-link.
You can use the graphical version of STlink-GUI.
I prefer do it from console.
Obstacles, that may stand between you and STM32
Make error
When you try to build a project, you will see the following error:
If you open Makefile, in block sources you will see repeated lines.
In my case is following lines:
This lines need delete and project should be compiling. This is bug of code generation in STM32CubeMX. We wrote to the developers of STM32CubeMX about this bug. It remains to wait until they fix and release an update.
No libraries
You may encounter the following error during build.
Compiler say what he cannot find library stdint.h. For fix it error need install
- arm-none-eabi-newlib
It can also be taken from the repository.