Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of IAP by
IAP.h
00001 /** IAP : internal Flash memory access library 00002 * 00003 * The internal Flash memory access is described in the LPC1768 and LPC11U24 usermanual. 00004 * http://www.nxp.com/documents/user_manual/UM10360.pdf 00005 * http://www.nxp.com/documents/user_manual/UM10462.pdf 00006 * 00007 * LPC1768 -- 00008 * Chapter 2: "LPC17xx Memory map" 00009 * Chapter 32: "LPC17xx Flash memory interface and programming" 00010 * refering Rev. 01 - 4 January 2010 00011 * 00012 * LPC11U24 -- 00013 * Chapter 2: "LPC11Uxx Memory mapping" 00014 * Chapter 20: "LPC11Uxx Flash programming firmware" 00015 * refering Rev. 03 - 16 July 2012 00016 * 00017 * Released under the MIT License: http://mbed.org/license/mit 00018 * 00019 * revision 1.0 09-Mar-2010 1st release 00020 * revision 1.1 12-Mar-2010 chaged: to make possible to reserve flash area for user 00021 * it can be set by USER_FLASH_AREA_START and USER_FLASH_AREA_SIZE in IAP.h 00022 * revision 2.0 26-Nov.2012 LPC11U24 code added 00023 * revision 2.1 26-Nov-2012 EEPROM access code imported from Suga koubou san's (http://mbed.org/users/okini3939/) library 00024 * http://mbed.org/users/okini3939/code/M0_EEPROM_test/ 00025 */ 00026 00027 #ifndef MBED_IAP 00028 #define MBED_IAP 00029 00030 #include "mbed.h" 00031 00032 #define LPC11U24_EEPROM_ONLY 00033 00034 #if defined(TARGET_LPC1768) 00035 00036 #define USER_FLASH_AREA_START FLASH_SECTOR_29 00037 #define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE_16_TO_29 * 1) 00038 00039 /* 00040 * memory map information is available in next URL also. 00041 * http://mbed.org/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h 00042 */ 00043 00044 /** Table for start adress of sectors 00045 * 00046 * LPC1768 internal flash memory sector numbers and addresses 00047 * 00048 * LPC1768 flash memory are and sector number/size 00049 * Table 568 "Sectors in a LPC17xx device", Section 5. "Sector numbers", usermanual 00050 * 00051 * 0x00000000 - 0x0007FFFF flash (29 sectors) 00052 * 00053 * Sector0: 0x00000000 - 0x00000FFF 4K 00054 * Sector1: 0x00001000 - 0x00001FFF 4K 00055 * Sector2: 0x00002000 - 0x00002FFF 4K 00056 * Sector3: 0x00003000 - 0x00003FFF 4K 00057 * Sector4: 0x00004000 - 0x00004FFF 4K 00058 * Sector5: 0x00005000 - 0x00005FFF 4K 00059 * Sector6: 0x00006000 - 0x00006FFF 4K 00060 * Sector7: 0x00007000 - 0x00007FFF 4K 00061 * Sector8: 0x00008000 - 0x00008FFF 4K 00062 * Sector9: 0x00009000 - 0x00009FFF 4K 00063 * Sector10: 0x0000A000 - 0x0000AFFF 4K 00064 * Sector11: 0x0000B000 - 0x0000BFFF 4K 00065 * Sector12: 0x0000C000 - 0x0000CFFF 4K 00066 * Sector13: 0x0000D000 - 0x0000DFFF 4K 00067 * Sector14: 0x0000E000 - 0x0000EFFF 4K 00068 * Sector15: 0x0000F000 - 0x0000FFFF 4K 00069 * 00070 * Sector16: 0x00010000 - 0x00017FFF 32K 00071 * Sector17: 0x00018000 - 0x0001FFFF 32K 00072 * Sector18: 0x00020000 - 0x00027FFF 32K 00073 * Sector19: 0x00028000 - 0x0002FFFF 32K 00074 * Sector20: 0x00030000 - 0x00037FFF 32K 00075 * Sector21: 0x00038000 - 0x0003FFFF 32K 00076 * Sector22: 0x00040000 - 0x00047FFF 32K 00077 * Sector23: 0x00048000 - 0x0004FFFF 32K 00078 * Sector24: 0x00050000 - 0x00057FFF 32K 00079 * Sector25: 0x00058000 - 0x0005FFFF 32K 00080 * Sector26: 0x00060000 - 0x00067FFF 32K 00081 * Sector27: 0x00068000 - 0x0006FFFF 32K 00082 * Sector28: 0x00070000 - 0x00077FFF 32K 00083 * Sector29: 0x00078000 - 0x0007FFFF 32K 00084 */ 00085 00086 #define FLASH_SECTOR_0 0x00000000 00087 #define FLASH_SECTOR_1 0x00001000 00088 #define FLASH_SECTOR_2 0x00002000 00089 #define FLASH_SECTOR_3 0x00003000 00090 #define FLASH_SECTOR_4 0x00004000 00091 #define FLASH_SECTOR_5 0x00005000 00092 #define FLASH_SECTOR_6 0x00006000 00093 #define FLASH_SECTOR_7 0x00007000 00094 #define FLASH_SECTOR_8 0x00008000 00095 #define FLASH_SECTOR_9 0x00009000 00096 #define FLASH_SECTOR_10 0x0000A000 00097 #define FLASH_SECTOR_11 0x0000B000 00098 #define FLASH_SECTOR_12 0x0000C000 00099 #define FLASH_SECTOR_13 0x0000D000 00100 #define FLASH_SECTOR_14 0x0000E000 00101 #define FLASH_SECTOR_15 0x0000F000 00102 #define FLASH_SECTOR_16 0x00010000 00103 #define FLASH_SECTOR_17 0x00018000 00104 #define FLASH_SECTOR_18 0x00020000 00105 #define FLASH_SECTOR_19 0x00028000 00106 #define FLASH_SECTOR_20 0x00030000 00107 #define FLASH_SECTOR_21 0x00038000 00108 #define FLASH_SECTOR_22 0x00040000 00109 #define FLASH_SECTOR_23 0x00048000 00110 #define FLASH_SECTOR_24 0x00050000 00111 #define FLASH_SECTOR_25 0x00058000 00112 #define FLASH_SECTOR_26 0x00060000 00113 #define FLASH_SECTOR_27 0x00068000 00114 #define FLASH_SECTOR_28 0x00070000 00115 #define FLASH_SECTOR_29 0x00078000 00116 #define FLASH_SECTOR_SIZE_0_TO_15 ( 4 * 1024) 00117 #define FLASH_SECTOR_SIZE_16_TO_29 (32 * 1024) 00118 00119 static char * sector_start_adress[] = { 00120 (char *)FLASH_SECTOR_0, 00121 (char *)FLASH_SECTOR_1, 00122 (char *)FLASH_SECTOR_2, 00123 (char *)FLASH_SECTOR_3, 00124 (char *)FLASH_SECTOR_4, 00125 (char *)FLASH_SECTOR_5, 00126 (char *)FLASH_SECTOR_6, 00127 (char *)FLASH_SECTOR_7, 00128 (char *)FLASH_SECTOR_8, 00129 (char *)FLASH_SECTOR_9, 00130 (char *)FLASH_SECTOR_10, 00131 (char *)FLASH_SECTOR_11, 00132 (char *)FLASH_SECTOR_12, 00133 (char *)FLASH_SECTOR_13, 00134 (char *)FLASH_SECTOR_14, 00135 (char *)FLASH_SECTOR_15, 00136 (char *)FLASH_SECTOR_16, 00137 (char *)FLASH_SECTOR_17, 00138 (char *)FLASH_SECTOR_18, 00139 (char *)FLASH_SECTOR_19, 00140 (char *)FLASH_SECTOR_20, 00141 (char *)FLASH_SECTOR_21, 00142 (char *)FLASH_SECTOR_22, 00143 (char *)FLASH_SECTOR_23, 00144 (char *)FLASH_SECTOR_24, 00145 (char *)FLASH_SECTOR_25, 00146 (char *)FLASH_SECTOR_26, 00147 (char *)FLASH_SECTOR_27, 00148 (char *)FLASH_SECTOR_28, 00149 (char *)FLASH_SECTOR_29 00150 }; 00151 00152 #elif defined(TARGET_LPC11U24) 00153 00154 #define USER_FLASH_AREA_START FLASH_SECTOR_7 00155 #define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE * 1) 00156 00157 /** Table for start adress of sectors 00158 * 00159 * LPC11U24 internal flash memory sector numbers and addresses 00160 * 00161 * LPC11U24 flash memory are and sector number/size 00162 * Table 334 "LPC11U1x/2x flash sectors", Section 20. "Sector numbers", usermanual 00163 * 00164 * 0x00000000 - 0x00007FFF flash (8 sectors) 00165 * 00166 * Sector0: 0x00000000 - 0x00000FFF 4K 00167 * Sector1: 0x00001000 - 0x00001FFF 4K 00168 * Sector2: 0x00002000 - 0x00002FFF 4K 00169 * Sector3: 0x00003000 - 0x00003FFF 4K 00170 * Sector4: 0x00004000 - 0x00004FFF 4K 00171 * Sector5: 0x00005000 - 0x00005FFF 4K 00172 * Sector6: 0x00006000 - 0x00006FFF 4K 00173 * Sector7: 0x00007000 - 0x00007FFF 4K 00174 */ 00175 00176 #define FLASH_SECTOR_0 0x00000000 00177 #define FLASH_SECTOR_1 0x00001000 00178 #define FLASH_SECTOR_2 0x00002000 00179 #define FLASH_SECTOR_3 0x00003000 00180 #define FLASH_SECTOR_4 0x00004000 00181 #define FLASH_SECTOR_5 0x00005000 00182 #define FLASH_SECTOR_6 0x00006000 00183 #define FLASH_SECTOR_7 0x00007000 00184 #define FLASH_SECTOR_SIZE (4 * 1024) 00185 00186 static char * sector_start_adress[] = { 00187 (char *)FLASH_SECTOR_0, 00188 (char *)FLASH_SECTOR_1, 00189 (char *)FLASH_SECTOR_2, 00190 (char *)FLASH_SECTOR_3, 00191 (char *)FLASH_SECTOR_4, 00192 (char *)FLASH_SECTOR_5, 00193 (char *)FLASH_SECTOR_6, 00194 (char *)FLASH_SECTOR_7, 00195 }; 00196 00197 #endif 00198 00199 00200 /** Error code by IAP routine 00201 * 00202 * Table 588 "ISP Return Codes Summary", Section 7.15 "ISP Return Codes", usermanual 00203 */ 00204 00205 enum error_code 00206 { 00207 CMD_SUCCESS, 00208 INVALID_COMMAND, 00209 SRC_ADDR_ERROR, 00210 DST_ADDR_ERROR, 00211 SRC_ADDR_NOT_MAPPED, 00212 DST_ADDR_NOT_MAPPED, 00213 COUNT_ERROR, 00214 INVALID_SECTOR, 00215 SECTOR_NOT_BLANK, 00216 SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION, 00217 COMPARE_ERROR, 00218 BUSY, 00219 PARAM_ERROR, 00220 ADDR_ERROR, 00221 ADDR_NOT_MAPPED, 00222 CMD_LOCKED, 00223 INVALID_CODE, 00224 INVALID_BAUD_RATE, 00225 INVALID_STOP_BIT, 00226 CODE_READ_PROTECTION_ENABLED 00227 }; 00228 00229 00230 00231 /* 00232 * IAP routine entry 00233 * 00234 * "IAP commands" 00235 */ 00236 00237 #define IAP_LOCATION 0x1fff1ff1 00238 typedef void (*IAP_call)(unsigned int [], unsigned int []); 00239 00240 /** IAP class 00241 * 00242 * Interface for internal flash memory access 00243 */ 00244 00245 00246 class IAP { 00247 public: 00248 00249 /* 00250 * SystemCoreClock ??? : 00251 * http://mbed.org/forum/mbed/topic/229/ 00252 * http://mbed.org/users/simon/programs/SystemCoreClock/16mhsh/ 00253 */ 00254 00255 00256 /** Constructor for IAP 00257 * 00258 */ 00259 00260 IAP() : iap_entry( reinterpret_cast<IAP_call>(IAP_LOCATION) ), cclk_kHz( SystemCoreClock / 1000 ) {} 00261 int read_ID( void ); 00262 int read_serial( void ); 00263 #ifndef LPC11U24_EEPROM_ONLY 00264 int blank_check( int start, int end ); 00265 int erase( int start, int end ); 00266 int prepare( int start, int end ); 00267 int write( char *source_addr, char *target_addr, int size ); 00268 int compare( char *source_addr, char *target_addr, int size ); 00269 int read_BootVer( void ); 00270 00271 char *reserved_flash_area_start( void ); 00272 int reserved_flash_area_size( void ); 00273 #endif 00274 00275 #if defined(TARGET_LPC11U24) 00276 int write_eeprom( char *source_addr, char *target_addr, int size ); 00277 int read_eeprom( char *source_addr, char *target_addr, int size ); 00278 #endif 00279 00280 private: 00281 IAP_call iap_entry; 00282 unsigned int IAP_command[ 5 ]; 00283 unsigned int IAP_result[ 5 ]; 00284 int cclk_kHz; 00285 00286 //int cpu_clock( void ); 00287 } 00288 ; 00289 00290 #endif // #ifndef MBED_IAP
Generated on Sun Jul 17 2022 01:45:45 by
1.7.2
