A definitive guide to developing the entire embedded C++ project for ARM Cortexm-M micro-controllers. This projects ais to provide as deep insight into the development of startup script in c++.
This project configures SysTick timer and uses it to generate time accurate delay for blinking an LED. The onboard LED connected to pin C13 blinks every second.
- 
make 
 Make utility is required for configuring and building this project. You can install make on linux by running command:sudo apt 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 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 openocd on linux by running command:sudo apt install openocd -y 
- 
st-link 
 This package is provided by STMicro-electronics for flashing the binary on the micro-controller
sudo apt install stlink- 
Cortex Debug extension 
 This extension for VSCode is helpful for debugging the application on Blue Pill. The contents of registers as well as memory are visible in the context menu. Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.ext install marus25.cortex-debug 
- srcdirectory contains all source files for the project
- includedirectory contains all header files for the project
- stm31f1.ld- linker script for STM32F103 MCU
- src\main.cpp- application code
- src\startup_stm32f103.cpp- startup script in cpp
- include\gpio.hpp- slibrary for handling gpio functions
- system_stm32f1xx.c- clock configuration and system initialization functions
- STM32F103.svd- contains the description of the system contained in Arm Cortex-M processor-based microcontrollers, in particular, the memory mapped registers of peripherals.
Running the project is super easy. Just clone, build, and flash.
- 
Using https git clone https://github.com/csrohit/stm32-startup-cpp.git cd stm32-startup-cpp
- 
Using ssh git clone [email protected]:csrohit/stm32-startup-cpp.git cd stm32-startup-cpp 
All the configuration required for building this project is given below.
- 
Build output directory In Makefile, output directory can be configured using variableBUILD_DIR.
- 
Binary name In Makefile, the name of binary can be configured using variableTARGET.
- 
MCU In Makefile, the target mcu can be selected by seting the following flags/variables- MCU_FAMILY: Specifies the family, it used to define a maco for inclusion of header files
- LD_SCRIPT: Specifies path to linker script of the target controller
- INSTR_SET: Specifies the instruction set to use. e.g.- thumb,- arm, etc
- FLOAT_ABI: Specifies the floating point implementation
- CPU: Specifies the processor on the MCU. e.g.- cortex-m3,- cortex-m4, etc
 
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 flashOutput
Onboard led connected to Pin C13 can be observed to be blinking every second.
- Run the following make command to build the program using debugging flags
make debug- Flash the controller using following command
make flash- Click in Run and Debug option in VsCode sidebar. Then launch Cortex Debug target.
Happy debugging....