Baremetal programming of the STM32L476 from ST Microelectronics
The STM32L476 Nucleo board is an mbed enabled development kit featuring the STM32L476 MCU. This is a Cortex L4
device. I like to program from the command line with all code contained in a single directory. This board works
with the latest version ( > 0.10 ) of OpenOCD which you need to download and compile if you want to make use of
the full debugging facilities. However, if you just want to download programs and try things out you can make use
of the MBED interface on the board. This is easy to use: you just copy the program to the virtual disk that the
board presents to your computer.
Blinky. Code for blinky.
To compile you do this:
arm-none-eabi-gcc -g -static -mthumb -mcpu=cortex-m4 main.c init.c -T linker_script.ld -o main.elf -nostartfiles
This creates a file called main.elf. This is not yet ready for copying to the discovery board. You need to convert it to a raw
binary first as follows:
arm-none-eabi-objcopy -O binary main.elf main.bin
That's it. Copy main.bin to virutal disk and the LED's on your board should blink.
Serial communicationsCode for serial communications example
This examples makes use of the built-in USB/Serial emulator in the ST-Link interface on the board. You will need a
dumb terminal application on your development PC. The communications settings are 9600,n,8,1. The example
prompts you to enter some (followed by the 'enter' key) which is then echoed back to you.
Using the 9 Degrees of Freedom sensorsDownload the code
This example includes code to read the accelerometer, compass and gyroscope on the Discovery board.
It sends the data over the serial link (built in to the ST-Link interface) to the host pc. The program
also makes use of the SysTick interrupt to ensure regular pacing of the data acquisition. Additionally,
the program also switches the MCU up to its full 80MHz at run time. To build the example on Windows
type build.bat (check the path statement at the beginning of this file to ensure it suits your setup).
To build on Linux type ./build.sh (again verify your PATH environment variable includes an entry for
your compiler directory). To download the program to the MCU simply copy main.bin to the virtual
disk presented by the Discovery board. The program waits for you to press the centre joystick button
before it starts sending.
Back to my ARM project page