A boilerplate for generating projects for stm32 blue pill board using cmake and makefile. The projects does not use any tools provided by ST Microelectronics. Everything from development, flashing to debugging can be done in Visual Studio Code only. C and C++ both languages are supported along with OOP concepts.
-
cmake Cmake utility is required for configuring and building this project. You can install cmake on linux by running command:
sudo apt install cmake
-
make Make utility is required for configuring and building this project. You can install cmake on linux by running command:
sudo apt-get install build-essential
-
gcc-arm-none-eabi toolchain ARM cross-platform toolchain is required to build applications for arm mcus. Toolchain can be installed by running following command:
sudo apt-get install gcc-arm-none-eabi
-
openocd It is an Open On Circuit Debugging tool used to flash and debug arm micro controllers. You can install cmake on linux by running command:
sudo apt install openocd -y
-
Cortex Debug extension This extension is required to enable debugging for cortex m microcontrollers in vscode. Install all the recommendded extension for better experience.
src
directory contains all source files for the projectinclude
directory contains all header files for the project
CMakeLists.txt
- Cmake configuration file for current projectgcc-arm-none-eabi.cmake
- Cmake configuration file for toolchainSTM32F103C8TX_FLASH.ld
- linker scriptSTM32F103.svd
- The CMSIS System View Description format(CMSIS-SVD) formalizes the description of the system contained in Arm Cortex-M processor-based microcontrollers, in particular, the memory mapped registers of peripherals. This file re required to debug device.src/main.c
- application codesrc/startup_stm32f103c8tx.s
- assembly startup script for blue pill boardsrc/system_stm32f1xx.c
- clock configuration and system initialization functions
All the configuration required for building this project is given below.
-
Build output directory In
Makefile
, output directory can be configured using variableBUILD_DIR
. -
Build type In
Makefile
, build type can be configured using variableBUILD_TYPE
. Possible values areDebug
andRelease
. -
Binary name In
CMakeLists.txt
, output binary name can be configured usingproject(<binary-name>)
macro. ** update above info in.vscode/launch.json
as well for debugging to work.
Run following command in terminal to generate flashable binaries for blue pill board. Build files will be written to Build Output Directory as configured.
make all
- Connect Stlink to PC and blue pill board using swd headers.
- Put blue pill board in programming mode.
- Run following to flash board with binary.
make flash
Onboard led connected to Pin C13 can be observed to be blinking after 500ms.
Click in Run and Debug
option in VsCode sidebar. Then launch Cortex Debug
target.
Happy debugging....