For my application I need 305Kbytes of RAM for the variables.
According to Reference manual for the chip I am using - STM32L4R5ZI: "The STM32L4Rxxx and STM32L4Sxxx devices feature up to 640 Kbytes SRAM: • 192 Kbytes SRAM1 • 64 Kbytes SRAM2 • 384 Kbytes SRAM3"
In my Truestudio I do see these RAM1 to RAM3 partitions, but when I try to build with values overflowing the 192 Kbytes of SRAM1 I have error. Reading around showed me that most probable issue is the linker script and in it I found:
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = 0x20030000; /* end of 192K RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
RAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 64K
RAM3 (rw) : ORIGIN = 0x20040000, LENGTH = 384K
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
}
It is the first time I touch that, so I am curious how does it work. Do I just update the ld file? Also, considering the current code, how should I change it to be able to use all three partitions together, or just SRAM3 which would be enough for me? Is there another place I have to be careful about?
I see further in the script we have:
/* used by the startup to initialize data */
_sidata = LOADADDR(.data);
/* Initialized data sections goes into RAM, load LMA copy after code */
.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM AT> FLASH
_siram2 = LOADADDR(.ram2);
/* RAM2 section
*
* IMPORTANT NOTE!
* If initialized variables will be placed in this section,
* the startup code needs to be modified to copy the init-values.
*/
.ram2 :
{
. = ALIGN(4);
_sram2 = .; /* create a global symbol at ram2 start */
*(.ram2)
*(.ram2*)
. = ALIGN(4);
_eram2 = .; /* create a global symbol at ram2 end */
} >RAM2 AT> FLASH
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM
Thank you!
EDIT: At the end, I used the proposed code to add RAM3 section, then allocated .bss in RAM3 and problem fixed.