From 6b4dfeb1abb935a49528d770ad4df54ae5959979 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Thu, 7 Apr 2016 18:09:55 -0500 Subject: [PATCH] Fix heap allocation when used with RTOS Remove the code which checks the heap against the stack to determine if there is space left. Using the stack pointer as a limit causes problems when used with an RTOS since the stack pointer depends on the current thread which can use a user-allocated stack residing anywhere in memory. --- hal/common/retarget.cpp | 6 ------ .../TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/startup_MK64F12.S | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/hal/common/retarget.cpp b/hal/common/retarget.cpp index 29f5d05f4c..79cb598b6d 100644 --- a/hal/common/retarget.cpp +++ b/hal/common/retarget.cpp @@ -461,9 +461,7 @@ extern "C" void __iar_argc_argv() { // Linker defined symbol used by _sbrk to indicate where heap should start. extern "C" int __end__; -#if defined(TARGET_CORTEX_A) extern "C" uint32_t __HeapLimit; -#endif // Turn off the errno macro and use actual global variable instead. #undef errno @@ -486,11 +484,7 @@ extern "C" caddr_t _sbrk(int incr) { unsigned char* prev_heap = heap; unsigned char* new_heap = heap + incr; -#if defined(TARGET_CORTEX_A) if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */ -#else - if (new_heap >= (unsigned char*)__current_sp()) { -#endif errno = ENOMEM; return (caddr_t)-1; } diff --git a/hal/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/startup_MK64F12.S b/hal/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/startup_MK64F12.S index 300dc050a4..cb7c8f8e83 100644 --- a/hal/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/startup_MK64F12.S +++ b/hal/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/startup_MK64F12.S @@ -64,7 +64,7 @@ __StackTop: #ifdef __HEAP_SIZE .equ Heap_Size, __HEAP_SIZE #else - .equ Heap_Size, 0x400 + .equ Heap_Size, 0x20000 #endif .globl __HeapBase .globl __HeapLimit