Published on

ARM Toolchain for STM32-F3 Discovery on Fedora

Authors

Basic steps :

  • Install stlink, so that linux recognizes the STM32 card over USB

  • Install OpenOCD, which provides a 'virtual JTAG' debugging environment

  • Redherring : CodeSourcery
  • Install ARM gnu tools 'gcc-arm-embedded'

  • Download the STM32-F3 supplier code (includes the demo .hex file, for instance)

  • Get the STM32-F3-Discovery template

  • Make the template's simple blinking LED demo work

  • Reflash the initial demo using stlink

  • Off to do our own projects...

Have a look at the stlink github site. It's confirmed to work (by me) :

git clone git://github.com/texane/stlink.git
cd stlink
./autogen.sh
./configure
# Tells us to install libusb1
su -c "yum install libusb1-devel"
./configure
make
su -c "make install"
su -c "cp 49-stlinkv2.rules /etc/udev/rules.d/"
#either reboot or execute
su -c "udevadm control --reload-rules"

# Not plugged in, the following gives no output :
ls -l /dev/stlink*

# When plugged in, gives following output :
# "lrwxrwxrwx. 1 root root 15 Mar 17 04:06 /dev/stlinkv2_1 -> bus/usb/003/004"

# All done setting up stlink
cd ..

Install OpenOCD

Have a look at the SourceForge site for the OpenOCD project. Then install it :

git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
cd openocd
su -c "yum install libtool texinfo"
./bootstrap
# Wait a while for sub-projects to git clone themselves
./configure --prefix=/usr --enable-maintainer-mode --enable-stlink
make
su -c "make install"

# All done setting up openocd
cd ..

NB : the following should show the config file we're interested in using :

ls -l /usr/share/openocd/scripts/board/stm32f3discovery.cfg

CodeSourcery (A bit of a red herring)

CodeSourcery seems to be the toolchain that's easiest to set up. However, the email sign-up thing is a bit grating, and at the end of the day, I decided to ditch their binaries, and go for the something closer to the metal. The following looks like it would work...

# Sign up for CodeSourcery LITE
#wget https://sourcery.mentor.com/GNUToolchain/package10928/public/arm-none-eabi/arm-2012.09-63-arm-none-eabi.bin
# Actually, this is probably a red herring : Let's go for more genuine OSS
#rm arm-2012.09-63-arm-none-eabi.bin
# Finished with CodeSourcery

Get the 'Official' ARM gnu gcc toolchain

Goto : the ARM gcc-arm-embedded site to download the Linux installation tarball on the RHS :

mv ~/Downloads/gcc-arm-none-eabi-4_7-2012q4-20121208-linux.tar.bz2 .
bunzip2 gcc-arm-none-eabi-4_7-2012q4-20121208-linux.tar.bz2
tar -xf gcc-arm-none-eabi-4_7-2012q4-20121208-linux.tar
rm gcc-arm-none-eabi-4_7-2012q4-20121208-linux.tar
cd gcc-arm-none-eabi-4_7-2012q4

Add the binaries into your PATH (NB: this apparently needs to be an absolute path, and yours will differ):

pwd
# : /home/andrewsm/sketchpad/teensized/STM32-F3-Discovery/gcc-arm-none-eabi-4_7-2012q4
PATH="/home/andrewsm/sketchpad/teensized/STM32-F3-Discovery/gcc-arm-none-eabi-4_7-2012q4/bin:$PATH"`

Finish up :

# All done setting up(!) the arm-none-eabi toolchain
cd ..

STM dev kit download (for examples)

Visit : the STM download site, and download the zip file :

mv ~/Downloads/stm32f3discovery_fw.zip .
unzip stm32f3discovery_fw.zip
cd STM32F3-Discovery_FW_V1.1.0/
# Sample code in ./Projects

# Original demo code in :
# STM32F3-Discovery_FW_V1.1.0/Project/Demonstration/Binary/STM32F3_Discovery_Demo_V1.1.0.hex

cd ..
rm stm32f3discovery_fw.zip

Get the STM32-F3-Discovery template

Oh, I didn't yet mention that a lot of the magic is done here. But just getting to this stage was pretty involved, so I thought I'd write it all out long-hand.

Anyway, without further ado, here's the magic sauce (not created by me) :

git clone git://github.com/mblythe86/stm32f3-discovery-basic-template.git
cd stm32f3-discovery-basic-template

# make the sample project
make

# Check that the .elf contains something reasonable...
arm-none-eabi-objdump -d main.elf

# Change the makefile to enable OpenOCD to find our board
#OPENOCD_BOARD_DIR=/home/andrewsm/sketchpad/teensized/STM32-F3-Discovery/openocd/tcl/board

# Recompile and Upload to the board
make program

# Done with ensuring that STM32 project template works
cd ..

The .hex file for the original demo code for the STM32F3 is in :

STM32F3-Discovery_FW_V1.1.0/Project/Demonstration/Binary/STM32F3_Discovery_Demo_V1.1.0.hex

Let's reflash that back onto the board to prove that nothing irreversible has happened :

openocd \
 -f /home/andrewsm/sketchpad/teensized/STM32-F3-Discovery/openocd/tcl/board/stm32f3discovery.cfg \
 -f ./stm32f3-discovery-basic-template/extra/stm32f3-openocd.cfg \
 -c "reset halt" \
 -c "flash write_image erase ./STM32F3-Discovery_FW_V1.1.0/Project/Demonstration/Binary/STM32F3_Discovery_Demo_V1.1.0.hex" \
 -c "shutdown"

Now let's move fowards with our own sample project

cp -R stm32f3-discovery-basic-template project-test
cd project-test
# ...