Using STM32's Serial Bootloader

All STM32 ARM chips contain a hard-coded bootloader that allows them to be programmed via USART1.

Note: Espruino boards have a USB implementation of the STM32 bootloader protocol built in. Do not follow these instructions unless you want to overwrite the bootloader.

Wiring Up

USART1 is usually on pins PA9 (TX) and PA10 (RX) of the chip itself, and it is 3.3v TTL level. If you have an:

  • Espruino board, you'll have to use a USB-TTL converter and connect directly to the pins. 
  • STM32DISCOVERY board, you'll have to use a USB-TTL converter and connect directly to the pins. 
  • Maple/Olimexino board, you'll have to use a USB-TTL converter and connect to either the pins marked TX1 and RX1, or D7(TX) and D8(RX) on the Olimexino.
  • 'HY' board, you don't have to do much at all - they have a USB-TTL converter onboard, and it is connected to USART1.

Enabling the Bootloader

To get into the bootloader, you need to reset the device with the BOOT0 pin set to 1, and  BOOT1 set to 0:

  • On Espruino boards, BOOT0 is labelled on a pin in the middle just below the top edge of the board and it'll need to be connected to 3.3v. BOOT1 is on pin B2 and needs connecting to GND.
  • On HY boards these are set by jumpers. Just set them up and press the Reset Button.
  • On Maple/Olimexino, the button is wired up to BOOT0. Hold it down, then tap the Reset Button.
  • On STM32DISCOVERY boards you'll have to connect the pins up manually.

Flashing

On Windows

ST provide an application called the 'ST Flash Loader Demonstrator' that allows you to easily flash your device. Just download the tool and follow their instructions.

On Mac OS / Linux 

  • Open a Terminal Window
  • Make sure you have Python installed (type python --help and see if anything happens)
  • Download the stm32loader.py Python script from https://github.com/espruino/Espruino/blob/master/scripts/stm32loader.py
  • Run python stm32loader.py -p MySerialPort -evw espruino_for_your_device.bin
    • For Espruino Boards add -k to the command-line. This will make flashing more reliable.
    • On Mac OS, MySerialPort will probably look a lot like /dev/tty.usbserial### where ### is a number. You can use the 'Tab' key to autocomplete once you have typed /dev/tty.usbserial
    • On LinuxMySerialPort will probably look a lot like /dev/ttyUSB# where # is a number. If you only have one USB-Serial device plugged in, it's almost certainly /dev/ttyUSB0
  • Note: The flasher may give you an error message such as Chip replied with a NACK. If so, just try running it again without resetting your board.

The instructions are detailed more fully here: http://leaflabs.com/docs/bootloader.html#flashing-a-custom-bootloader

Beaglebone Black (or other embedded Linux)

See this forum post for more details.

After Flashing

Just ensure that the BOOT0 pin is set to 0 again (On Maple/Olimexino you don't need to worry) and press Reset. Espruino should start right up!