cancel
Showing results for 
Search instead for 
Did you mean: 

Problem saving data in flash memory.

LMehm
Associate II

Hello, guys!

I have problem saving data in STM32L0's flash memory.

If I save the data twice in the same location it works fine.

If I save the data once CRC check fails - data writing goes wrong?!

I have attached my code.

Sorry for the "magic" numbers in the code!

Thank you!

10 REPLIES 10

You are saying:

> eeAddr=DATA_EEPROM_BASE; //Second write to the same location!!!

But your original eeAddr in the top is something different:

> uint32_t eeAddr= (DATA_EEPROM_BASE+ADDR_SEN_SETT);

So that is not the same location is it?

LMehm
Associate II

ADDR_SEN_SETT is 0x00

Try to check what does HAL_FLASHEx_DATAEEPROM_Program function return. Maybe there is an error and you are ignoring it.

LMehm
Associate II

Ok!I will check it now!

LMehm
Associate II

Only for the first byte HAL_FLASHEx_DATAEEPROM_Program returns -> HAL_ERROR?!

LMehm
Associate II

For the rest of the bytes HAL_OK is returned.

Well that's it, this is how debugging works. Now try to debug step-by-step into the first call of HAL_FLASHEx_DATAEEPROM_Program function to see what exactly causes it to return HAL_ERROR.

LMehm
Associate II

Seems first try to write always returns HAL_ERROR and I have to ignore this.

Bob S
Principal

> Seems first try to write always returns HAL_ERROR and I have to ignore this.

Oh please don't just ignore the error. Find out why you get the error and fix that issue. Unless of course you have already used your debugger to step through the call to HAL_FLASHEx_DATAEEPROM_Program() that is returning the error and you proven that the error can be ignored. Then document in your code why you are ignoring the return from that function call. Your future self or some other poor soul who has to maintain that code will thank you.