Running ARM samples on the STM32F4-Discovery

Now that we have an original flash image that we know how to restore, it is time to start building and running our own software on the board.

When it comes to the toolchain, I started with the version provided by Manjaro, but I ran into an issue related to Newlib-Nano, which is the C library that is supposed to be used with that toolchain. After a few other tries, I was finally successful with the toolchain provided by ARM and located at GNU Tools for ARM Embedded Processors, that the arch/Manjaro packages are built on anyway. As mentioned in a previous post, the installation is not more intrusive than unpacking a compressed folder and pointing to it in my PATH.
Led by The Definitive Guide to ARM® Cortex®-M4…, who recommended the use of linker scripts provided by ARM in their toolchain samples, I decided to start by building and running the actual samples.
To start with, I reuse the exact code structure provided by ARM in their samples. My purpose was to be able to just run make after as few adaptations as possible. The structure is the following:

The dump directory is mine. The rest is a copy/paste of the contents of ARM’s sample folder.
Under ldscripts, I have modified the contents of the mem.ld file to match my board:

Since gcc.ld (used in most samples) and nokeep.ld had the same rows, I replaced the redundancy by some INCLUDE commands:

The default processor in the samples being a Cortex-M0, I also change the processor to a Cortex-M4:
[nilo@floor arm-none-eabi]$ head src/makefile.conf

And then, under the src directory, I just ran make. :-)
Here for the short version:

The simplest of these examples being minimum, that is the one I decided to test.

Under openocd telnet:

The PC and the MSP match the disassembled image:

Now debugging in gdb (openocd still started, telnet closed, gdb connected instead):

One thought on “Running ARM samples on the STM32F4-Discovery

  1. I appreciate, cause I discovered just what I used to be looking for. You have ended my four day long hunt! God Bless you man. Have a nice day. Bye kefeffedkacb

Leave a Reply

Your email address will not be published. Required fields are marked *