add: test programm and linker script

Signed-off-by: Nicolas Robert <nicolas.robert@epita.fr>
This commit is contained in:
Nicolas Robert 2021-09-16 03:42:59 +02:00
parent d966107648
commit 3b87f1c39e
3 changed files with 222 additions and 0 deletions

29
test/Makefile Normal file

@ -0,0 +1,29 @@
CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
LDS=test.lds
OPTI=-O0
CFLAGS= $(OPTI) -g -gdwarf-2 -mthumb -fno-builtin -mcpu=cortex-m4 -Wall -std=c99 -ffunction-sections -fdata-sections -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -fverbose-asm
LDFLAGS=-nostartfiles -Wl,-gc-sections -T$(LDS) -L. --specs=nano.specs
all: test.bin
test.o: test.c
$(CC) $(CFLAGS) -c test.o test.c
test.elf: test.o test.lds
$(CC) $(LDFLAGS) test.o -o test.elf
test.bin: test.elf
$(OBJCOPY) -O binary -S test.elf test.bin
debug: test.bin
st-flash write test.bin 0x8000000
st-util
run: test.bin
st-flash write test.bin 0x8000000
clean:
$(RM) test.o test.elf test.bin

144
test/test.c Normal file

@ -0,0 +1,144 @@
#include <stdint.h>
int default_handler(void)
{
while(1);
return 0;
}
int reset_handler(void)
{
while(1);
return 0;
}
uint32_t vector_table[128] __attribute__((section(".isr_vector"))) = {
(uint32_t) default_handler,
(uint32_t) reset_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler,
(uint32_t) default_handler
};

49
test/test.lds Normal file

@ -0,0 +1,49 @@
MEMORY
{
FLASH (rx): ORIGIN = 0x8000000, LENGTH = 512K
RAM (rwx): ORIGIN = 0x20000000, LENGTH = 96K
}
ENTRY(reset_handler)
SECTIONS
{
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector))
. = ORIGIN(FLASH) + 512;
} > FLASH
.text :
{
*(.text)
. = ALIGN(4);
_etext = .;
} > FLASH
.data :
{
_sdata = .;
*(.data*)
_edata = .;
. = ALIGN(4);
} > RAM AT>FLASH
.bss :
{
__bss_start__ = .;
*(.bss)
__bss_end__ = .;
} > RAM
/DISCARD/ :
{
*(.ARM.exidx*)
}
PROVIDE(_heap = __bss_end__);
PROVIDE(_heap_end = _stack - _stack_size);
PROVIDE(_stack_size = 1024);
PROVIDE(_stack = ORIGIN(RAM) + LENGTH(RAM));
}