EmbeddedRelated.com
Forums
Memfault Beyond the Launch

LPC2129 - reading/writing char array to flash

Started by lawzaz May 16, 2013
I have appnote 11008 open right now and this seems like overkill for what I want (and I'm confused as to how I would extend for char arrays).

I have a board that reads a configuration file from an SD memory card. Sometimes, that card is unreadable and a value is needed regardless. The boards are tuned for different devices, so a single default will not work.

Since I have tons of flash memory free (from 0x10000 to 0x30000), I thought it would be nice to read the char array from the SD card and store it in flash (writing only if the values differ). This way, if the SD card is unreadable, the value in flash is the "last good" configuration. Just a little failsafe in the event of a corrupt card (which happens a lot when I'm using FatFS/FreeRTOS - but I'm sure that's poor concurrency management on my part).

Is AN11008 the best way, or is there a simpler way if I'm not worried about wear leveling? These values change a few times per year and if I understand correctly, it's the writing - not the reading - that wears the memory out.

I'm trying to store:
3 x 32 char array (max)
1 x 16 char array (max)
1 x 8
1 x 5
1 x 3

Not all values will change at the same time. I know that I have to erase a whole sector at a time, so I would need to find a way to check multiple strings against the flash before writing.

Thanks!

An Engineer's Guide to the LPC2100 Series

--- In l..., "lawzaz" wrote:
>
> I have appnote 11008 open right now and this seems like overkill for what I want (and I'm confused as to how I would extend for char arrays).

You just need to think about it a little more. The AN is trying to create a new copy in a separate area before it erases the previous area. The size of the area must be a multiple of 16 bytes but in their scheme, only 12 data bytes are stored in each area due to the header and checksum fields.

Break up your data into 12 byte fields, define multiple areas (I'm deliberately NOT calling them sectors) and try to implement what the AN is describing. It's really pretty clever.

You could redefine the concept to allow for 256 byte areas with 252 bytes of actual user data. I might reduce the data portion to 249 bytes and use a 32 bit CRC.

Richard


Memfault Beyond the Launch