How to write a time counter in internal flash of STM32WB(55RG)
Hello everyone,
For my application, I need to record a time counter in flash memory, with a resolution of 1/10 of hour (eg. 6 minutes).
Here is what I do :
As I know there is a limitation for flash lifetime (10000 erase cycles), I built an algorithm which only write zeros in one flash sector (I'm using the 18th sector for that and tried with others). The idea was to write zeros because this normally don't needs to erase before writting (the number of 0s is equal to the number of 1/10 hour elapsed). I saw that there is an other constraint which is to write only dwords (64 bits) from FF to 00, and built my algorythm thaking that into account (using full dword table values set from FFFFFFFFFFFFFFFF to 0000000000000000).
The problem encountered :
My algorithm is Ok as I coded, and I could test the general principle, but I encounter a HAL_ERROR status returned by the HAL write function "HAL_FLASH_Program". I have investigate much deeper and could see the "FLASH_WaitForLastOperation" function found the PROGERR bit set in the SR register of the flash.
My tests and investigations :
I made many tests and trials to check if it was not because of a protection or alignment problem, but all seems to be OK on theese points.
I finally tested both with STM32CubeProgrammer and ST-LINKUtility, and obtain a similar results when I change FLASH memory cells values from FFFFFFFF to 00000000 . In fact, while I write 32 bits at non consecutive adresses, all wrtites are performed correctly and with no rrors. But if I write 00000000 at two consecutive adresses, then the next following writes return with the write error...
Do someone could give me explanations about what would be the origin of the problem ? if needed I can post my code (functions used for write operation), just let me know.
I hope someone will be able to help me, I'm workig on that point for more than 2 full days !
With by best regards, I wish a nice day to all.
Patrick