Tuesday, June 24, 2014

STM32 Flash Loader for Linux

e-Gizmo STM32 MCU Board
I've had this STM32 Board from e-Gizmo for about 2 years now and I think it's about time it gets powered up.

The STM32 features a built-in serial bootloader. ST Microelectronics provides a Flash Loader command line tool for Windows here:

Since I've been on a Linux workstation (Xubuntu 14.04 LTS) for a few months now, I started looking for an alternative, preferably open source, to load the flash memory of the STM32. I found stm32flash.

I used git to clone the repository on my home directory. Git can be downloaded from the Ubuntu repository:

sudo apt-get install git

Clone the repository.

git clone https://git.gitorious.org/stm32flash/stm32flash.git

A directory stm32flash will be made. Change directory then make the project.

cd stm32flash
sudo make install

The last line installs stm32flash on /usr/local/bin.

The e-Gizmo STM32 board provides a switch to access the bootloader. To test if stm32flash is properly installed and can communicate with the STM32 board, the board must be switched to bootloader mode, and run stm32flash to get device information. The e-Gizmo STM32 board uses a Prolific PL2303 chip, its serial port's name is typically of the form /dev/ttyUSBx.

stm32flash /dev/ttyUSB0

If stm32flash successfully communicates with the board, it will display:

stm32flash - http://stm32flash.googlecode.com/

Serial Config: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0420 (Medium-density VL)
- RAM        : 8KiB  (512b reserved by bootloader)
- Flash      : 128KiB (sector size: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB

Resetting device... done.

If otherwise it displays:

stm32flash - http://stm32flash.googlecode.com/

Serial Config: 57600 8E1
Failed to read byte: read_byte: Success

Check to make sure that the switch is on bootloader mode, then press the reset button before running stm32flash again.

If the serial port name is improperly entered, it will display something like this:

stm32flash - http://stm32flash.googlecode.com/

Failed to open serial port: /dev/ttyUSB1: No such file or directory

If it is taking a long time after displaying Serial Config: 57600 8E1, it can be terminated using Ctrl-C, then try pushing the reset button before running stm32flash again.

No comments:

Post a Comment