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.
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/
Diff: main.cpp
- Revision:
- 1:a85b51eeb446
- Parent:
- 0:b802bd2f4cc9
- Child:
- 2:c22f0c87fee6
--- a/main.cpp Fri Mar 12 10:24:57 2010 +0000 +++ b/main.cpp Mon Nov 26 04:02:14 2012 +0000 @@ -1,12 +1,19 @@ /** IAP demo : demo code for internal Flash memory access library * - * The internal Flash memory access is described in the LPC1768 usermanual. + * The internal Flash memory access is described in the LPC1768 and LPC11U24 usermanual. * http://www.nxp.com/documents/user_manual/UM10360.pdf + * http://www.nxp.com/documents/user_manual/UM10462.pdf * - * Chapter 2: "LPC17xx Memory map" - * Chapter 32: "LPC17xx Flash memory interface and programming" - * refering Rev. 01 - 4 January 2010 - * + * LPC1768 -- + * Chapter 2: "LPC17xx Memory map" + * Chapter 32: "LPC17xx Flash memory interface and programming" + * refering Rev. 01 - 4 January 2010 + * + * LPC11U24 -- + * Chapter 2: "LPC11Uxx Memory mapping" + * Chapter 20: "LPC11Uxx Flash programming firmware" + * refering Rev. 03 - 16 July 2012 + * * This main.cpp demonstrates how the flash can be erased and wrote. * * This program tries to... @@ -25,18 +32,24 @@ * The SRAM memory should be allocated in * * - * Released under the MIT License: http://mbed.org/license/mit + * Released under the MIT License: http://mbed.org/license/mit * * revision 1.0 09-Mar-2010 1st release * 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 */ #include "mbed.h" #include "IAP.h" #define MEM_SIZE 256 -#define TARGET_SECTOR 29 + +#if defined(TARGET_LPC1768) +#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 +#endif void memdump( char *p, int n ); int isprint( int c ); @@ -48,9 +61,10 @@ char mem[ MEM_SIZE ]; // memory, it should be aligned to word boundary int r; - printf( "IAP: Flash memory writing test\n" ); - printf( " device-ID = 0x%08X, serial# = 0x%08X, CPU running %dkHz\n", iap.read_ID(), iap.read_serial(), SystemCoreClock / 1000 ); - printf( " user reserved flash area: start_address=0x%08X, size=%d bytes\n", iap.reserved_flash_area_start(), iap.reserved_flash_area_size() ); + printf( "IAP: Flash memory writing test\r\n" ); + printf( " device-ID = 0x%08X, serial# = 0x%08X, CPU running %dkHz\r\n", iap.read_ID(), iap.read_serial(), SystemCoreClock / 1000 ); + printf( " user reserved flash area: start_address=0x%08X, size=%d bytes\r\n", iap.reserved_flash_area_start(), iap.reserved_flash_area_size() ); + printf( " read_BootVer=0x%08X\r\r\n", iap.read_BootVer() ); for ( int i = 0; i < MEM_SIZE; i++ ) mem[ i ] = i & 0xFF; @@ -58,26 +72,26 @@ // blank check: The mbed will erase all flash contents after downloading new executable r = iap.blank_check( TARGET_SECTOR, TARGET_SECTOR ); - printf( "blank check result = 0x%08X\n", r ); + printf( "blank check result = 0x%08X\r\n", r ); // erase sector, if required if ( r == SECTOR_NOT_BLANK ) { iap.prepare( TARGET_SECTOR, TARGET_SECTOR ); r = iap.erase( TARGET_SECTOR, TARGET_SECTOR ); - printf( "erase result = 0x%08X\n", r ); + printf( "erase result = 0x%08X\r\n", r ); } // copy RAM to Flash iap.prepare( TARGET_SECTOR, TARGET_SECTOR ); r = iap.write( mem, sector_start_adress[ TARGET_SECTOR ], MEM_SIZE ); - printf( "copied: SRAM(0x%08X)->Flash(0x%08X) for %d bytes. (result=0x%08X)\n", mem, sector_start_adress[ TARGET_SECTOR ], MEM_SIZE, r ); + printf( "copied: SRAM(0x%08X)->Flash(0x%08X) for %d bytes. (result=0x%08X)\r\n", mem, sector_start_adress[ TARGET_SECTOR ], MEM_SIZE, r ); // compare r = iap.compare( mem, sector_start_adress[ TARGET_SECTOR ], MEM_SIZE ); - printf( "compare result = \"%s\"\n", r ? "FAILED" : "OK" ); + printf( "compare result = \"%s\"\r\n", r ? "FAILED" : "OK" ); //#define WRITE_NEXT_BLOCK #ifdef WRITE_NEXT_BLOCK @@ -86,16 +100,16 @@ iap.prepare( TARGET_SECTOR, TARGET_SECTOR ); r = iap.write( mem, sector_start_adress[ TARGET_SECTOR ] + 256, MEM_SIZE ); - printf( "copied: SRAM(0x%08X)->Flash(0x%08X) for %d bytes. (result=0x%08X)\n", mem, sector_start_adress[ TARGET_SECTOR ], MEM_SIZE, r ); + printf( "copied: SRAM(0x%08X)->Flash(0x%08X) for %d bytes. (result=0x%08X)\r\n", mem, sector_start_adress[ TARGET_SECTOR ], MEM_SIZE, r ); // compare r = iap.compare( mem, sector_start_adress[ TARGET_SECTOR ] + 256, MEM_SIZE ); - printf( "compare result = \"%s\"\n", r ? "FAILED" : "OK" ); + printf( "compare result = \"%s\"\r\n", r ? "FAILED" : "OK" ); #endif - printf( "showing the flash contents...\n" ); + printf( "showing the flash contents...\r\n" ); memdump( sector_start_adress[ TARGET_SECTOR ], MEM_SIZE * 3 ); } @@ -109,10 +123,10 @@ for ( int i = 0; i < (n >> 2); i++, p++ ) { if ( !(i % 4) ) - printf( "\n 0x%08X :", (unsigned int)p ); + printf( "\r\n 0x%08X :", (unsigned int)p ); printf( " 0x%08X", *p ); } - printf( "\n" ); + printf( "\r\n" ); }