I have the following code for my LPC2138 that writes to RAM, writes to ROM through IAP call, and then checks to see if it wrote to RAM and ROM correctly:
void testMem(){ unsigned char index; unsigned command[5]; unsigned result[5]; int i; char Ram_Arry[] = "Hello World "; char* Ram_Pointer; u08 text[11]; u08 text2[20] = "WHAT THE ABCDEFG"; IAP iap_bypointer; iap_bypointer = (IAP) 0x7FFFFFF1; //set IAP entry address in function pointer Ram_Pointer = (char*) 0x40004000; //Set pointer to RAM for (index = 0; index<0x0C; index++){ //Copy data to be written to flash into the RAM *Ram_Pointer = Ram_Arry[index]; Ram_Pointer++; } command[0] = 50; //Prepare sector five for a write operayion command[1] = 15; command[2] = 15; iap_bypointer(command,result); clearScreen(); switch(result[0]) { case 0: writeText("success "); break; default: writeText("something went wrong "); break; } command[0] = 51; //write 256 bytes from address 0x40004000 command[1] = 0x00040000; //to 0x00005000 in flash memory; command[2] = 0x40004000; command[3] = 256; command[4] = 14000; // see erase comment above iap_bypointer(command,result); switch(result[0]) { case 0: writeText("success "); break; default: writeText("something went wrong "); break; } Ram_Pointer = (char*)0x40004000; for(i=0; i<12; i++) { text[i] = *Ram_Pointer; Ram_Pointer++; } delay(DELAY_WAIT); Ram_Pointer = (char*)0x00040000; memcpy(&text2, &(*Ram_Pointer), 11); /* for(i=0; i<11; i++) { text2[i] = *Ram_Pointer; Ram_Pointer++; } */ i2cMasterSendNI(0x50, 0xC, text); i2cMasterSendNI(0x50, 0x14, (u08*)text2); }
This output's to my LCD as:
success success Hello World @(@@' ABCDEFG"
I thought you just read from Flash by simply giving the address location of the data you wish to copy? I'm sure I'm missing something small, but if you can't see anything wrong with my code, can you outline the process for reading from flash into RAM?
Thanks for responding and helping me solve my issue. I have taken your advice and cleaned up my code. Here is the revised copy of it:
void testMem(){ unsigned char index; unsigned command[5]; unsigned result[5]; int i; int len; u08 hexlen; char Ram_Arry[] = "Hello World"; char* Ram_Pointer; char* Rom_Pointer; u08 text[20]; u08 text2[20]; IAP iap_bypointer; iap_bypointer = (IAP) 0x7FFFFFF1; //set IAP entry address in function pointer Ram_Pointer = (char*) 0x40004000; //Set pointer to RAM len = strlen(Ram_Arry) + 1; for (index = 0; index<len; index++){ //Copy data to be written to flash into the RAM *Ram_Pointer = Ram_Arry[index]; Ram_Pointer++; } command[0] = 50; //Prepare sector five for a write operayion command[1] = 15; command[2] = 15; iap_bypointer(command,result); clearScreen(); switch(result[0]) { case 0: writeText("success "); break; default: writeText("something went wrong "); break; } command[0] = 51; //write 256 bytes from address 0x40004000 command[1] = 0x00040000; //to 0x00005000 in flash memory; command[2] = 0x40004000; command[3] = 256; command[4] = 14000; // see erase comment above iap_bypointer(command,result); switch(result[0]) { case 0: writeText("success "); break; default: writeText("something went wrong "); break; } Ram_Pointer = (char*)0x40004000; for(i=0; i<len; i++) { text[i] = *Ram_Pointer; Ram_Pointer++; } delay(DELAY_WAIT); Rom_Pointer = (char*)0x00040000; for(i=0; i<len; i++) { text2[i] = *Rom_Pointer; Rom_Pointer++; } if(strlen((const char*)text) == 11) writeText("equal "); if(strlen((const char*)text2) == 0) writeText("zero "); else writeText("not zero "); hexlen = intToHex(len); text[len-1] = '\0'; text2[len-1] = '\0'; i2cMasterSendNI(0x50, hexlen, text); i2cMasterSendNI(0x50, hexlen, text2); }
Output:
success success equal zero Hello World@(@@h
This is what this code is suppose to do: - Write "Hello World" to specified RAM location 0x40004000 - Call IAP function "Write from RAM to Flash" from RAM 0x40004000 to Flash 0x00040000 (sector 15) - Check to make sure "Hello World" was written to RAM by printing to my LCD - Check to make sure "Hello World" was written to Flash by printing to my LCD -Inserted a couple debug statements to try and figure out my problem.
Unfortunately, the last statement fails, and I can't figure out what is causing this problem. I realize now that you reference data from Flash by simply using pointers. The only other problem would be interrupts or syntax error? This issue is crucial to the functionality of our device, and any further questions I will respond with as much detail as possible.
Also, I don't/can't use the debugger b/c I do not own the full version of Keil Tools. That is why I am just writing to my LCD screen to check for a specific condition or return value.