MEMORY
{
flash (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000 /* 256k */
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x8000 /* 32k */
}
__top_flash = ORIGIN(flash) + LENGTH(flash);
__top_ram = ORIGIN(ram) + LENGTH(ram);
ENTRY(irq_handler_reset)
SECTIONS
{
.text : ALIGN(4)
{
FILL(0xff)
KEEP(*(.vectors))
*(.text)
*(.rodata)
. = ALIGN(4);
} > flash
. = ALIGN(4);
_etext = .;
.data : ALIGN(4)
{
FILL(0xff)
_data = .;
*(.data)
. = ALIGN(4);
_edata = .;
} > ram AT > flash
.bss : ALIGN(4)
{
_bss = .;
*(.bss)
. = ALIGN(4);
_ebss = .;
PROVIDE(_end = .);
} > ram
PROVIDE(_stack_top = __top_ram - 0);
}
#define SCB_BASE 0xE000ED00
#define SCB_OFFSET(o) (*(volatile uint32_t *)(SCB_BASE+o))
#define SCB_VTOR SCB_OFFSET(0x08)
...
void (* const vectors[])(void) =
{
&_stack_top, // 0 - Initial Stack Pointer Value
// Cortex-M0+ handlers
irq_handler_reset, // 1 - Reset
irq_handler_nmi, // 2 - NMI
irq_handler_hard_fault, // 3 - Hard Fault
...
};
void irq_handler_reset(void)
{
unsigned int *src, *dst;
src = &_etext;
dst = &_data;
while (dst < &_edata)
*dst++ = *src++;
dst = &_bss;
while (dst < &_ebss)
*dst++ = 0;
SCB_VTOR = (uint32_t)vectors;
main();
while (1);
}
...