Skip to content
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

Heap is defined in linkerscript for FLAT builds. #2277

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fjpanag
Copy link
Contributor

@fjpanag fjpanag commented Nov 10, 2020

Summary

Currently the heap regions are hardcoded. The code makes assumptions on how the memory regions should be mapped, and calculates the boundaries according to the MCU's available memory.

This creates problems in many cases, where the uses needs a "non-standard" memory map. See issue #2002.

This PR is about refactoring the heap configuration, and have the user define the Heap in the linkerscript. That way anyone will be able to adapt the memory map to their actual needs. NuttX will be able to support any arbitrary memory configuration, and no assumptions will be made about the final application.

Impact

Linkerscripts need to be updated, so they define the new .heap region.

Testing

None yet.


Note! This is a draft PR, just a proposition. Please review the concept behind the changes, and not the actual changes.
I am only working on STM32 for now, and I chose STM32F4Discovery board as the "reference board" for these changes.
Nxstyle errors are ignored for the moment.

Things to do:

  • Also adapt the heap configuration in PROTECTED & KERNEL builds.
  • Add support for multiple heap regions.
  • Add support for memories external to the MCU.
  • Update all linker scripts.
  • Eventually update other MCU families.

@davids5 davids5 self-requested a review November 10, 2020 13:03
@hartmannathan
Copy link
Contributor

How would you envision treating MCUs that have multiple "banks" of SRAM? (I don't know if "bank" is the correct term.) For example, a chip I use, STM32G474x, has:

  • SRAM 1, 80 Kbyte at 0x20000000
  • SRAM 2, 16 Kbyte at 0x20014000
  • CCM SRAM, 32 Kbyte, at 0x10000000 and aliased at 0x20018000

@fjpanag
Copy link
Contributor Author

fjpanag commented Dec 14, 2020

Hi @hartmannathan,
I am sorry that there is no progress on this, but I have limited free time lately.

I am thinking of having the number of heap regions defined either in Kconfig, or in board.h.
Then, the linkerscript shall define each region as heap1, heap2 etc. Like:

   .heap1 (NOLOAD) : ALIGN(4) {
        _sheap1 = ABSOLUTE(.);
        . = ORIGIN(h1ram) + LENGTH(h1ram);
        . = ALIGN(4);
        _eheap1 = ABSOLUTE(.);
    } > h1ram

This way the user will be able to set up any memory layout that they like, with multiple heap regions in arbitrary positions.
It wouldn't matter whether each heap region lives within the same RAM bank or not.

@hartmannathan
Copy link
Contributor

Hi @hartmannathan,
I am sorry that there is no progress on this, but I have limited free time lately.

Hello, @fjpanag , no worries. Thanks for your reply

@hartmannathan
Copy link
Contributor

For anyone following along, a related discussion occurred in the dev@ mailing list thread "How to ensure HEAP will not overlap static DMA buffer?" started on 2021/03/25 and archived here: https://lists.apache.org/thread.html/recf2bb9043f8c9f53c10917e2adb2ec64fe35dc5e6f9a695a7ac6ecc%40%3Cdev.nuttx.apache.org%3E

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants