From a69d83d312396ee604426dce5341a54316c7c9b5 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 3 Oct 2012 18:15:20 +0200 Subject: unified vector table initialization the cortex generic interrupts get moved to lib/cm3/vector.c, the platorms' individual irq names, initialization and handler prototypes go to platoform specific irq.h files. as the vector.c file heavily depends on platoform specific headers, it can't be built once-and-for-all in lib/cm3/, so there are inclusion stubs in the various architecture dirs; this might be better solved with Makefile / include path handling. one particular file is lib/lpc43xx/vector.c; that platform's initialization code contains an additional section to copy everything from flash to ram (which probably performs better there). that code still resides in the inclusion stub, and gets mashed in using defines. would need a cleaner implementation together with the Makefile solution. this commit contains some files of the upcoming efm32 branch, from which it was cherry-picked. the .bin files produced from before and after this commit only differ in lpc43xx, where the startup sequence was subtly modified. --- lib/lpc43xx/vector.c | 224 ++------------------------------------------------- 1 file changed, 7 insertions(+), 217 deletions(-) (limited to 'lib/lpc43xx/vector.c') diff --git a/lib/lpc43xx/vector.c b/lib/lpc43xx/vector.c index 23008bc..66e9b63 100644 --- a/lib/lpc43xx/vector.c +++ b/lib/lpc43xx/vector.c @@ -18,156 +18,20 @@ * along with this library. If not, see . */ -#define WEAK __attribute__ ((weak)) +#include +#define reset_handler original_reset_handler +#include "../cm3/vector.c" +#undef reset_handler +#include -/* Symbols exported by the linker script(s): */ -extern unsigned _data_loadaddr, _data, _edata, _ebss, _stack; extern unsigned _etext_ram, _text_ram, _etext_rom; -void main(void); -void reset_handler(void); -void blocking_handler(void); -void null_handler(void); - -void WEAK nmi_handler(void); -void WEAK hard_fault_handler(void); -void WEAK mem_manage_handler(void); -void WEAK bus_fault_handler(void); -void WEAK usage_fault_handler(void); -void WEAK sv_call_handler(void); -void WEAK debug_monitor_handler(void); -void WEAK pend_sv_handler(void); -void WEAK sys_tick_handler(void); -void WEAK dac_irqhandler(void); -void WEAK m0core_irqhandler(void); -void WEAK dma_irqhandler(void); -void WEAK ethernet_irqhandler(void); -void WEAK sdio_irqhandler(void); -void WEAK lcd_irqhandler(void); -void WEAK usb0_irqhandler(void); -void WEAK usb1_irqhandler(void); -void WEAK sct_irqhandler(void); -void WEAK ritimer_irqhandler(void); -void WEAK timer0_irqhandler(void); -void WEAK timer1_irqhandler(void); -void WEAK timer2_irqhandler(void); -void WEAK timer3_irqhandler(void); -void WEAK mcpwm_irqhandler(void); -void WEAK adc0_irqhandler(void); -void WEAK i2c0_irqhandler(void); -void WEAK i2c1_irqhandler(void); -void WEAK spi_irqhandler(void); -void WEAK adc1_irqhandler(void); -void WEAK ssp0_irqhandler(void); -void WEAK ssp1_irqhandler(void); -void WEAK usart0_irqhandler(void); -void WEAK uart1_irqhandler(void); -void WEAK usart2_irqhandler(void); -void WEAK usart3_irqhandler(void); -void WEAK i2s0_irqhandler(void); -void WEAK i2s1_irqhandler(void); -void WEAK spifi_irqhandler(void); -void WEAK sgpio_irqhandler(void); -void WEAK pin_int0_irqhandler(void); -void WEAK pin_int1_irqhandler(void); -void WEAK pin_int2_irqhandler(void); -void WEAK pin_int3_irqhandler(void); -void WEAK pin_int4_irqhandler(void); -void WEAK pin_int5_irqhandler(void); -void WEAK pin_int6_irqhandler(void); -void WEAK pin_int7_irqhandler(void); -void WEAK gint0_irqhandler(void); -void WEAK gint1_irqhandler(void); -void WEAK eventrouter_irqhandler(void); -void WEAK c_can1_irqhandler(void); -void WEAK atimer_irqhandler(void); -void WEAK rtc_irqhandler(void); -void WEAK wwdt_irqhandler(void); -void WEAK c_can0_irqhandler(void); -void WEAK qei_irqhandler(void); - -__attribute__ ((section(".vectors"))) -void (*const vector_table[]) (void) = { - /* Cortex-M4 interrupts */ - (void*)&_stack, - reset_handler, - nmi_handler, - hard_fault_handler, - mem_manage_handler, - bus_fault_handler, - usage_fault_handler, - 0, 0, 0, 0, /* reserved */ - sv_call_handler, - debug_monitor_handler, - 0, /* reserved */ - pend_sv_handler, - sys_tick_handler, - - /* LPC43xx interrupts */ - dac_irqhandler, - m0core_irqhandler, - dma_irqhandler, - 0, /* reserved */ - 0, /* reserved */ - ethernet_irqhandler, - sdio_irqhandler, - lcd_irqhandler, - usb0_irqhandler, - usb1_irqhandler, - sct_irqhandler, - ritimer_irqhandler, - timer0_irqhandler, - timer1_irqhandler, - timer2_irqhandler, - timer3_irqhandler, - mcpwm_irqhandler, - adc0_irqhandler, - i2c0_irqhandler, - i2c1_irqhandler, - spi_irqhandler, - adc1_irqhandler, - ssp0_irqhandler, - ssp1_irqhandler, - usart0_irqhandler, - uart1_irqhandler, - usart2_irqhandler, - usart3_irqhandler, - i2s0_irqhandler, - i2s1_irqhandler, - spifi_irqhandler, - sgpio_irqhandler, - pin_int0_irqhandler, - pin_int1_irqhandler, - pin_int2_irqhandler, - pin_int3_irqhandler, - pin_int4_irqhandler, - pin_int5_irqhandler, - pin_int6_irqhandler, - pin_int7_irqhandler, - gint0_irqhandler, - gint1_irqhandler, - eventrouter_irqhandler, - c_can1_irqhandler, - 0, /* reserved */ - 0, /* reserved */ - atimer_irqhandler, - rtc_irqhandler, - 0, /* reserved */ - wwdt_irqhandler, - 0, /* reserved */ - c_can0_irqhandler, - qei_irqhandler, -}; - -#define MMIO32(addr) (*(volatile unsigned long*)(addr)) #define CREG_M4MEMMAP MMIO32( (0x40043000 + 0x100) ) -void reset_handler(void) +void WEAK reset_handler(void) { volatile unsigned *src, *dest; - __asm__("MSR msp, %0" : : "r"(&_stack)); - /* Copy the code from ROM to Real RAM (if enabled) */ if( (&_etext_ram-&_text_ram) > 0 ) { @@ -186,79 +50,5 @@ void reset_handler(void) /* Continue Execution in RAM */ } - for (src = &_data_loadaddr, dest = &_data; dest < &_edata; src++, dest++) - *dest = *src; - - while (dest < &_ebss) - *dest++ = 0; - - /* Call the application's entry point. */ - main(); + original_reset_handler(); } - -void blocking_handler(void) -{ - while (1) ; -} - -void null_handler(void) -{ - /* Do nothing. */ -} - -#pragma weak nmi_handler = null_handler -#pragma weak hard_fault_handler = blocking_handler -#pragma weak mem_manage_handler = blocking_handler -#pragma weak bus_fault_handler = blocking_handler -#pragma weak usage_fault_handler = blocking_handler -#pragma weak sv_call_handler = null_handler -#pragma weak debug_monitor_handler = null_handler -#pragma weak pend_sv_handler = null_handler -#pragma weak sys_tick_handler = null_handler -#pragma weak dac_irqhandler = null_handler -#pragma weak m0core_irqhandler = null_handler -#pragma weak dma_irqhandler = null_handler -#pragma weak ethernet_irqhandler = null_handler -#pragma weak sdio_irqhandler = null_handler -#pragma weak lcd_irqhandler = null_handler -#pragma weak usb0_irqhandler = null_handler -#pragma weak usb1_irqhandler = null_handler -#pragma weak sct_irqhandler = null_handler -#pragma weak ritimer_irqhandler = null_handler -#pragma weak timer0_irqhandler = null_handler -#pragma weak timer1_irqhandler = null_handler -#pragma weak timer2_irqhandler = null_handler -#pragma weak timer3_irqhandler = null_handler -#pragma weak mcpwm_irqhandler = null_handler -#pragma weak adc0_irqhandler = null_handler -#pragma weak i2c0_irqhandler = null_handler -#pragma weak i2c1_irqhandler = null_handler -#pragma weak spi_irqhandler = null_handler -#pragma weak adc1_irqhandler = null_handler -#pragma weak ssp0_irqhandler = null_handler -#pragma weak ssp1_irqhandler = null_handler -#pragma weak usart0_irqhandler = null_handler -#pragma weak uart1_irqhandler = null_handler -#pragma weak usart2_irqhandler = null_handler -#pragma weak usart3_irqhandler = null_handler -#pragma weak i2s0_irqhandler = null_handler -#pragma weak i2s1_irqhandler = null_handler -#pragma weak spifi_irqhandler = null_handler -#pragma weak sgpio_irqhandler = null_handler -#pragma weak pin_int0_irqhandler = null_handler -#pragma weak pin_int1_irqhandler = null_handler -#pragma weak pin_int2_irqhandler = null_handler -#pragma weak pin_int3_irqhandler = null_handler -#pragma weak pin_int4_irqhandler = null_handler -#pragma weak pin_int5_irqhandler = null_handler -#pragma weak pin_int6_irqhandler = null_handler -#pragma weak pin_int7_irqhandler = null_handler -#pragma weak gint0_irqhandler = null_handler -#pragma weak gint1_irqhandler = null_handler -#pragma weak eventrouter_irqhandler = null_handler -#pragma weak c_can1_irqhandler = null_handler -#pragma weak atimer_irqhandler = null_handler -#pragma weak rtc_irqhandler = null_handler -#pragma weak wwdt_irqhandler = null_handler -#pragma weak c_can0_irqhandler = null_handler -#pragma weak qei_irqhandler = null_handler -- cgit v1.2.3 From 5afa53f01abb3f19e1140d1a6407c43e8b3947cf Mon Sep 17 00:00:00 2001 From: chrysn Date: Thu, 18 Oct 2012 16:29:58 +0200 Subject: drop two-line vector.c dispatchers in favor of central dispatch --- lib/cm3/vector.c | 6 ++++++ lib/dispatch/vector.c | 11 +++++++++++ lib/efm32/tinygecko/vector.c | 2 -- lib/lm3s/vector.c | 2 -- lib/lpc17xx/vector.c | 2 -- lib/lpc43xx/vector.c | 8 +------- lib/stm32/f1/vector.c | 2 -- lib/stm32/f2/vector.c | 2 -- lib/stm32/f4/vector.c | 8 +------- 9 files changed, 19 insertions(+), 24 deletions(-) create mode 100644 lib/dispatch/vector.c delete mode 100644 lib/efm32/tinygecko/vector.c delete mode 100644 lib/lm3s/vector.c delete mode 100644 lib/lpc17xx/vector.c delete mode 100644 lib/stm32/f1/vector.c delete mode 100644 lib/stm32/f2/vector.c (limited to 'lib/lpc43xx/vector.c') diff --git a/lib/cm3/vector.c b/lib/cm3/vector.c index 200e8e5..7b660f9 100644 --- a/lib/cm3/vector.c +++ b/lib/cm3/vector.c @@ -20,6 +20,9 @@ #include +/* load optional platform dependent initialization routines */ +#include "../dispatch/vector.c" + #define WEAK __attribute__ ((weak)) /* Symbols exported by the linker script(s): */ @@ -70,6 +73,9 @@ void WEAK reset_handler(void) while (dest < &_ebss) *dest++ = 0; + /* might be provided by platform specific vector.c */ + pre_main(); + /* Call the application's entry point. */ main(); } diff --git a/lib/dispatch/vector.c b/lib/dispatch/vector.c new file mode 100644 index 0000000..baab436 --- /dev/null +++ b/lib/dispatch/vector.c @@ -0,0 +1,11 @@ +#if defined(STM32F4) +# include "../stm32/f4/vector.c" + +#elif defined(LPC43XX) +# include "../lpc43xx/vector.c" + +#else + +static void pre_main(void) {} + +#endif diff --git a/lib/efm32/tinygecko/vector.c b/lib/efm32/tinygecko/vector.c deleted file mode 100644 index d6da5a2..0000000 --- a/lib/efm32/tinygecko/vector.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../../cm3/vector.c" diff --git a/lib/lm3s/vector.c b/lib/lm3s/vector.c deleted file mode 100644 index e9e7e06..0000000 --- a/lib/lm3s/vector.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../cm3/vector.c" diff --git a/lib/lpc17xx/vector.c b/lib/lpc17xx/vector.c deleted file mode 100644 index 61342f4..0000000 --- a/lib/lpc17xx/vector.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../cm3/vector.c" diff --git a/lib/lpc43xx/vector.c b/lib/lpc43xx/vector.c index 66e9b63..0463a65 100644 --- a/lib/lpc43xx/vector.c +++ b/lib/lpc43xx/vector.c @@ -18,17 +18,13 @@ * along with this library. If not, see . */ -#include -#define reset_handler original_reset_handler -#include "../cm3/vector.c" -#undef reset_handler #include extern unsigned _etext_ram, _text_ram, _etext_rom; #define CREG_M4MEMMAP MMIO32( (0x40043000 + 0x100) ) -void WEAK reset_handler(void) +static void pre_main(void) { volatile unsigned *src, *dest; @@ -49,6 +45,4 @@ void WEAK reset_handler(void) /* Continue Execution in RAM */ } - - original_reset_handler(); } diff --git a/lib/stm32/f1/vector.c b/lib/stm32/f1/vector.c deleted file mode 100644 index 795773b..0000000 --- a/lib/stm32/f1/vector.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../../cm3/vector.c" diff --git a/lib/stm32/f2/vector.c b/lib/stm32/f2/vector.c deleted file mode 100644 index 24d1185..0000000 --- a/lib/stm32/f2/vector.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include "../../cm3/vector.c" diff --git a/lib/stm32/f4/vector.c b/lib/stm32/f4/vector.c index a5017b3..5304299 100644 --- a/lib/stm32/f4/vector.c +++ b/lib/stm32/f4/vector.c @@ -18,16 +18,10 @@ * along with this library. If not, see . */ -#include -#define reset_handler original_reset_handler -#include "../../cm3/vector.c" -#undef reset_handler #include -void WEAK reset_handler(void) +static void pre_main(void) { /* Enable access to Floating-Point coprocessor. */ SCB_CPACR |= SCB_CPACR_FULL * (SCB_CPACR_CP10 | SCB_CPACR_CP11); - - original_reset_handler(); } -- cgit v1.2.3 From 0548317683f2dacce4c895f2460c0f7762ee8b40 Mon Sep 17 00:00:00 2001 From: chrysn Date: Thu, 18 Oct 2012 18:54:52 +0200 Subject: fix bug resulting from equally named files the local vector.o files shadowed the ../cm3/vector.c from VPATH, resulting in empty reset vectors. --- lib/cm3/vector.c | 2 +- lib/dispatch/vector.c | 11 ---------- lib/dispatch/vector_chipset.c | 11 ++++++++++ lib/lpc43xx/vector.c | 48 ------------------------------------------- lib/lpc43xx/vector_chipset.c | 48 +++++++++++++++++++++++++++++++++++++++++++ lib/stm32/f4/vector.c | 27 ------------------------ lib/stm32/f4/vector_chipset.c | 27 ++++++++++++++++++++++++ 7 files changed, 87 insertions(+), 87 deletions(-) delete mode 100644 lib/dispatch/vector.c create mode 100644 lib/dispatch/vector_chipset.c delete mode 100644 lib/lpc43xx/vector.c create mode 100644 lib/lpc43xx/vector_chipset.c delete mode 100644 lib/stm32/f4/vector.c create mode 100644 lib/stm32/f4/vector_chipset.c (limited to 'lib/lpc43xx/vector.c') diff --git a/lib/cm3/vector.c b/lib/cm3/vector.c index a6d2e93..b049526 100644 --- a/lib/cm3/vector.c +++ b/lib/cm3/vector.c @@ -21,7 +21,7 @@ #include /* load optional platform dependent initialization routines */ -#include "../dispatch/vector.c" +#include "../dispatch/vector_chipset.c" /* load the weak symbols for IRQ_HANDLERS */ #include "../dispatch/vector_nvic.c" diff --git a/lib/dispatch/vector.c b/lib/dispatch/vector.c deleted file mode 100644 index baab436..0000000 --- a/lib/dispatch/vector.c +++ /dev/null @@ -1,11 +0,0 @@ -#if defined(STM32F4) -# include "../stm32/f4/vector.c" - -#elif defined(LPC43XX) -# include "../lpc43xx/vector.c" - -#else - -static void pre_main(void) {} - -#endif diff --git a/lib/dispatch/vector_chipset.c b/lib/dispatch/vector_chipset.c new file mode 100644 index 0000000..796276c --- /dev/null +++ b/lib/dispatch/vector_chipset.c @@ -0,0 +1,11 @@ +#if defined(STM32F4) +# include "../stm32/f4/vector_chipset.c" + +#elif defined(LPC43XX) +# include "../lpc43xx/vector_chipset.c" + +#else + +static void pre_main(void) {} + +#endif diff --git a/lib/lpc43xx/vector.c b/lib/lpc43xx/vector.c deleted file mode 100644 index 0463a65..0000000 --- a/lib/lpc43xx/vector.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2010 Piotr Esden-Tempski - * Copyright (C) 2012 Michael Ossmann - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include - -extern unsigned _etext_ram, _text_ram, _etext_rom; - -#define CREG_M4MEMMAP MMIO32( (0x40043000 + 0x100) ) - -static void pre_main(void) -{ - volatile unsigned *src, *dest; - - /* Copy the code from ROM to Real RAM (if enabled) */ - if( (&_etext_ram-&_text_ram) > 0 ) - { - src = &_etext_rom-(&_etext_ram-&_text_ram); - /* Change Shadow memory to ROM (for Debug Purpose in case Boot has not set correctly the M4MEMMAP because of debug) */ - CREG_M4MEMMAP = (unsigned long)src; - - for(dest = &_text_ram; dest < &_etext_ram; ) - { - *dest++ = *src++; - } - - /* Change Shadow memory to Real RAM */ - CREG_M4MEMMAP = (unsigned long)&_text_ram; - - /* Continue Execution in RAM */ - } -} diff --git a/lib/lpc43xx/vector_chipset.c b/lib/lpc43xx/vector_chipset.c new file mode 100644 index 0000000..0463a65 --- /dev/null +++ b/lib/lpc43xx/vector_chipset.c @@ -0,0 +1,48 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2010 Piotr Esden-Tempski + * Copyright (C) 2012 Michael Ossmann + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include + +extern unsigned _etext_ram, _text_ram, _etext_rom; + +#define CREG_M4MEMMAP MMIO32( (0x40043000 + 0x100) ) + +static void pre_main(void) +{ + volatile unsigned *src, *dest; + + /* Copy the code from ROM to Real RAM (if enabled) */ + if( (&_etext_ram-&_text_ram) > 0 ) + { + src = &_etext_rom-(&_etext_ram-&_text_ram); + /* Change Shadow memory to ROM (for Debug Purpose in case Boot has not set correctly the M4MEMMAP because of debug) */ + CREG_M4MEMMAP = (unsigned long)src; + + for(dest = &_text_ram; dest < &_etext_ram; ) + { + *dest++ = *src++; + } + + /* Change Shadow memory to Real RAM */ + CREG_M4MEMMAP = (unsigned long)&_text_ram; + + /* Continue Execution in RAM */ + } +} diff --git a/lib/stm32/f4/vector.c b/lib/stm32/f4/vector.c deleted file mode 100644 index 5304299..0000000 --- a/lib/stm32/f4/vector.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2010 Piotr Esden-Tempski - * Copyright (C) 2011 Fergus Noble - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -#include - -static void pre_main(void) -{ - /* Enable access to Floating-Point coprocessor. */ - SCB_CPACR |= SCB_CPACR_FULL * (SCB_CPACR_CP10 | SCB_CPACR_CP11); -} diff --git a/lib/stm32/f4/vector_chipset.c b/lib/stm32/f4/vector_chipset.c new file mode 100644 index 0000000..5304299 --- /dev/null +++ b/lib/stm32/f4/vector_chipset.c @@ -0,0 +1,27 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2010 Piotr Esden-Tempski + * Copyright (C) 2011 Fergus Noble + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include + +static void pre_main(void) +{ + /* Enable access to Floating-Point coprocessor. */ + SCB_CPACR |= SCB_CPACR_FULL * (SCB_CPACR_CP10 | SCB_CPACR_CP11); +} -- cgit v1.2.3