How to properly initialize shared arrays on STM32745?
In my application I am using initialized data in shared memory for the use in a user interface. The memory is in the SRAM2 at 0x30020000. Both cores need to access that data, so I use code of the following form:
__attribute__((section(".sram2"))) uiSelDef uiSelItem[4] = {
[0] = {"abc", 0.0f, 50, CENTER_CENTER},
[1] = {"def", 0.0f, 100, CENTER_CENTER},
[2] = {"ghi", 0.0f, 200, CENTER_CENTER},
[3] = {"jkl", 0.0f, 500, CENTER_CENTER},
}This code is placed in the Common directory so that it is picked up during compile time for both CM4 and for CM7 individually. Note that the initialization is not static on purpose.
Why am I doing this? Roughly speaking, CM7 reacts on user inputs via interrupts (using encoders and switches) and shows updates on a screen based on user selection referring data from the array shown above. The CM7 then requests CM4 via semaphores to react to the user input. The CM4 access that very same array.
So far so good. This works very well when I am in debug mode. However, when I compile the code in Release mode, the MCU gets stuck. I don't have a way to debug this, because as stated above, I am not running into this issue during debug mode. So I can only surmise that there is some sort of a clash or a race during the exection of the startup code "startup_stm32h745ihx.s" on each of the two cores.
What ideas do you have to make this work? Why would the two startup codes cause a clash (if my theory is correct)?
For completeness sake, here are the relevant entries of my two linker scripts:
CM7:
MEMORY
{
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
AXISRAM (xrw) : ORIGIN = 0x24000000, LENGTH = 256K
SRAM1 (xrw) : ORIGIN = 0x30000000, LENGTH = 128K
SRAM2 (xrw) : ORIGIN = 0x30020000, LENGTH = 128K
SRAM3 (xrw) : ORIGIN = 0x30040000, LENGTH = 32K
SRAM4 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
}CM4:
MEMORY
{
AXISRAM (xrw) : ORIGIN = 0x24040000, LENGTH = 256K
SRAM1 (xrw) : ORIGIN = 0x30000000, LENGTH = 128K
SRAM2 (xrw) : ORIGIN = 0x30020000, LENGTH = 128K
SRAM3 (xrw) : ORIGIN = 0x30040000, LENGTH = 32K
SRAM4 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x08100000, LENGTH = 1024K
}And to ensure proper initialization, both linker scripts have the following lines of code (it's identical in both scripts):
/* Configure SRAM2 */
.SRAM2 :
{
. = ALIGN(4);
__SRAM2_START__ = .;
*(.sram2)
*(.sram2*)
. = ALIGN(4);
__SRAM2_END__ = .;
} >SRAM2I realize that this leads to both startup routines writing the initialized array to the same location but I have no better idea how to ensure both cores access the corresponding data at the same memory address.