Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [gmane.comp.hardware.arm.lpc2100] Partial (Less than 512 bytes) Flash Programming

2004-08-14 by chazeltopman

--- In lpc2000@yahoogroups.com, Frank Sergeant <frank@p...> wrote:
> "philips_apps" <philips_apps@y...> writes:
> 
> > > Regarding the discussion of writing 16 bytes at a time, is this for 
> > > the LPC2106 chip or for a different processor?
>  
> > It is for LPC 2104, 2105, 2106, 2114 2124 2119 2129 2194 2212 2214 
> > 2292 2294 
> 
> Ok, so the discussion applied to the chip I'm using, an LPC2106.
>   
> > Minumum write size is 512 bytes.
> 
> Ok, that agrees with the way I read the manual.  I guess I read the
> earlier posting with too much wishful thinking.
> 
> > Above mentioned approach will not work. You need to fill all bytes in 
> > the RAM buffer with 0xFF. Only change the 16 bytes you want to write. 
> > The modified 16 byte chunk must be aligned at 16 bytes boundary 
> > within the 512 bytes buffer. The corresponding 16 bytes in the Flash 
> > must  be 0xFF. If you want to write to a flash location that has 
> > already  been programmed then you must erase the sector.
> 
> Ok, I think I understand now.  Thank you 

 Here's an explanation in Forth which should make the algorithms
 clear.  This allows writing to a 16 byte aligned area when it is
 all 0xFF with just one write.  If the area is not clear, then it
 is copied, erased, modified and written.  This is just for writing
 16 bit values (FL!) but can be torn apart and adapted as needed.

HEX
: DUMBFL!  ( n \ a -- )  \ use erase and move
   DUP A>S S>A  ( sector address )
   DUP HERE OVER A>Z CMOVE  ( copy sector )
   DUP DUP A>Z FLERASE  ( erase old copy )
   DUP >R  - HERE + !  ( modify )
   HERE R> DUP A>Z FLMOVE ;

: NALIGN  ( a \ n -- a' )  1 -  DUP >R  +  R> NOT AND ;

: FL!  ( n \ a -- )  \ minimize flash operations but allow write always
   -1  OVER 10 NALIGN  10 OVER + SWAP  DO  I @ AND  4 +LOOP  NOT
   IF  DUMBFL!     \ must erase first then write
   ELSE  1FF NOT  OVER AND DUP >R  HERE 200 CMOVE  \ copy out sector
         R@ -  HERE + !      \ change location
         HERE R> 200 FLMOVE  \ update flash
   THEN ;

 Other words referenced:
  A>S  ( a -- s )   \ change address to sector#
  S>A  ( s -- )   \ change sector to start address of sector
  A>Z  ( a -- n )   \ use address to get sector size
  FLERASE  ( a \ n -- )  \ erase n bytes from address a
  FLMOVE  ( a1 \ a2 \ u -- )  \ copy u bytes from a1 to a2

 I use this on both the 2106 and the 2129.

 Rob

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.