From 1739d7e6dd76680e1e9d62f674e8375be6495f66 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 20 Dec 2018 10:09:17 +0100 Subject: [PATCH] Define heap/stack start and size based on linker script symbols for ARM and GCC_ARM --- .../TOOLCHAIN_ARM_MICRO/mbed_boot_arm_micro.c | 4 ++++ .../TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c | 11 ++++++++++- .../TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c | 11 ++++++++++- rtos/TARGET_CORTEX/mbed_boot.h | 5 ----- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/rtos/TARGET_CORTEX/TOOLCHAIN_ARM_MICRO/mbed_boot_arm_micro.c b/rtos/TARGET_CORTEX/TOOLCHAIN_ARM_MICRO/mbed_boot_arm_micro.c index 58080a168d..06373232de 100644 --- a/rtos/TARGET_CORTEX/TOOLCHAIN_ARM_MICRO/mbed_boot_arm_micro.c +++ b/rtos/TARGET_CORTEX/TOOLCHAIN_ARM_MICRO/mbed_boot_arm_micro.c @@ -25,6 +25,10 @@ extern uint32_t __initial_sp[]; extern uint32_t __heap_base[]; extern uint32_t __heap_limit[]; +#if !defined(ISR_STACK_SIZE) +#define ISR_STACK_SIZE ((uint32_t)1024) +#endif + /* * mbed entry point for the MICROLIB toolchain * diff --git a/rtos/TARGET_CORTEX/TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c b/rtos/TARGET_CORTEX/TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c index 482870f501..78e05a88a8 100644 --- a/rtos/TARGET_CORTEX/TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c +++ b/rtos/TARGET_CORTEX/TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c @@ -27,11 +27,20 @@ __value_in_regs struct __argc_argv __rt_lib_init(unsigned heapbase, unsigned heaptop); void _platform_post_stackheap_init(void); +#if !defined(ISR_STACK_SIZE) +#if (defined(__CC_ARM)) +extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[]; +extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Length[]; +#define ISR_STACK_START ((unsigned char*)Image$$ARM_LIB_STACK$$ZI$$Base) +#define ISR_STACK_SIZE ((uint32_t)Image$$ARM_LIB_STACK$$ZI$$Length) +#endif +#endif + #if !defined(HEAP_START) /* Defined by linker script */ extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[]; #define HEAP_START ((unsigned char*)Image$$RW_IRAM1$$ZI$$Limit) -#define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START)) +#define HEAP_SIZE ((uint32_t)((uint32_t)ISR_STACK_START - (uint32_t)HEAP_START)) #endif /* diff --git a/rtos/TARGET_CORTEX/TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c b/rtos/TARGET_CORTEX/TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c index 1060f349f6..a99339133c 100644 --- a/rtos/TARGET_CORTEX/TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c +++ b/rtos/TARGET_CORTEX/TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c @@ -29,11 +29,20 @@ static osMutexId_t env_mutex_id; static mbed_rtos_storage_mutex_t env_mutex_obj; static osMutexAttr_t env_mutex_attr; +#if !defined(ISR_STACK_SIZE) +#if (defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC_VERSION)) +extern uint32_t __StackLimit; +extern uint32_t __StackTop; +#define ISR_STACK_START ((unsigned char*)&__StackLimit) +#define ISR_STACK_SIZE ((uint32_t)((uint32_t)&__StackTop - (uint32_t)&__StackLimit)) +#endif +#endif + #if !defined(HEAP_START) /* Defined by linker script */ extern uint32_t __end__[]; #define HEAP_START ((unsigned char*)__end__) -#define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START)) +#define HEAP_SIZE ((uint32_t)((uint32_t)ISR_STACK_START - (uint32_t)HEAP_START)) #endif extern void __libc_init_array(void); diff --git a/rtos/TARGET_CORTEX/mbed_boot.h b/rtos/TARGET_CORTEX/mbed_boot.h index aed0cdd707..65f7af6fcb 100644 --- a/rtos/TARGET_CORTEX/mbed_boot.h +++ b/rtos/TARGET_CORTEX/mbed_boot.h @@ -50,11 +50,6 @@ extern "C" { * @{ */ -/* Define stack sizes if they haven't been set already */ -#if !defined(ISR_STACK_SIZE) -#define ISR_STACK_SIZE ((uint32_t)1024) -#endif - /* Heap limits - only used if set */ extern unsigned char *mbed_heap_start; extern uint32_t mbed_heap_size;