1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2022 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef _FSL_FLASHIAP_H_
10 #define _FSL_FLASHIAP_H_
11
12 #include "fsl_common.h"
13
14 /*!
15 * @addtogroup flashiap_driver
16 * @{
17 */
18
19 /*! @file */
20
21 /*******************************************************************************
22 * Definitions
23 ******************************************************************************/
24
25 /*! @name Driver version */
26 /*@{*/
27 #define FSL_FLASHIAP_DRIVER_VERSION (MAKE_VERSION(2, 0, 6))
28 /*@}*/
29
30 /*!
31 * @brief Flashiap status codes.
32 */
33 enum _flashiap_status
34 {
35 kStatus_FLASHIAP_Success = kStatus_Success, /*!< Api is executed successfully */
36 kStatus_FLASHIAP_InvalidCommand = MAKE_STATUS(kStatusGroup_FLASHIAP, 1U), /*!< Invalid command */
37 kStatus_FLASHIAP_SrcAddrError =
38 MAKE_STATUS(kStatusGroup_FLASHIAP, 2U), /*!< Source address is not on word boundary */
39 kStatus_FLASHIAP_DstAddrError =
40 MAKE_STATUS(kStatusGroup_FLASHIAP, 3U), /*!< Destination address is not on a correct boundary */
41 kStatus_FLASHIAP_SrcAddrNotMapped =
42 MAKE_STATUS(kStatusGroup_FLASHIAP, 4U), /*!< Source address is not mapped in the memory map */
43 kStatus_FLASHIAP_DstAddrNotMapped =
44 MAKE_STATUS(kStatusGroup_FLASHIAP, 5U), /*!< Destination address is not mapped in the memory map */
45 kStatus_FLASHIAP_CountError =
46 MAKE_STATUS(kStatusGroup_FLASHIAP, 6U), /*!< Byte count is not multiple of 4 or is not a permitted value */
47 kStatus_FLASHIAP_InvalidSector =
48 MAKE_STATUS(kStatusGroup_FLASHIAP,
49 7), /*!< Sector number is invalid or end sector number is greater than start sector number */
50 kStatus_FLASHIAP_SectorNotblank = MAKE_STATUS(kStatusGroup_FLASHIAP, 8U), /*!< One or more sectors are not blank */
51 kStatus_FLASHIAP_NotPrepared =
52 MAKE_STATUS(kStatusGroup_FLASHIAP, 9U), /*!< Command to prepare sector for write operation was not executed */
53 kStatus_FLASHIAP_CompareError =
54 MAKE_STATUS(kStatusGroup_FLASHIAP, 10U), /*!< Destination and source memory contents do not match */
55 kStatus_FLASHIAP_Busy =
56 MAKE_STATUS(kStatusGroup_FLASHIAP, 11U), /*!< Flash programming hardware interface is busy */
57 kStatus_FLASHIAP_ParamError =
58 MAKE_STATUS(kStatusGroup_FLASHIAP, 12U), /*!< Insufficient number of parameters or invalid parameter */
59 kStatus_FLASHIAP_AddrError = MAKE_STATUS(kStatusGroup_FLASHIAP, 13U), /*!< Address is not on word boundary */
60 kStatus_FLASHIAP_AddrNotMapped =
61 MAKE_STATUS(kStatusGroup_FLASHIAP, 14U), /*!< Address is not mapped in the memory map */
62 kStatus_FLASHIAP_NoPower = MAKE_STATUS(kStatusGroup_FLASHIAP, 24U), /*!< Flash memory block is powered down */
63 kStatus_FLASHIAP_NoClock =
64 MAKE_STATUS(kStatusGroup_FLASHIAP, 27U), /*!< Flash memory block or controller is not clocked */
65 };
66
67 /*!
68 * @brief Flashiap command codes.
69 */
70 enum _flashiap_commands
71 {
72 kIapCmd_FLASHIAP_PrepareSectorforWrite = 50U, /*!< Prepare Sector for write */
73 kIapCmd_FLASHIAP_CopyRamToFlash = 51U, /*!< Copy RAM to flash */
74 kIapCmd_FLASHIAP_EraseSector = 52U, /*!< Erase Sector */
75 kIapCmd_FLASHIAP_BlankCheckSector = 53U, /*!< Blank check sector */
76 kIapCmd_FLASHIAP_ReadPartId = 54U, /*!< Read part id */
77 kIapCmd_FLASHIAP_Read_BootromVersion = 55U, /*!< Read bootrom version */
78 kIapCmd_FLASHIAP_Compare = 56U, /*!< Compare */
79 kIapCmd_FLASHIAP_ReinvokeISP = 57U, /*!< Reinvoke ISP */
80 kIapCmd_FLASHIAP_ReadUid = 58U, /*!< Read Uid isp */
81 kIapCmd_FLASHIAP_ErasePage = 59U, /*!< Erase Page */
82 kIapCmd_FLASHIAP_ReadMisr = 70U, /*!< Read Misr */
83 kIapCmd_FLASHIAP_ReinvokeI2cSpiISP = 71U /*!< Reinvoke I2C/SPI isp */
84 };
85
86 /*! @brief IAP_ENTRY API function type */
87 typedef void (*FLASHIAP_ENTRY_T)(uint32_t cmd[5], uint32_t stat[4]);
88
89 /*******************************************************************************
90 * API
91 ******************************************************************************/
92
93 #if defined(__cplusplus)
94 extern "C" {
95 #endif
96
97 /*!
98 * @brief IAP_ENTRY API function type
99 *
100 * Wrapper for rom iap call
101 *
102 * @param cmd_param IAP command and relevant parameter array.
103 * @param status_result IAP status result array.
104 *
105 * @retval None. Status/Result is returned via status_result array.
106 */
iap_entry(uint32_t * cmd_param,uint32_t * status_result)107 static inline void iap_entry(uint32_t *cmd_param, uint32_t *status_result)
108 {
109 ((FLASHIAP_ENTRY_T)FSL_FEATURE_SYSCON_IAP_ENTRY_LOCATION)(cmd_param, status_result);
110 }
111
112 /*!
113 * @brief Prepare sector for write operation
114
115 * This function prepares sector(s) for write/erase operation. This function must be
116 * called before calling the FLASHIAP_CopyRamToFlash() or FLASHIAP_EraseSector() or
117 * FLASHIAP_ErasePage() function. The end sector must be greater than or equal to
118 * start sector number.
119 *
120 * @deprecated Do not use this function. It has benn moved to iap driver.
121 *
122 * @param startSector Start sector number.
123 * @param endSector End sector number.
124 *
125 * @retval #kStatus_FLASHIAP_Success Api was executed successfully.
126 * @retval #kStatus_FLASHIAP_NoPower Flash memory block is powered down.
127 * @retval #kStatus_FLASHIAP_NoClock Flash memory block or controller is not clocked.
128 * @retval #kStatus_FLASHIAP_InvalidSector Sector number is invalid or end sector number
129 * is greater than start sector number.
130 * @retval #kStatus_FLASHIAP_Busy Flash programming hardware interface is busy.
131 */
132 status_t FLASHIAP_PrepareSectorForWrite(uint32_t startSector, uint32_t endSector);
133
134 /*!
135 * @brief Copy RAM to flash.
136
137 * This function programs the flash memory. Corresponding sectors must be prepared
138 * via FLASHIAP_PrepareSectorForWrite before calling calling this function. The addresses
139 * should be a 256 byte boundary and the number of bytes should be 256 | 512 | 1024 | 4096.
140 *
141 * @deprecated Do not use this function. It has benn moved to iap driver.
142 *
143 * @param dstAddr Destination flash address where data bytes are to be written.
144 * @param srcAddr Source ram address from where data bytes are to be read.
145 * @param numOfBytes Number of bytes to be written.
146 * @param systemCoreClock SystemCoreClock in Hz. It is converted to KHz before calling the
147 * rom IAP function.
148 *
149 * @retval #kStatus_FLASHIAP_Success Api was executed successfully.
150 * @retval #kStatus_FLASHIAP_NoPower Flash memory block is powered down.
151 * @retval #kStatus_FLASHIAP_NoClock Flash memory block or controller is not clocked.
152 * @retval #kStatus_FLASHIAP_SrcAddrError Source address is not on word boundary.
153 * @retval #kStatus_FLASHIAP_DstAddrError Destination address is not on a correct boundary.
154 * @retval #kStatus_FLASHIAP_SrcAddrNotMapped Source address is not mapped in the memory map.
155 * @retval #kStatus_FLASHIAP_DstAddrNotMapped Destination address is not mapped in the memory map.
156 * @retval #kStatus_FLASHIAP_CountError Byte count is not multiple of 4 or is not a permitted value.
157 * @retval #kStatus_FLASHIAP_NotPrepared Command to prepare sector for write operation was not executed.
158 * @retval #kStatus_FLASHIAP_Busy Flash programming hardware interface is busy.
159 */
160 status_t FLASHIAP_CopyRamToFlash(uint32_t dstAddr, uint32_t *srcAddr, uint32_t numOfBytes, uint32_t systemCoreClock);
161
162 /*!
163 * @brief Erase sector
164
165 * This function erases sector(s). The end sector must be greater than or equal to
166 * start sector number. FLASHIAP_PrepareSectorForWrite must be called before
167 * calling this function.
168 *
169 * @deprecated Do not use this function. It has benn moved to iap driver.
170 *
171 * @param startSector Start sector number.
172 * @param endSector End sector number.
173 * @param systemCoreClock SystemCoreClock in Hz. It is converted to KHz before calling the
174 * rom IAP function.
175 *
176 * @retval #kStatus_FLASHIAP_Success Api was executed successfully.
177 * @retval #kStatus_FLASHIAP_NoPower Flash memory block is powered down.
178 * @retval #kStatus_FLASHIAP_NoClock Flash memory block or controller is not clocked.
179 * @retval #kStatus_FLASHIAP_InvalidSector Sector number is invalid or end sector number
180 * is greater than start sector number.
181 * @retval #kStatus_FLASHIAP_NotPrepared Command to prepare sector for write operation was not executed.
182 * @retval #kStatus_FLASHIAP_Busy Flash programming hardware interface is busy.
183 */
184 status_t FLASHIAP_EraseSector(uint32_t startSector, uint32_t endSector, uint32_t systemCoreClock);
185
186 /*!
187
188 * This function erases page(s). The end page must be greater than or equal to
189 * start page number. Corresponding sectors must be prepared via FLASHIAP_PrepareSectorForWrite
190 * before calling calling this function.
191 *
192 * @deprecated Do not use this function. It has benn moved to iap driver.
193 *
194 * @param startPage Start page number
195 * @param endPage End page number
196 * @param systemCoreClock SystemCoreClock in Hz. It is converted to KHz before calling the
197 * rom IAP function.
198 *
199 * @retval #kStatus_FLASHIAP_Success Api was executed successfully.
200 * @retval #kStatus_FLASHIAP_NoPower Flash memory block is powered down.
201 * @retval #kStatus_FLASHIAP_NoClock Flash memory block or controller is not clocked.
202 * @retval #kStatus_FLASHIAP_InvalidSector Page number is invalid or end page number
203 * is greater than start page number
204 * @retval #kStatus_FLASHIAP_NotPrepared Command to prepare sector for write operation was not executed.
205 * @retval #kStatus_FLASHIAP_Busy Flash programming hardware interface is busy.
206 */
207 status_t FLASHIAP_ErasePage(uint32_t startPage, uint32_t endPage, uint32_t systemCoreClock);
208
209 /*!
210 * @brief Blank check sector(s)
211 *
212 * Blank check single or multiples sectors of flash memory. The end sector must be greater than or equal to
213 * start sector number. It can be used to verify the sector eraseure after FLASHIAP_EraseSector call.
214 *
215 * @deprecated Do not use this function. It has benn moved to iap driver.
216 *
217 * @param startSector : Start sector number. Must be greater than or equal to start sector number
218 * @param endSector : End sector number
219 * @retval #kStatus_FLASHIAP_Success One or more sectors are in erased state.
220 * @retval #kStatus_FLASHIAP_NoPower Flash memory block is powered down.
221 * @retval #kStatus_FLASHIAP_NoClock Flash memory block or controller is not clocked.
222 * @retval #kStatus_FLASHIAP_SectorNotblank One or more sectors are not blank.
223 */
224 status_t FLASHIAP_BlankCheckSector(uint32_t startSector, uint32_t endSector);
225
226 /*!
227 * @brief Compare memory contents of flash with ram.
228
229 * This function compares the contents of flash and ram. It can be used to verify the flash
230 * memory contents after FLASHIAP_CopyRamToFlash call.
231 *
232 * @deprecated Do not use this function. It has benn moved to iap driver.
233 *
234 * @param dstAddr Destination flash address.
235 * @param srcAddr Source ram address.
236 * @param numOfBytes Number of bytes to be compared.
237 *
238 * @retval #kStatus_FLASHIAP_Success Contents of flash and ram match.
239 * @retval #kStatus_FLASHIAP_NoPower Flash memory block is powered down.
240 * @retval #kStatus_FLASHIAP_NoClock Flash memory block or controller is not clocked.
241 * @retval #kStatus_FLASHIAP_AddrError Address is not on word boundary.
242 * @retval #kStatus_FLASHIAP_AddrNotMapped Address is not mapped in the memory map.
243 * @retval #kStatus_FLASHIAP_CountError Byte count is not multiple of 4 or is not a permitted value.
244 * @retval #kStatus_FLASHIAP_CompareError Destination and source memory contents do not match.
245 */
246 status_t FLASHIAP_Compare(uint32_t dstAddr, uint32_t *srcAddr, uint32_t numOfBytes);
247
248 #ifdef __cplusplus
249 }
250 #endif
251
252 /*@}*/
253
254 #endif /* _FSL_FLASHIAP_H_ */
255