2019-03-29 09:56 AM
Hello,
I want to realize a startup-counter in a STM32L0xxx MCU.
This means a counter which counts how often the MCU is doing a power fail and restart for the whole life.
I want to save the actual counter-value in the flash memory.
But I don't want to kill the flash-memory-cells with more than 10k write an erase-cycles.
To solve this I want to save the counter-value without erasing-cycles:
Is it possible to write to a flash-cell more than one time without an erase cycle if I only want to *set* the bits? I know it is not possible to clear a bit.
A flash page has a capacity of 128Bytes. If I use every single bit for a counter-step, I can save 128x8=1024 counter-steps without an erase-cycle.
I've tested this, but I get some strange effects.
Is there a reason for this effects?
Maybe multi-level-flash-cells or ECC-correction?
Best regards
Andreas Fecht
2019-03-29 10:04 AM
What kind of strange effect?
2019-03-29 10:30 AM
The following happens:
At an erased page all bits are cleared to 0.
My CPU (STM32L051) supports only a 32-Bit Flash HAL writing method (FLASH_TYPEPROGRAM_WORD).
For example:
Start at a flash adress with value 0x00000000
first set to 0x000000FF -> works
second set to 0x0000FFFF -> works
third set to 0x00FFFFFF -> works
at the next step I want to set it to 0xFFFFFFFF
and I get 0xBFFFFFFF back
Best regards
Andreas
2019-03-29 11:13 AM
Journal a write of words over a whole sector, pick the largest one, and increment that putting it in the next cell. Erase when you fill the whole sector, writing the old count at the front.
2019-03-29 11:15 AM
Not multi-level, but the flash lines are quite wide and 32-bits have additional bits of ECC/Hamming, which is why changing the word breaks things.
I don't see them mention it, but I'd assume at least 4-bits, so 32-bit stored as 36-bit. Sure you could extract specifics from an FAE.
2019-03-29 02:25 PM
JW
2019-03-29 03:01 PM
Thank You,
I think this helps me for my next Project.
I'm searching also for such a counter if a MCU has no internal EEPROM
Best regards
Andreas
2019-03-29 03:38 PM
> I'm searching also for such a counter if a MCU has no internal EEPROM
If you're talking about a different mcu, then you have to read the relevant chapters in that mcu's datasheet and reference manual. There's no universal answer to FLASH-related questions.
JW
2019-03-31 09:01 PM
"Is it possible to write to a flash-cell more than one time without an erase cycle if I only want to *set* the bits? I know it is not possible to clear a bit."
Isn't it the other way around? Usually erasing sets all bits? And you program the zeroes?
2019-04-01 12:46 AM
This depends on the CPU-type.
This L0-series set all erased bits to 0.
I also use A L4-Type which set all erased Bits to 1.
Best regards
Andreas