student project

Dependencies:   mbed

Fork of myiot by joseph chen

Committer:
William_HO
Date:
Thu Jun 23 05:17:36 2016 +0000
Revision:
5:f6a5fc6e1ddd
Added an IAP example to read device ID and serial number.; For feature implement.

Who changed what in which revision?

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