Just a basic setup to code, compile and debug using VSCode and STM32 HAL libraries in a linux environment.
This program is targeted as STM32F429 Discovery board, however can be applied to any ST MCU by modifing some defines and using the correct ST files.
First install all dependencies:
Can be downloaded for debian based distros by clicking in this blue words, if you use other platform please check their website. I strongly recommend installing from link because the one available in apt repository does not have gdb.
Used to program and debug, the one at opt repository works with ST-link out of the box.
$ sudo apt install openocd
Supported board files are located in usr/shared/openocd/boards
This one can be obtained either using STMCube or just clone ST Repository. I recommend taking a look into these folders to find the correct path for your board/MCU files, it may not be as straightfoward as it seems.
First check all paths on toolchain.cmake and CMakeLists.txt to make sure it points to whatever folder you chose to install. In my case SDK was in home
folder and toolchain was in /opt
.
Once paths are correct, create a build folder inside project root and build.
$ mkdir build
$ cd build
$ cmake ..
$ make
If everything is OK it should compile and generate a test.elf file. Just run make program
and it should flash the MCU connected to your PC.
For now it just toggle green led whenever you press user button.