Skip to content

Commit d311a96

Browse files
author
Cruz Monrreal
authored
Merge pull request #7950 from c1728p9/l4_malloc_fix
Fix memory allocation on STM32L4 devices
2 parents 76827c3 + e084865 commit d311a96

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

targets/TARGET_STM/TARGET_STM32L4/l4_retarget.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
extern uint32_t __mbed_sbrk_start;
3939
extern uint32_t __mbed_krbs_start;
4040

41-
#define STM32L4_HEAP_ALIGN 32
42-
#define STM32L4_ALIGN_UP(X, ALIGN) (((X) + (ALIGN) - 1) & ~((ALIGN) - 1))
4341
/**
4442
* The default implementation of _sbrk() (in platform/mbed_retarget.cpp) for GCC_ARM requires one-region model (heap and
4543
* stack share one region), which doesn't fit two-region model (heap and stack are two distinct regions), for example,
@@ -50,10 +48,10 @@ extern uint32_t __mbed_krbs_start;
5048
void *__wrap__sbrk(int incr)
5149
{
5250
static uint32_t heap_ind = (uint32_t) &__mbed_sbrk_start;
53-
uint32_t heap_ind_old = STM32L4_ALIGN_UP(heap_ind, STM32L4_HEAP_ALIGN);
54-
uint32_t heap_ind_new = STM32L4_ALIGN_UP(heap_ind_old + incr, STM32L4_HEAP_ALIGN);
51+
uint32_t heap_ind_old = heap_ind;
52+
uint32_t heap_ind_new = heap_ind_old + incr;
5553

56-
if (heap_ind_new > &__mbed_krbs_start) {
54+
if (heap_ind_new > (uint32_t)&__mbed_krbs_start) {
5755
errno = ENOMEM;
5856
return (void *) - 1;
5957
}

0 commit comments

Comments
 (0)