The STM32L476 Discovery board has an LSM303 Accelerometer/Compass IC and an L3GD20 gyroscope attached to the MCU using an SPI bus and some chip select lines. I wanted to experiment with them with a view to putting together a balancing robot. Supporting code for the following was needed for this:
- an SPI interface
- the LSM303
- the L3GD20
- serial communications
- periodic interrupts to pace data capture
Rather than build a complex Makefile I went with a simple shell script (or batch file if you prefer) with the following commands:
arm-none-eabi-gcc -static -mthumb -g -mcpu=cortex-m4 *.c -T linker_script.ld -o main.elf -nostartfiles
arm-none-eabi-objcopy -g -O binary main.elf main.bin
Note: your PATH environment variable must include the directory where arm-none-eabi-gcc is located.
The resulting main.bin file can then be copied to the virtual disk presented by the mbed interface on the STM32L476 discovery board. (The program waits for you to press the centre joystick button before starting).`
Serial communications is carried out over the built-in ST-Link USB-Serial emulator so no additional hardware is needed (9600,n,8,1).
Code is available over here