Flashing Olimex STM32-H103 using a Raspberry Pi

If you want to flash an Olimex STM32-H103, you don't actually need an expensive JTAG cable. The expensive JTAG cable was suggested by GNUK's README [1]. Well, I decided to buy a STM32-H103 to store my OpenPGP master key, using GNUK. This is possibly the cheapest option to obtain a OpenPGP smartcard. STM32-H103 is available on Amazon for £14 [2].

It might be possible to read the STM32-H103's ROM content back into the Raspberry Pi. I haven't personally tried it yet. I know the ROM is read-locked if you follow the flashing process above. However, the rumour says that is is fairly easy to do. So using a USB smartcard may not deter GCHQ / NSA from extracting your private key! I don't actually know if this is safer than storing your private key on an encrypted USB drive. However if you use a GNUK device, it is safer than storing your private key on the actual computer, and it is more convenient to use the private key than having to re-import it from a USB drive.

Pinouts

You need to connect the two devices together following the two diagrams below:

Raspberry Pi JTAG using GPIO pins

STM32-H103 JTAG connector


Note: nTRST connects to TRST on Raspberry Pi. [3]

Starting OpenOCD

sudo openocd -f interface/raspberrypi-native.cfg -f board/olimex_stm32_h103.cfg

Flashing STM32-H103

telnet localhost 4444
reset halt
stm32f1x unlock 0
reset halt
flash erase_sector 0 0 127
flash erase_check 0
flash write_image erase gnuk.elf
verify_image gnuk.elf
stm32f1x lock 0
reset
shutdown

Note: You need to shutdown OpenOCD before using the GNUK device.


[[1]] “Q7: How much does it cost? A7: Olimex STM32-H103 plus ARM-USB-TINY-H cost 70 Euro or so.”, GNUK Readme