STM32G0 - internal flash read operation returns always 0
Hello
I have a const variable located in the internal flash memory. When I directly access this variable in flash, the read operation returns always 0 (even when the content of that location in flash is not 0). When I change the code to first copy the variable from flash to ram, the correct values are read and next comparisons work.
Code which returns always 0:
volatile const t_Control mControl __attribute__((section(".saved_context")));
if ( mControl.MemoryInitialised == MEMORY_INITIALISED)
{
....
if (wChecksum == mControl.Checksum)
{
....
}
}
Code which returns the correct values:
t_MemoryControl wControl;
stooMemCopy((uint8_t*)&mControl, (uint8_t*)&wControl, sizeof(t_Control));
if ( wControl.MemoryInitialised == MEMORY_INITIALISED)
{
....
if (wChecksum == wControl.Checksum)
{
....
}
}
Do you have an idea why the direct to flash the variable in flash always return 0 and the comparisons always fail. But when I copy the content of the variable from flash to ram, the values are correct and the comparisons work.
I tried to set a wait state for the flash access but the problem remains. When I look at the assembly, the R3 register contains the correct value of the variable in the flash memory location but the instruction ldr r3, [r3, #0] returns 0.
Did you already face this kind of issue?
Thanks for your answer