Skip to content

Commit f13a3e3

Browse files
author
Deepika
committed
Fix GCC _sbrk allocation
1 parent b36147f commit f13a3e3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

platform/mbed_retarget.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,16 +1245,17 @@ extern "C" int errno;
12451245
// Weak attribute allows user to override, e.g. to use external RAM for dynamic memory.
12461246
extern "C" WEAK caddr_t _sbrk(int incr)
12471247
{
1248-
static unsigned char *heap = (unsigned char *) &__end__;
1249-
unsigned char *prev_heap = heap;
1250-
unsigned char *new_heap = heap + incr;
1248+
static uint32_t heap = (uint32_t) &__end__;
1249+
uint32_t prev_heap = heap;
1250+
uint32_t new_heap = heap + incr;
12511251

12521252
/* __HeapLimit is end of heap section */
1253-
if (new_heap >= (unsigned char *) &__HeapLimit) {
1253+
if (new_heap >= (uint32_t) &__HeapLimit) {
12541254
errno = ENOMEM;
12551255
return (caddr_t) -1;
12561256
}
12571257

1258+
heap = new_heap;
12581259
return (caddr_t) prev_heap;
12591260
}
12601261
#endif

rtos/TARGET_CORTEX/TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ extern void __libc_init_array(void);
4444
void software_init_hook(void)
4545
{
4646
mbed_stack_isr_start = (unsigned char *) &__StackLimit;
47-
mbed_stack_isr_size = ((uint32_t)((uint32_t) &__StackTop - (uint32_t) &__StackLimit));
47+
mbed_stack_isr_size = (uint32_t) &__StackTop - (uint32_t) &__StackLimit;
4848
mbed_heap_start = (unsigned char *) &__end__;
49-
mbed_heap_size = ((uint32_t)((uint32_t) &__HeapLimit - (uint32_t) &__end__));
49+
mbed_heap_size = (uint32_t) &__HeapLimit - (uint32_t) &__end__;
5050

5151
mbed_init();
5252
mbed_rtos_start();

0 commit comments

Comments
 (0)