Quick explorations of different ways to bootstrap a GNU C (or rust) application on a cortex-M based MCU.
While the concepts apply broadly, these examples run on an Arduino M0 Pro (they should work fine on an Arduino Zero as well).
I chose the M0 Pro because:
- It was available at my local electronics shop
- It comes with an integrated SWD debugger (Atmel EDBG)
- It sports a cortex-M mcu (cortex-M0+)
- It is reasonably cheap ($40)
An STM32-based Nucleo or an mbed board would do just as well.
In my experience, many of the techniques highlighted here are often glossed over, poorly documented, and rarely understood. Most people rely on startup files and linker scripts bundled with their vendor's BSP that they tweak haphazardly as their needs evolve.
The following scenarios are currently covered:
default
: simple LED blink using the default startup file & linker script from the BSPminimal
: a bare minimum LED blink app with a pared down script, startup, and no libcwith-libc
: builds onminimal
to add newlib support, including printfreloc
: builds onwith-libc
to add functions relocated to RAM as well as ROMbootload
: splits the code into two applications, a bootloader and an application. The bootloader simply starts the applicationsbootload-reloc
: builds onbootload
but runs the applications entirely in RAM. The bootloader thus needs to copy it over first.rust
: barebones rust app
More to come, and blog posts will follow.
- A unix-like environment
- A version of openOCD that works with your board (in my case I used the Arduino fork).
- GNU Make
- GNU ARM embedded toolchain
make
builds all apps, the resulting elfs and bins are in their respective folders under
build
make <app-name>
builds a specific app. E.g. make bootload-reloc
make flash-<app-name>
flashes a specific app (it needs to have been built
first)
- https://github.com/cbiffle/minimal-embedded-rust/ - A minimal embedded rust app on cortex-M MCU by @cbiffle