supported LPC11U35

Fork of IAP by Tedd OKANO

Committer:
okini3939
Date:
Thu Dec 01 01:58:30 2016 +0000
Revision:
8:568aa0b1dc9e
Parent:
7:c8bf974ecb33
supported LPC11U35

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:ada7fb504504 1 /** IAP : internal Flash memory access library
okano 0:ada7fb504504 2 *
okano 2:17f3464672c1 3 * The internal Flash memory access is described in the LPC1768 and LPC11U24 usermanual.
okano 0:ada7fb504504 4 * http://www.nxp.com/documents/user_manual/UM10360.pdf
okano 0:ada7fb504504 5 * http://www.nxp.com/documents/user_manual/UM10462.pdf
okano 0:ada7fb504504 6 *
okano 0:ada7fb504504 7 * LPC1768 --
okano 0:ada7fb504504 8 * Chapter 2: "LPC17xx Memory map"
okano 0:ada7fb504504 9 * Chapter 32: "LPC17xx Flash memory interface and programming"
okano 0:ada7fb504504 10 * refering Rev. 01 - 4 January 2010
okano 2:17f3464672c1 11 *
okano 0:ada7fb504504 12 * LPC11U24 --
okano 0:ada7fb504504 13 * Chapter 2: "LPC11Uxx Memory mapping"
okano 0:ada7fb504504 14 * Chapter 20: "LPC11Uxx Flash programming firmware"
okano 0:ada7fb504504 15 * refering Rev. 03 - 16 July 2012
okano 2:17f3464672c1 16 *
okano 0:ada7fb504504 17 * Released under the MIT License: http://mbed.org/license/mit
okano 0:ada7fb504504 18 *
okano 0:ada7fb504504 19 * revision 1.0 09-Mar-2010 1st release
okano 0:ada7fb504504 20 * revision 1.1 12-Mar-2010 chaged: to make possible to reserve flash area for user
okano 0:ada7fb504504 21 * it can be set by USER_FLASH_AREA_START and USER_FLASH_AREA_SIZE in IAP.h
okano 2:17f3464672c1 22 * revision 2.0 26-Nov-2012 LPC11U24 code added
okano 1:ff906ad52cf9 23 * revision 2.1 26-Nov-2012 EEPROM access code imported from Suga koubou san's (http://mbed.org/users/okini3939/) library
okano 1:ff906ad52cf9 24 * http://mbed.org/users/okini3939/code/M0_EEPROM_test/
okano 4:cee1a2a734c9 25 * revision 3.0 09-Jan-2015 LPC812 and LPC824 support added
okano 4:cee1a2a734c9 26 * revision 3.1 13-Jan-2015 LPC1114 support added
okano 4:cee1a2a734c9 27 * revision 3.1.1 16-Jan-2015 Target MCU name changed for better compatibility across the platforms
okano 0:ada7fb504504 28 */
okano 0:ada7fb504504 29
okano 2:17f3464672c1 30
okano 0:ada7fb504504 31 #ifndef MBED_IAP
okano 0:ada7fb504504 32 #define MBED_IAP
okano 0:ada7fb504504 33
okano 0:ada7fb504504 34 #include "mbed.h"
okano 0:ada7fb504504 35
okano 4:cee1a2a734c9 36 #if defined(TARGET_LPC176X)
okano 0:ada7fb504504 37
okano 0:ada7fb504504 38 #define USER_FLASH_AREA_START FLASH_SECTOR_29
okano 0:ada7fb504504 39 #define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE_16_TO_29 * 1)
okano 0:ada7fb504504 40
okano 0:ada7fb504504 41 /*
okano 0:ada7fb504504 42 * memory map information is available in next URL also.
okano 0:ada7fb504504 43 * http://mbed.org/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h
okano 0:ada7fb504504 44 */
okano 2:17f3464672c1 45
okano 0:ada7fb504504 46 /** Table for start adress of sectors
okano 2:17f3464672c1 47 *
okano 0:ada7fb504504 48 * LPC1768 internal flash memory sector numbers and addresses
okano 0:ada7fb504504 49 *
okano 0:ada7fb504504 50 * LPC1768 flash memory are and sector number/size
okano 0:ada7fb504504 51 * Table 568 "Sectors in a LPC17xx device", Section 5. "Sector numbers", usermanual
okano 0:ada7fb504504 52 *
okano 0:ada7fb504504 53 * 0x00000000 - 0x0007FFFF flash (29 sectors)
okano 0:ada7fb504504 54 *
okano 0:ada7fb504504 55 * Sector0: 0x00000000 - 0x00000FFF 4K
okano 0:ada7fb504504 56 * Sector1: 0x00001000 - 0x00001FFF 4K
okano 0:ada7fb504504 57 * Sector2: 0x00002000 - 0x00002FFF 4K
okano 0:ada7fb504504 58 * Sector3: 0x00003000 - 0x00003FFF 4K
okano 0:ada7fb504504 59 * Sector4: 0x00004000 - 0x00004FFF 4K
okano 0:ada7fb504504 60 * Sector5: 0x00005000 - 0x00005FFF 4K
okano 0:ada7fb504504 61 * Sector6: 0x00006000 - 0x00006FFF 4K
okano 0:ada7fb504504 62 * Sector7: 0x00007000 - 0x00007FFF 4K
okano 0:ada7fb504504 63 * Sector8: 0x00008000 - 0x00008FFF 4K
okano 0:ada7fb504504 64 * Sector9: 0x00009000 - 0x00009FFF 4K
okano 0:ada7fb504504 65 * Sector10: 0x0000A000 - 0x0000AFFF 4K
okano 0:ada7fb504504 66 * Sector11: 0x0000B000 - 0x0000BFFF 4K
okano 0:ada7fb504504 67 * Sector12: 0x0000C000 - 0x0000CFFF 4K
okano 0:ada7fb504504 68 * Sector13: 0x0000D000 - 0x0000DFFF 4K
okano 0:ada7fb504504 69 * Sector14: 0x0000E000 - 0x0000EFFF 4K
okano 0:ada7fb504504 70 * Sector15: 0x0000F000 - 0x0000FFFF 4K
okano 0:ada7fb504504 71 *
okano 0:ada7fb504504 72 * Sector16: 0x00010000 - 0x00017FFF 32K
okano 0:ada7fb504504 73 * Sector17: 0x00018000 - 0x0001FFFF 32K
okano 0:ada7fb504504 74 * Sector18: 0x00020000 - 0x00027FFF 32K
okano 0:ada7fb504504 75 * Sector19: 0x00028000 - 0x0002FFFF 32K
okano 0:ada7fb504504 76 * Sector20: 0x00030000 - 0x00037FFF 32K
okano 0:ada7fb504504 77 * Sector21: 0x00038000 - 0x0003FFFF 32K
okano 0:ada7fb504504 78 * Sector22: 0x00040000 - 0x00047FFF 32K
okano 0:ada7fb504504 79 * Sector23: 0x00048000 - 0x0004FFFF 32K
okano 0:ada7fb504504 80 * Sector24: 0x00050000 - 0x00057FFF 32K
okano 0:ada7fb504504 81 * Sector25: 0x00058000 - 0x0005FFFF 32K
okano 0:ada7fb504504 82 * Sector26: 0x00060000 - 0x00067FFF 32K
okano 0:ada7fb504504 83 * Sector27: 0x00068000 - 0x0006FFFF 32K
okano 0:ada7fb504504 84 * Sector28: 0x00070000 - 0x00077FFF 32K
okano 0:ada7fb504504 85 * Sector29: 0x00078000 - 0x0007FFFF 32K
okano 0:ada7fb504504 86 */
okano 0:ada7fb504504 87
okano 0:ada7fb504504 88 #define FLASH_SECTOR_0 0x00000000
okano 0:ada7fb504504 89 #define FLASH_SECTOR_1 0x00001000
okano 0:ada7fb504504 90 #define FLASH_SECTOR_2 0x00002000
okano 0:ada7fb504504 91 #define FLASH_SECTOR_3 0x00003000
okano 0:ada7fb504504 92 #define FLASH_SECTOR_4 0x00004000
okano 0:ada7fb504504 93 #define FLASH_SECTOR_5 0x00005000
okano 0:ada7fb504504 94 #define FLASH_SECTOR_6 0x00006000
okano 0:ada7fb504504 95 #define FLASH_SECTOR_7 0x00007000
okano 0:ada7fb504504 96 #define FLASH_SECTOR_8 0x00008000
okano 0:ada7fb504504 97 #define FLASH_SECTOR_9 0x00009000
okano 0:ada7fb504504 98 #define FLASH_SECTOR_10 0x0000A000
okano 0:ada7fb504504 99 #define FLASH_SECTOR_11 0x0000B000
okano 0:ada7fb504504 100 #define FLASH_SECTOR_12 0x0000C000
okano 0:ada7fb504504 101 #define FLASH_SECTOR_13 0x0000D000
okano 0:ada7fb504504 102 #define FLASH_SECTOR_14 0x0000E000
okano 0:ada7fb504504 103 #define FLASH_SECTOR_15 0x0000F000
okano 0:ada7fb504504 104 #define FLASH_SECTOR_16 0x00010000
okano 0:ada7fb504504 105 #define FLASH_SECTOR_17 0x00018000
okano 0:ada7fb504504 106 #define FLASH_SECTOR_18 0x00020000
okano 0:ada7fb504504 107 #define FLASH_SECTOR_19 0x00028000
okano 0:ada7fb504504 108 #define FLASH_SECTOR_20 0x00030000
okano 0:ada7fb504504 109 #define FLASH_SECTOR_21 0x00038000
okano 0:ada7fb504504 110 #define FLASH_SECTOR_22 0x00040000
okano 0:ada7fb504504 111 #define FLASH_SECTOR_23 0x00048000
okano 0:ada7fb504504 112 #define FLASH_SECTOR_24 0x00050000
okano 0:ada7fb504504 113 #define FLASH_SECTOR_25 0x00058000
okano 0:ada7fb504504 114 #define FLASH_SECTOR_26 0x00060000
okano 0:ada7fb504504 115 #define FLASH_SECTOR_27 0x00068000
okano 0:ada7fb504504 116 #define FLASH_SECTOR_28 0x00070000
okano 0:ada7fb504504 117 #define FLASH_SECTOR_29 0x00078000
okano 0:ada7fb504504 118 #define FLASH_SECTOR_SIZE_0_TO_15 ( 4 * 1024)
okano 0:ada7fb504504 119 #define FLASH_SECTOR_SIZE_16_TO_29 (32 * 1024)
okano 0:ada7fb504504 120
okano 0:ada7fb504504 121 static char * sector_start_adress[] = {
okano 0:ada7fb504504 122 (char *)FLASH_SECTOR_0,
okano 0:ada7fb504504 123 (char *)FLASH_SECTOR_1,
okano 0:ada7fb504504 124 (char *)FLASH_SECTOR_2,
okano 0:ada7fb504504 125 (char *)FLASH_SECTOR_3,
okano 0:ada7fb504504 126 (char *)FLASH_SECTOR_4,
okano 0:ada7fb504504 127 (char *)FLASH_SECTOR_5,
okano 0:ada7fb504504 128 (char *)FLASH_SECTOR_6,
okano 0:ada7fb504504 129 (char *)FLASH_SECTOR_7,
okano 0:ada7fb504504 130 (char *)FLASH_SECTOR_8,
okano 0:ada7fb504504 131 (char *)FLASH_SECTOR_9,
okano 0:ada7fb504504 132 (char *)FLASH_SECTOR_10,
okano 0:ada7fb504504 133 (char *)FLASH_SECTOR_11,
okano 0:ada7fb504504 134 (char *)FLASH_SECTOR_12,
okano 0:ada7fb504504 135 (char *)FLASH_SECTOR_13,
okano 0:ada7fb504504 136 (char *)FLASH_SECTOR_14,
okano 0:ada7fb504504 137 (char *)FLASH_SECTOR_15,
okano 0:ada7fb504504 138 (char *)FLASH_SECTOR_16,
okano 0:ada7fb504504 139 (char *)FLASH_SECTOR_17,
okano 0:ada7fb504504 140 (char *)FLASH_SECTOR_18,
okano 0:ada7fb504504 141 (char *)FLASH_SECTOR_19,
okano 0:ada7fb504504 142 (char *)FLASH_SECTOR_20,
okano 0:ada7fb504504 143 (char *)FLASH_SECTOR_21,
okano 0:ada7fb504504 144 (char *)FLASH_SECTOR_22,
okano 0:ada7fb504504 145 (char *)FLASH_SECTOR_23,
okano 0:ada7fb504504 146 (char *)FLASH_SECTOR_24,
okano 0:ada7fb504504 147 (char *)FLASH_SECTOR_25,
okano 0:ada7fb504504 148 (char *)FLASH_SECTOR_26,
okano 0:ada7fb504504 149 (char *)FLASH_SECTOR_27,
okano 0:ada7fb504504 150 (char *)FLASH_SECTOR_28,
okano 2:17f3464672c1 151 (char *)FLASH_SECTOR_29
okano 0:ada7fb504504 152 };
okano 0:ada7fb504504 153
okini3939 8:568aa0b1dc9e 154 #elif defined(TARGET_LPC11U35_401)
okini3939 8:568aa0b1dc9e 155
okini3939 8:568aa0b1dc9e 156 #define USER_FLASH_AREA_START FLASH_SECTOR_7
okini3939 8:568aa0b1dc9e 157 #define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE * 1)
okini3939 8:568aa0b1dc9e 158
okini3939 8:568aa0b1dc9e 159 #define FLASH_SECTOR_0 0x00000000
okini3939 8:568aa0b1dc9e 160 #define FLASH_SECTOR_1 0x00001000
okini3939 8:568aa0b1dc9e 161 #define FLASH_SECTOR_2 0x00002000
okini3939 8:568aa0b1dc9e 162 #define FLASH_SECTOR_3 0x00003000
okini3939 8:568aa0b1dc9e 163 #define FLASH_SECTOR_4 0x00004000
okini3939 8:568aa0b1dc9e 164 #define FLASH_SECTOR_5 0x00005000
okini3939 8:568aa0b1dc9e 165 #define FLASH_SECTOR_6 0x00006000
okini3939 8:568aa0b1dc9e 166 #define FLASH_SECTOR_7 0x00007000
okini3939 8:568aa0b1dc9e 167 #define FLASH_SECTOR_8 0x00008000
okini3939 8:568aa0b1dc9e 168 #define FLASH_SECTOR_9 0x00009000
okini3939 8:568aa0b1dc9e 169 #define FLASH_SECTOR_10 0x0000a000
okini3939 8:568aa0b1dc9e 170 #define FLASH_SECTOR_11 0x0000b000
okini3939 8:568aa0b1dc9e 171 #define FLASH_SECTOR_12 0x0000c000
okini3939 8:568aa0b1dc9e 172 #define FLASH_SECTOR_13 0x0000d000
okini3939 8:568aa0b1dc9e 173 #define FLASH_SECTOR_14 0x0000e000
okini3939 8:568aa0b1dc9e 174 #define FLASH_SECTOR_15 0x0000f000
okini3939 8:568aa0b1dc9e 175 #define FLASH_SECTOR_SIZE (4 * 1024)
okini3939 8:568aa0b1dc9e 176
okini3939 8:568aa0b1dc9e 177 static char * sector_start_adress[] = {
okini3939 8:568aa0b1dc9e 178 (char *)FLASH_SECTOR_0,
okini3939 8:568aa0b1dc9e 179 (char *)FLASH_SECTOR_1,
okini3939 8:568aa0b1dc9e 180 (char *)FLASH_SECTOR_2,
okini3939 8:568aa0b1dc9e 181 (char *)FLASH_SECTOR_3,
okini3939 8:568aa0b1dc9e 182 (char *)FLASH_SECTOR_4,
okini3939 8:568aa0b1dc9e 183 (char *)FLASH_SECTOR_5,
okini3939 8:568aa0b1dc9e 184 (char *)FLASH_SECTOR_6,
okini3939 8:568aa0b1dc9e 185 (char *)FLASH_SECTOR_7,
okini3939 8:568aa0b1dc9e 186 (char *)FLASH_SECTOR_8,
okini3939 8:568aa0b1dc9e 187 (char *)FLASH_SECTOR_9,
okini3939 8:568aa0b1dc9e 188 (char *)FLASH_SECTOR_10,
okini3939 8:568aa0b1dc9e 189 (char *)FLASH_SECTOR_11,
okini3939 8:568aa0b1dc9e 190 (char *)FLASH_SECTOR_12,
okini3939 8:568aa0b1dc9e 191 (char *)FLASH_SECTOR_13,
okini3939 8:568aa0b1dc9e 192 (char *)FLASH_SECTOR_14,
okini3939 8:568aa0b1dc9e 193 (char *)FLASH_SECTOR_15
okini3939 8:568aa0b1dc9e 194 };
okini3939 8:568aa0b1dc9e 195
okini3939 8:568aa0b1dc9e 196
okano 4:cee1a2a734c9 197 #elif defined(TARGET_LPC11UXX) || defined(TARGET_LPC11XX)
okano 0:ada7fb504504 198
okano 0:ada7fb504504 199 #define USER_FLASH_AREA_START FLASH_SECTOR_7
okano 0:ada7fb504504 200 #define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE * 1)
okano 2:17f3464672c1 201
okano 0:ada7fb504504 202 /** Table for start adress of sectors
okano 2:17f3464672c1 203 *
okano 0:ada7fb504504 204 * LPC11U24 internal flash memory sector numbers and addresses
okano 0:ada7fb504504 205 *
okano 0:ada7fb504504 206 * LPC11U24 flash memory are and sector number/size
okano 0:ada7fb504504 207 * Table 334 "LPC11U1x/2x flash sectors", Section 20. "Sector numbers", usermanual
okano 0:ada7fb504504 208 *
okano 0:ada7fb504504 209 * 0x00000000 - 0x00007FFF flash (8 sectors)
okano 0:ada7fb504504 210 *
okano 0:ada7fb504504 211 * Sector0: 0x00000000 - 0x00000FFF 4K
okano 0:ada7fb504504 212 * Sector1: 0x00001000 - 0x00001FFF 4K
okano 0:ada7fb504504 213 * Sector2: 0x00002000 - 0x00002FFF 4K
okano 0:ada7fb504504 214 * Sector3: 0x00003000 - 0x00003FFF 4K
okano 0:ada7fb504504 215 * Sector4: 0x00004000 - 0x00004FFF 4K
okano 0:ada7fb504504 216 * Sector5: 0x00005000 - 0x00005FFF 4K
okano 0:ada7fb504504 217 * Sector6: 0x00006000 - 0x00006FFF 4K
okano 0:ada7fb504504 218 * Sector7: 0x00007000 - 0x00007FFF 4K
okano 0:ada7fb504504 219 */
okano 0:ada7fb504504 220
okano 0:ada7fb504504 221 #define FLASH_SECTOR_0 0x00000000
okano 0:ada7fb504504 222 #define FLASH_SECTOR_1 0x00001000
okano 0:ada7fb504504 223 #define FLASH_SECTOR_2 0x00002000
okano 0:ada7fb504504 224 #define FLASH_SECTOR_3 0x00003000
okano 0:ada7fb504504 225 #define FLASH_SECTOR_4 0x00004000
okano 0:ada7fb504504 226 #define FLASH_SECTOR_5 0x00005000
okano 0:ada7fb504504 227 #define FLASH_SECTOR_6 0x00006000
okano 0:ada7fb504504 228 #define FLASH_SECTOR_7 0x00007000
okano 0:ada7fb504504 229 #define FLASH_SECTOR_SIZE (4 * 1024)
okano 0:ada7fb504504 230
okano 0:ada7fb504504 231 static char * sector_start_adress[] = {
okano 0:ada7fb504504 232 (char *)FLASH_SECTOR_0,
okano 0:ada7fb504504 233 (char *)FLASH_SECTOR_1,
okano 0:ada7fb504504 234 (char *)FLASH_SECTOR_2,
okano 0:ada7fb504504 235 (char *)FLASH_SECTOR_3,
okano 0:ada7fb504504 236 (char *)FLASH_SECTOR_4,
okano 0:ada7fb504504 237 (char *)FLASH_SECTOR_5,
okano 0:ada7fb504504 238 (char *)FLASH_SECTOR_6,
okano 0:ada7fb504504 239 (char *)FLASH_SECTOR_7,
okano 0:ada7fb504504 240 };
okano 0:ada7fb504504 241
okano 4:cee1a2a734c9 242 #elif defined(TARGET_LPC81X) || defined(TARGET_LPC82X)
okano 2:17f3464672c1 243
okano 2:17f3464672c1 244 #define USER_FLASH_AREA_START FLASH_SECTOR_15
okano 2:17f3464672c1 245 #define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE * 1)
okano 2:17f3464672c1 246
okano 2:17f3464672c1 247 /** Table for start adress of sectors
okano 2:17f3464672c1 248 *
okano 2:17f3464672c1 249 * LPC812/LPC824 internal flash memory sector numbers and addresses
okano 2:17f3464672c1 250 *
okano 2:17f3464672c1 251 * 0x00000000 - 0x00003FFF flash (16 sectors for LPC812)
okano 2:17f3464672c1 252 * 0x00000000 - 0x00007FFF flash (32 sectors for LPC824)
okano 2:17f3464672c1 253 *
okano 2:17f3464672c1 254 * Sector0: 0x00000000 - 0x000003FF 1K
okano 2:17f3464672c1 255 * Sector1: 0x00000400 - 0x000007FF 1K
okano 2:17f3464672c1 256 * Sector2: 0x00000800 - 0x00000BFF 1K
okano 2:17f3464672c1 257 * Sector3: 0x00000C00 - 0x00000FFF 1K
okano 2:17f3464672c1 258 * Sector4: 0x00001000 - 0x000013FF 1K
okano 2:17f3464672c1 259 * Sector5: 0x00001400 - 0x000017FF 1K
okano 2:17f3464672c1 260 * Sector6: 0x00001800 - 0x00001BFF 1K
okano 2:17f3464672c1 261 * Sector7: 0x00001C00 - 0x00001FFF 1K
okano 2:17f3464672c1 262 * Sector8: 0x00002000 - 0x000023FF 1K
okano 2:17f3464672c1 263 * Sector9: 0x00002400 - 0x000027FF 1K
okano 2:17f3464672c1 264 * Sector10: 0x00002800 - 0x00002BFF 1K
okano 2:17f3464672c1 265 * Sector11: 0x00002C00 - 0x00002FFF 1K
okano 2:17f3464672c1 266 * Sector12: 0x00003000 - 0x000033FF 1K
okano 2:17f3464672c1 267 * Sector13: 0x00003400 - 0x000037FF 1K
okano 2:17f3464672c1 268 * Sector14: 0x00003800 - 0x00003BFF 1K
okano 2:17f3464672c1 269 * Sector15: 0x00003C00 - 0x00003FFF 1K
okano 2:17f3464672c1 270 * Sector16: 0x00004000 - 0x000043FF 1K (LPC824 only)
okano 2:17f3464672c1 271 * Sector17: 0x00004400 - 0x000047FF 1K (LPC824 only)
okano 2:17f3464672c1 272 * Sector18: 0x00004800 - 0x00004BFF 1K (LPC824 only)
okano 2:17f3464672c1 273 * Sector19: 0x00004C00 - 0x00004FFF 1K (LPC824 only)
okano 2:17f3464672c1 274 * Sector20: 0x00005000 - 0x000053FF 1K (LPC824 only)
okano 2:17f3464672c1 275 * Sector21: 0x00005400 - 0x000057FF 1K (LPC824 only)
okano 2:17f3464672c1 276 * Sector22: 0x00005800 - 0x00005BFF 1K (LPC824 only)
okano 2:17f3464672c1 277 * Sector23: 0x00005C00 - 0x00005FFF 1K (LPC824 only)
okano 2:17f3464672c1 278 * Sector24: 0x00006000 - 0x000063FF 1K (LPC824 only)
okano 2:17f3464672c1 279 * Sector25: 0x00006400 - 0x000067FF 1K (LPC824 only)
okano 2:17f3464672c1 280 * Sector26: 0x00006800 - 0x00006BFF 1K (LPC824 only)
okano 2:17f3464672c1 281 * Sector27: 0x00006C00 - 0x00006FFF 1K (LPC824 only)
okano 2:17f3464672c1 282 * Sector28: 0x00007000 - 0x000073FF 1K (LPC824 only)
okano 2:17f3464672c1 283 * Sector29: 0x00007400 - 0x000077FF 1K (LPC824 only)
okano 2:17f3464672c1 284 * Sector30: 0x00007800 - 0x00007BFF 1K (LPC824 only)
okano 2:17f3464672c1 285 * Sector31: 0x00007C00 - 0x00007FFF 1K (LPC824 only)
okano 2:17f3464672c1 286 */
okano 2:17f3464672c1 287
okano 2:17f3464672c1 288 #define FLASH_SECTOR_0 0x00000000
okano 2:17f3464672c1 289 #define FLASH_SECTOR_1 0x00000400
okano 2:17f3464672c1 290 #define FLASH_SECTOR_2 0x00000800
okano 2:17f3464672c1 291 #define FLASH_SECTOR_3 0x00000C00
okano 2:17f3464672c1 292 #define FLASH_SECTOR_4 0x00001000
okano 2:17f3464672c1 293 #define FLASH_SECTOR_5 0x00001400
okano 2:17f3464672c1 294 #define FLASH_SECTOR_6 0x00001800
okano 2:17f3464672c1 295 #define FLASH_SECTOR_7 0x00001C00
okano 2:17f3464672c1 296 #define FLASH_SECTOR_8 0x00002000
okano 2:17f3464672c1 297 #define FLASH_SECTOR_9 0x00002400
okano 2:17f3464672c1 298 #define FLASH_SECTOR_10 0x00002800
okano 2:17f3464672c1 299 #define FLASH_SECTOR_11 0x00002C00
okano 2:17f3464672c1 300 #define FLASH_SECTOR_12 0x00003000
okano 2:17f3464672c1 301 #define FLASH_SECTOR_13 0x00003400
okano 2:17f3464672c1 302 #define FLASH_SECTOR_14 0x00003800
okano 2:17f3464672c1 303 #define FLASH_SECTOR_15 0x00003C00
okano 2:17f3464672c1 304 #define FLASH_SECTOR_16 0x00004000 // for LPC824 only
okano 2:17f3464672c1 305 #define FLASH_SECTOR_17 0x00004400 // for LPC824 only
okano 2:17f3464672c1 306 #define FLASH_SECTOR_18 0x00004800 // for LPC824 only
okano 2:17f3464672c1 307 #define FLASH_SECTOR_19 0x00004C00 // for LPC824 only
okano 2:17f3464672c1 308 #define FLASH_SECTOR_20 0x00005000 // for LPC824 only
okano 2:17f3464672c1 309 #define FLASH_SECTOR_21 0x00005400 // for LPC824 only
okano 2:17f3464672c1 310 #define FLASH_SECTOR_22 0x00005800 // for LPC824 only
okano 2:17f3464672c1 311 #define FLASH_SECTOR_23 0x00005C00 // for LPC824 only
okano 2:17f3464672c1 312 #define FLASH_SECTOR_24 0x00006000 // for LPC824 only
okano 2:17f3464672c1 313 #define FLASH_SECTOR_25 0x00006400 // for LPC824 only
okano 2:17f3464672c1 314 #define FLASH_SECTOR_26 0x00006800 // for LPC824 only
okano 2:17f3464672c1 315 #define FLASH_SECTOR_27 0x00006C00 // for LPC824 only
okano 2:17f3464672c1 316 #define FLASH_SECTOR_28 0x00007000 // for LPC824 only
okano 2:17f3464672c1 317 #define FLASH_SECTOR_29 0x00007400 // for LPC824 only
okano 2:17f3464672c1 318 #define FLASH_SECTOR_30 0x00007800 // for LPC824 only
okano 2:17f3464672c1 319 #define FLASH_SECTOR_31 0x00007C00 // for LPC824 only
okano 2:17f3464672c1 320 #define FLASH_SECTOR_SIZE (1 * 1024)
okano 2:17f3464672c1 321
okano 2:17f3464672c1 322 static char * sector_start_adress[] = {
okano 2:17f3464672c1 323 (char *)FLASH_SECTOR_0,
okano 2:17f3464672c1 324 (char *)FLASH_SECTOR_1,
okano 2:17f3464672c1 325 (char *)FLASH_SECTOR_2,
okano 2:17f3464672c1 326 (char *)FLASH_SECTOR_3,
okano 2:17f3464672c1 327 (char *)FLASH_SECTOR_4,
okano 2:17f3464672c1 328 (char *)FLASH_SECTOR_5,
okano 2:17f3464672c1 329 (char *)FLASH_SECTOR_6,
okano 2:17f3464672c1 330 (char *)FLASH_SECTOR_7,
okano 2:17f3464672c1 331 (char *)FLASH_SECTOR_8,
okano 2:17f3464672c1 332 (char *)FLASH_SECTOR_9,
okano 2:17f3464672c1 333 (char *)FLASH_SECTOR_10,
okano 2:17f3464672c1 334 (char *)FLASH_SECTOR_11,
okano 2:17f3464672c1 335 (char *)FLASH_SECTOR_12,
okano 2:17f3464672c1 336 (char *)FLASH_SECTOR_13,
okano 2:17f3464672c1 337 (char *)FLASH_SECTOR_14,
okano 2:17f3464672c1 338 (char *)FLASH_SECTOR_15,
okano 2:17f3464672c1 339 (char *)FLASH_SECTOR_16, // for LPC824 only
okano 2:17f3464672c1 340 (char *)FLASH_SECTOR_17, // for LPC824 only
okano 2:17f3464672c1 341 (char *)FLASH_SECTOR_18, // for LPC824 only
okano 2:17f3464672c1 342 (char *)FLASH_SECTOR_19, // for LPC824 only
okano 2:17f3464672c1 343 (char *)FLASH_SECTOR_20, // for LPC824 only
okano 2:17f3464672c1 344 (char *)FLASH_SECTOR_21, // for LPC824 only
okano 2:17f3464672c1 345 (char *)FLASH_SECTOR_22, // for LPC824 only
okano 2:17f3464672c1 346 (char *)FLASH_SECTOR_23, // for LPC824 only
okano 2:17f3464672c1 347 (char *)FLASH_SECTOR_24, // for LPC824 only
okano 2:17f3464672c1 348 (char *)FLASH_SECTOR_25, // for LPC824 only
okano 2:17f3464672c1 349 (char *)FLASH_SECTOR_26, // for LPC824 only
okano 2:17f3464672c1 350 (char *)FLASH_SECTOR_27, // for LPC824 only
okano 2:17f3464672c1 351 (char *)FLASH_SECTOR_28, // for LPC824 only
okano 2:17f3464672c1 352 (char *)FLASH_SECTOR_29, // for LPC824 only
okano 2:17f3464672c1 353 (char *)FLASH_SECTOR_30, // for LPC824 only
okano 2:17f3464672c1 354 (char *)FLASH_SECTOR_31 // for LPC824 only
okano 2:17f3464672c1 355 };
okano 2:17f3464672c1 356
okini3939 8:568aa0b1dc9e 357 #else
okini3939 8:568aa0b1dc9e 358 #error "Device"
okano 0:ada7fb504504 359 #endif
okano 0:ada7fb504504 360
okano 0:ada7fb504504 361 /** Error code by IAP routine
okano 2:17f3464672c1 362 *
okano 0:ada7fb504504 363 * Table 588 "ISP Return Codes Summary", Section 7.15 "ISP Return Codes", usermanual
okano 0:ada7fb504504 364 */
okano 0:ada7fb504504 365
okano 2:17f3464672c1 366 enum error_code {
okano 2:17f3464672c1 367 CMD_SUCCESS,
okano 2:17f3464672c1 368 INVALID_COMMAND,
okano 2:17f3464672c1 369 SRC_ADDR_ERROR,
okano 2:17f3464672c1 370 DST_ADDR_ERROR,
okano 2:17f3464672c1 371 SRC_ADDR_NOT_MAPPED,
okano 2:17f3464672c1 372 DST_ADDR_NOT_MAPPED,
okano 2:17f3464672c1 373 COUNT_ERROR,
okano 2:17f3464672c1 374 INVALID_SECTOR,
okano 2:17f3464672c1 375 SECTOR_NOT_BLANK,
okano 2:17f3464672c1 376 SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION,
okano 2:17f3464672c1 377 COMPARE_ERROR,
okano 2:17f3464672c1 378 BUSY,
okano 2:17f3464672c1 379 PARAM_ERROR,
okano 2:17f3464672c1 380 ADDR_ERROR,
okano 2:17f3464672c1 381 ADDR_NOT_MAPPED,
okano 2:17f3464672c1 382 CMD_LOCKED,
okano 2:17f3464672c1 383 INVALID_CODE,
okano 2:17f3464672c1 384 INVALID_BAUD_RATE,
okano 2:17f3464672c1 385 INVALID_STOP_BIT,
okano 2:17f3464672c1 386 CODE_READ_PROTECTION_ENABLED
okano 2:17f3464672c1 387 };
okano 0:ada7fb504504 388
okano 0:ada7fb504504 389
okano 0:ada7fb504504 390
okano 0:ada7fb504504 391 /*
okano 0:ada7fb504504 392 * IAP routine entry
okano 0:ada7fb504504 393 *
okano 0:ada7fb504504 394 * "IAP commands"
okano 0:ada7fb504504 395 */
okano 0:ada7fb504504 396
okano 0:ada7fb504504 397 #define IAP_LOCATION 0x1fff1ff1
okano 0:ada7fb504504 398 typedef void (*IAP_call)(unsigned int [], unsigned int []);
okano 0:ada7fb504504 399
okano 2:17f3464672c1 400
okano 0:ada7fb504504 401 /** IAP class
okano 2:17f3464672c1 402 *
okano 0:ada7fb504504 403 * Interface for internal flash memory access
okano 0:ada7fb504504 404 */
okano 0:ada7fb504504 405
okano 2:17f3464672c1 406 class IAP
okano 2:17f3464672c1 407 {
okano 0:ada7fb504504 408 public:
okano 0:ada7fb504504 409
okano 0:ada7fb504504 410 /** Constructor for IAP
okano 0:ada7fb504504 411 *
okano 0:ada7fb504504 412 */
okano 2:17f3464672c1 413 IAP() : iap_entry( reinterpret_cast<IAP_call>(IAP_LOCATION) ), cclk_kHz( SystemCoreClock / 1000 ) {}
okano 0:ada7fb504504 414
okano 7:c8bf974ecb33 415 /** Reinvoke ISP
okano 7:c8bf974ecb33 416 *
okano 7:c8bf974ecb33 417 * @return error code
okano 7:c8bf974ecb33 418 */
jaerts 5:7484398d50ea 419 int reinvoke_isp( void );
okano 7:c8bf974ecb33 420
okano 2:17f3464672c1 421 /** Read part identification number
okano 2:17f3464672c1 422 *
okano 2:17f3464672c1 423 * @return device ID
okano 2:17f3464672c1 424 * @see read_serial()
okano 2:17f3464672c1 425 */
okano 0:ada7fb504504 426 int read_ID( void );
okano 2:17f3464672c1 427
okano 2:17f3464672c1 428 /** Read device serial number
okano 2:17f3464672c1 429 *
okano 2:17f3464672c1 430 * @return device serial number
okano 2:17f3464672c1 431 * @see read_ID()
okano 2:17f3464672c1 432 */
sam_grove 6:f794a51897b8 433 int *read_serial( void );
okano 2:17f3464672c1 434
okano 2:17f3464672c1 435 /** Blank check sector(s)
okano 2:17f3464672c1 436 *
okano 2:17f3464672c1 437 * @param start a Start Sector Number
okano 2:17f3464672c1 438 * @param end an End Sector Number (should be greater than or equal to start sector number).
okano 2:17f3464672c1 439 * @return error code: CMD_SUCCESS | BUSY | SECTOR_NOT_BLANK | INVALID_SECTOR
okano 2:17f3464672c1 440 */
okano 0:ada7fb504504 441 int blank_check( int start, int end );
okano 2:17f3464672c1 442
okano 2:17f3464672c1 443 /** Erase Sector(s)
okano 2:17f3464672c1 444 *
okano 2:17f3464672c1 445 * @param start a Start Sector Number
okano 2:17f3464672c1 446 * @param end an End Sector Number (should be greater than or equal to start sector number).
okano 2:17f3464672c1 447 * @return error code: CMD_SUCCESS | BUSY | SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | INVALID_SECTOR
okano 2:17f3464672c1 448 */
okano 0:ada7fb504504 449 int erase( int start, int end );
okano 2:17f3464672c1 450
okano 2:17f3464672c1 451 /** Prepare sector(s) for write operation
okano 2:17f3464672c1 452 *
okano 2:17f3464672c1 453 * @param start a Start Sector Number
okano 2:17f3464672c1 454 * @param end an End Sector Number (should be greater than or equal to start sector number).
okano 2:17f3464672c1 455 * @return error code: CMD_SUCCESS | BUSY | INVALID_SECTOR
okano 2:17f3464672c1 456 */
okano 0:ada7fb504504 457 int prepare( int start, int end );
okano 2:17f3464672c1 458
okano 2:17f3464672c1 459 /** Copy RAM to Flash
okano 2:17f3464672c1 460 *
okano 2:17f3464672c1 461 * @param source_addr Source RAM address from which data bytes are to be read. This address should be a word boundary.
okano 2:17f3464672c1 462 * @param target_addr Destination flash address where data bytes are to be written. This address should be a 256 byte boundary.
okano 2:17f3464672c1 463 * @param size Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
okano 2:17f3464672c1 464 * @return error code: CMD_SUCCESS | SRC_ADDR_ERROR (Address not a word boundary) | DST_ADDR_ERROR (Address not on correct boundary) | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED | COUNT_ERROR (Byte count is not 256 | 512 | 1024 | 4096) | SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | BUSY
okano 2:17f3464672c1 465 */
okano 0:ada7fb504504 466 int write( char *source_addr, char *target_addr, int size );
okano 2:17f3464672c1 467
okano 2:17f3464672c1 468 /** Compare <address1> <address2> <no of bytes>
okano 2:17f3464672c1 469 *
okano 2:17f3464672c1 470 * @param source_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
okano 2:17f3464672c1 471 * @param target_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
okano 2:17f3464672c1 472 * @param size Number of bytes to be compared; should be a multiple of 4.
okano 2:17f3464672c1 473 * @return error code: CMD_SUCCESS | COMPARE_ERROR | COUNT_ERROR (Byte count is not a multiple of 4) | ADDR_ERROR | ADDR_NOT_MAPPED
okano 2:17f3464672c1 474 */
okano 0:ada7fb504504 475 int compare( char *source_addr, char *target_addr, int size );
okano 2:17f3464672c1 476
okano 2:17f3464672c1 477 /** Read Boot code version number
okano 2:17f3464672c1 478 *
okano 2:17f3464672c1 479 * @return 2 bytes of boot code version number
okano 2:17f3464672c1 480 */
okano 0:ada7fb504504 481 int read_BootVer( void );
okano 2:17f3464672c1 482
okano 2:17f3464672c1 483 /** Get user reserved flash start address
okano 2:17f3464672c1 484 *
okano 2:17f3464672c1 485 * @return start address of user reserved flash memory
okano 2:17f3464672c1 486 * @see reserved_flash_area_size()
okano 2:17f3464672c1 487 */
okano 2:17f3464672c1 488
okano 0:ada7fb504504 489 char *reserved_flash_area_start( void );
okano 2:17f3464672c1 490
okano 2:17f3464672c1 491 /** Get user reserved flash size
okano 2:17f3464672c1 492 *
okano 2:17f3464672c1 493 * @return size of user reserved flash memory
okano 2:17f3464672c1 494 * @see reserved_flash_area_start()
okano 2:17f3464672c1 495 */
okano 0:ada7fb504504 496 int reserved_flash_area_size( void );
okano 0:ada7fb504504 497
okano 4:cee1a2a734c9 498 #if defined(TARGET_LPC11UXX)
okano 2:17f3464672c1 499
okano 2:17f3464672c1 500 /** Copy RAM to EEPROM (LPC11U24)
okano 2:17f3464672c1 501 *
okano 2:17f3464672c1 502 * @param source_addr Source RAM address from which data bytes are to be read.
okano 2:17f3464672c1 503 * @param target_addr Destination EEPROM address where data bytes are to be written.
okano 2:17f3464672c1 504 * @param size Number of bytes to be written.
okano 2:17f3464672c1 505 * @return error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED
okano 2:17f3464672c1 506 * Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to.
okano 2:17f3464672c1 507 */
okano 1:ff906ad52cf9 508 int write_eeprom( char *source_addr, char *target_addr, int size );
okano 2:17f3464672c1 509
okano 2:17f3464672c1 510 /** Copy EEPROM to RAM (LPC11U24)
okano 2:17f3464672c1 511 *
okano 2:17f3464672c1 512 * @param source_addr Source EEPROM address from which data bytes are to be read.
okano 2:17f3464672c1 513 * @param target_addr Destination RAM address where data bytes are to be written.
okano 2:17f3464672c1 514 * @param size Number of bytes to be written.
okano 2:17f3464672c1 515 * @return error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED
okano 2:17f3464672c1 516 * Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to.
okano 2:17f3464672c1 517 */
okano 1:ff906ad52cf9 518 int read_eeprom( char *source_addr, char *target_addr, int size );
okano 2:17f3464672c1 519
okano 4:cee1a2a734c9 520 #elif defined(TARGET_LPC81X) || defined(TARGET_LPC82X)
okano 2:17f3464672c1 521
okano 2:17f3464672c1 522 /** Erase page(s) (LPC812, LPC824)
okano 2:17f3464672c1 523 *
okano 2:17f3464672c1 524 * @param start Start page number.
okano 2:17f3464672c1 525 * @param end End page number (should be greater than or equal to start page).
okano 2:17f3464672c1 526 * @return error code: CMD_SUCCESS | BUSY | SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | INVALID_SECTOR
okano 2:17f3464672c1 527 */
okano 2:17f3464672c1 528 int erase_page( int start, int end );
okano 2:17f3464672c1 529
okano 1:ff906ad52cf9 530 #endif
okano 1:ff906ad52cf9 531
okano 0:ada7fb504504 532 private:
okano 0:ada7fb504504 533 IAP_call iap_entry;
okano 0:ada7fb504504 534 unsigned int IAP_command[ 5 ];
okano 0:ada7fb504504 535 unsigned int IAP_result[ 5 ];
okano 0:ada7fb504504 536 int cclk_kHz;
okano 0:ada7fb504504 537 }
okano 0:ada7fb504504 538 ;
okano 0:ada7fb504504 539
okano 0:ada7fb504504 540 #endif // #ifndef MBED_IAP