-->
Page 1 of 2

Saving info to flash memory...

PostPosted: Sat May 23, 2015 9:30 pm
by hdrut
Hi all,

I am developing an application that needs to save info about GPIO toggling to flash memory.
For example, if a specific GPIO port is toggled I need to store date, time and name of device who requested the action.

So far i have managed to write flash memory, but only in 4KB sectors, so it´s really not efficient if the info is only some bytes long.

Does anyone know how to write (append) to same sector?

Re: Saving info to flash memory...

PostPosted: Sun May 24, 2015 12:02 am
by lethe
Write operations on the (NOR) flash memory can only toggle bits from 1 to 0. To get a bit back to 1, you need to perform an erase operation. An erase can only be performed on an entire memory block (at least 4KB), so when you want to write repeatedly to the same memory location, you always need to erase the entire block first.

What you could do to work around this limitation is to write new data to a new memory location after the old one, until the sector is full. To find your data, you can write a fixed marker (any int with at least a few 0 bits) before your data. At startup you would read the entire sector to find the last occurence of that marker and safe a pointer to that location (which will point to your most recent data).
This obviously adds quite a bit of complexity to your code, which only pays of, when you write new data quite frequently. The Winbond W25Qxx flash modules most commonly used are rated for 100,000 erase/write cycles, so if you erase a sector every 30 minutes, your flash should still be good for about 5 years.

Re: Saving info to flash memory...

PostPosted: Sun May 24, 2015 2:17 am
by cal
Moin lethe,

thanks for that information.
Do you have any recommendation of some "flash basics for dummies" introduction?

Here i found a datasheet that has the same 100,000 figure.

http://partner.winbond.com/NR/rdonlyres ... 5Q40BV.pdf

I think that is even high enough to think about setting software breakpoints in flash memory!

Does someone know if writing to code flash memory area in contrast to data flash memory is
possible while chip is running?
What interrupts must be or must not be disabled?

Cal

Re: Saving info to flash memory...

PostPosted: Mon May 25, 2015 5:20 pm
by hdrut
Thanks Lethe,

my problem is i need to save many 36-byte strings, so I think I'll create my own code to write them to consecutive sectors, and once I get to 4KB i´ll reallocate all back into one sector.