Skip to content

Commit 6b4dfeb

Browse files
committed
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.
1 parent 98a8c49 commit 6b4dfeb

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

hal/common/retarget.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,7 @@ extern "C" void __iar_argc_argv() {
461461
// Linker defined symbol used by _sbrk to indicate where heap should start.
462462
extern "C" int __end__;
463463

464-
#if defined(TARGET_CORTEX_A)
465464
extern "C" uint32_t __HeapLimit;
466-
#endif
467465

468466
// Turn off the errno macro and use actual global variable instead.
469467
#undef errno
@@ -486,11 +484,7 @@ extern "C" caddr_t _sbrk(int incr) {
486484
unsigned char* prev_heap = heap;
487485
unsigned char* new_heap = heap + incr;
488486

489-
#if defined(TARGET_CORTEX_A)
490487
if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */
491-
#else
492-
if (new_heap >= (unsigned char*)__current_sp()) {
493-
#endif
494488
errno = ENOMEM;
495489
return (caddr_t)-1;
496490
}

hal/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/startup_MK64F12.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ __StackTop:
6464
#ifdef __HEAP_SIZE
6565
.equ Heap_Size, __HEAP_SIZE
6666
#else
67-
.equ Heap_Size, 0x400
67+
.equ Heap_Size, 0x20000
6868
#endif
6969
.globl __HeapBase
7070
.globl __HeapLimit

0 commit comments

Comments
 (0)