lpcware

IAP copy RAM to Flash problem with 32KB sectors

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 18, 2016 by lpcware
Content originally posted in LPCWare by mostafanfs on Mon Apr 11 08:48:47 MST 2016
LPC1778 has 30 sectors numbered sector #0 to sector #29 . The first 16th sectors (0 to 15) are 4KB wide and remains sectors are 32KB wide (16 to 28). Sector #29 is where bootloader functions resides. So we leave it just there.

Now I have new firmware in RAM in a 4KB buffer. There is no problem with 4KB sectors (0 to 15). First I prepare them for writing then simply copy buffer in RAM to the desired sector. And it works just fine.

Problem begins when I try to copy buffer in RAM into 32KB sectors (16 to 28). Because I have 4KB of data in RAM each time and when I prepare a sector for writing (say sector 16 which is 32KB) I can write to first 4KB of that sector. Then when I want to copy the next 4KB it returns that sector has not been prepared for writing which kind of makes sense considering I just wrote into its first 4KB address.
So I figured I call prepare function on a 32KB sector 8 times (that is 32/4 = 8). Each time before writing a 4KB into a 32KB sector.
But I think it's not the right thing to do because I believe it corrupts the data that has already been written to the sector whenever I try to prepare that sector for another 4KB writing. (because prepare function needs sector numbers NOT memory addresses)

So you see what I'm dealing with here. I'm gonna ask one more time. How can I copy 4KB data (size of buffer) from RAM into a 32KB sector correctly?

Outcomes