Working with libflash

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
boeserbaer
Active Member
Posts: 51
Joined: Fri Jan 29, 2010 4:36 pm

Working with libflash

Post by boeserbaer »

Hi, I am concerned about flash wear-out in my application. I need to log events over several years, along with recording the elapsed running time of our system. I can imagine ways to use the flash which would minimize wear:

erase page to initialize
write parameters to first location
write parameters to second location
...
till page is full.

re-erase page
write parameters to first location
write parameters to second location
...
till page is full.

keep repeating...

it is important to not erase the flash every time it is written to.
so my question is does fl_write flash() do anything besides writing the data to the requested buffer?
further, lets say I use the first 8 bytes of the buffer to indicate byte usage, where I indicate buffer in is written to by writing a 1 to the nth bit out of 256.

Should this work, not stressing any cell more than once per full page erase?

Regards, Mike


ale500
Respected Member
Posts: 259
Joined: Thu Sep 16, 2010 9:15 am

Post by ale500 »

If you are writting a log that means you do not need to re-write over and over, do you ?. A sector has 512 bytes ? how many entries (of log) can you put in there ? 32 ? (say 16 bytes per entry) then it should be ok. You will need quite a bit of flash in the case there are many cycles and think what will happen if the flash is full !

Another scenario where you want to write only the last entry of the last few entries:

The flash can be written reliably say 100,000 times, then let's say we shorten it to 50 % and we write to a sector the number of times we used it already and we put a CRC for the whole block of data. When the sector is "worn" according to the rule above we go to the next sector marking this one as "used", and so on.
m_y
Experienced Member
Posts: 69
Joined: Mon May 17, 2010 10:19 am

Post by m_y »

boeserbaer wrote:fl_write flash() do anything besides writing the data to the requested buffer?
"fl_write flash()" isn't a function in libflash so I can't answer your question directly.

All the simple flash writing functions just do the requested write. Responsibilty for erasing in advance lies with the user. The exception is fl_writeData() which copies into RAM, erases the sector then writes back the modified data.

To do what you want I recommend you use fl_eraseDataSector() to clear the sector(s) of interest then fl_writeDataPage() to write. This latter function does nothing but write.
User avatar
boeserbaer
Active Member
Posts: 51
Joined: Fri Jan 29, 2010 4:36 pm

Post by boeserbaer »

Thank you, I meant:
int fl_writeData(unsigned offset, unsigned size, const unsigned char src[],
unsigned char buffer[]);
Should have copy pasted.

fl_writeDataPage(unsigned n, const unsigned char src[]) sounds like it will work.

My next question is how do the libflash data-partition functions know where the boot partition ends?
Specifically, do I need to use any call other than fl_connect(fl_SPIPorts& SPI) before calling fl_writeDataPage(unsigned n, const unsigned char src[])?

Finally, for anyone who might be familiar with flash internals, if I were to read a sector, and then re-write the same data back without erasing (ie not actually change any bits), should it "wear" the cells?

Regards, Mike
m_y
Experienced Member
Posts: 69
Joined: Mon May 17, 2010 10:19 am

Post by m_y »

boeserbaer wrote:My next question is how do the libflash data-partition functions know where the boot partition ends?
It's written to (near) the start of the flash by xflash. When libflash starts it reads this word so it knows where the data partition starts.
Specifically, do I need to use any call other than fl_connect(fl_SPIPorts& SPI) before calling fl_writeDataPage(unsigned n, const unsigned char src[])?
No, you don't.