STM32 Increasing Stack, Heap and/or Filesystem size

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
User avatar
nikol900
Posts: 4
Joined: Thu Feb 11, 2021 12:36 pm

Re: STM32 Increasing Stack, Heap and/or Filesystem size

Post by nikol900 » Mon Feb 15, 2021 7:29 am

jimmo wrote:
Sun Feb 14, 2021 10:50 pm
I don't see where you're defining _sstack, but what it looks like is happening is that you're now making the heap use the entire SRAM1+SRAM2 (after ebss), which means it will collide with the stack. I imagine this will look like it's working until it doesn't.

0x20020000 is the same as ORIGIN(RAM) + LENGTH(RAM)

If you want to do this (make the heap use the entire remaining SRAM1+SRAM2, after ebss), then you need to move the stack somewhere else. It appears that's what Chris is doing, I imagine he's setting sstack and estack to put it in CCM. Because the stack is 16kiB, that's why he gets 16kiB of extra heap.

You need to be careful because the CCM is used for the flash cache. I don't think the filesystem uses any flash blocks larger than 16k (it uses the first four blocks, as you can see in the linker script).
understood you. it may well be that I got on the stack = ((
try another approach.

can i change the linker script?
I want to resize the Flash FS and Flash Text areas.
I tried to make

Code: Select all

MEMORY
{
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */
    FLASH_ISR (rx)  : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
    FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 752K /* sectors 1,2,3,4,5,6,7,8,9 */
    FLASH_FS (rx)   : ORIGIN = 0x080C0000, LENGTH = 256K /* sectors 10,11 are for filesystem */
    CCMRAM (xrw)    : ORIGIN = 0x10000000, LENGTH = 64K
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
}
vs origin

Code: Select all

    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */
    FLASH_ISR (rx)  : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
    FLASH_FS (rx)   : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1,2,3,4 are for filesystem */
    FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 896K /* sectors 5,6,7,8,9,10,11 */
    CCMRAM (xrw)    : ORIGIN = 0x10000000, LENGTH = 64K
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
    
as follows, but when flashing the device was no longer detected. what should be changed in the code? or is this approach not possible?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: STM32 Increasing Stack, Heap and/or Filesystem size

Post by jimmo » Mon Feb 15, 2021 9:09 am

nikol900 wrote:
Mon Feb 15, 2021 7:29 am
I want to resize the Flash FS and Flash Text areas.
This is a bit complicated because of the variable-sized flash blocks. It will require some changes to stm32/flash.c and stm32/flashbdev.c

User avatar
nikol900
Posts: 4
Joined: Thu Feb 11, 2021 12:36 pm

Re: STM32 Increasing Stack, Heap and/or Filesystem size

Post by nikol900 » Mon Feb 15, 2021 9:59 am

jimmo wrote:
Mon Feb 15, 2021 9:09 am

This is a bit complicated because of the variable-sized flash blocks. It will require some changes to stm32/flash.c and stm32/flashbdev.c
yes, I got it already.
I decided to expand FlashFS by 128Kb (sector 5)
the scheme in "stm32f405.ld" is as follows:

Code: Select all

    
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */
    FLASH_ISR (rx)  : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
    FLASH_FS (rx)   : ORIGIN = 0x08004000, LENGTH = 240K /* sectors 1,2,3,4 + 5 are for filesystem */
    FLASH_TEXT (rx) : ORIGIN = 0x08040000, LENGTH = 768K /* sectors 6,7,8,9,10,11 - 5 */
    CCMRAM (xrw)    : ORIGIN = 0x10000000, LENGTH = 64K
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 128K
    
changes in "flashbdev.c":

Code: Select all

#define CACHE_MEM_START_ADDR (0x10000000) // CCM data RAM, 64k
#define FLASH_SECTOR_SIZE_MAX (0x10000) // 64k max, size of CCM
#define FLASH_MEM_SEG1_START_ADDR (0x08004000) // sector 1
#define FLASH_MEM_SEG1_NUM_BLOCKS (480) //!!!!!!!!  224 !!!!!!!!  sectors 1,2,3,4: 16k+16k+16k+64k=112k + 128k(5)
I don't understand what to do in "flash.c"

I also noticed that in "mpconfigport.mk" there is a starting address of the program code TEXT0_ADDR = 0x08020000
it turns out that if my markup is shifted in "stm32f405.ld", I also need to specify the TEXT0_ADDR = 0x08040000

and .... it all worked!
now I have ~ 222 KB FLASH FS available

Sampath
Posts: 1
Joined: Mon Jan 03, 2022 11:49 pm

Re: STM32 Increasing Stack, Heap and/or Filesystem size

Post by Sampath » Tue Jan 04, 2022 12:27 am

Drako wrote:
Mon Oct 23, 2017 6:17 am
Thanks mate,

it worked out! Increased the filesystem size from 79 kb to 1,06 MB.

Keep up the great work.
Is it possible to share .ld file?

Post Reply