Since buying my first Bluepill a couple of years ago I've had a couple of very half-assed attempts to get them running. Only really having success through long and tedious processes that involve a lot of manual command entry, by no means enabling a smooth development process.
Since doing a lot of work with STM32F4s and CMake, such as this STM32F4 uGFX/FreeRTOS build, STM32F4 Tensorflow Micro and the great STM32 CMake project that I've been contrinbuting to, things have gotten a bit smoother.
As such, now when I decided to set up a simple build system it was a lot easier. Hopefully this will also enable others to make better use of the bluepill as it is such a great and cheap board.
As seen in the image below, both jumpers should be in the '0' position, on the USB port's side. I have been programming the board with a Chinese ST-Link clone and the pinout is straight forward. GND and 3.3V should be connected as well as SWDIO and SWCLK, see my bad ass pinout graphic.
STM libraries are automatically pulled from here and put into a lib
directory where the cmake modules will find them and use in the build.
The default build is configured to use FreeRTOS and the STM HAL library, the required components can be easily set from CMakeLists.txt
.
I might get around to doing a STD peripherals library build at some point.
The build sources were generated from STM Cube MX and you are able to do the same if you are wishing to customize your build and generate the sources yourself. Startup ASM, system c and the linker script are automatically resolved by the cmake modules found in the cmake
directory. You should only need to populate the inc
and src
folders.
It's hard for me to say exactly which packages I have installed becuase I have not modified the toolchain on my machine in years. On my arch system I believe the required packages are
yaourt arm-none-eabi-binutils arm-none-eabi-gcc arm-none-eabi-gdb cmake openocd
The complete toolchain gcc-arm-none-eabi-bin
does not contain GDB and as such you can just get gcc
and gdb
.
Debian based users should only need the packages
sudo apt-get install -y gcc-arm-none-eabi cmake openocd
The entire idea of the build was to make it simple. As such the process is pretty standard.
mkdir build
cd build
cmake ..
make
make flash
make debug
make clean #Removes build files
or
make clean_all #Removes cmake files, build files and libraries
Enjoy.
For reasons unknown to me, sometimes boards don't want to cooperated. Giving output similar to
...
Info : STLINK v2 JTAG v28 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.249867
Error: init mode failed (unable to connect to the target)
in procedure 'program'
in procedure 'init' called at file "embedded:startup.tcl", line 495
in procedure 'ocd_bouncer'
** OpenOCD init failed **
shutdown command invoked
...
I have managed to solve this issue by holding the reset button when running make flash
then releasing it half way through, you'll notice the point when the programming procedure sort of hangs for a split second, release at this moment.
Sometimes when using the board in an application it fails to run after flashing, generating an output similar to
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20004ffc
verified 6696 bytes in 0.142008s (46.047 KiB/s)
** Verified OK **
** Resetting Target **
in procedure 'program'
in procedure 'reset' called at file "embedded:startup.tcl", line 529
in procedure 'ocd_bouncer'
This is the result of the board being possibly underpowered making it unstable, provide more power to the board.