Nucleo STM32F103RB Toolchain - LieBtrau/electronics-design-data GitHub Wiki
Nucleo ST-Link firmware update
The Nucleo boards I received had an older ST-Link firmware which didn't work very well. Follow the instructions on this link to update your board.
Toolchain setup
I worked a short time with the libmaple libraries, but found that they are outdated. You can opt for two toolchains. Either use the Stm32duino toolchain, based on libmaple, or use the newer HAL MX toolchain.
- Download a recent version of the Arduino toolchain from the Arduino website. Some Linux versions, like Fedora have a version of Arduino included, but that version is almost always outdated. Let's assume that you extracted it to ~/Programs.
-
- For the HAL MX toolchain, follow the instructions about "How to use STM32 in the ARDUINO IDE".
- For the STM32Duino toolchain, follow the instructions on Set up STM32 "blue pill" for Arduino IDE.
Build and upload your first program
Command line
Create ~/Arduino/blinky_nucleo/blinky_nucleo.ino with the following contents
#line 1 "blinky_nucleo.ino"
#include "Arduino.h"
void setup();
void loop();
#line 1
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}
Build your project (replace /home/ctack with your own home folder):
~/Programs/arduino-1.6.5/arduino --verify --board Arduino_STM32:STM32F1:nucleo_f103rb --pref target_package=Arduino_STM32 --pref build.path=. --pref target_platform=STM32F1 --pref board=nucleo_f103rb /home/ctack/Arduino/blinky_nucleo/blinky_nucleo.ino --verbose
This can also easily be set in the QtCreator build settings
Upload the binary to the Nucleo:
On my computer, the Nucleo appears as "/run/media/ctack/NODE_F103RB"
cp ~/Arduino/blinky_nucleo/build/blinky_nucleo.cpp.bin /run/media/ctack/NODE_F103RB
If you don't need debugging, you could set the above command line up in the run settings of QtCreator.
Pitfalls
- When debugging or uploading code with the STLINKV2 and using the UART connection of the STLINKV2, be sure not to flood the STLINKV2 with serial data. The device will loose USB connection. The solution is to disconnect the UART lines from the STLINKV2 to your debugging target.
Working with Arduino libraries
The above toolchain only wants to build and link libraries when they are in the ~/Arduino/libraries folder. An extra conditions is that the name of the library must match the folder name.
Libraries that you check out from git don't always have that structure. An elegant workaround is to use symlinks.
-
Check your library out to a random folder
git clone [email protected]:LieBtrau/arduino-xterm.git ~/git/arduino-xterm
-
Make a symlink to the Arduino library
ln -s ~/git/arduino-xterm/Xterm ~/Arduino/libraries
Setting up your debug environment
You can follow the steps as decribed in STM32L053 Nucleo toolchain setup. Below only the differences with the SMT32L053 setup are described.
You can test the openocd connection with:
openocd -f board/st_nucleo_f103rb.cfg
The QtCreator BareMetal setup is different for this nucleo board. Use "usr/share/openocd/scripts/board/st_nucleo_f103rb.cfg" instead of "/usr/share/openocd/scripts/board/stm32l0discovery.cfg"
Screenshot of bare metal plugin setup for STM32F103
Screenshot of Devices Setup
Screenshot of Kit setup (top)
Screenshot of Kit setup (bot)
Screenshot of Run Settings
Serial ports
The behavior of the serial ports might depend on the programmer used. Select "USBtinyISP" to get the following settings:
Object | UART | TX | RX | Remark |
---|---|---|---|---|
Serial | UART2 | D1 | D0 | Connected to debugger |
Serial1 | UART1 | D8 | D2 | |
Serial2 | UART3 | PC10 | PC11 |
- See Nucleo pin mapping for the mapping of Serial objects to port pins.