This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LP23XX Correct Write Embbeded Flash Sequence

As I did not manage to write to 512 Ko Flash using FL-Flash. I coded routines from the LPC23XX manual that make use of IAP commands.
I use the CCLK wired to 12MHz XTAL : CCLK is 48000 kHz.
I coded the following sequence to write to a sector :

prepare
erase
prepare
write
return compare.

I have 2 questions :

1) Do I Have to Erase the sector before writing. I ask this because it make much time, for example erase a 4K flash takes 400 ms, while writing 256 bytes taks 1.1 ms.

2) As writing disable Flash access, how can I know I my code is executed from flash or RAM ?

Thanks.

  • You can normally perform several writes to the same sector, without any erase in-between, if every write is a continuation, i.e. writes bits that haven't been written before.

    With flash, the erase is setting all bits to a fixed state - normally every cell will read back 0xff. Then, every write may change bits from 1 to 0 but not from 0 to 1.

    So you may either patch data by toggling individual bits in the "correct" direction.
    Or you may write the first 256 bytes of a 4kB sector and at a later time write the next 256 bytes.

    I haven't seen anything about it in the datasheets, but have on NXP forum seen notices that you shouldn't do more than maybe 8 or 10 updates to the same sector without an erase, because every time you write to some of the bytes of the sector, you slightly affect the charges of all sector bytes, making the other information you have written slightly weaker.

    But in the end, you can't get away from the erase operations. And they do take time. You may possibly be able to have important interrupt handlers in RAM, and have them buffer jobs while you wait for the erase.

  • For the LPC23xx devices, you can not perform multiple writes to the same page because of ECC. The ECC is the error correction algorithm, which tries to correct single bit errors in flash.

    When the page is programmed, ECC code is also written to hidden flash area. If you reprogram the same page without erasing the sector, (by trying to flip some other bits from 1 to 0), the ECC code is not valid anymore and ECC algorithm tries to correct bit errors. This appears as some bits in a page, that were previously programmed to 0, suddenly become 1.

  • OK.
    Many thanks for these useful explainations.