LPCOpen Platform for LPC18XX/43XX microcontrollers  18XX43XX
LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers
iap_18xx_43xx.c
Go to the documentation of this file.
1 /*
2  * @brief Common FLASH IAP support functions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2013
6  * All rights reserved.
7  *
8  * @par
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.
22  *
23  * @par
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
29  * this code.
30  */
31 
32 #include "chip.h"
33 
34 /*****************************************************************************
35  * Private types/enumerations/variables
36  ****************************************************************************/
37 
38 /*****************************************************************************
39  * Public types/enumerations/variables
40  ****************************************************************************/
41 
42 /*****************************************************************************
43  * Private functions
44  ****************************************************************************/
45 
46 /*****************************************************************************
47  * Public functions
48  ****************************************************************************/
49 
50 /* Prepare sector for write operation */
51 uint8_t Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
52 {
53  uint32_t command[5], result[4];
54 
55  command[0] = IAP_PREWRRITE_CMD;
56  command[1] = strSector;
57  command[2] = endSector;
58  command[3] = flashBank;
59  iap_entry(command, result);
60 
61  return result[0];
62 }
63 
64 /* Copy RAM to flash */
65 uint8_t Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt)
66 {
67  uint32_t command[5], result[4];
68 
69  command[0] = IAP_WRISECTOR_CMD;
70  command[1] = dstAdd;
71  command[2] = (uint32_t) srcAdd;
72  command[3] = byteswrt;
73  command[4] = SystemCoreClock / 1000;
74  iap_entry(command, result);
75 
76  return result[0];
77 }
78 
79 /* Erase sector */
80 uint8_t Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
81 {
82  uint32_t command[5], result[4];
83 
84  command[0] = IAP_ERSSECTOR_CMD;
85  command[1] = strSector;
86  command[2] = endSector;
87  command[3] = SystemCoreClock / 1000;
88  command[4] = flashBank;
89  iap_entry(command, result);
90 
91  return result[0];
92 }
93 
94 /* Blank check sector */
95 uint8_t Chip_IAP_BlankCheckSector(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
96 {
97  uint32_t command[5], result[4];
98 
99  command[0] = IAP_BLANK_CHECK_SECTOR_CMD;
100  command[1] = strSector;
101  command[2] = endSector;
102  command[3] = flashBank;
103  iap_entry(command, result);
104 
105  return result[0];
106 }
107 
108 /* Read part identification number */
110 {
111  uint32_t command[5], result[4];
112 
113  command[0] = IAP_REPID_CMD;
114  iap_entry(command, result);
115 
116  return result[1];
117 }
118 
119 /* Read boot code version number */
121 {
122  uint32_t command[5], result[4];
123 
124  command[0] = IAP_READ_BOOT_CODE_CMD;
125  iap_entry(command, result);
126 
127  return result[0];
128 }
129 
130 /* IAP compare */
131 uint8_t Chip_IAP_Compare(uint32_t dstAdd, uint32_t srcAdd, uint32_t bytescmp)
132 {
133  uint32_t command[5], result[4];
134 
135  command[0] = IAP_COMPARE_CMD;
136  command[1] = dstAdd;
137  command[2] = srcAdd;
138  command[3] = bytescmp;
139  iap_entry(command, result);
140 
141  return result[0];
142 }
143 
144 /* Reinvoke ISP */
146 {
147  uint32_t command[5], result[4];
148 
149  command[0] = IAP_REINVOKE_ISP_CMD;
150  iap_entry(command, result);
151 
152  return result[0];
153 }
154 
155 /* Read the unique ID */
157 {
158  uint32_t command[5], result[4];
159 
160  command[0] = IAP_READ_UID_CMD;
161  iap_entry(command, result);
162 
163  return result[1];
164 }
165 
166 /* Erase page */
167 uint8_t Chip_IAP_ErasePage(uint32_t strPage, uint32_t endPage)
168 {
169  uint32_t command[5], result[4];
170 
171  command[0] = IAP_ERASE_PAGE_CMD;
172  command[1] = strPage;
173  command[2] = endPage;
174  command[3] = SystemCoreClock / 1000;
175  iap_entry(command, result);
176 
177  return result[0];
178 }
179 
180 /* Set active boot flash bank */
181 uint8_t Chip_IAP_SetBootFlashBank(uint8_t bankNum)
182 {
183  uint32_t command[5], result[4];
184 
185  command[0] = IAP_SET_BOOT_FLASH;
186  command[1] = bankNum;
187  command[2] = SystemCoreClock / 1000;
188  iap_entry(command, result);
189 
190  return result[0];
191 }