Hi,
I want to implement the functionality of IAP in LPC2214.... for testing purpose I have taken the sample code form keil..... 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 ......
void IAP_download(void);
volatile int ret; // Return Code static unsigned char buf[1024]; // Programming Buffer 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(); // Test Full Chip Erase
ret |= EraseSector(0x00000000); // Test Sector Erase ( 8kB Sector 0) ret |= EraseSector(0x00002000); // Test Sector Erase ( 8kB Sector 1) ret |= EraseSector(0x00004000); // Test Sector Erase ( 8kB Sector 2) ret |= EraseSector(0x00006000); // Test Sector Erase ( 8kB Sector 3) ret |= EraseSector(0x00008000); // Test Sector Erase ( 8kB Sector 4) ret |= EraseSector(0x0000A000); // Test Sector Erase ( 8kB Sector 5) ret |= EraseSector(0x0000C000); // Test Sector Erase ( 8kB Sector 6) ret |= EraseSector(0x0000E000); // Test Sector Erase ( 8kB Sector 7)
ret |= EraseSector(0x00010000); // Test Sector Erase (64kB Sector 8) ret |= EraseSector(0x00020000); // Test Sector Erase (64kB Sector 9)
ret |= EraseSector(0x00030000); // Test Sector Erase ( 8kB Sector 10) ret |= EraseSector(0x00032000); // Test Sector Erase ( 8kB Sector 11) ret |= EraseSector(0x00034000); // Test Sector Erase ( 8kB Sector 12) ret |= EraseSector(0x00036000); // Test Sector Erase ( 8kB Sector 13) ret |= EraseSector(0x00038000); // Test Sector Erase ( 8kB Sector 14) ret |= EraseSector(0x0003A000); // Test Sector Erase ( 8kB Sector 15) ret |= EraseSector(0x0003C000); // Test Sector Erase ( 8kB Sector 16)
// Programming Test Pattern for (n = 0; n < 1024; n++) { buf[n] = ( unsigned char )n; } // Programming Test Pattern 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 */ //This is for testing of IAP routines for LPC2366 //Sector 0x00038000 #include <lpc21xx.h> #include <stdio.h> #include "FlashOS.H"
#define M8(adr) (*((volatile unsigned char *) (adr)))
extern void IAP_download(void);
int main(void) { IODIR0 = 0xFFFFFFFF; IODIR1 = 0xFFFFFFFF; //#pragma arm VICIntEnClr = 0xFFFFFFFF; // Disable all interrupt // added by Mustafa IAP_download( ); // #pragma thumb while (1); }
/* FlasDev.c function */
#include "FlashOS.H" // FlashOS Structures
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 };
This thread continues here: http://www.keil.com/forum/docs/thread14715.asp