Sample code for how to erase/write LPC1768, LPC11U24, LPC1114, LPC812 and LPC824 internal flash memory. This program uses IAP call of MCU's ROM routines. The IAP library also supports read/write of EEPROM in LPC11U24.

Dependencies:   mbed IAP

Sample code for how to erase/write LPC1768, LPC11U24, LPC1114, LPC812 and LPC824 internal flash memory. This program uses IAP call of MCU's ROM routines.

No filesystem interface available. This program is just an interface to flash erasing and writing. User need manage where to store the data in the flash area.

This IAP library supports read/write of EEPROM in LPC11U24.

More information available in
http://mbed.org/users/okano/notebook/iap-in-application-programming-internal-flash-eras/

Revision:
2:c22f0c87fee6
Parent:
1:a85b51eeb446
Child:
3:63a0993315e5
--- a/main.cpp	Mon Nov 26 04:02:14 2012 +0000
+++ b/main.cpp	Mon Nov 26 06:03:39 2012 +0000
@@ -38,6 +38,8 @@
  *        revision 1.1  12-Mar-2010   chaged: to make possible to reserve flash area for user
  *                                            it can be set by USER_FLASH_AREA_START and USER_FLASH_AREA_SIZE in IAP.h
  *        revision 2.0  26-Nov.2012   LPC11U24 code added
+ *        revision 2.1  26-Nov-2012   EEPROM access code imported from Suga koubou san's (http://mbed.org/users/okini3939/) library
+ *                                            http://mbed.org/users/okini3939/code/M0_EEPROM_test/
  */
 
 #include    "mbed.h"
@@ -49,6 +51,7 @@
 #define     TARGET_SECTOR    29     //  use sector 29 as target sector if it is on LPC1768
 #elif defined(TARGET_LPC11U24)
 #define     TARGET_SECTOR    7      //  use sector  7 as target sector if it is on LPC11U24
+#define     TARGET_EEPROM_ADDRESS   64
 #endif
 
 void    memdump( char *p, int n );
@@ -111,6 +114,25 @@
 
     printf( "showing the flash contents...\r\n" );
     memdump( sector_start_adress[ TARGET_SECTOR ], MEM_SIZE * 3 );
+    
+#if defined(TARGET_LPC11U24)    //  SAMPLE OF EEPROM ACCESS (LPC11U24 only)
+    printf( "IAP: EEPROM writing test\r\n" );
+    char    mem2[ MEM_SIZE ];
+
+    r   = iap.write_eeprom( mem, (char*)TARGET_EEPROM_ADDRESS, MEM_SIZE );
+    printf( "copied: SRAM(0x%08X)->EEPROM(0x%08X) for %d bytes. (result=0x%08X)\r\n", mem, TARGET_EEPROM_ADDRESS, MEM_SIZE, r );
+ 
+    r   = iap.read_eeprom( (char*)TARGET_EEPROM_ADDRESS, mem2, MEM_SIZE );
+    printf( "copied: EEPROM(0x%08X)->SRAM(0x%08X) for %d bytes. (result=0x%08X)\r\n", TARGET_EEPROM_ADDRESS, mem, MEM_SIZE, r );
+ 
+    // compare
+    r = memcmp(mem, mem2, MEM_SIZE);
+    printf( "compare result     = \"%s\"\r\n", r ? "FAILED" : "OK" );
+ 
+    printf( "showing the EEPROM contents...\r\n" );
+    memdump( mem2, MEM_SIZE );
+#endif
+
 }