2024-10-01 05:46 AM
Hi,
I am working with SBSFU on a STM32U575 microcontroller, and I want to use the __attribute__((section(‘.ram2’))) to place a variable in the secure SRAM2 memory section so that the variable can write to it. However, the secure SRAM2 memory is reset every time the microcontroller is rebooted. I would like to know if it is possible to retain the data in secure SRAM2 permanently, and if so, would the linker script need to be modified to accommodate the use of this attribute?
Solved! Go to Solution.
2024-10-01 07:08 AM
Hello @Istillaga ,
If you need to write in secure you have the beginning of SRAM3 that is also secure
(You can check this in the region_defs.h :
#define S_TOTAL_RAM_SIZE (_SRAM2_SIZE_MAX + SRAM3_S_SIZE )
So, you will need to adapt your linker file to create a dedicated SRAM3 area
For instance, replace
RAM (xrw): ORIGIN = S_DATA_START, LENGTH = S_DATA_SIZE
by
RAM (xrw): ORIGIN = S_DATA_START, LENGTH = S_DATA_SIZE - RETAIN_SIZE
RAM3_RETAIN(xrw): ORIGIN = S_DATA_START + S_DATA_SIZE - RETAIN_SIZE, LENGTH = RETAIN_SIZE
then create a section that points on RAM3_RETAIN with NOLOAD keyword.
Something like
.noinit (NOLOAD) :
{
. = ALIGN(4);
*(.noinit)
. = ALIGN(4);
} > RAM3_RETAIN
Best regards
Jocelyn
2024-10-01 06:16 AM
Hello @Istillaga ,
the SRAM2 content is erased on reset. This is a security feature. If you want to keep something in memory you should use other SRAM. Now if you still want to do that, you can change this behaviour in option bytes.
You will need to modify the SBSFU also because it checks this setting.
Best regards
Jocelyn
2024-10-01 06:49 AM
Hello @Jocelyn RICARD,
If I use another memory in the secure zone SRAM1 for example to be able to write using the __attribute__((section(‘.ram'))) I would have to modify the linker script right? how should I modify it?
2024-10-01 07:08 AM
Hello @Istillaga ,
If you need to write in secure you have the beginning of SRAM3 that is also secure
(You can check this in the region_defs.h :
#define S_TOTAL_RAM_SIZE (_SRAM2_SIZE_MAX + SRAM3_S_SIZE )
So, you will need to adapt your linker file to create a dedicated SRAM3 area
For instance, replace
RAM (xrw): ORIGIN = S_DATA_START, LENGTH = S_DATA_SIZE
by
RAM (xrw): ORIGIN = S_DATA_START, LENGTH = S_DATA_SIZE - RETAIN_SIZE
RAM3_RETAIN(xrw): ORIGIN = S_DATA_START + S_DATA_SIZE - RETAIN_SIZE, LENGTH = RETAIN_SIZE
then create a section that points on RAM3_RETAIN with NOLOAD keyword.
Something like
.noinit (NOLOAD) :
{
. = ALIGN(4);
*(.noinit)
. = ALIGN(4);
} > RAM3_RETAIN
Best regards
Jocelyn
2024-10-02 12:55 AM - edited 2024-10-02 02:27 AM
Hello @Jocelyn RICARD,
I have made the changes and modified all the partitions so that the SRAM3 address, in my case 0x300D0000, is Non-Secure Callable, allowing me to write from secure_nsc. However, when I attempt to write to or read from the SRAM3 address, the system resets.
I have added the following code in secure_nsc.c:
__attribute__((section(“.noinit”))) uint32_t* ptr;
CMSE_NS_ENTRY void WRITE(void){
ptr = (uint32_t*)0x300D0000;
*ptr = 0x12345678;
uint32_t value_read = *ptr;
}
2024-10-02 04:47 AM
Hello,
I made a mistake with the memory address which was SRAM3 0x30040000 with 0x300D0000. With 0x30040000 it works perfectly.