OpenSourceCortexM DevAndDebugging
OpenSourceCortexM DevAndDebugging
Development and
Debugging
May 20, 2015
Gareth McMullin
Overview
● Introduction to open-source bare-metal ARM stack
● Highlight differences between Unix and embedded
● Introduction to remote debugging with GDB
● Demonstrate complete workflow with an example using
Newlib’s <stdio.h>
● Some simple techniques for reducing binary size
*.c
gcc-arm-embedded
build
process
Makefile AS
● Your fav text editor
binutils
● make *.o
*.hex
Target Flash /
*.srec
RAM
*.bin
ARM Toolchain Links
● gcc-arm-embedded
https://launchpad.net/gcc-arm-embedded/
● libopencm3
https://github.com/libopencm3/libopencm3
● Black Magic Probe
https://github.com/blacksphere/blackmagic
Unix Demo Program Github: tree
/* demo.c */ # Makefile
#include <stdio.h> CFLAGS = -Wall -Wextra -g3 -O0 -MD
+CROSS_COMPILE = arm-none-eabi-
+CC = $(CROSS_COMPILE)gcc
+CPUFLAGS = -mcpu=cortex-m3 -mthumb
-CFLAGS = -Wall -Wextra -g3 -O0 -MD
+CFLAGS = -Wall -Wextra -g3 -O0 -MD $(CPUFLAGS)
+LDFLAGS = $(CPUFLAGS)
+LDLIBS = -lc -lnosys
%.hex: %.elf
$(OBJCOPY) -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -O srec $< $@
What’s still missing?
We have a binary using ARM instructions, but no OS loader:
+.PHONY: libopencm3
+libopencm3:
+ if [ ! -f libopencm3/Makefile ]; then \
+ git submodule init; \
+ git submodule update; \
+ fi
+ $(MAKE) -C libopencm3 lib/stm32/f1
+
.PHONY: clean
clean:
+ -$(MAKE) -C libopencm3 clean
/* lisa-m.ld - Linker script for Lisa-M -CFLAGS = -Wall -Wextra -g3 -O0 -MD $(CPUFLAGS)
*/
+CFLAGS = -Wall -Wextra -g3 -O0 -MD $(CPUFLAGS) \
LEDS:
Power UART
Error indicator 3.3V CMOS
Debug state
UART TX/RX
Note: Semihosting calls use BKPT instructions for communication with the
debugger. If no debugger is connected these will trigger faults.
STM32 USART with libopencm3 Github: tree / diff
int _read(int file, char *ptr, int len) int _write(int file, const char *ptr, int len)
{ {
int i; int i;
After:
$ arm-none-eabi-size demo.elf
text data bss dec hex filename
8820 116 16 8952 22f8 demo.elf
More examples
● libopencm3 Examples repository:
https://github.com/libopencm3/libopencm3-examples.git