STM32F4 Discovery Board with Linux

STM32F4-Discovery in original packagingThe STM32F4-Discovery board is a great little board that ST Micro is literally giving away.  It features a Cortex-M4 MCU, with: a 3-axis accelerometer, omni-directional digital microphone, audio DAC with integrated class D speaker driver, and all 100 pins broken out to headers.

You can get a Linux or Mac OS X toolchain up and running quickly with eden’s summon-arm-toolchain.

Best of all, thanks to texane, you can write to this board from Linux or Mac OS X using stlink.

Initially I had trouble compiling the stlink source on Ubuntu, I ended up  placing -lusb-1.0 as the last of the linker options.  I have forked texane’s project on github https://github.com/csamuelson/stlink if you need the fix to compile.  I also submitted a pull request to texane for the change, and I will update this post if/when the Makefiles are updated. This has been fixed in github.com/texane/stlink.

Here is a quick rundown of what you’ll need to do to get up and running quickly on Oneiric Ocelot:
[code]
$ sudo apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev
libmpc-dev autoconf texinfo build-essential libftdi-dev
$ git clone https://github.com/esden/summon-arm-toolchain.git
$ cd summon-arm-toolchain
$ sudo ./summon-arm-toolchain
$ cd ..
$ sudo apt-get install libsgutils2-dev libusb-1.0-dev
$ git clone https://github.com/texane/stlink.git
$ cd stlink
$ make
[/code]

Then, try out one of the examples, in one terminal start the connection to the board…

[code]
$ cd stlink/
$ sudo ./gdbserver/st-util fu bar
[/code]

In another terminal, start by compiling the example…

[code]
$ EXPORT PATH=~/sat/bin:$PATH
$ cd stlink/examples/blink
$ make CONFIG_STM32F4_DISCOVERY=1
[/code]

Then connect to the debugger and try it out…

[code]
$ arm-none-eabi-gdb
(gdb) target extended localhost:4242
(gdb) load blink.elf
(gdb) continue
[/code]

