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 #if defined(TARGET_LPC1768) 00033 00034 #define USER_FLASH_AREA_START FLASH_SECTOR_29 00035 #define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE_16_TO_29 * 1) 00036 00037 /* 00038 * memory map information is available in next URL also. 00039 * http://mbed.org/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h 00040 */ 00041 00042 /** Table for start adress of sectors 00043 * 00044 * LPC1768 internal flash memory sector numbers and addresses 00045 * 00046 * LPC1768 flash memory are and sector number/size 00047 * Table 568 "Sectors in a LPC17xx device", Section 5. "Sector numbers", usermanual 00048 * 00049 * 0x00000000 - 0x0007FFFF flash (29 sectors) 00050 * 00051 * Sector0: 0x00000000 - 0x00000FFF 4K 00052 * Sector1: 0x00001000 - 0x00001FFF 4K 00053 * Sector2: 0x00002000 - 0x00002FFF 4K 00054 * Sector3: 0x00003000 - 0x00003FFF 4K 00055 * Sector4: 0x00004000 - 0x00004FFF 4K 00056 * Sector5: 0x00005000 - 0x00005FFF 4K 00057 * Sector6: 0x00006000 - 0x00006FFF 4K 00058 * Sector7: 0x00007000 - 0x00007FFF 4K 00059 * Sector8: 0x00008000 - 0x00008FFF 4K 00060 * Sector9: 0x00009000 - 0x00009FFF 4K 00061 * Sector10: 0x0000A000 - 0x0000AFFF 4K 00062 * Sector11: 0x0000B000 - 0x0000BFFF 4K 00063 * Sector12: 0x0000C000 - 0x0000CFFF 4K 00064 * Sector13: 0x0000D000 - 0x0000DFFF 4K 00065 * Sector14: 0x0000E000 - 0x0000EFFF 4K 00066 * Sector15: 0x0000F000 - 0x0000FFFF 4K 00067 * 00068 * Sector16: 0x00010000 - 0x00017FFF 32K 00069 * Sector17: 0x00018000 - 0x0001FFFF 32K 00070 * Sector18: 0x00020000 - 0x00027FFF 32K 00071 * Sector19: 0x00028000 - 0x0002FFFF 32K 00072 * Sector20: 0x00030000 - 0x00037FFF 32K 00073 * Sector21: 0x00038000 - 0x0003FFFF 32K 00074 * Sector22: 0x00040000 - 0x00047FFF 32K 00075 * Sector23: 0x00048000 - 0x0004FFFF 32K 00076 * Sector24: 0x00050000 - 0x00057FFF 32K 00077 * Sector25: 0x00058000 - 0x0005FFFF 32K 00078 * Sector26: 0x00060000 - 0x00067FFF 32K 00079 * Sector27: 0x00068000 - 0x0006FFFF 32K 00080 * Sector28: 0x00070000 - 0x00077FFF 32K 00081 * Sector29: 0x00078000 - 0x0007FFFF 32K 00082 */ 00083 00084 #define FLASH_SECTOR_0 0x00000000 00085 #define FLASH_SECTOR_1 0x00001000 00086 #define FLASH_SECTOR_2 0x00002000 00087 #define FLASH_SECTOR_3 0x00003000 00088 #define FLASH_SECTOR_4 0x00004000 00089 #define FLASH_SECTOR_5 0x00005000 00090 #define FLASH_SECTOR_6 0x00006000 00091 #define FLASH_SECTOR_7 0x00007000 00092 #define FLASH_SECTOR_8 0x00008000 00093 #define FLASH_SECTOR_9 0x00009000 00094 #define FLASH_SECTOR_10 0x0000A000 00095 #define FLASH_SECTOR_11 0x0000B000 00096 #define FLASH_SECTOR_12 0x0000C000 00097 #define FLASH_SECTOR_13 0x0000D000 00098 #define FLASH_SECTOR_14 0x0000E000 00099 #define FLASH_SECTOR_15 0x0000F000 00100 #define FLASH_SECTOR_16 0x00010000 00101 #define FLASH_SECTOR_17 0x00018000 00102 #define FLASH_SECTOR_18 0x00020000 00103 #define FLASH_SECTOR_19 0x00028000 00104 #define FLASH_SECTOR_20 0x00030000 00105 #define FLASH_SECTOR_21 0x00038000 00106 #define FLASH_SECTOR_22 0x00040000 00107 #define FLASH_SECTOR_23 0x00048000 00108 #define FLASH_SECTOR_24 0x00050000 00109 #define FLASH_SECTOR_25 0x00058000 00110 #define FLASH_SECTOR_26 0x00060000 00111 #define FLASH_SECTOR_27 0x00068000 00112 #define FLASH_SECTOR_28 0x00070000 00113 #define FLASH_SECTOR_29 0x00078000 00114 #define FLASH_SECTOR_SIZE_0_TO_15 ( 4 * 1024) 00115 #define FLASH_SECTOR_SIZE_16_TO_29 (32 * 1024) 00116 00117 static char * sector_start_adress[] = { 00118 (char *)FLASH_SECTOR_0, 00119 (char *)FLASH_SECTOR_1, 00120 (char *)FLASH_SECTOR_2, 00121 (char *)FLASH_SECTOR_3, 00122 (char *)FLASH_SECTOR_4, 00123 (char *)FLASH_SECTOR_5, 00124 (char *)FLASH_SECTOR_6, 00125 (char *)FLASH_SECTOR_7, 00126 (char *)FLASH_SECTOR_8, 00127 (char *)FLASH_SECTOR_9, 00128 (char *)FLASH_SECTOR_10, 00129 (char *)FLASH_SECTOR_11, 00130 (char *)FLASH_SECTOR_12, 00131 (char *)FLASH_SECTOR_13, 00132 (char *)FLASH_SECTOR_14, 00133 (char *)FLASH_SECTOR_15, 00134 (char *)FLASH_SECTOR_16, 00135 (char *)FLASH_SECTOR_17, 00136 (char *)FLASH_SECTOR_18, 00137 (char *)FLASH_SECTOR_19, 00138 (char *)FLASH_SECTOR_20, 00139 (char *)FLASH_SECTOR_21, 00140 (char *)FLASH_SECTOR_22, 00141 (char *)FLASH_SECTOR_23, 00142 (char *)FLASH_SECTOR_24, 00143 (char *)FLASH_SECTOR_25, 00144 (char *)FLASH_SECTOR_26, 00145 (char *)FLASH_SECTOR_27, 00146 (char *)FLASH_SECTOR_28, 00147 (char *)FLASH_SECTOR_29 00148 }; 00149 00150 #elif defined(TARGET_LPC11U24) 00151 00152 #define USER_FLASH_AREA_START FLASH_SECTOR_7 00153 #define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE * 1) 00154 00155 /** Table for start adress of sectors 00156 * 00157 * LPC11U24 internal flash memory sector numbers and addresses 00158 * 00159 * LPC11U24 flash memory are and sector number/size 00160 * Table 334 "LPC11U1x/2x flash sectors", Section 20. "Sector numbers", usermanual 00161 * 00162 * 0x00000000 - 0x00007FFF flash (8 sectors) 00163 * 00164 * Sector0: 0x00000000 - 0x00000FFF 4K 00165 * Sector1: 0x00001000 - 0x00001FFF 4K 00166 * Sector2: 0x00002000 - 0x00002FFF 4K 00167 * Sector3: 0x00003000 - 0x00003FFF 4K 00168 * Sector4: 0x00004000 - 0x00004FFF 4K 00169 * Sector5: 0x00005000 - 0x00005FFF 4K 00170 * Sector6: 0x00006000 - 0x00006FFF 4K 00171 * Sector7: 0x00007000 - 0x00007FFF 4K 00172 */ 00173 00174 #define FLASH_SECTOR_0 0x00000000 00175 #define FLASH_SECTOR_1 0x00001000 00176 #define FLASH_SECTOR_2 0x00002000 00177 #define FLASH_SECTOR_3 0x00003000 00178 #define FLASH_SECTOR_4 0x00004000 00179 #define FLASH_SECTOR_5 0x00005000 00180 #define FLASH_SECTOR_6 0x00006000 00181 #define FLASH_SECTOR_7 0x00007000 00182 #define FLASH_SECTOR_SIZE (4 * 1024) 00183 00184 static char * sector_start_adress[] = { 00185 (char *)FLASH_SECTOR_0, 00186 (char *)FLASH_SECTOR_1, 00187 (char *)FLASH_SECTOR_2, 00188 (char *)FLASH_SECTOR_3, 00189 (char *)FLASH_SECTOR_4, 00190 (char *)FLASH_SECTOR_5, 00191 (char *)FLASH_SECTOR_6, 00192 (char *)FLASH_SECTOR_7, 00193 }; 00194 00195 #endif 00196 00197 00198 /** Error code by IAP routine 00199 * 00200 * Table 588 "ISP Return Codes Summary", Section 7.15 "ISP Return Codes", usermanual 00201 */ 00202 00203 enum error_code 00204 { 00205 CMD_SUCCESS, 00206 INVALID_COMMAND, 00207 SRC_ADDR_ERROR, 00208 DST_ADDR_ERROR, 00209 SRC_ADDR_NOT_MAPPED, 00210 DST_ADDR_NOT_MAPPED, 00211 COUNT_ERROR, 00212 INVALID_SECTOR, 00213 SECTOR_NOT_BLANK, 00214 SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION, 00215 COMPARE_ERROR, 00216 BUSY, 00217 PARAM_ERROR, 00218 ADDR_ERROR, 00219 ADDR_NOT_MAPPED, 00220 CMD_LOCKED, 00221 INVALID_CODE, 00222 INVALID_BAUD_RATE, 00223 INVALID_STOP_BIT, 00224 CODE_READ_PROTECTION_ENABLED 00225 }; 00226 00227 00228 00229 /* 00230 * IAP routine entry 00231 * 00232 * "IAP commands" 00233 */ 00234 00235 #define IAP_LOCATION 0x1fff1ff1 00236 typedef void (*IAP_call)(unsigned int [], unsigned int []); 00237 00238 /** IAP class 00239 * 00240 * Interface for internal flash memory access 00241 */ 00242 00243 00244 class IAP { 00245 public: 00246 00247 /* 00248 * SystemCoreClock ??? : 00249 * http://mbed.org/forum/mbed/topic/229/ 00250 * http://mbed.org/users/simon/programs/SystemCoreClock/16mhsh/ 00251 */ 00252 00253 00254 /** Constructor for IAP 00255 * 00256 */ 00257 00258 IAP() : iap_entry( reinterpret_cast<IAP_call>(IAP_LOCATION) ), cclk_kHz( SystemCoreClock / 1000 ) {} 00259 int reinvoke_isp( void ); 00260 int read_ID( void ); 00261 int read_serial( void ); 00262 int blank_check( int start, int end ); 00263 int erase( int start, int end ); 00264 int prepare( int start, int end ); 00265 int write( char *source_addr, char *target_addr, int size ); 00266 int compare( char *source_addr, char *target_addr, int size ); 00267 int read_BootVer( void ); 00268 00269 char *reserved_flash_area_start( void ); 00270 int reserved_flash_area_size( void ); 00271 00272 #if defined(TARGET_LPC11U24) 00273 int write_eeprom( char *source_addr, char *target_addr, int size ); 00274 int read_eeprom( char *source_addr, char *target_addr, int size ); 00275 #endif 00276 00277 private: 00278 IAP_call iap_entry; 00279 unsigned int IAP_command[ 5 ]; 00280 unsigned int IAP_result[ 5 ]; 00281 int cclk_kHz; 00282 00283 //int cpu_clock( void ); 00284 } 00285 ; 00286 00287 #endif // #ifndef MBED_IAP
Generated on Thu Jul 14 2022 06:21:59 by
1.7.2
