STM32 Blue Pill - LieBtrau/electronics-design-data GitHub Wiki

Hardware

Where to buy?

IC Socket

Standard 2x20pin, 0.6" row spacing sockets can be used.
When using the stamped & formed sockets, standard pin headers can be soldered to the Blue Pill. No need to use special headers with fine round pins. To limit the stacking height, the pin headers can be inserted from top and soldered on bottom side.

  • On shore Tech ED40DT
  • Assmann WSW A 40-LC-TT
  • CNC Tech 243-40-1-06
  • Amphenol DILB40P-223TLF
  • TE 1-2199299-5

Blue Pill adjustments

  • R10 0603 resistor : Replace 10K by 1K5
  • Leave jumper on BOOT0 to "0" (jumper closest to B10) during debugging. If code uploading fails, then try this procedure
  • Replace C9 & C12 by 6.8pF or 8.2pF. If you leave the 20pF in place, the RTC crystal might not oscillate.

STM32Nucleo as debugger : adjustments

The ST-Link part of an STM32Nucleo will be used for debugging the Blue Pill.

  1. Remove jumpers on CN2 (ST-LINK NUCLEO)
  2. Open SB12 (NRST)

Hardware interconnection

PIN CN4 ST-LINK SIGNAL NAME Blue Pill
1 VDD-TARGET 3.3
2 SWCLK DCLK
3 GND G
4 SWDIO DIO
5 NRST R

Optionally powering the Blue Pill from the ST-LINK

If you're not powering the Blue Pill through its USB-connector, you can connect CN10.8 (5V power out) of Nucleo ST-LINK to 5V of the Blue Pill.

Optionally connecting UART1 of Blue Pill to virtual COM-port of ST-LINK

You can connect this UART to the UART pins of the ST-Link debugger. During debugging low power application, where the MCU frequently goes to standby or stop modes, the debug connection will be lost. The ST-LINK will not send the UART data through. In those cases it might be beneficial to use one of these overpriced FTDI USB TTL cables to connect the Blue Pill UART port to your PC.

  • Open SB13 and SB14 of the ST-LINK debugger
Blue Pill PIN CN3 ST-LINK FTDI USB TTL Cable
A9 (TX) RX TX-TARGET YELLOW
A10 (RX) TX RX-TARGET ORANGE
G BLACK

Blue Pill Remarks

  • The STM32F103 doesn't have internal EEPROM. Arduino libraries that emulate flash sectors as EEPROM exist. I experienced trouble (maybe because code size was already >60KB and EEPROM size is 16KB)? In debug mode it works (maybe because access to program flash is open then), not in run mode.
  • The LED connected to PC13 is active low, unlike the Nucleo or Arduino boards.
  • The STM32F103C8T6 is really a 64K part, not 128K. The debugger will refuse to debug it as a 128K part. Code uploading using the serial bootloader with Arduino seems to work for code sizes > 64K with these parts. PlatformIO also seems to ignore the 64K limitation.
  • If you want 128K flash instead of 64K, replace U2 by STM32F103CBT6.
  • The STM32F103 doesn't have an I²C repeated start condition in the Arduino-STM32 framework.

Blue Pill Pinout

Blue Pill Pinout

More information

Available cores

Command line build using arduino-builder

  • Open the IDE and set all the options as they should. Build and upload your code to see if everything works.
  • Copy the build.options.json file from the build directory to your sketch folder. On Linux systems you can typically find the build folder under /tmp/arduino-*.
  • The following command line is an example of the use of arduino-builder

~/git/Aiakos/Firmware/Aiakos$ ~/Downloads/arduino-1.6.9/arduino-builder -warnings=all -verbose -build-options-file="./build.options.json" ./Aiakos.ino

Command line build using the Arduino-Java toolchain

`arduino --verify --board Arduino_STM32:STM32F1:genericSTM32F103C --pref target_package=Arduino_STM32 --pref build.path=$HOME/build --pref target_platform=STM32F1 --pref board=genericSTM32F103C --pref custom_device_variant=genericSTM32F103C_STM32F103C8 --pref custom_cpu_speed=genericSTM32F103C_speed_72mhz --pref custom_upload_method=genericSTM32F103C_serialMethod $HOME/git/Click_BLE2_RN4020/examples/rn4020-ex1/rn4020-ex1.ino --verbose  `

For the 128K MCU, replace genericSTM32F103C_STM32F103C8 by genericSTM32F103C_STM32F103CB.

More information

Debugging

Installation

sudo apt install openocd

