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

STM32 Define start of stack separately from heap end. #4789

Closed
wants to merge 1 commit into from

Conversation

chrismas9
Copy link
Contributor

boards/*.ld Add _sstack symbol. Define stack and heap in a clearer way.
gccollect.h, main.c, pybthread.c, stm32_it.c Use _sstackk instead of _heap_end
modmachine.c machine.info() print _sstack.

@chrismas9
Copy link
Contributor Author

@dpgeorge This format clearly shows the stack and heap size and highlights some anomalies. For example some parts with 256k RAM have 16k stack and other have 32k. H7 with 512k RAM has 16k stack.
Could you please review and adjust stack sizes as you see fit?

@chrismas9
Copy link
Contributor Author

chrismas9 commented May 14, 2019

i would like to clean up the MEMORY section of the linker scripts to be more consistent and make it more obvious what the RAM block sizes are and what they are used for. The reason is to make it easier to configure custom ports that need variations of the linker script, eg to use small cache for external FS, move stack to CCRAM, etc. It won't change any memory allocations. Should that be another commit, or a separate PR?

@dpgeorge
Copy link
Member

The reason is to make it easier to configure custom ports that need variations of the linker script, eg to use small cache for external FS, move stack to CCRAM, etc.

A given board can easily use its own linker script to declare the MEMORY section, it doesn't need to use any of the shared provided ones. See #4043 for a related discussion.

Should that be another commit, or a separate PR?

Let's do it a step at a time, so please make it a separate PR.

@dpgeorge
Copy link
Member

Note that the STM32F769DISC board doesn't build with this patch.

boards/*.ld  Add _sstack symbol. Define stack and heap in a clearer way.
gccollect.h, main.c, pybthread.c, stm32_it.c  Use _sstackk instead of _heap_end
modmachine.c machine.info()  print _sstack.
@chrismas9
Copy link
Contributor Author

All ports compile error free. micropython.mem_info() and mahine.info() report the correct (same) memory ranges after this change on NUCLEO_L432KC and PYBV3

@chrismas9
Copy link
Contributor Author

Please hold off merging this yet. I have an improved layout in the STM32L452 port:

`MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 384K /* sectors 0-191 /
FLASH_FS (r) : ORIGIN = 0x08060000, LENGTH = 128K /
sectors 192-255 /
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 160K /
SRAM1, 128K + SRAM2, 32K */
}

/* produce a link error if there is not this amount of RAM for these sections */
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;

/* Define the top end of the stack. The stack is full descending so begins just
above last byte of RAM, or bottom of FS cache. Note that EABI requires the stack to be
8-byte aligned for a call. */

/* RAM extents for the garbage collector */
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_ram_start = ORIGIN(RAM);

_ram_fs_cache_end = _ram_end;
_ram_fs_cache_start = _ram_fs_cache_end - 2K; /* fs cache = 2K */

_estack = _ram_fs_cache_start;
_sstack = _estack - 16K; /* stack = 16K */

_heap_end = _sstack; /* heap = 142K, tunable by adjusting stack size /
_heap_start = _ebss; /
heap starts just after statically allocated memory */

_flash_fs_start = ORIGIN(FLASH_FS);
_flash_fs_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
`

There are are two changes that improve clarity:

  1. In the MEMORY section contiguous blocks are merged into one region. This is currently inconsistent between boards.
  2. The memory regions are defined in descending order and the top of each region is defined as the bottom of the region above if they are contiguous. It is much easier to visualise the regions and see or change their sizes.

Would you like me to remove the minimum heap and stack size checks. These don't work when the heap or stack are moved into other memory regions (CCRAM, DRAM, etc)?

@dpgeorge
Copy link
Member

Would you like me to remove the minimum heap and stack size checks. These don't work when the heap or stack are moved into other memory regions (CCRAM, DRAM, etc)?

I'll have to have a good look at it first. I don't want to make too many changes at once.

@dpgeorge
Copy link
Member

This PR was merged in 14cf91f

@dpgeorge dpgeorge closed this Jun 14, 2019
@chrismas9 chrismas9 deleted the SSTACK branch December 8, 2019 10:29
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.

None yet

2 participants