Small HOW-TO: Run miniblink from libopencm3 on STM32-P405 with ARM-USB-TINY JTAG

Started by tkoskine, March 11, 2014, 09:06:42 PM

Previous topic - Next topic

tkoskine

Hi,

At the moment, STM32-P405 product page didn't have any examples for arm-gcc + libopencm3, so I had to do it from scratch. Here are the steps which I did. They should work on Ubuntu 13.10. On Fedora Linux, just replace apt-get commands with yum equivalents.

Required equipment:


Building:
mkdir -p $HOME/arm && cd $HOME/arm
wget https://launchpad.net/gcc-arm-embedded/4.8/4.8-2013-q4-major/+download/gcc-arm-none-eabi-4_8-2013q4-20131204-linux.tar.bz2
tar jxf gcc-arm-none-eabi-4_8-2013q4-20131204-linux.tar.bz2
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 openocd
git clone --recursive https://github.com/tkoskine/libopencm3-examples
export PATH=$PWD/gcc-arm-none-eabi-4_8-2013q4/bin:$PATH
cd libopencm3-examples
make V=1


Flashing:
cd examples/stm32/f4/stm32-p405/miniblink
cat > $HOME/arm/openocd-olimex-stm32-p405.cfg<<EOF
#
# Olimex STM32-P405
#
# http://olimex.com/dev/stm32-p405.html
#

# Work-area size (RAM size) = 128kB for STM32F4xxx device
set WORKAREASIZE 0x20000

source [find target/stm32f4x.cfg]
EOF
sudo openocd -f /usr/share/openocd/scripts/interface/olimex-jtag-tiny.cfg -f ~/arm/openocd-olimex-stm32-p405.cfg

# another console
telnet localhost 4444
# inside telnet
reset halt
flash write_image erase miniblink.elf
reset
exit


Now you should have the status LED blinking on the board.

Some notes:

  • openocd + arm-usb-tiny works somewhat unreliably on Ubuntu 13.10, I had to run openocd multiple times in a row to get it working. On Fedora 20 everything was ok.
  • Remember to install 32-bit support libraries if you are on 64-bit system, otherwise gcc does not work
  • Use --recursive flag when cloning libopencm3-examples, otherwise you don't get libopencm3
  • No guarantees given about the instructions or code. They worked for me, but if you are (really) unlucky, you might fry your board or wipe out your root file system.

Successfull openocd telnet session should look like this

tkoskine@ubuntu:~/arm/libopencm3-examples$ telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reset halt
JTAG tap: stm32f4x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
JTAG tap: stm32f4x.bs tap/device found: 0x06413041 (mfg: 0x020, part: 0x6413, ver: 0x0)
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000224 msp: 0x20020000
> flash write_image erase miniblink.elf
auto erase enabled
device id = 0x10016413
flash size = 1024kbytes
wrote 16384 bytes from file miniblink.elf in 2.079852s (7.693 KiB/s)
> reset
JTAG tap: stm32f4x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
JTAG tap: stm32f4x.bs tap/device found: 0x06413041 (mfg: 0x020, part: 0x6413, ver: 0x0)
> exit
Connection closed by foreign host.
tkoskine@ubuntu:~/arm/libopencm3-examples$