11/3/2020 – Loading STM32 Firmware

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:

  1. Install libusb and git: sudo apt-get install libusb-1.0-0-dev git
  2. Move to home: cd ~
  3. Grab stlink code: git clone https://github.com/texane/stlink
  4. Move into stlink folder: cd stlink
  5. Build stlink: make
  6. Copy binary to /usr/bin: sudo cp build/Release/bin/st-flash /usr/bin

Attaching the debugger and programming firmware:

  1. 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
  2. Move the Boot0 jumper from position 0 to 1
  3. Plug the ST-LINK V2 into a USB port
  4. Program firmware (firmware is found at repos/Stm32Workbench/Gen3Images): sudo st-flash –format ihex write OppStm32.2.0.0.6.hex
  5. After programming is completed (printing out Jolly Good!), unplug the ST-LINK V2 from the USB port
  6. Move the Boot0 jumper from position 1 to 0

Verify firmware version:

  1. Plug the stm32f103c8t6 into a USB port
  2. 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:

  1. Download STSW-LINK004 from http://www.st.com: https://www.st.com/en/development-tools/stsw-link004.html
  2. Run setup.exe found in the zip file. This will install the STM32 ST-Link Utility

Attaching the debugger and programming firmware:

  1. 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
  2. Move the Boot0 jumper from position 0 to 1
  3. Plug the ST-LINK V2 into a USB port
  4. Run STM32 ST-Link Utility
    1. File->Open File and browse and select firmware file (firmware is found at repos/Stm32Workbench/Gen3Images)
    2. Target->Program and Verify
  5. After programming is completed, unplug the ST-LINK V2 from the USB port
  6. Move the Boot0 jumper from position 1 to 0

Verify firmware version:

  1. Plug the stm32f103c8t6 into a USB port
  2. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s