cancel
Showing results for 
Search instead for 
Did you mean: 

Saving Information in Flash-Memory without Erasing Cycle

Andreas Fecht
Associate II

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

9 REPLIES 9
S.Ma
Principal

What kind of strange effect?

Andreas Fecht
Associate II

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

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.

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

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.

https://www.st.com/content/ccc/resource/sales_and_marketing/promotional_material/brochure/6c/48/c0/f1/bb/35/4a/b4/brstm32ulp.pdf/files/brstm32ulp.pdf/jcr:content/translations/en.brstm32ulp.pdf

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

0690X0000089HieQAE.png

0690X0000089HioQAE.png

JW

Andreas Fecht
Associate II

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

> 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

turboscrew
Senior III

"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?

Andreas Fecht
Associate II

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