Well, for a long time, I’ve been referring people to a random YouTube video that tells them how to install firmware on a STM32. That seems both inadequate and relatively lazy on my part. I’ve been meaning to write down a little bit more detailed instructions, so here they are. The instructions assume using a ST-LINK V2 to program the stm32f103c8t6 blue pill board. So without further ado, here we go.
Linux (Ubuntu) Instructions:
Install required software:
- Install libusb and git: sudo apt-get install libusb-1.0-0-dev git
- Move to home: cd ~
- Grab stlink code: git clone https://github.com/texane/stlink
- Move into stlink folder: cd stlink
- Build stlink: make
- Copy binary to /usr/bin: sudo cp build/Release/bin/st-flash /usr/bin
Attaching the debugger and programming firmware:
- Connect the four pins at the edge of the stm32f103c8t6 to 3.3V, SWD, SWCLK and GND to the pins on the ST-LINK V2
- Move the Boot0 jumper from position 0 to 1
- Plug the ST-LINK V2 into a USB port
- Program firmware (firmware is found at repos/Stm32Workbench/Gen3Images): sudo st-flash –format ihex write OppStm32.2.0.0.6.hex
- After programming is completed (printing out Jolly Good!), unplug the ST-LINK V2 from the USB port
- Move the Boot0 jumper from position 1 to 0
Verify firmware version:
- Plug the stm32f103c8t6 into a USB port
- Run Gen2Test.py (Gen2Test is found at repos/Python/Gen2Test): sudo python Gen2Test.py -port=/dev/ttyACM0
Note: Gen2Test.py may need to be run a few times to “sync” the serial port because plugging in the USB port may send garbage on the serial port.
Windows Instructions:
Install required software:
- Download STSW-LINK004 from http://www.st.com: https://www.st.com/en/development-tools/stsw-link004.html
- Run setup.exe found in the zip file. This will install the STM32 ST-Link Utility
Attaching the debugger and programming firmware:
- Connect the four pins at the edge of the stm32f103c8t6 to 3.3V, SWD, SWCLK and GND to the pins on the ST-LINK V2
- Move the Boot0 jumper from position 0 to 1
- Plug the ST-LINK V2 into a USB port
- Run STM32 ST-Link Utility
- File->Open File and browse and select firmware file (firmware is found at repos/Stm32Workbench/Gen3Images)
- Target->Program and Verify
- After programming is completed, unplug the ST-LINK V2 from the USB port
- Move the Boot0 jumper from position 1 to 0
Verify firmware version:
- Plug the stm32f103c8t6 into a USB port
- Run Gen2Test.py (Gen2Test is found at repos/Python/Gen2Test): c:\Python27\python.exe Gen2Test.py -port=COM3
Note: Gen2Test.py may need to be run a few times to “sync” the serial port because plugging in the USB port may send garbage on the serial port.
Ending Comments:
That’s it. Hopefully these instructions are a little bit easier than doing a bunch of web searches and sussing out which instructions are applicable to your situation.