2 * @brief Flash/EEPROM programming
5 * Copyright(C) NXP Semiconductors, 2012
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
32 #ifndef __FLASH_EEPROM_001_H
33 #define __FLASH_EEPROM_001_H
35 #include "sys_config.h"
42 /** @defgroup IP_FLASH_EEPROM_001 IP: Flash/EEPROM programming
47 #if defined(CHIP_LPC1347)
48 #define ERASE_PAGE_SUPPORT
49 #define EEPROM_RW_SUPPORT
52 /** The maximum number of flash programing parameters */
53 #define FLASH_PARAMETER_NUM (5)
55 /** The maximum number of flash programing results */
56 #define FLASH_RESULT_NUM (4)
58 /** Flash programming function type */
59 typedef void (*FLASH_ENTRY_T)(unsigned int[], unsigned int[]);
62 * @brief Flash command code definitions
65 FLASH_PREPARE = 50, /*!< Prepare sector(s) for write operation */
66 FLASH_COPY_RAM_TO_FLASH = 51, /*!< Copy RAM to Flash */
67 FLASH_ERASE = 52, /*!< Erase sector(s) */
68 FLASH_BLANK_CHECK = 53, /*!< Blank check sector(s) */
69 FLASH_READ_PART_ID = 54, /*!< Read chip part ID */
70 FLASH_READ_BOOT_VER = 55, /*!< Read chip boot code version */
71 FLASH_COMPARE = 56, /*!< Compare memory areas */
72 FLASH_REINVOKE_ISP = 57, /*!< Reinvoke ISP */
73 FLASH_READ_UID = 58, /*!< Read UID */
74 #if defined(ERASE_PAGE_SUPPORT)
75 FLASH_ERASE_PAGE = 59, /*!< Erase page */
77 #if defined(EEPROM_RW_SUPPORT)
78 FLASH_EEPROM_WRITE = 61, /*!< EEPROM Write */
79 FLASH_EEPROM_READ = 62, /*!< EEPROM Read */
84 * @brief Flash status code definitions
87 CMD_SUCCESS, /*!< Command is executed successfully. */
88 INVALID_COMMAND, /*!< Invalid command. */
89 SRC_ADDR_ERROR, /*!< Source address is not on a word boundary. */
90 DST_ADDR_ERROR, /*!< Destination address is not on a correct boundary. */
91 SRC_ADDR_NOT_MAPPED, /*!< Source address is not mapped in the memory map. */
92 DST_ADDR_NOT_MAPPED, /*!< Destination address is not mapped in the memory map. */
93 COUNT_ERROR, /*!< Byte count is not multiple of 4 or is not a permitted value. */
94 INVALID_SECTOR, /*!< Sector number is invalid. */
95 SECTOR_NOT_BLANK, /*!< Sector is not blank. */
96 SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION, /*!< Command to prepare sector for write operation was not executed. */
97 COMPARE_ERROR, /*!< Source and destination data is not same. */
98 BUSY, /*!< Flash programming hardware interface is busy. */
99 } FLASH_STATUS_CODE_T;
102 * @brief Command parameter table structure
105 uint32_t cmd; /*!< Command code */
106 uint32_t pParams[FLASH_PARAMETER_NUM]; /*!< Parameters*/
110 * @brief Command result table structure
113 uint32_t status; /*!< Status code */
114 uint32_t pResult[FLASH_RESULT_NUM]; /*!< Results*/
117 /* Flash Programming Command Description
118 Command Parameters Return Code Result
119 ----------------------------------------------------------------------------------------------------------
120 FLASH_PREPARE Start Sector Number CMD_SUCCESS None
121 End Sector Number BUSY
123 FLASH_COPY_RAM2FLASH Destination Flash Addr CMD_SUCCESS None
124 Source RAM Addr SRC_ADDR_ERROR
125 Number of bytes written SRC_ADDR_NOT_MAPPED
126 CCLK in kHz DST_ADDR_NOT_MAPPED
128 SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION
130 FLASH_ERASE Start Sector Number CMD_SUCCESS None
131 Emd Sector Number BUSY
132 CCLK in kHz SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION
134 FLASH_BLANK_CHECK Start Sector Number CMD_SUCCESS Non Blank Sector Offset(if Status code is SECTOR_NOT_BLANK)
135 End Sector Number BUSY Content of non blank word location
138 FLASH_READ_PART_ID None CMD_SUCCESS Part ID
139 FLASH_READ_BOOT_VER None CMD_SUCCESS <byte1(Major)>.<byte0(Minor)>
140 FLASH_COMPARE Destination Addr CMD_SUCCESS Offset of the first mismatch
141 Source Address COMPARE_ERROR
142 Number of bytes compared COUNT_ERROR
145 FLASH_REINVOKE_ISP None None None
146 FLASH_READ_UID None CMD_SUCCESS The first 32-bit word
147 The second 32-bit word.
148 The third 32-bit word.
149 The fourth 32-bit word
150 FLASH_ERASE_PAGE Start Page Number CMD_SUCCESS None
152 CCLK in kHz SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION
154 FLASH_EEPROM_WRITE EEPROM Addr CMD_SUCCESS None
155 RAM Addr SRC_ADDR_NOT_MAPPED
156 Number of bytes written DST_ADDR_NOT_MAPPED
158 FLASH_EEPROM_READ EEPROM Addr CMD_SUCCESS None
159 RAM Addr SRC_ADDR_NOT_MAPPED
160 Number of bytes read DST_ADDR_NOT_MAPPED
165 * @brief Execute flash programming command
166 * @param entry : Flash Programing entry
167 * @param pCommand : Command information
168 * @param pOutput : Output information
171 STATIC INLINE void IP_FLASH_Execute(FLASH_ENTRY_T entry, FLASH_COMMAND_T *pCommand, FLASH_OUTPUT_T *pOutput)
173 (entry) ((unsigned int *) pCommand, (unsigned int *) pOutput);
177 * @brief [Prepare sectors] command parameter table structure
180 uint32_t cmd; /*!< Command code */
181 uint32_t start; /*!< Start Sector Number */
182 uint32_t end; /*!<End Sector Number (should be greater than or equal to start sector number).*/
183 } FLASH_PREPARE_SECTORS_COMMAND_T;
186 * @brief [Prepare sectors] command result table structure
189 uint32_t status; /*!< Status code */
190 } FLASH_PREPARE_SECTORS_OUTPUT_T;
193 * @brief [Copy Ram to Flash] command parameter table structure
196 uint32_t cmd; /*!< Command code */
197 uint32_t dst; /*!< Destination flash address where data bytes are to be written (256 byte boundary) */
198 uint32_t src; /*!<Source RAM address from which data bytes are to be read (a word boudary).*/
199 uint32_t byteNum; /*!<Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.*/
200 uint32_t cclk; /*!<System Clock Frequency (CCLK) in kHz.*/
201 } FLASH_COPY_RAM_TO_FLASH_COMMAND_T;
204 * @brief [Copy Ram to Flash] command result table structure
207 uint32_t status; /*!< Status code */
208 } FLASH_COPY_RAM_TO_FLASH_OUTPUT_T;
211 * @brief [Erase Sector(s)] command parameter table structure
214 uint32_t cmd; /*!< Command code */
215 uint32_t start; /*!< Start Sector Number */
216 uint32_t end; /*!<End Sector Number (should be greater than or equal to start sector number).*/
217 uint32_t cclk; /*!<System Clock Frequency (CCLK) in kHz.*/
218 } FLASH_ERASE_SECTORS_COMMAND_T;
221 * @brief [Erase Sector(s)] command result table structure
224 uint32_t status; /*!< Status code */
225 } FLASH_ERASE_SECTORS_OUTPUT_T;
228 * @brief [Blank check sector(s)] command parameter table structure
231 uint32_t cmd; /*!< Command code */
232 uint32_t start; /*!< Start Sector Number */
233 uint32_t end; /*!<End Sector Number (should be greater than or equal to start sector number).*/
234 } FLASH_BLANK_CHECK_SECTORS_COMMAND_T;
237 * @brief [Blank check sector(s)] command result table structure
240 uint32_t status; /*!< Status code */
241 uint32_t firstNonBlankLoc; /*!< Offset of the first non blank word location if the Status Code is SECTOR_NOT_BLANK.*/
242 uint32_t firstNonBlankVal; /*!<Contents of non blank word location.*/
243 } FLASH_BLANK_CHECK_SECTORS_OUTPUT_T;
246 * @brief [Read Part Identification number] command parameter table structure
249 uint32_t cmd; /*!< Command code */
250 } FLASH_READ_PART_ID_COMMAND_T;
253 * @brief [Read Part Identification number] command result table structure
256 uint32_t status; /*!< Status code */
257 uint32_t partID; /*!< Part Identification Number*/
258 } FLASH_READ_PART_ID_OUTPUT_T;
261 * @brief [Read Boot code version number] command parameter table structure
264 uint32_t cmd; /*!< Command code */
265 } FLASH_READ_BOOTCODE_VER_COMMAND_T;
268 * @brief [Read Boot code version number] command result table structure
271 uint32_t status; /*!< Status code */
272 uint8_t minor; /*!< Minor*/
273 uint8_t major; /*!< Major*/
274 } FLASH_READ_BOOTCODE_VER_OUTPUT_T;
277 * @brief [Compare memory] command parameter table structure
280 uint32_t cmd; /*!< Command code */
281 uint32_t dst; /*!<Starting flash or RAM address of data bytes to be compared (a word boundary) */
282 uint32_t src; /*!<Starting flash or RAM address of data bytes to be compared (a word boudary).*/
283 uint32_t byteNum; /*!<Number of bytes to be compared; should be a multiple of 4.*/
284 } FLASH_COMPARE_MEM_COMMAND_T;
287 * @brief [Compare memory] command result table structure
290 uint32_t status; /*!< Status code */
291 uint32_t offset; /*!< Offset of the first mismatch if the Status Code is COMPARE_ERROR.*/
292 } FLASH_COMPARE_MEM_OUTPUT_T;
295 * @brief [Reinvoke ISP] command parameter table structure
298 uint32_t cmd; /*!< Command code */
299 } FLASH_REINVOKE_ISP_COMMAND_T;
302 * @brief [Reinvoke ISP] command result table structure
305 uint32_t status; /*!< Status code */
306 } FLASH_REINVOKE_ISP_OUTPUT_T;
309 * @brief [ReadUID] command parameter table structure
312 uint32_t cmd; /*!< Command code */
313 } FLASH_READ_UID_COMMAND_T;
316 * @brief [ReadUID] command result table structure
319 uint32_t status; /*!< Status code */
320 uint32_t id[4]; /*!< UID*/
321 } FLASH_READ_UID_OUTPUT_T;
323 #if defined(ERASE_PAGE_SUPPORT)
325 * @brief [Erase page(s)] command parameter table structure
328 uint32_t cmd; /*!< Command code */
329 uint32_t start; /*!< Start Page Number */
330 uint32_t end; /*!<End Page Number (should be greater than or equal to start page number).*/
331 uint32_t cclk; /*!<System Clock Frequency (CCLK) in kHz.*/
332 } FLASH_ERASE_PAGES_COMMAND_T;
335 * @brief [Erase page(s)] command result table structure
338 uint32_t status; /*!< Status code */
339 } FLASH_ERASE_PAGES_OUTPUT_T;
341 #endif /* defined(ERASE_PAGE_SUPPORT) */
343 #if defined(EEPROM_RW_SUPPORT)
345 * @brief [Write EEPROM] command parameter table structure
348 uint32_t cmd; /*!< Command code */
349 uint32_t eepromAddr; /*!< EEPROM address.*/
350 uint32_t ramAddr; /*!< RAM address.*/
351 uint32_t byteNum; /*!<Number of bytes to be written.*/
352 uint32_t cclk; /*!<System Clock Frequency (CCLK) in kHz.*/
353 } EEPROM_WRITE_COMMAND_T;
356 * @brief [Write EEPROM] command result table structure
359 uint32_t status; /*!< Status code */
360 } EEPROM_WRITE_OUTPUT_T;
363 * @brief [Read EEPROM] command parameter table structure
366 uint32_t cmd; /*!< Command code */
367 uint32_t eepromAddr; /*!< EEPROM address.*/
368 uint32_t ramAddr; /*!< RAM address.*/
369 uint32_t byteNum; /*!<Number of bytes to be written.*/
370 uint32_t cclk; /*!<System Clock Frequency (CCLK) in kHz.*/
371 } EEPROM_READ_COMMAND_T;
374 * @brief [Read EEPROM] command result table structure
377 uint32_t status; /*!< Status code */
378 } EEPROM_READ_OUTPUT_T;
380 #endif /* defined(EEPROM_RW_SUPPORT) */
390 #endif /* __FLASH_EEPROM_001_H */