Thanks Peter....... My Apology for not putting the
Code in proper format ......
I want to implement the functionality of IAP in LPC2214.... for testing purpose I have taken the sample code from keil..... C:\Keil\ARM\Flash\LPC_IAP_256...In this code I have tried to erase all the sector & write data . I am able to erase all the sectors & write the data successfully.......except sector 0 ? as I try to erase sector 0 and write some data on it ......... it erases all the sectors and not data has been written ? The sample code form keil is ...... As You can see in the main function, we have disable the Interrupt function .........
/* IAP Download Function */
#include "FlashOS.H" // FlashOS Structures
#define M8(adr) (*((volatile unsigned char *) (adr)))
void IAP_download(void);
volatile int ret; // Return Code unsigned char TempBuf[1024] = " CMS CMS CMS "; static unsigned char TempBuf2[1024]; unsigned int Cnt;
void IAP_download (void ) { unsigned long n; unsigned short Cnt; ret = Init(0, 48000000, 1); //ret |= EraseChip();
ret |= EraseSector(0x00000000);
ret |= EraseSector(0x00002000);
ret |= EraseSector(0x00004000);
ret |= EraseSector(0x00006000);
ret |= EraseSector(0x00008000);
ret |= EraseSector(0x0000A000);
ret |= EraseSector(0x0000C000);
ret |= EraseSector(0x0000E000);
ret |= EraseSector(0x00010000);
ret |= EraseSector(0x00020000);
ret |= EraseSector(0x00030000);
ret |= EraseSector(0x00032000);
ret |= EraseSector(0x00034000);
ret |= EraseSector(0x00036000);
ret |= EraseSector(0x00038000);
ret |= EraseSector(0x0003A000);
ret |= EraseSector(0x0003C000);
/* Fill the buffer for writeing in Flash Sector */
for (n = 0; n < 1024; n++)
{
buf[n] = ( unsigned char )n;
}
for (Cnt = 0; Cnt <1024; Cnt++)
TempBuf2[Cnt] = '*';
ret |= ProgramPage(0x00000000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x00002000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x00004000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x00006000 ,1024, (unsigned char *)TempBuf );
ret |= ProgramPage(0x00008000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x0000A000 ,1024, (unsigned char *)TempBuf );
ret |= ProgramPage(0x0000C000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x0000E000 ,1024, (unsigned char *)TempBuf );
ret |= ProgramPage(0x00010000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x00020000 ,1024, (unsigned char *)TempBuf );
ret |= ProgramPage(0x00030000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x00032000 ,1024, (unsigned char *)TempBuf );
ret |= ProgramPage(0x00034000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x00036000 ,1024, (unsigned char *)TempBuf );
ret |= ProgramPage(0x00038000 ,1024, (unsigned char *)TempBuf2 );
ret |= ProgramPage(0x0003A000 ,1024, (unsigned char *)TempBuf );
ret |= ProgramPage(0x0003C000 ,1024, (unsigned char *)TempBuf2 );
while (1); // Wait forever }
/* Main Function */
#include <lpc21xx.h> #include <stdio.h> #include "FlashOS.H"
extern void IAP_download(void);
int main(void)
IODIR0 = 0xFFFFFFFF;
IODIR1 = 0xFFFFFFFF;
//#pragma arm
VICIntEnClr = 0xFFFFFFFF; // Disable all interrupt IAP_download( );
// #pragma thumb
while (1); }
/* FlashDev.c Function */
struct FlashDevice const FlashDevice =
FLASH_DRV_VERS, // Driver Version, do not modify!
"LPC2000 IAP 256kB Flash", // Device Name
ONCHIP, // Device Type
0x00000000, // Device Start Address
0x0003E000, // Device Size without Boot Loader
// (248kB)
1024, // Programming Page Size
0, // Reserved, must be 0
0xFF, // Initial Content of Erased Memory
100, // Program Page Timeout 100 mSec
3000, // Erase Sector Timeout 3000 mSec
// Specify Size and Address of Sectors
0x002000, 0x000000, // Sector Size 8kB (8 Sectors)
0x010000, 0x010000, // Sector Size 64kB (2 Sectors)
0x002000, 0x030000, // Sector Size 8kB (7 Sectors)
SECTOR_END };