EmbeddedRelated.com
Forums

LPC214x read internal flash

Started by Dominik February 19, 2012
Hi. all.
I have question for all who use IAP in own code.
I download some code (sparcfun) - usb SD card bootloader.
If connect to USB then mass storage detect and if copy new firmware and unplug USB then upload file from SD card to internal flash.
In LPC2148 is :
sector 0 to 7 4kB size
sector 8 to 21 32kB size
sector 22 to 26 4kB size.

Now if want use some sector like eeprom and store some information then:
example :
use last sector 26 , then on first I must read this sector to ram -> change data -> prepare sector -> erase sector -> prepare sector -> store data from ram to sector ??? and if is sector 4kB then if use 512byte buffer do it 8x.
is it true???

and what about Error Correction Code?? in sector what is used only for storage data is not used ECC?

have any one sample how to read data from internal flash to buffer???
need this for test if data are write to flash.

and code protection??? how I can write specific code to defined address for code read protection???
in my code must possible define direct place in flash and data for this place.

any one help???

best regards

An Engineer's Guide to the LPC2100 Series

--- In l..., "Dominik" wrote:
>
> Hi. all.
> I have question for all who use IAP in own code.
> I download some code (sparcfun) - usb SD card bootloader.
> If connect to USB then mass storage detect and if copy new firmware and unplug USB then upload file from SD card to internal flash.
> In LPC2148 is :
> sector 0 to 7 4kB size
> sector 8 to 21 32kB size
> sector 22 to 26 4kB size.
>
> Now if want use some sector like eeprom and store some information then:
> example :
> use last sector 26 , then on first I must read this sector to ram -> change data -> prepare sector -> erase sector -> prepare sector -> store data from ram to sector ??? and if is sector 4kB then if use 512byte buffer do it 8x.
> is it true???
>
> and what about Error Correction Code?? in sector what is used only for storage data is not used ECC?
>
> have any one sample how to read data from internal flash to buffer???
> need this for test if data are write to flash.
>
> and code protection??? how I can write specific code to defined address for code read protection???
> in my code must possible define direct place in flash and data for this place.
>
> any one help???
>
> best regards
>
I would recommend the LPC2148 demo code from www.jcwren.com/arm There is code for IAP.

Richard

Indeed to change a value in flash you need to:
Read to ram -> modify in ram -> Prepare sector -> erase sector -> Prepare sector -> write ram to flash

However you can only clear an entire sector (in this case 4K).
Which means that your buffer in ram needs to be 4K.
However writing to flash can be done in smaller blocks.

Keep in mind that this is relatively slow, interrupts need to be disabled and the flash can only be written to 10000 times.

As to reading from flash, just use a pointer (no need to use IAP to read).

I would also recommend to change the link script so that your code cannot be placed in the sectors you use for data storage.
--- In l..., "Dominik" wrote:
>
> Hi. all.
> I have question for all who use IAP in own code.
> I download some code (sparcfun) - usb SD card bootloader.
> If connect to USB then mass storage detect and if copy new firmware and unplug USB then upload file from SD card to internal flash.
> In LPC2148 is :
> sector 0 to 7 4kB size
> sector 8 to 21 32kB size
> sector 22 to 26 4kB size.
>
> Now if want use some sector like eeprom and store some information then:
> example :
> use last sector 26 , then on first I must read this sector to ram -> change data -> prepare sector -> erase sector -> prepare sector -> store data from ram to sector ??? and if is sector 4kB then if use 512byte buffer do it 8x.
> is it true???
>
> and what about Error Correction Code?? in sector what is used only for storage data is not used ECC?
>
> have any one sample how to read data from internal flash to buffer???
> need this for test if data are write to flash.
>
> and code protection??? how I can write specific code to defined address for code read protection???
> in my code must possible define direct place in flash and data for this place.
>
> any one help???
>
> best regards
>

HI

As Kevin points out
memcpy (flash_pointer, buffer, sizeof(buffer));
will copy flash back to buffer.

The Flash in the LPC2xxx has ECC built in and so extra ECC is not really needed (see http://tech.groups.yahoo.com/group/lpc2000/message/2681 )

Generally the LPC2xxx Flash is not very appropriate for FAT. It's granularity is very large and inconsistent and so it is possible to hold about one one small file in such a FAT, with the main parts of memory used for the FAT table and other information in a very inefficient manner. If FAT is used it is best on an SD card via SPI (or SDIO when the chip support is) (huge space) or on an ATMEL AT45DBxxx Flash via SPI (264, 524, 1048 byte pages for sectors plus ECC storage).

Regards

Mark

--- In l..., "Dominik" wrote:
>
> Hi. all.
> I have question for all who use IAP in own code.
> I download some code (sparcfun) - usb SD card bootloader.
> If connect to USB then mass storage detect and if copy new firmware and unplug USB then upload file from SD card to internal flash.
> In LPC2148 is :
> sector 0 to 7 4kB size
> sector 8 to 21 32kB size
> sector 22 to 26 4kB size.
>
> Now if want use some sector like eeprom and store some information then:
> example :
> use last sector 26 , then on first I must read this sector to ram -> change data -> prepare sector -> erase sector -> prepare sector -> store data from ram to sector ??? and if is sector 4kB then if use 512byte buffer do it 8x.
> is it true???
>
> and what about Error Correction Code?? in sector what is used only for storage data is not used ECC?
>
> have any one sample how to read data from internal flash to buffer???
> need this for test if data are write to flash.
>
> and code protection??? how I can write specific code to defined address for code read protection???
> in my code must possible define direct place in flash and data for this place.
>
> any one help???
>
> best regards
>