39 thoughts on “STM32F4 Discovery Board with Linux”

    1. I am enjoying the dev board. The onboard accessories are great, if you haven’t gotten the board yet, I would recommend it highly.

      This board is a great introduction to ARM processors and the STM32 line in particular.

  1. Thanks for the post! The UPS guy just dropped off my board about an hour ago. It was nice to have it blinking within 30 minutes.

  2. Hi,
    Thanks for the great tips for using this in Linux.

    Have you figured out how to build code using the floating point capabilities of the F4? If I don’t delete the -nostdinc in the Makefile, I can’t #include . If I don’t delete the -nostdlib, I can’t link with -lm, but if I delete -nostdlib, I get complaints about undefined references to main and _exit.

    I’m also not sure the summon-arm-toolchain works with hardware fpu. Do you know anything about that?

    Thanks,

    Rob

  3. Me again. Got my board and build a toolchain from scratch on OSX Lion (instructions will be posted on my site soon), however stlink does not seem to work. I get lots of this when running load in gdb

    *** stlink_read_mem32 ***
    data_len = 4 0x4
    c0 00 00 11

    It appears stlink does not support this board yet.
    https://github.com/texane/stlink/issues/12

    How did you get yours working?

  4. I was able to do all the steps except the actual debugging. When I load the elf file into debugger and do refresh, I don’t see the sources. When I continue, it working (at least I see the led blinking). However when I break it I get this:
    0x08000100 in ?? ()
    (gdb)

    Note that I build blink with debug on and optimization off.

  5. There have been several fixes to texane/stlink which fix writing to flash. I propose you update the description.

    I also recommend to take a look at ChibiOS which is already including preliminary STM32F4 support.

  6. I think a few things have changed since you wrote this up:

    1) ‘git’ is not installed on Oneric by default.
    2) You need to do a ‘sudo apt-get build-dep gcc-4.5’.
    3) You then eed to do a ‘sudo apt-get install libftdi-dev’
    4) ‘libusb-1.0-dev’ should instead be ‘libusb-1.0-0-dev’
    5) The ‘EXPORT’ command should be in lower case.
    6) The command ‘load blink.elf’ should be ‘load blink_F4.elf’

    This made it work on a plain vanilla install for me (I try to build my development tools in clean VM’s to keep them all separate).

  7. There has been a change in the naming of the files. For example instead of arm-none-gnueabi-gcc we have arm-none-linux-gnueabi-gcc. The same goes for all others (gdb etc.). It’s a pain in the butt and I really can’t understand why would someone do something like this. All scripts that involve these commands should be altered. For how long will they be working properly is just a matter of time before names get changed…again. 😀 I’m still trying to fix other things like the error “cannot find -lstm32_stdperiph_l1xx”. I’m using STM32L-Discovery btw. but I used accordingly the examples from /stlink/example/32l_lcd. I also have Sourcery G++ CodeBench Lite installed. I have the required libs in there but it seems they can’t be found by the compiler. Any help would be appreciated! Great tutorial btw. Helped a lot so far. It’s really sad that no decent official documentation is available by the venodors (ST etc.). All they do is give you links to various commercial products. It’s a fact though that under Windows with Keil I had my board running (flashing + debugging) in no time. Still it’ll be nice if those fatties pay more attention to the Linux world. :-/

  8. configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
    Try the –with-gmp, –with-mpfr and/or –with-mpc options to specify
    their locations. Source code for these libraries can be found at
    their respective hosting sites as well as at
    ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
    http://gcc.gnu.org/install/prerequisites.html for additional info. If
    you obtained GMP, MPFR and/or MPC from a vendor distribution package,
    make sure that you have installed both the libraries and the header
    files. They may be located in separate packages.

    1. I’m trying to install on Linux Mint release 10.

      If it’s complaining about mpc, as it did for me, install libmpc-dev.

      For me it also complained about some compression library, just install the dev package.

      libftdi-dev is also required.

      Now it’s installed. Let’s hope it will work as well.

  9. Hi guys,

    I followed the steps above and I installed all the utilities: gdb, stlink.. etc.. but when I’m trying to compile the example blink (make CONFIG_STM32F4_DISCOVERY=1), the following error occurs:
    make: arm-none-eabi-gcc: Command not found
    make: *** [blink_32VL.elf] Error 127
    Where is the issue?? Knowing that I have followed aal the steps above!
    Thanks in advance

  10. The compiler is not found by the system.
    Are your tools located at ~/sat/bin ?

    $ export PATH=~/sat/bin:$PATH

    Otherwise you will have to modify the above command.

  11. Hi, I have tried the toolchain on both Ubuntu 11.10 and 12.04, and you should do some extra steps:
    sudo apt-get install zlib1g-dev
    Also, you have to get libmpc from http://www.multiprecision.org/index.php?prog=mpc&page=download
    libgmp from here http://gmplib.org/
    and libmpfr from here
    http://www.mpfr.org/
    You have to unpack them and remove the numbers in the folder names and also you have to copy them into gcc_linaro folder, after you have extracted it and then comment the line with extraction from script.

  12. Great post. After struggling with other guides, this is the first time I see some life in my STM32F4DISCOVERY board.

    It would be great to make another post on how to use the peripheral libraries.

    I tried to do it, the compiler works, but the linker throws an “undefined” error.

    Cheers!

  13. Hi,

    I am a beginner at Linux.
    when I do third step-$ cd summon-arm-toolchain, “bash: cd: summon-arm-toolchain: No such file or directory” is shown in the screen.

    Thanks,

  14. I also needed zlibc, libmpc-dev and libgmp-dev.

    libusb-1.0-dev has been moved to libusb-1.0-0-dev and st-link can be build by using ./autogen.sh&&./configure&&make.

  15. Hey,

    I am very new to embedded system and my first task assigned is to install freertos on STM32F4-Discovery board. Its been more than a month i m trying and i just end not installing. I need some help,
    Can somebody give me set of instructions which i can execute and install FreeRTOS on the board. Please do help, i really want to start programming on this board.

  16. Hey,

    I am using a linux system (linux mint) and this is the first time i am working with embedded system. My first task is to install FreeRTOS on STM32F4-Discovery board. I don’t have any idea how to do this. Can somebody tell me, which softwares to install first and then give me instructions to install the os on the board? Please do reply i really need to finish this task and continue with other tasks. it will be great to get help and move a head as i am stuck from past 1 month and don’t know how to proceed and install.

Leave a Reply