cancel
Showing results for 
Search instead for 
Did you mean: 

Weird behaviour with data in flash ( STM32F412RE)

Bertrand1
Senior

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

11 REPLIES 11

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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>

   

TDK
Guru

Maybe it's just optimized out or the line has been shuffled somewhere else.

If you feel a post has answered your question, please click "Accept as Solution".

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 ;)

Bertrand1
Senior

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)

Read out that FLASH area - does it contain what you think it should?

Step through disasm and observe registers.

JW

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

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

I am on Atollic Studio 9.3.

Not difficult to find the disassembly but to understand what the programm do exactly.