Skip to content

Firmware Programming

Keir Fraser edited this page Jan 7, 2020 · 21 revisions

NOTE: If you have a pre-assembled Greaseweazle device then it is already programmed and you should skip this section!!

Two methods are available for initial programming of the STM32 microcontroller:

In general the ST-Link method is easiest in Windows, especially for F730-based boards. However, serial programming is an alternative for all boards, and is particularly suitable for Linux users.

ST-Link Programming

This method requires an ST-Link v2 programmer, clones of which are available cheaply on Ebay:

Example ST-Link v2 clone

Connect the programmer to the DEBUG header of the STM32F730 board, or the right-angle four-pin header of the Blue Pill board:

Programmer Blue Pill STM32F730 DEBUG
SWCLK DCL CK
SWDIO DIO DIO
GND GND GND
3.3V 3.3 VCC

WARNING: Do not connect to the programmer's 5.0V pin as you will destroy your STM32 chip!

Windows:

  • Download the firmware zip file from here.
  • Download and run the ST-Link software (STSW-LINK004).
  • Connect your board to your Windows PC via USB.
  • Click Connect to the target in the ST-Link software.
  • Click Open file and open the correct HEX file for your board (F1 HEX file for Blue Pill, F7 HEX file for STM32F730).
  • Click Program verify

Serial Programming

This method requires a USB-TTL adapter such as shown below, available for around £1-2 on Ebay. My own experience is with the PL2303HX-based adapters, which are automatically detected and initialised in Linux. In Windows the correct Prolific driver is installed, but since the cheap adapters are using cloned chips, the driver may fail to initialise the device. In this case the driver must be replaced by an older version and auto-update disabled for the driver, as described here.

Programming steps now depend on your board type:

Example USB-TTL serial adapter

STM32F103 (Blue Pill)

Adjust the boot jumpers on the STM32 board and attach the Dupont jumper cables supplied with the USB-TTL adapter as shown. Note that 2.54mm header pins have been soldered for this purpose: you may wish to do similar at least for 5V, G, A9 and A10. In this example the cables connect back to the following USB-TTL pins: White to GND, Black to 5V, Purple to RXD, Blue to TXD.

Programming the STM32

Download the firmware zip file from here and program according to OS-specific instructions below. Note that STM32F103 boards such as Blue Pill should be programmed with the F1 HEX file (eg. Greaseweazle-F1-v0.7.hex). Once the device is programmed you should set both yellow boot jumpers to 0. This will cause the Greaseweazle firmware to run automatically when powered on.

Windows: The programming process is described, along with suitable Windows software, on the Cortex firmware webpage.

Linux: The firmware HEX image can now be programmed with the stm32flash command-line utility:

 # unzip Greaseweazle-v0.3.zip
 # sudo stm32flash -b 115200 -vw Greaseweazle-v0.7/Greaseweazle-F1-v0.7.hex /dev/ttyUSB0

STM32F730

Set the BOOT jumper and attach Dupont jumper cables to the UART header. Remember to connect RXI to USB-TTL TX, and TXO to USB-TTL RX.

Download the firmware zip file from here and program according to OS-specific instructions below. Note that STM32F730 boards should be programmed with the F7 HEX file (eg. Greaseweazle-F7-v0.7.hex). Once the device is programmed you should remove the BOOT jumper. This will cause the Greaseweazle firmware to run automatically when powered on.

Windows: The ST-provided serial software does not support STM32F730. It is therefore necessary to use WSL (Windows Subsystem for Linux) to clone and build the latest version of stm32flash. From within Ubuntu bash:

 # apt install gcc make git
 # git clone https://github.com/stm32duino/stm32flash
 # cd stm32flash
 # make
 # sudo ./stm32flash -vw ../Greaseweazle-v0.7/Greaseweazle-F7-v0.7.hex /dev/ttyS3

Note that the correct ttyS number depends on the Windows COM port of your serial adapter. ttyS3 corresponds to COM3, for example.

Linux: The firmware HEX image can be programmed with the stm32flash command-line utility:

 # unzip Greaseweazle-v0.7.zip
 # sudo stm32flash -b 115200 -vw Greaseweazle-v0.7/Greaseweazle-F7-v0.7.hex /dev/ttyUSB0

Note that the distro-packaged stm32flash version may not support STM32F730. In this case you must build stm32flash from source:

 # git clone https://github.com/stm32duino/stm32flash
 # cd stm32flash
 # make