Download the "ST-LINK, ST-LINK/V2, ST-LINK/V2-1 firmware upgrade" from the ST website. Run it and copy the udev rules.

udevadm control --reload-rules && udevadm trigger

If that doesn't work, then reboot your computer.

Checking openOcd connection

Open a terminal and run the following command

:~$ openocd -f interface/stlink-v2-1.cfg -f target/stm32f1x.cfg  

The output should show some messages starting with "Info :"
If that is not the case, run the openocd command with debugging info enabled and see if you can find where it goes wrong.

:~$ openocd -f interface/stlink-v2-1.cfg -f target/stm32f1x.cfg -d  

Pressing the reset button one might fix the debug connection.

Check with gdb

While openocd is running, run the gdb version of your toolchain or the one from Fedora in another terminal window. The following commands should work without generating errors. In case you're working with PlatformIO, arm-none-eabi-gdb will be installed in your home directory. You can access it by: /home/$USER/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gdb

:~$ arm-none-eabi-gdb  
(gdb) target remote :3333  
(gdb) mon reg  
(gdb) info frame 
(gdb) monitor reset halt
(gdb) load ~/build/BluePillBlinky.ino.elf
(gdb) continue
Ctrl-C
(gdb) kill
(gdb) quit

More info

Roger Clark

Setting up IDE

Arduino

If you connect the Blue Pill with an ST-Link debugger and want to test something quickly with the Arduino IDE, this is the way to go.

Arduino IDE settings

Serial port settings for the HAL MX core, when Serial-USB is disabled (build_unflags = -DSERIAL_USB)

Object UART TX RX Remark
Serial UART1 PA9 PA10 connected to ST-LINK
Serial1 UART1 PA9 PA10 connected to ST-LINK
Serial2 UART2 PA2 PA3 add "build_flags = -DENABLE_HWSERIAL2" to platformio.ini
Serial3 UART3 PB10 PB11 add "build_flags = -DENABLE_HWSERIAL3" to platformio.ini

Serial port settings depend on the way of uploading your code that is chosen in the Arduino IDE.

QtCreator

Open a new project: File -> New File or Project... -> Import Project -> Import Existing Project:

  • Project Name: ArduinoBluePillBlinky
  • Location: /path to your homedir/Arduino/BluePillBlinky

Debugger setup

Tools -> Options -> Build&Run -> Debuggers -> Add
QtCreator BareMetal setup

Enabling the BareMetal plugin

Help -> About Plugins... -> Device Support -> BareMetal
This is a plugin developed by Tim Sander. If you want to see that guy in action, watch the FOSDEM video.

BareMetal setup

Tools -> Options -> BareMetal -> Add -> OpenOCD
Configuration file = /usr/share/openocd/scripts/board/st_nucleo_f103rb.cfg
QtCreator BareMetal setup

Devices setup

Tools -> Options -> Devices -> Add -> Bare Metal Device -> Start Wizard -> GDB server provider: Blue_Pill QtCreator Devices setup

Kit setup

Tools -> Options -> Build&Run -> Kits -> Add
This step ties all of the above steps together
QtCreator Kit setup

Attaching the kit to your project

Press Ctrl+5 -> Add Kit (or change the current Kit by clicking on the current kit)

Project settings

Build settings for Arduino toolchain

  • Build directory: $HOME/build
  • Build steps
    • Custom process step command: $HOME/Downloads/arduino-1.6.9/arduino
    • Custom process step arguments: --verify --board Arduino_STM32:STM32F1:genericSTM32F103C --pref target_package=Arduino_STM32 --pref build.path=$HOME/build --pref target_platform=STM32F1 --pref board=genericSTM32F103C --pref custom_device_variant=genericSTM32F103C_STM32F103C8 --pref custom_cpu_speed=genericSTM32F103C_speed_72mhz --pref custom_upload_method=genericSTM32F103C_serialMethod /home/ctack/Arduino/BluePillBlinky/BluePillBlinky.ino --verbose
    • Custom process step working directory: %{buildDir}
  • Clean steps
    • Custom process step command: rm
    • Custom process step argument: -rf $HOME/build
    • Custom process step working directory: %{buildDir} QtCreator Kit setup

Run settings

You'll first have to build the elf-file before you can select it in this step QtCreator Kit setup

Flashing the firmware

If you're using the Arduino-toolchain and you've debugged your application, there's nothing more to do. Debugging automatically writes the application to flash. Disconnect the "R" from the ST-LINK debugger in case the BluePill application doesn't start.

More info