2020-08-17 09:33 AM
Hello,
I have some application parameters stored in flash area, declared like this :
__attribute__((__section__(".storageFlash"))) const parametersTable_t flashParameters;
The linker script has been modified as follow:
/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 384K
PARAMETERS_STORAGE (rx) : ORIGIN = 0x08060000, LENGTH = 64K
CALIBRATION_STORAGE (rx) : ORIGIN = 0x08068000, LENGTH = 64K
}
....
.storageFlash (NOLOAD) :
{
. = ALIGN(4);
*(storageFlash)
. = ALIGN(4);
} >PARAMETERS_STORAGE
In my program I do a simple copy on a local data or make a comparaison with Ram data like this : temp = flashParameters.version;
With Atollic , I can read that flashParameters.version = 12 but temp = 0!!
If I read the raw memory I can also find 12.
I don't understand why the programm read always 0 instead of 12.
Thanks for your help
Bertrand
2020-08-17 10:27 AM
Some of your memory regions overlap.
Check the addresses in .MAP
Check the code generated in the listing file (.LST, .LSS, whatever)
The optimizer might assume a const region with nothing defined in it might be zero
2020-08-17 11:23 AM
Thanks Clive for your prompt reply.
I checked .map : flashParameter is located at 0x08060000.
It is correct according to the linker script.
I am try to understand the .list file but too low level for me. Here an extract :
temp = flashParameters.version;
temp2 = flashParam.version;
sprintf(sBuf, " Stored parameters version is %d ...", temp);
8019988: 4c25 ldr r4, [pc, #148] ; (8019a20 <isConfigInFlashValid+0xac>)
801998a: 2200 movs r2, #0
801998c: 4925 ldr r1, [pc, #148] ; (8019a24 <isConfigInFlashValid+0xb0>)
801998e: 4620 mov r0, r4
8019990: f004 f98c bl 801dcac <siprintf>
2020-08-17 03:21 PM
Maybe it's just optimized out or the line has been shuffled somewhere else.
2020-08-17 11:05 PM
I don't think so. I removed almost all optimization and I do a comparaison after that and it fails.
12 == 12 -> Wrong!
I am crazy ;)
2020-08-17 11:22 PM
Additionnal information : If I place the code in the main.c ( uint16_t test = flashParameters.version). it works!
For today, I do a memcpy on a RAM structure in a step before ( I don't know how to explain, but I do this memcpy one step before in the call stack)
2020-08-18 12:18 AM
Read out that FLASH area - does it contain what you think it should?
Step through disasm and observe registers.
JW
2020-08-18 01:08 AM
Thanks for your help.
I read out the flash and I can find the right value on it.
For disassembly analysis with register, I have a lack ok knowledge to do it yet. :(
Bertrand
2020-08-18 01:25 AM
I don't know what development environment are you using, but in IDEs it's usually just about clicking into the disasm window and single-stepping as usually. Shouldn't be that hard to try.
JW
2020-08-18 01:29 AM
I am on Atollic Studio 9.3.
Not difficult to find the disassembly but to understand what the programm do exactly.