EmbeddedRelated.com
Forums
Memfault Beyond the Launch

LPC2378 Data written to flash

Started by pete...@courtara.com.au January 17, 2007
Greetings All,

I need to write data to the flash from within the application but in the documentation I have the min numbers of bytes for IAP is 256 I want to store only 4 bytes (1 word) at a time. Is there a way to do this or is there documentation to directly configure and control the flash registers?

Thanks in Advance,

Peter

An Engineer's Guide to the LPC2100 Series

--- In l..., peter@... wrote:
>
> Greetings All,
>
> I need to write data to the flash from within the application but in
the documentation I have the min numbers of bytes for IAP is 256 I
want to store only 4 bytes (1 word) at a time. Is there a way to do
this or is there documentation to directly configure and control the
flash registers?
>
> Thanks in Advance,
>
> Peter

Peter,

AFIAK the minimum storage unit for all LPC flash memory writes is an
aligned block of 16-bytes. The IAP requirement to write 256 bytes is
a (software) limitation.

You can overcome 256-byte IAP limitation by filling just the 16-byte
you want to write with data, the remaining 240-bytes with 0xff's.
However there is no way to overcome the 16-byte LPC flash memory write
limitation.

Hope this helps.

Jaya
Hi Jaya,

Do you mean the data in the 240 bytes will remain as it is ? and only
the 16 bytes will change

Suvidh
--- In l..., "jayasooriah" wrote:
>
> --- In l..., peter@ wrote:
> >
> > Greetings All,
> >
> > I need to write data to the flash from within the application but in
> the documentation I have the min numbers of bytes for IAP is 256 I
> want to store only 4 bytes (1 word) at a time. Is there a way to do
> this or is there documentation to directly configure and control the
> flash registers?
> >
> > Thanks in Advance,
> >
> > Peter
>
> Peter,
>
> AFIAK the minimum storage unit for all LPC flash memory writes is an
> aligned block of 16-bytes. The IAP requirement to write 256 bytes is
> a (software) limitation.
>
> You can overcome 256-byte IAP limitation by filling just the 16-byte
> you want to write with data, the remaining 240-bytes with 0xff's.
> However there is no way to overcome the 16-byte LPC flash memory write
> limitation.
>
> Hope this helps.
>
> Jaya
>
--- In l..., "suvidhk" wrote:
>
> Hi Jaya,
>
> Do you mean the data in the 240 bytes will remain as it is ? and only
> the 16 bytes will change
>
> Suvidh

Yes. Writing 0xf to flash memory is in effect a NOP.

The other way is to read back 256-byte block, change the 16-byte block
you want to 'write' and then save the entire 256-bytes using IAP call.

Normally writing 0xff does not consume flash write/erase cycles, but
rewriting any other data, even if it the already there, will.

Jaya
--- In l..., "jayasooriah" wrote:
>
> --- In l..., "suvidhk" wrote:
> >
> > Hi Jaya,
> >
> > Do you mean the data in the 240 bytes will remain as it is ? and only
> > the 16 bytes will change
> >
> > Suvidh
>
> Yes. Writing 0xf to flash memory is in effect a NOP.
>
> The other way is to read back 256-byte block, change the 16-byte block
> you want to 'write' and then save the entire 256-bytes using IAP call.
>
> Normally writing 0xff does not consume flash write/erase cycles, but
> rewriting any other data, even if it the already there, will.
>
> Jaya
>
Hi Jaya,

This problem is something that I have been pondering too. I was
wondering if it would be possible to make successive writes to the
same 256 byte block. Let me make an example:

I wish to write 8 byte blocks to the internal flash, could I make the
first write look like

0x1111111111111111FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

and a second write like
0x11111111111111112222222222222222FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

at all times I would be writing 256 byte blocks but the bytes that I
don't want to use (yet) are "written" as 1's

Would this be possible? Would it reduce the reliably of the data written?

Regards, James Brown
--- In l..., "suvidhk" wrote:
>>
>> Hi Jaya,
>>
>> Do you mean the data in the 240 bytes will remain as it is ? and only
>> the 16 bytes will change
>>
>> Suvidh
>
>Yes. Writing 0xf to flash memory is in effect a NOP.
>
>The other way is to read back 256-byte block, change the 16-byte block
>you want to 'write' and then save the entire 256-bytes using IAP call.
>
>Normally writing 0xff does not consume flash write/erase cycles, but
>rewriting any other data, even if it the already there, will.
>
>Jaya
>

Hello Jaya,

Thanks for the posting I did discover the same by reading more in the archive of other posts and I am employing the read 256 bytes to a buffer changing the next 16 bytes and writing back so far I have written and erased the flash ok next the read, modify and write cycle.

Out of interest I tried using the 16K RAM block that the ethernet module uses but it will not work. I first had the enable the ethernet block using PCONP control register this allowed me to read and write the SRAM but when I assigned it to the IAP source RAM address I just get FF's when I try to write it to flash strange? (with the buffer in normal RAM ok)

Thank you for posting.

All the best,

Peter
--- In l..., "jjbro1" wrote:
> Hi Jaya,
>
> This problem is something that I have been pondering too. I was
> wondering if it would be possible to make successive writes to the
> same 256 byte block. Let me make an example:
>
> I wish to write 8 byte blocks to the internal flash, could I make the
> first write look like
>
> 0x1111111111111111FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...
>
> and a second write like
> 0x11111111111111112222222222222222FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...
>
> at all times I would be writing 256 byte blocks but the bytes that I
> don't want to use (yet) are "written" as 1's
>
> Would this be possible? Would it reduce the reliably of the data
written?
>
> Regards, James Brown

Hi James,

LPC flash unlike any other flash, is organised 128-bit wide (16-bytes)
and this is done so as enable prefetch caching used by MAM to speed up
flash access. To achieve the required number of erase/write cycles
they had to error detection and correction (EDC) checksums.

When you write the first 8 bytes, the checksum for all 16-bytes is
written. Now when you update the second 8 bytes (you can in non-LPC
flash memory), on the LPC it fails because the checksum will be
overwritten and being flash memory, it will retain the bit-wise AND
value of the two checksums.

So after the second write, the entire 16-byte block will read as bad data.

Hope this makes it clearer.

Jaya
--- In l..., peter@... wrote:
> Out of interest I tried using the 16K RAM block
> that the ethernet module uses but it will not work.
> I first had the enable the ethernet block using PCONP
> control register this allowed me to read and write
> the SRAM but when I assigned it to the IAP source
> RAM address I just get FF's when I try to write it
> to flash strange? (with the buffer in normal RAM ok)

Hi Peter,

Although you can have the source data for writing to flash reside in
any memory, the NXP boot loader implementation puts some restrictions.

You should get an error code returned when you try to specify the
source data in your case. Are you checking the return codes?

Regards

Jaya

Memfault Beyond the Launch