-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
Depending on initial size allocated on STM32L4 devices with TWO_RAM_REGIONS set a crash may occur. This is because there is a mismatch between the size newlib is expecting and the size actually returned by _sbrk. This is because the STM32L4 implementation of _sbrk is performing alignment internally. This patch fixes this problem by removing the code in __wrap__sbrk which performs the alignment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, could we take the opportunity of removing a compilation warning here ?
[Warning] l4_retarget.c@54,22: comparison between pointer and integer
[DEBUG] Return: 0
[DEBUG] Output: .\targets\TARGET_STM\TARGET_STM32L4\l4_retarget.c: In function '__wrap__sbrk':
[DEBUG] Output: .\targets\TARGET_STM\TARGET_STM32L4\l4_retarget.c:54:22: warning: comparison between pointer and integer
[DEBUG] Output: if (heap_ind_new > &__mbed_krbs_start) {
[DEBUG] Output: ^
With
- if (heap_ind_new > &__mbed_krbs_start) {
+ if (heap_ind_new > (uint32_t)&__mbed_krbs_start) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this warning 💯
@adustm 😄 |
Hi @c1728p9 , as you requested I tested it. It works for l475 and l476. I also checked all the tests that mbed-os and ci test shield provides - everything is ok about this fix, no regression anywhere |
Cast the pointer used in l4_retarget to uint32_t before comparing it to fix the warning: "comparison between pointer and integer"
Fixed warnings as well. @cmonr can you make sure this gets into the next RC? |
Marked for RC2 for now, but this doesn't look like it was discovered during OOB. |
@cmonr We should only be bringing in essential fixes for RC2. As this has not been found to be an issue so far we should probably push it to 5.10.1 |
This is maybe because there is no STM32L4 devices with TWO_RAM_REGIONS in the CI :-) |
Hello @adbridge Please refer to #7867 Kind regards |
Moving this back to RC2 so that we can get the fix into 5.10 as it looks like this has a bigger impact than originally thought. |
/morph build |
Build : SUCCESSBuild number : 3030 Triggering tests/morph test |
Test : FAILUREBuild number : 2801 |
Test failure does not appear to be related to PR. /morph test |
Test : FAILUREBuild number : 2802 |
Test failure does not appear to be related to PR. |
Exporter Build : FAILUREBuild number : 2647 |
Test : SUCCESSBuild number : 2804 |
/morph export-build |
Exporter Build : SUCCESSBuild number : 2651 |
Description
Depending on initial size allocated on STM32L4 devices with TWO_RAM_REGIONS set a crash may occur. This is because there is a mismatch between the size newlib is expecting and the size actually returned by _sbrk. This is because the STM32L4 implementation of _sbrk is performing alignment internally.
This patch fixes this problem by removing the code in __wrap__sbrk which performs the alignment.
Pull request type