Skip to content

Fix memory allocation on STM32L4 devices #7950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions targets/TARGET_STM/TARGET_STM32L4/l4_retarget.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
extern uint32_t __mbed_sbrk_start;
extern uint32_t __mbed_krbs_start;

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

if (heap_ind_new > &__mbed_krbs_start) {
if (heap_ind_new > (uint32_t)&__mbed_krbs_start) {
errno = ENOMEM;
return (void *) - 1;
}
Expand Down