6 years, 8 months ago.

Lifetime of Flash Memory (LPC1768)

As I understand it, when I download a program to the mbed flash drive, it is not immediately loaded into the target chip's flash memory, but instead is loaded when the reset button is pressed or when the power is cycled.

Does the flash get reloaded every time the power is cycled, or only if the image has changed? (if so, I'm curious: how does it know that the image has changed)

Is there any practical limit to how many times this can be done without wearing out the flash on the target? I'm building a system that may be rebooted/repowered many times a day, and I'm wondering if this is a concern. I'm also loading data tables into the flash programmatically at startup, so that adds more write cycles to the flash. I'm talking specifically about the flash internal to the processor chip, not the 2MB external flash.

I searched through the LPC1768 manuals, but I couldn't seem to find a figure for flash lifetime.

Secondary question: How long does it take to load a large program image (say 256KB) to the processor flash? All the short programs I've tested with seem to launch pretty quick, but I'm wondering how that will be with a "real" program.

Thanks,

Chuck

1 Answer

6 years, 8 months ago.

Since I have heard conflicting stories about this, it was a nice moment to test it to be sure. To start with, on all the newer mbeds flash is only written when there is a new program being loaded, since it can't store it anyway.

Now to test it on yours, I used this elegant program, which uses the IAP library:

IAP     iap;

DigitalOut led(LED1);

int main() {
    for (int i = 0; i<10; i++) {
        wait(0.15);
        led = !led;
    }
    
    iap.prepare( 0, 0 );
    iap.erase( 0, 0 );
     while(1);
}

Okay, it isn't elegant. It blinks an LED, and then erases its first flash sector, pretty much ruining the chance the program is going to do anything. Simple answer: LED blinks after programming the first time, when resetting it next nothing happens. In other words, flash is not reprogrammed at reset. It just tracks what the latest bin file is (using date probably, although overwriting old one with same one doesn't seem to trigger it, so I guess it checks if the latest file has a different name than the currently loaded one, which it stores somewhere).

Now size which you are programming doesn't really matter for your flash cycles, since sector 0 is going to be used most anyway and will most likely die first (or one close to there). A microcontroller doesn't employ rotation for which flash is used, since in normal usage you will never run out of flash cycles.

In the LPC1768s datasheet the flash cycles are defined, and it is the same as pretty much every uC: 10k min, 100k typ. So there is no way you are going to run out of flash cycles by programming it, only way that can happen is if you use IAP (ie, programming flash from your application) in such a way that it is programming your flash very often.