EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

LPC2148 - Writing to flash

Started by Kiran Karanki April 9, 2013
Hi All -

I have a program running on LPC2148. There is a requirement to store some
of the user data onto Flash.

I'm using the IAP commands to do the same. Whenever I write to flash
location, it seems to work only if I first Erase the sector, prepare the
sector and then write whereas the LPC2148 User Manual seems to indicate
that only preparing the sector is sufficient (erase is not required).
I find that if I do not erase, not all data is written. Only some of the
bytes are written properly and some are not.

Am I missing anything? Is it required to erase the sector before writing to
it?

Please advise.

Regards,
Kiran.


An Engineer's Guide to the LPC2100 Series

Hi,

> I have a program running on LPC2148. There is a requirement to store some
> of the user data onto Flash.
>
> I'm using the IAP commands to do the same. Whenever I write to flash
> location, it seems to work only if I first Erase the sector, prepare the
> sector and then write whereas the LPC2148 User Manual seems to indicate
> that only preparing the sector is sufficient (erase is not required).
> I find that if I do not erase, not all data is written. Only some of the
> bytes are written properly and some are not.
>
> Am I missing anything? Is it required to erase the sector before writing
> to it?

Yes.

Flash memory can change one-bits to zero-bits in a programming cycle. And
most flash devices are specified with a cumulative programming time or cycle
count before you must erase the page after overprogramming.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
SolderCore Development Platform http://www.soldercore.com

Hi Paul -

Thanks for the reply.

Just to clarify, I'm using Sector 26 (0x7C000 onwards) of LPC2148 to write
user's configuration data - things like users language preference. Now user
is allowed to change this. What I am finding is that if the user change is
to be saved successfully to the sector 26 back, I have to erase the content
first and then write the changed content (of course by preparing first). It
is not enough to just prepare and write, the content does not get
successfully overwritten.

Is that correct?

Regards,
Kiran.
On Tue, Apr 9, 2013 at 4:00 PM, Paul Curtis wrote:

> Hi,
>
> > I have a program running on LPC2148. There is a requirement to store some
> > of the user data onto Flash.
> >
> > I'm using the IAP commands to do the same. Whenever I write to flash
> > location, it seems to work only if I first Erase the sector, prepare the
> > sector and then write whereas the LPC2148 User Manual seems to indicate
> > that only preparing the sector is sufficient (erase is not required).
> > I find that if I do not erase, not all data is written. Only some of the
> > bytes are written properly and some are not.
> >
> > Am I missing anything? Is it required to erase the sector before writing
> > to it?
>
> Yes.
>
> Flash memory can change one-bits to zero-bits in a programming cycle. And
> most flash devices are specified with a cumulative programming time or
> cycle
> count before you must erase the page after overprogramming.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> SolderCore Development Platform http://www.soldercore.com
>
>
> Just to clarify, I'm using Sector 26 (0x7C000 onwards) of LPC2148 to write
> user's configuration data - things like users language preference. Now
> user is allowed to change this. What I am finding is that if the user
> change is to be saved successfully to the sector 26 back, I have to erase
> the content first and then write the changed content (of course by
> preparing first). It is not enough to just prepare and write, the content
> does not get successfully overwritten.
>
> Is that correct?

If you are programming a second time, without erase, you will be disturbing
the ECC sideband associated with that sector which also has the
flip-1-to-zero-only (IIRC) and you won't be able to flip zeroes to ones in
your user data. So yes, you must prepare and erase the sector before
*over*writing it. This is covered in the LPC2148 manual, see "Flash content
protection mechanism".

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
SolderCore Development Platform http://www.soldercore.com

Just as Paul said: a write operation to the flash cannot change a 0 bit to a 1 bit, only the converse.
Typically, you have to erase the sector you are writing to if not blank.
Therefore yes, what you are doing is correct.

Hint: depending on your usage of flash, you may find it beneficial to use the "BLANK CHECK SECTORS" IAP command prior to writing. If not blank, erase the sector(s) then write.
--
Serge Zloto



Dear Kiran,

As per data sheet we can write at sector level. So whenever you want to
write any data in flash you have write it at sector level. So only few
bytes also you want to write then first you have to erase the sector. If
you dont want to erase previously data then first take that sector data in
RAM, add new data and then erase sector and write.

From,
Naresh Panchal
On Tue, Apr 9, 2013 at 3:56 PM, Kiran Karanki wrote:

> **
> Hi All -
>
> I have a program running on LPC2148. There is a requirement to store some
> of the user data onto Flash.
>
> I'm using the IAP commands to do the same. Whenever I write to flash
> location, it seems to work only if I first Erase the sector, prepare the
> sector and then write whereas the LPC2148 User Manual seems to indicate
> that only preparing the sector is sufficient (erase is not required).
> I find that if I do not erase, not all data is written. Only some of the
> bytes are written properly and some are not.
>
> Am I missing anything? Is it required to erase the sector before writing to
> it?
>
> Please advise.
>
> Regards,
> Kiran.
>
>
>
>
>

--
From,
Naresh Panchal



The 2024 Embedded Online Conference