Building an ARM toolchain
To compile code for the STM32F4DISCOVERY you’ll need an ARM toolchain that supports the Cortex-M3. I used the build script
summon-arm-toolchain to build one. Before running the script you need to install several dependencies:
su -c "apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential libftdi-dev"
You might also need to run:
su -c "apt-get build-dep gcc-4.5"
Now make a directory to hold the files you’ll need to work with the STM32F4DISCOVERY:
Next clone the
summon-arm-toolchain, read the README, and begin the build:
git clone https://github.com/esden/summon-arm-toolchain.git
Setting up the software to communicate with the STLINK
While the toolchain is compiling you can set up the software required to communicate with the STLINK, which is the on-board JTAG programmer/debugger on the lefthand side of the board. From a new shell run:
su -c "apt-get install libusb-1.0-0-dev"
git clone git://github.com/texane/stlink.git stlink_texane
Now you should install the udev rules
49-stm32l-discovery.rules and restart udev. These steps will create a symbolic link called /dev/stm32l_stlinkN and give a normal user permission to access it.
cp 49-stm32l-discovery.rules /etc/udev/rules.d/
Example projects and makefiles
Next, download the STM32F4DISCOVERY firmware package and an archive of makefiles for building some of the example projects found in the firmware package.
cp Makefile.IO_Toggle ~/stm32f4discovery_root/STM32F4-Discovery_FW_V1.1.0/Project/Peripheral_Examples/IO_Toggle/
If the toolchain installation still hasn’t finished, then familiarize yourself with the example code and makefiles or take a break.
Compiling and Flashing
summon-arm-toolchain has finished building your ARM toolchain you can try it out on the IO_Toggle example by using the following commands.
make -f Makefile.IO_Toggle
If the build finished without error, then you’re ready to try downloading it to the board. Plug in the board and use stlink to write the blinking LED example, IO_Toggle.bin, to the STM32F4DISCOVERY’s flash memory.
flash write IO_Toggle.bin 0x8000000
Power cycle the board by removing then reinserting the USB plug. If the download was successful, the LEDs should light up in a clockwise pattern and pressing the pushbutton will not result in the board entering test mode.
You can easily modify one of the sample makefiles to work with another example by examining the .uvproj file (found in the example’s MDK-ARM directory) to determine which defines (-D), includes (-I), source files, etc. to add to the new makefile. Just open the .uvproj file in a text editor and look for lines like these:
There is a lot I don’t understand about compiling for the STM32F4DISCOVERY and I’m certain that the Makefiles I’ve provided could be improved. For example, I don’t know which
-m options (see the Makefile’s
MCUFLAGS variable) to set, when to set them, and why. If you have any corrections or improvements to share, please leave a comment.
The STM32F4 high-performance discovery board (STM32F4DISCOVERY) and a range of of STMicroelectronics products are available at Newark
Alternate method of programming the STM32F4DISCOVERY using the Bus Blaster and OpenOCD
A fork of the summon-arm-toolchain that builds gcc for the Cortex-M4F
A comment discussing this fork