RAM in stm32l476

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
ajie_dirgantara
Posts: 81
Joined: Fri Sep 02, 2016 9:26 am

RAM in stm32l476

Post by ajie_dirgantara » Thu Aug 03, 2017 9:23 am

Code: Select all

/*
    GNU linker script for STM32L476XG
*/

/* Specify the memory areas */
MEMORY
{                                                   
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K
    FLASH_ISR (rx)  : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sectors 0-7, 16 KiB */
    FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 0x007C000 /* sectors 8-255, 496 KiB */
    FLASH_FS (r)    : ORIGIN = 0x08080000, LENGTH = 0x0080000 /* sectors 256-511 512 KiB */
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 96K
    SRAM2 (xrw)     : ORIGIN = 0x10000000, LENGTH = 32K
}

ENTRY(Reset_Handler)

/* 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.  Note that EABI requires the stack to be 8-byte
   aligned for a call. */
_estack = ORIGIN(RAM) + LENGTH(RAM);

/* define common sections and symbols */
INCLUDE common.ld

/* RAM extents for the garbage collector */
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x20014000;

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

From the linker script above, I don't think it make use of the SRAM2. Can this be enabled so we can get more RAM from SRAM2?

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: RAM in stm32l476

Post by chrismas9 » Sat Aug 05, 2017 5:35 pm

Unlike some STM32's SRAM2 is not contiguous with SRAM1 in the L476. Currently SRAM2 is used as cache for the Flash FS when internal Flash is used. Since the L476 has 2K page size 30K of SRAM2 is wasted.

By reducing the FS cache to 2K and moving the stack into the remaining 30K of SRAM2 I have been able to increase the heap by 16K and the stack by 14K. There is an experimental version here:

https://github.com/chrismas9/micropytho ... ganisation

It only builds for L476. The linker scripts need to be modified for all the other STM32 MCU's. I plan to submit a PR covering all STM32's after more testing and feedback.

The changes to the linker script also allow you to increase the cache size on MCU's with large sectors and enough ram. With 128k cache you can get between 512K and 1.5M of internal Flash FS.

Post Reply