diff --git a/Makefile b/Makefile index ca7078953..273b62408 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,19 @@ CFLAGS=-march=armv7e-m -mcpu=cortex-m4 -mthumb -std=c99 -g -Iarch/stm32f429 CC=clang CFLAGS=-target thumbv7em-unknown-eabi -mcpu=cortex-m4 -Iarch/stm32f429 -Wall -objs := boot/crt0.o src/blinky.o arch/stm32f429/registers/rcc.o arch/stm32f429/registers/gpio.o +objs := boot/crt0.o arch/stm32f429/registers/rcc.o arch/stm32f429/registers/gpio.o + +default: boot.elf run: boot.elf $(GDB) -x gdb_script.gdb boot.elf +test: test.elf + $(GDB) -x test/gdb_script.gdb test.elf + +test.elf: $(objs) test/runner.o + @$(LD) -T boot/stm32f429_flash.ld $(objs) test/runner.o -o $@ + boot.hex: boot.elf @echo "OBJCOPY $@" @$(OBJCOPY) -O ihex boot.elf boot.hex @@ -20,9 +28,9 @@ boot.bin: boot.elf @echo "OBJCOPY $@" @$(OBJCOPY) -O binary boot.elf boot.bin -boot.elf: $(objs) +boot.elf: $(objs) src/blinky.o @echo "LD $@" - @$(LD) -T boot/stm32f429_flash.ld $(objs) -o $@ + @$(LD) -T boot/stm32f429_flash.ld $(objs) src/blinky.o -o $@ %.o: %.c @echo "CC $@" diff --git a/test/gdb_script.gdb b/test/gdb_script.gdb new file mode 100644 index 000000000..7079d9d25 --- /dev/null +++ b/test/gdb_script.gdb @@ -0,0 +1,14 @@ +# Let's connect to OpenOCD +target remote localhost:3333 + +# Load our executable +load test.elf + +# Tell OpenOCD to reset and halt +monitor reset halt + +# Add a breakpoint +break debugger + +# Launch the test suite +continue diff --git a/test/runner.c b/test/runner.c new file mode 100644 index 000000000..55f6d7306 --- /dev/null +++ b/test/runner.c @@ -0,0 +1,46 @@ +#include + +void assert(int condition); + +void low_level_sleep(int iterations) { + for (int i=0;iGPIOGEN = 1; + if (success) { + GPIO_MODER(GPIOG)->MODER13 = GPIO_MODE_OUTPUT; + for (int i=0;i<5; i++) { + GPIO_ODR(GPIOG)->ODR13 = 0; + low_level_sleep(50000); + GPIO_ODR(GPIOG)->ODR13 = 1; + low_level_sleep(50000); + } + } else { + GPIO_MODER(GPIOG)->MODER14 = GPIO_MODE_OUTPUT; + for (int i=0;i<5; i++) { + GPIO_ODR(GPIOG)->ODR14 = 0; + low_level_sleep(50000); + GPIO_ODR(GPIOG)->ODR14 = 1; + low_level_sleep(50000); + } + } + debugger(); +} + +void assert(int condition) { + if (!condition) { + halt(0); + } +} + +int main(int argc, char * argv[]) { + // Run assertions + halt(1); +}