From a61181f8614fe8257dc21bf1762a380165932348 Mon Sep 17 00:00:00 2001 From: arighi Date: Wed, 31 Mar 2010 16:54:12 +0000 Subject: [PATCH] CM3: startup refactoring. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3366 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/hw/crt_cm3.S | 96 +++++++++++++++++++ bertos/cpu/cortex-m3/hw/init_lm3s.c | 78 +++++++++++++++ .../hw/{startup_lm3s.c => vectors_lm3s.c} | 65 ++----------- examples/lm3s1968/lm3s1968.mk | 10 +- 4 files changed, 187 insertions(+), 62 deletions(-) create mode 100644 bertos/cpu/cortex-m3/hw/crt_cm3.S create mode 100644 bertos/cpu/cortex-m3/hw/init_lm3s.c rename bertos/cpu/cortex-m3/hw/{startup_lm3s.c => vectors_lm3s.c} (69%) diff --git a/bertos/cpu/cortex-m3/hw/crt_cm3.S b/bertos/cpu/cortex-m3/hw/crt_cm3.S new file mode 100644 index 00000000..a442bc59 --- /dev/null +++ b/bertos/cpu/cortex-m3/hw/crt_cm3.S @@ -0,0 +1,96 @@ +/** + * \file + * + * + * \brief Cortex-M3 architecture's entry point + * + * \author Andrea Righi + */ + +.syntax unified +.thumb +.section .init, "ax", %progbits + +.weak __init +.set __init, __init0 + +.weak __init1 +.set __init1, __dummy_init + +.weak __init2 +.set __init2, __dummy_init + +.balign 2 +.thumb_func +__dummy_init: + bx lr + +/* + * Reset handler. + */ +.balign 2 +.thumb_func +__init0: + /* Disable IRQs */ + cpsid i + + /* Call the early hardware initialization routine */ + bl __init1 + + /* Copy the data segment initializers from flash to SRAM */ + ldr r0, =__text_end + ldr r1, =__data_start + ldr r2, =__data_end +data_loop: + cmp r1, r2 + ittt lo + ldrlo r3, [r0], #4 + strlo r3, [r1], #4 + blo data_loop + + /* Zero fill the bss segment */ + ldr r1, =__bss_start + ldr r2, =__bss_end + mov r0, #0 +bss_loop: + cmp r1, r2 + itt lo + strlo r0, [r1], #4 + blo bss_loop + + /* Call the hardware initialization routine */ + bl __init2 + + /* Call the application's entry point */ + bl main +end: + wfi + b end diff --git a/bertos/cpu/cortex-m3/hw/init_lm3s.c b/bertos/cpu/cortex-m3/hw/init_lm3s.c new file mode 100644 index 00000000..eaa05edf --- /dev/null +++ b/bertos/cpu/cortex-m3/hw/init_lm3s.c @@ -0,0 +1,78 @@ +/** + * \file + * + * + * \brief Cortex-M3 architecture's entry point + * + * \author Andrea Righi + */ + +#include +#include +#include /* PAUSE */ +#include "drv/irq_lm3s.h" +#include "drv/clock_lm3s.h" +#include "io/lm3s.h" + +extern size_t __text_end, __data_start, __data_end, __bss_start, __bss_end; + +extern void __init2(void); + +/* Architecture's entry point */ +void __init2(void) +{ + /* + * PLL may not function properly at default LDO setting. + * + * Description: + * + * In designs that enable and use the PLL module, unstable device + * behavior may occur with the LDO set at its default of 2.5 volts or + * below (minimum of 2.25 volts). Designs that do not use the PLL + * module are not affected. + * + * Workaround: Prior to enabling the PLL module, it is recommended that + * the default LDO voltage setting of 2.5 V be adjusted to 2.75 V using + * the LDO Power Control (LDOPCTL) register. + * + * Silicon Revision Affected: A1, A2 + * + * See also: Stellaris LM3S1968 A2 Errata documentation. + */ + if (REVISION_IS_A1 | REVISION_IS_A2) + HWREG(SYSCTL_LDOPCTL) = SYSCTL_LDOPCTL_2_75V; + + /* Set the appropriate clocking configuration */ + clock_set_rate(); + + /* Initialize IRQ vector table in RAM */ + sysirq_init(); +} diff --git a/bertos/cpu/cortex-m3/hw/startup_lm3s.c b/bertos/cpu/cortex-m3/hw/vectors_lm3s.c similarity index 69% rename from bertos/cpu/cortex-m3/hw/startup_lm3s.c rename to bertos/cpu/cortex-m3/hw/vectors_lm3s.c index 2e985f64..5cf0a54d 100644 --- a/bertos/cpu/cortex-m3/hw/startup_lm3s.c +++ b/bertos/cpu/cortex-m3/hw/vectors_lm3s.c @@ -30,67 +30,16 @@ * * --> * - * \brief Cortex-M3 architecture's entry point + * \brief LM3S1968 startup interrupt vector table * * \author Andrea Righi */ #include -#include -#include "drv/irq_lm3s.h" -#include "drv/clock_lm3s.h" -#include "io/lm3s.h" +#include /* PAUSE, UNREACHABLE */ -extern size_t __text_end, __data_start, __data_end, - __bss_start, __bss_end, __stack_end; - -extern int main(void); - -/* Architecture's entry point */ -static void NORETURN NAKED _entry(void) -{ - size_t *src, *dst; - - /* - * PLL may not function properly at default LDO setting. - * - * Description: - * - * In designs that enable and use the PLL module, unstable device - * behavior may occur with the LDO set at its default of 2.5 volts or - * below (minimum of 2.25 volts). Designs that do not use the PLL - * module are not affected. - * - * Workaround: Prior to enabling the PLL module, it is recommended that - * the default LDO voltage setting of 2.5 V be adjusted to 2.75 V using - * the LDO Power Control (LDOPCTL) register. - * - * Silicon Revision Affected: A1, A2 - * - * See also: Stellaris LM3S1968 A2 Errata documentation. - */ - if (REVISION_IS_A1 | REVISION_IS_A2) - HWREG(SYSCTL_LDOPCTL) = SYSCTL_LDOPCTL_2_75V; - - /* Set the appropriate clocking configuration */ - clock_set_rate(); - - /* Copy the data segment initializers from flash to SRAM */ - src = &__text_end; - for (dst = &__data_start; dst < &__data_end ; ) - *dst++ = *src++; - - /* Zero fill the bss segment */ - for (dst = &__bss_start; dst < &__bss_end ; ) - *dst++ = 0; - - /* Initialize IRQ vector table in RAM */ - sysirq_init(); - - /* Call the application's entry point */ - main(); - UNREACHABLE(); -} +extern size_t __stack_end; +extern void __init(void); static void NORETURN NAKED default_isr(void) { @@ -98,10 +47,10 @@ static void NORETURN NAKED default_isr(void) UNREACHABLE(); } -/* Startup vector table */ -static void (* const irq_vectors[])(void) __attribute__ ((section(".vectors"))) = { +static void (* const irq_vectors[])(void) __attribute__ ((section(".vectors"))) = +{ (void (*)(void))&__stack_end, /* Initial stack pointer */ - _entry, /* The reset handler */ + __init, /* The reset handler */ default_isr, /* The NMI handler */ default_isr, /* The hard fault handler */ default_isr, /* The MPU fault handler */ diff --git a/examples/lm3s1968/lm3s1968.mk b/examples/lm3s1968/lm3s1968.mk index 453fddaf..db952703 100644 --- a/examples/lm3s1968/lm3s1968.mk +++ b/examples/lm3s1968/lm3s1968.mk @@ -33,10 +33,12 @@ lm3s1968_CSRC = \ bertos/cpu/cortex-m3/drv/timer_lm3s.c \ bertos/cpu/cortex-m3/drv/clock_lm3s.c \ bertos/cpu/cortex-m3/drv/kdebug_lm3s.c \ - bertos/cpu/cortex-m3/hw/startup_lm3s.c + bertos/cpu/cortex-m3/hw/vectors_lm3s.c \ + bertos/cpu/cortex-m3/hw/init_lm3s.c lm3s1968_CPPASRC = \ bertos/cpu/cortex-m3/hw/switch_ctx_cm3.S \ + bertos/cpu/cortex-m3/hw/crt_cm3.S \ # # This is an hosted application @@ -56,7 +58,7 @@ lm3s1968_DEBUG_SCRIPT = bertos/prg_scripts/arm/debug.sh lm3s1968_STOPDEBUG_SCRIPT = bertos/prg_scripts/arm/stopopenocd.sh # Debug stuff -ifeq ($(demo_DEBUG),0) - demo_CFLAGS += -Os -fomit-frame-pointer - demo_CXXFLAGS += -Os -fomit-frame-pointer +ifeq ($(lm3s1968_DEBUG),0) + demo_CFLAGS += -O1 -fomit-frame-pointer + demo_CXXFLAGS += -O1 -fomit-frame-pointer endif -- 2.25.1