Skip to content

MCUXpresso: Update ARM linker files to eliminate reserving RAM for stack & heap #4137

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 1 commit into from
Apr 20, 2017

Conversation

mmahadevan108
Copy link
Contributor

@mmahadevan108 mmahadevan108 commented Apr 7, 2017

Description

Update ARM linker files to eliminate reserving RAM for stack & heap. Heap and stack size is determined via the RTOS. This should fix the below issue:
#3763

Status

**READY

  • Tests
    Ran & passed mbed-os tests.

@mmahadevan108
Copy link
Contributor Author

cc @0xc0170 @sg- @maclobdell

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 10, 2017

@mmahadevan108 Again, this is fine for mbed 5 ,but some of these targets that you are changing are enabled for mbed 2 (non rtos applications).

@mmahadevan108
Copy link
Contributor Author

Is there a way to do this for mbed 5 only. We are wasting memory as this is handled in the RTOS as well.

@sg-
Copy link
Contributor

sg- commented Apr 10, 2017

What about using MBED_CONF_RTOS_PRESENT given the linkers now support preprocessing?

@theotherjimmy @0xc0170 @c1728p9

@c1728p9
Copy link
Contributor

c1728p9 commented Apr 10, 2017

This change is relevant to both mbed 2 and 5. Even when the rtos is not present the heap and stack are determined at runtime, similar to with the rtos. These sizes can be decreased, but it would probably be good to set them to non-zero values so you get a compile time error, rather than runtime, on both 2 and 5 if your program is too big. Something like ~1k for both should be sufficient.

@sg-
Copy link
Contributor

sg- commented Apr 10, 2017

Even when the rtos is not present the heap and stack are determined at runtime, similar to with the rto

What happens to the symbols defined for the heap in the linker scripts, are they not used ie wasted space?

@c1728p9
Copy link
Contributor

c1728p9 commented Apr 10, 2017

These defines aren't used to set the size of a dedicated heap region. Instead they are subtracted off the max size of the RW data section so you have at least __stack_size__ + __heap_size__ of free space. At run-time both mbed 2 and 5 setup the stack and heap based on this free space.

@mmahadevan108
Copy link
Contributor Author

Thanks Russ. Why do we need this free space?

@c1728p9
Copy link
Contributor

c1728p9 commented Apr 10, 2017

This space is for the stack and the heap. If it isn't big enough then the stack will grow into valid data and clobber it leading to a crash.

@mmahadevan108
Copy link
Contributor Author

I am confused. I thought the stack & heap space is reserved in the RTOS file for both mbed 2 & 5.

@c1728p9
Copy link
Contributor

c1728p9 commented Apr 10, 2017

With the ARM compiler the free space starts at the end of RW_IRAM1 and goes to the end of the RAM bank. This is the case both for mbed 2 and mbed 5.

  • mbed 5 uses this space for the interrupt stack and for the heap. The code to do this is located here
  • mbed 2 uses this space for the main stack and for the heap. The code to do this for ARM is target specific at the moment and can be found here for the K66F.

@mmahadevan108
Copy link
Contributor Author

Thanks Russ. Some of the platform linker files for ARM compiler do not have __stack & __heap defined and no space is not reserved. Setting these to 0 would result in a similar environment.

@c1728p9
Copy link
Contributor

c1728p9 commented Apr 10, 2017

It works with the size set to zero, you just get a runtime error rather than a compile time error if your program is too big. If the scatter file has support for this extra level of checking why not use it?

@mmahadevan108
Copy link
Contributor Author

I understand. I will reduce the stack & heap size but not make them 0.

…& heap

Heap and stack size is determined via the RTOS.

Signed-off-by: Mahadevan Mahesh <[email protected]>
@mmahadevan108 mmahadevan108 force-pushed the Kinetis_Fix_ARM_Linker_Scripts branch from d7ab045 to 5b866b7 Compare April 14, 2017 16:27
@mmahadevan108
Copy link
Contributor Author

@0xc0170 @sg- @c1728p9 I have pushed in an updated patch. Space reserved for stack & heap has been reduced but is not 0.

@c1728p9
Copy link
Contributor

c1728p9 commented Apr 14, 2017

Thanks for the update @mmahadevan108. This PR looks good to me.

@sg-
Copy link
Contributor

sg- commented Apr 19, 2017

/morph test-nightly

@sg- sg- added needs: CI and removed needs: work labels Apr 19, 2017
@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 34

All builds and test passed!

@adbridge adbridge merged commit 5b86a10 into ARMmbed:master Apr 20, 2017
@mmahadevan108 mmahadevan108 deleted the Kinetis_Fix_ARM_Linker_Scripts branch April 20, 2017 21:38
aisair pushed a commit to aisair/mbed that referenced this pull request Apr 30, 2024
Ports for Upcoming Targets


Fixes and Changes

4008: [NUC472/M453] Support Bootloader and FlashIAP ARMmbed/mbed-os#4008
4102: Add SCL and SDA defs for I2C[0-2]; redefine I2C_[SCL,SDA] to I2C2 ARMmbed/mbed-os#4102
4118: STM32F4 Internal ADC channels rework ARMmbed/mbed-os#4118
4126: STM32F4 : remove SERIAL_TX and SERIAL_RX from available pins ARMmbed/mbed-os#4126
4148: Revert "STM32F4 Internal ADC channels rework" ARMmbed/mbed-os#4148
4152: STM32F4 Internal ADC channels rework ARMmbed/mbed-os#4152
4074: [Silicon Labs] Update pinout ARMmbed/mbed-os#4074
4133: U-BLOX_C030: Default XTAL is now 12MHz onboard. Option to use Debug 8MHz ARMmbed/mbed-os#4133
4142: EFM32: Fixed `pwmout_all_inactive` being inversed ARMmbed/mbed-os#4142
4016: [NRF5]: fix rtc overflow-while-set-timestamp issue ARMmbed/mbed-os#4016
4031: STM32 increase IAR heap size for big RAM targets ARMmbed/mbed-os#4031
4137: MCUXpresso: Update ARM linker files to eliminate reserving RAM for stack & heap ARMmbed/mbed-os#4137
4176: STM32L4 Internal ADC channels rework ARMmbed/mbed-os#4176
4154: STM32F7 Internal ADC channels rework ARMmbed/mbed-os#4154
4174: [NRF52840]:  fix rtc overflow-while-set-timestamp issue ARMmbed/mbed-os#4174
4180: [UBLOX_C030] create target hierarchy for the specific versions of the C030 board ARMmbed/mbed-os#4180
4153: STM32F2: Internal ADC channels rework ARMmbed/mbed-os#4153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants