1 /*
2  * Copyright 2021 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  */
8 
9 #ifndef _FSL_FLASH_H_
10 #define _FSL_FLASH_H_
11 
12 #include "fsl_common.h"
13 /*!
14  * @addtogroup flash_driver
15  * @{
16  */
17 
18 /*! @file */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 /*!
24  * @name Flash version
25  * @{
26  */
27 /*! @brief Constructs the version number for drivers. */
28 #if !defined(MAKE_VERSION)
29 #define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
30 #endif
31 
32 /*! @brief Flash driver version for SDK*/
33 #define FSL_FLASH_DRIVER_VERSION (MAKE_VERSION(1, 0, 1)) /*!< Version 1.0.1. */
34 
35 /*! @brief Flash driver version for ROM*/
36 enum _flash_driver_version_constants
37 {
38     kFLASH_DriverVersionName   = 'F', /*!< Flash driver version name.*/
39     kFLASH_DriverVersionMajor  = 1,   /*!< Major flash driver version.*/
40     kFLASH_DriverVersionMinor  = 0,   /*!< Minor flash driver version.*/
41     kFLASH_DriverVersionBugfix = 1    /*!< Bugfix for flash driver version.*/
42 };
43 /*@}*/
44 
45 /*!
46  * @name Flash driver support feature
47  * @{
48  */
49 /*! @brief IAP driver support non-block erase function */
50 #define FSL_SUPPORT_ERASE_SECTOR_NON_BLOCKING 1U
51 
52 /*! @brief IAP driver support flash hiding */
53 #define FSL_FEATURE_SYSCON_HAS_FLASH_HIDING 1U
54 
55 /*! @brief IAP driver support CDPA */
56 #define FSL_FEATURE_SYSCON_HAS_CDPA 1U
57 /*@}*/
58 
59 /*!
60  * @name Flash status
61  * @{
62  */
63 /*! @brief Flash driver status group. */
64 #if defined(kStatusGroup_FlashDriver)
65 #define kStatusGroupGeneric     kStatusGroup_Generic
66 #define kStatusGroupFlashDriver kStatusGroup_FlashDriver
67 #elif defined(kStatusGroup_FLASHIAP)
68 #define kStatusGroupGeneric     kStatusGroup_Generic
69 #define kStatusGroupFlashDriver kStatusGroup_FLASH
70 #else
71 #define kStatusGroupGeneric     0
72 #define kStatusGroupFlashDriver 1
73 #endif
74 
75 /*! @brief Constructs a status code value from a group and a code number. */
76 #if !defined(MAKE_STATUS)
77 #define MAKE_STATUS(group, code) ((((group) * 100) + (code)))
78 #endif
79 
80 /*!
81  * @brief Flash driver status codes.
82  */
83 enum
84 {
85     kStatus_FLASH_Success         = MAKE_STATUS(kStatusGroupGeneric, 0),     /*!< API is executed successfully*/
86     kStatus_FLASH_InvalidArgument = MAKE_STATUS(kStatusGroupGeneric, 4),     /*!< Invalid argument*/
87     kStatus_FLASH_SizeError       = MAKE_STATUS(kStatusGroupFlashDriver, 0), /*!< Error size*/
88     kStatus_FLASH_AlignmentError =
89         MAKE_STATUS(kStatusGroupFlashDriver, 1), /*!< Parameter is not aligned with the specified baseline*/
90     kStatus_FLASH_AddressError = MAKE_STATUS(kStatusGroupFlashDriver, 2), /*!< Address is out of range */
91     kStatus_FLASH_AccessError =
92         MAKE_STATUS(kStatusGroupFlashDriver, 3), /*!< Invalid instruction codes and out-of bound addresses */
93     kStatus_FLASH_ProtectionViolation = MAKE_STATUS(
94         kStatusGroupFlashDriver, 4), /*!< The program/erase operation is requested to execute on protected areas */
95     kStatus_FLASH_CommandFailure =
96         MAKE_STATUS(kStatusGroupFlashDriver, 5), /*!< Run-time error during command execution. */
97     kStatus_FLASH_UnknownProperty = MAKE_STATUS(kStatusGroupFlashDriver, 6), /*!< Unknown property.*/
98     kStatus_FLASH_EraseKeyError   = MAKE_STATUS(kStatusGroupFlashDriver, 7), /*!< API erase key is invalid.*/
99     kStatus_FLASH_RegionExecuteOnly =
100         MAKE_STATUS(kStatusGroupFlashDriver, 8),                             /*!< The current region is execute-only.*/
101     kStatus_FLASH_ExecuteInRamFunctionNotReady =
102         MAKE_STATUS(kStatusGroupFlashDriver, 9), /*!< Execute-in-RAM function is not available.*/
103 
104     kStatus_FLASH_CommandNotSupported = MAKE_STATUS(kStatusGroupFlashDriver, 11), /*!< Flash API is not supported.*/
105     kStatus_FLASH_ReadOnlyProperty = MAKE_STATUS(kStatusGroupFlashDriver, 12), /*!< The flash property is read-only.*/
106     kStatus_FLASH_InvalidPropertyValue =
107         MAKE_STATUS(kStatusGroupFlashDriver, 13), /*!< The flash property value is out of range.*/
108     kStatus_FLASH_InvalidSpeculationOption =
109         MAKE_STATUS(kStatusGroupFlashDriver, 14), /*!< The option of flash prefetch speculation is invalid.*/
110     kStatus_FLASH_EccError = MAKE_STATUS(kStatusGroupFlashDriver,
111                                          0x10),   /*!< A correctable or uncorrectable error during command execution. */
112     kStatus_FLASH_CompareError =
113         MAKE_STATUS(kStatusGroupFlashDriver, 0x11), /*!< Destination and source memory contents do not match. */
114     kStatus_FLASH_RegulationLoss = MAKE_STATUS(kStatusGroupFlashDriver, 0x12), /*!< A loss of regulation during read. */
115     kStatus_FLASH_InvalidWaitStateCycles =
116         MAKE_STATUS(kStatusGroupFlashDriver, 0x13), /*!< The wait state cycle set to r/w mode is invalid. */
117 
118     kStatus_FLASH_OutOfDateCfpaPage =
119         MAKE_STATUS(kStatusGroupFlashDriver, 0x20), /*!< CFPA page version is out of date. */
120     kStatus_FLASH_BlankIfrPageData = MAKE_STATUS(kStatusGroupFlashDriver, 0x21), /*!< Blank page cannnot be read. */
121     kStatus_FLASH_EncryptedRegionsEraseNotDoneAtOnce =
122         MAKE_STATUS(kStatusGroupFlashDriver, 0x22), /*!< Encrypted flash subregions are not erased at once. */
123     kStatus_FLASH_ProgramVerificationNotAllowed = MAKE_STATUS(
124         kStatusGroupFlashDriver, 0x23), /*!< Program verification is not allowed when the encryption is enabled. */
125     kStatus_FLASH_HashCheckError =
126         MAKE_STATUS(kStatusGroupFlashDriver, 0x24), /*!< Hash check of page data is failed. */
127     kStatus_FLASH_SealedFfrRegion      = MAKE_STATUS(kStatusGroupFlashDriver, 0x25), /*!< The FFR region is sealed. */
128     kStatus_FLASH_FfrRegionWriteBroken = MAKE_STATUS(
129         kStatusGroupFlashDriver, 0x26), /*!< The FFR Spec region is not allowed to be written discontinuously. */
130     kStatus_FLASH_NmpaAccessNotAllowed =
131         MAKE_STATUS(kStatusGroupFlashDriver, 0x27), /*!< The NMPA region is not allowed to be read/written/erased. */
132     kStatus_FLASH_CmpaCfgDirectEraseNotAllowed =
133         MAKE_STATUS(kStatusGroupFlashDriver, 0x28), /*!< The CMPA Cfg region is not allowed to be erased directly. */
134     kStatus_FLASH_FfrBankIsLocked = MAKE_STATUS(kStatusGroupFlashDriver, 0x29), /*!< The FFR bank region is locked. */
135     kStatus_FLASH_CfpaScratchPageInvalid =
136         MAKE_STATUS(kStatusGroupFlashDriver, 0x30),                             /*!< CFPA Scratch Page is invalid*/
137     kStatus_FLASH_CfpaVersionRollbackDisallowed =
138         MAKE_STATUS(kStatusGroupFlashDriver, 0x31), /*!< CFPA version rollback is not allowed */
139     kStatus_FLASH_ReadHidingAreaDisallowed =
140         MAKE_STATUS(kStatusGroupFlashDriver, 0x32), /*!< Flash hiding read is not allowed */
141     kStatus_FLASH_ModifyProtectedAreaDisallowed =
142         MAKE_STATUS(kStatusGroupFlashDriver, 0x33), /*!< Flash firewall page locked erase and program are not allowed */
143     kStatus_FLASH_CommandOperationInProgress = MAKE_STATUS(
144         kStatusGroupFlashDriver, 0x34), /*!< The flash state is busy, indicate that a flash command in progress. */
145 };
146 /*@}*/
147 
148 /*!
149  * @name Flash API key
150  * @{
151  */
152 /*! @brief Constructs the four character code for the Flash driver API key. */
153 #if !defined(FOUR_CHAR_CODE)
154 #define FOUR_CHAR_CODE(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | ((a)))
155 #endif
156 
157 /*!
158  * @brief Enumeration for Flash driver API keys.
159  *
160  * @note The resulting value is built with a byte order such that the string
161  * being readable in expected order when viewed in a hex editor, if the value
162  * is treated as a 32-bit little endian value.
163  */
164 enum _flash_driver_api_keys
165 {
166     kFLASH_ApiEraseKey = FOUR_CHAR_CODE('l', 'f', 'e', 'k') /*!< Key value used to validate all flash erase APIs.*/
167 };
168 /*@}*/
169 
170 /*!
171  * @brief Enumeration for various flash properties.
172  */
173 typedef enum _flash_property_tag
174 {
175     kFLASH_PropertyPflashSectorSize    = 0x00U, /*!< Pflash sector size property.*/
176     kFLASH_PropertyPflashTotalSize     = 0x01U, /*!< Pflash total size property.*/
177     kFLASH_PropertyPflashBlockSize     = 0x02U, /*!< Pflash block size property.*/
178     kFLASH_PropertyPflashBlockCount    = 0x03U, /*!< Pflash block count property.*/
179     kFLASH_PropertyPflashBlockBaseAddr = 0x04U, /*!< Pflash block base address property.*/
180 
181     kFLASH_PropertyPflashPageSize   = 0x30U,    /*!< Pflash page size property.*/
182     kFLASH_PropertyPflashSystemFreq = 0x31U,    /*!< System Frequency System Frequency.*/
183 
184     kFLASH_PropertyFfrSectorSize    = 0x40U,    /*!< FFR sector size property.*/
185     kFLASH_PropertyFfrTotalSize     = 0x41U,    /*!< FFR total size property.*/
186     kFLASH_PropertyFfrBlockBaseAddr = 0x42U,    /*!< FFR block base address property.*/
187     kFLASH_PropertyFfrPageSize      = 0x43U,    /*!< FFR page size property.*/
188 } flash_property_tag_t;
189 
190 /*!
191  * @brief Enumeration for flash max pages to erase.
192  */
193 enum _flash_max_erase_page_value
194 {
195     kFLASH_MaxPagesToErase = 100U /*!< The max value in pages to erase. */
196 };
197 
198 /*!
199  * @brief Enumeration for flash alignment property.
200  */
201 enum _flash_alignment_property
202 {
203     kFLASH_AlignementUnitVerifyErase = 4U,       /*!< The alignment unit in bytes used for verify erase operation.*/
204     kFLASH_AlignementUnitProgram     = 512U,     /*!< The alignment unit in bytes used for program operation.*/
205     /*kFLASH_AlignementUnitVerifyProgram = 4U,*/ /*!< The alignment unit in bytes used for verify program operation.*/
206     kFLASH_AlignementUnitSingleWordRead = 16U    /*!< The alignment unit in bytes used for SingleWordRead command.*/
207 };
208 
209 /*!
210  * @brief Enumeration for flash read ecc option
211  */
212 enum _flash_read_ecc_option
213 {
214     kFLASH_ReadWithEccOn  = 0U, /*! ECC is on */
215     kFLASH_ReadWithEccOff = 1U  /*! ECC is off */
216 };
217 
218 /*!
219  * @brief Enumeration for flash read margin option
220  */
221 enum _flash_read_margin_option
222 {
223     kFLASH_ReadMarginNormal                = 0U, /*!< Normal read */
224     kFLASH_ReadMarginVsProgram             = 1U, /*!< Margin vs. program */
225     kFLASH_ReadMarginVsErase               = 2U, /*!< Margin vs. erase */
226     kFLASH_ReadMarginIllegalBitCombination = 3U  /*!< Illegal bit combination */
227 };
228 
229 /*!
230  * @brief Enumeration for flash read dmacc option
231  */
232 enum _flash_read_dmacc_option
233 {
234     kFLASH_ReadDmaccDisabled = 0U, /*!< Memory word */
235     kFLASH_ReadDmaccEnabled  = 1U  /*!< DMACC word */
236 };
237 
238 /*!
239  * @brief Enumeration for flash ramp control option
240  */
241 enum _flash_ramp_control_option
242 {
243     kFLASH_RampControlDivisionFactorReserved = 0U, /*!< Reserved */
244     kFLASH_RampControlDivisionFactor256      = 1U, /*!< clk48mhz / 256 = 187.5KHz */
245     kFLASH_RampControlDivisionFactor128      = 2U, /*!< clk48mhz / 128 = 375KHz */
246     kFLASH_RampControlDivisionFactor64       = 3U  /*!< clk48mhz / 64 = 750KHz */
247 };
248 
249 /*! @brief Flash ECC log info. */
250 typedef struct _flash_ecc_log
251 {
252     uint32_t firstEccEventAddress;
253     uint32_t eccErrorCount;
254     uint32_t eccCorrectionCount;
255     uint32_t reserved;
256 } flash_ecc_log_t;
257 
258 /*! @brief Flash controller paramter config. */
259 typedef struct _flash_mode_config
260 {
261     uint32_t sysFreqInMHz;
262     /* ReadSingleWord parameter. */
263     struct
264     {
265         uint8_t readWithEccOff : 1;
266         uint8_t readMarginLevel : 2;
267         uint8_t readDmaccWord : 1;
268         uint8_t reserved0 : 4;
269         uint8_t reserved1[3];
270     } readSingleWord;
271     /* SetWriteMode parameter. */
272     struct
273     {
274         uint8_t programRampControl;
275         uint8_t eraseRampControl;
276         uint8_t reserved[2];
277     } setWriteMode;
278     /* SetReadMode parameter. */
279     struct
280     {
281         uint16_t readInterfaceTimingTrim;
282         uint16_t readControllerTimingTrim;
283         uint8_t readWaitStates;
284         uint8_t reserved[3];
285     } setReadMode;
286 } flash_mode_config_t;
287 
288 /*! @brief Flash controller paramter config. */
289 typedef struct _flash_ffr_config
290 {
291     uint32_t ffrBlockBase;
292     uint32_t ffrTotalSize;
293     uint32_t ffrPageSize;
294     uint32_t cfpaPageVersion;
295     uint32_t cfpaPageOffset;
296 } flash_ffr_config_t;
297 
298 /*! @brief Flash driver state information.
299  *
300  * An instance of this structure is allocated by the user of the flash driver and
301  * passed into each of the driver APIs.
302  */
303 typedef struct
304 {
305     uint32_t PFlashBlockBase;  /*!< A base address of the first PFlash block */
306     uint32_t PFlashTotalSize;  /*!< The size of the combined PFlash block. */
307     uint32_t PFlashBlockCount; /*!< A number of PFlash blocks. */
308     uint32_t PFlashPageSize;   /*!< The size in bytes of a page of PFlash. */
309     uint32_t PFlashSectorSize; /*!< The size in bytes of a sector of PFlash. */
310     flash_ffr_config_t ffrConfig;
311     flash_mode_config_t modeConfig;
312     uint32_t *nbootCtx;
313     bool useAhbRead;
314 } flash_config_t;
315 
316 /*******************************************************************************
317  * API
318  ******************************************************************************/
319 
320 #if defined(__cplusplus)
321 extern "C" {
322 #endif
323 
324 /*!
325  * @name Initialization
326  * @{
327  */
328 
329 /*!
330  * @brief Initializes the global flash properties structure members.
331  *
332  * This function checks and initializes the Flash module for the other Flash APIs.
333  *
334  * @param config Pointer to the storage for the driver runtime state.
335  *
336  * @retval #kStatus_FLASH_Success API was executed successfully.
337  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
338  * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
339  * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
340  * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
341  * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read.
342  */
343 status_t FLASH_Init(flash_config_t *config);
344 
345 /*@}*/
346 
347 /*!
348  * @name Erasing
349  * @{
350  */
351 
352 /*!
353  * @brief Erases the flash sectors encompassed by parameters passed into function.
354  *
355  * This function erases the appropriate number of flash sectors based on the
356  * desired start address and length.
357  *
358  * @param config The pointer to the storage for the driver runtime state.
359  * @param start The start address of the desired flash memory to be erased.
360  *              NOTE: The start address need to be 4 Bytes-aligned.
361  *
362  * @param lengthInBytes The length, given in bytes need be 4 Bytes-aligned.
363  *
364  * @param key The value used to validate all flash erase APIs.
365  *
366  * @retval #kStatus_FLASH_Success API was executed successfully.
367  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
368  * @retval #kStatus_FLASH_AlignmentError The parameter is not aligned with the specified baseline.
369  * @retval #kStatus_FLASH_AddressError The address is out of range.
370  * @retval #kStatus_FLASH_EraseKeyError The API erase key is invalid.
371  * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash firewall page locked erase and program are not allowed
372  * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
373  * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
374  * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
375  * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read.
376  */
377 status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
378 
379 /*!
380  * @brief Non-blocking Erases the flash sectors encompassed by parameters passed into function.
381  *
382  * This is a non-blocking function, which returns right away.
383  * This function erases the appropriate number of flash sectors based on the desired start
384  * address and length, and get the command execute status from the "FLASH_GetCommandState".
385  *
386  * @param config The pointer to the storage for the driver runtime state.
387  * @param start The start address of the desired flash memory to be erased.
388  *              NOTE: The start address need be 4 Bytes-aligned.
389  *
390  * @param lengthInBytes The length, given in bytes need be 4 Bytes-aligned.
391  *
392  * @param key The value used to validate all flash erase APIs.
393  *
394  * @retval #kStatus_FLASH_Success API was executed successfully.
395  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
396  * @retval #kStatus_FLASH_AlignmentError The parameter is not aligned with the specified baseline.
397  * @retval #kStatus_FLASH_AddressError The address is out of range.
398  * @retval #kStatus_FLASH_EraseKeyError The API erase key is invalid.
399  * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash firewall page locked erase and program are not allowed
400  */
401 status_t FLASH_EraseNonBlocking(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
402 
403 /*@}*/
404 
405 /*!
406  * @name Programming
407  * @{
408  */
409 
410 /*!
411  * @brief Programs flash with data at locations passed in through parameters.
412  *
413  * This function programs the flash memory with the desired data for a given
414  * flash area as determined by the start address and the length.
415  *
416  * @param config A pointer to the storage for the driver runtime state.
417  * @param start The start address of the desired flash memory to be programmed. Must be
418  *              word-aligned.
419  * @param src A pointer to the source buffer of data that is to be programmed
420  *            into the flash.
421  * @param lengthInBytes The length, given in bytes (not words or long-words),
422  *                      to be programmed. Must be word-aligned.
423  *
424  * @retval #kStatus_FLASH_Success API was executed successfully.
425  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
426  * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline.
427  * @retval #kStatus_FLASH_AddressError Address is out of range.
428  * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
429  * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash firewall page locked erase and program are not allowed
430  * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
431  * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
432  * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read.
433  * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
434  */
435 status_t FLASH_Program(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
436 
437 /*@}*/
438 
439 /*!
440  * @name Reading
441  * @{
442  */
443 
444 /*!
445  * @brief Reads flash at locations passed in through parameters.
446  *
447  * This function read the flash memory from a given flash area as determined
448  * by the start address and the length.
449  *
450  * @param config A pointer to the storage for the driver runtime state.
451  * @param start The start address of the desired flash memory to be read.
452  * @param dest A pointer to the dest buffer of data that is to be read
453  *            from the flash.
454  * @param lengthInBytes The length, given in bytes (not words or long-words),
455  *                      to be read.
456  *
457  * @retval #kStatus_FLASH_Success API was executed successfully.
458  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
459  * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline.
460  * @retval #kStatus_FLASH_AddressError Address is out of range.
461  * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed
462  * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
463  * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
464  * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read.
465  * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
466  */
467 status_t FLASH_Read(flash_config_t *config, uint32_t start, uint8_t *dest, uint32_t lengthInBytes);
468 
469 /*@}*/
470 
471 /*!
472  * @name Verification
473  * @{
474  */
475 
476 /*!
477  * @brief Verifies an erasure of the desired flash area at a specified margin level.
478  *
479  * This function checks the appropriate number of flash sectors based on
480  * the desired start address and length to check whether the flash is erased
481  * to the specified read margin level.
482  *
483  * @param config A pointer to the storage for the driver runtime state.
484  * @param start The start address of the desired flash memory to be verified.
485  *        The start address does not need to be sector-aligned but must be word-aligned.
486  * @param lengthInBytes The length, given in bytes (not words or long-words),
487  *        to be verified. Must be word-aligned.
488  *
489  * @retval #kStatus_FLASH_Success API was executed successfully.
490  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
491  * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
492  * @retval #kStatus_FLASH_AddressError Address is out of range.
493  * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
494  * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
495  * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read.
496  * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
497  */
498 status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes);
499 
500 /*!
501  * @brief Verifies programming of the desired flash area at a specified margin level.
502  *
503  * This function verifies the data programed in the flash memory using the
504  * Flash Program Check Command and compares it to the expected data for a given
505  * flash area as determined by the start address and length.
506  *
507  * @param config A pointer to the storage for the driver runtime state.
508  * @param start The start address of the desired flash memory to be verified. Must be word-aligned.
509  * @param lengthInBytes The length, given in bytes (not words or long-words),
510  *        to be verified. Must be word-aligned.
511  * @param expectedData A pointer to the expected data that is to be
512  *        verified against.
513  * @param failedAddress A pointer to the returned failing address.
514  * @param failedData A pointer to the returned failing data.  Some derivatives do
515  *        not include failed data as part of the FCCOBx registers.  In this
516  *        case, zeros are returned upon failure.
517  *
518  * @retval #kStatus_FLASH_Success API was executed successfully.
519  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
520  * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
521  * @retval #kStatus_FLASH_AddressError Address is out of range.
522  * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
523  * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed
524  * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
525  * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
526  * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read.
527  * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
528  */
529 status_t FLASH_VerifyProgram(flash_config_t *config,
530                              uint32_t start,
531                              uint32_t lengthInBytes,
532                              const uint8_t *expectedData,
533                              uint32_t *failedAddress,
534                              uint32_t *failedData);
535 
536 /*@}*/
537 
538 /*!
539  * @name Properties
540  * @{
541  */
542 
543 /*!
544  * @brief Returns the desired flash property.
545  *
546  * @param config A pointer to the storage for the driver runtime state.
547  * @param whichProperty The desired property from the list of properties in
548  *        enum flash_property_tag_t
549  * @param value A pointer to the value returned for the desired flash property.
550  *
551  * @retval #kStatus_FLASH_Success API was executed successfully.
552  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
553  * @retval #kStatus_FLASH_UnknownProperty An unknown property tag.
554  */
555 status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value);
556 
557 /*@}*/
558 
559 /*!
560  * @name flash status
561  * @{
562  */
563 #if defined(FSL_FEATURE_SYSCON_HAS_FLASH_HIDING) && (FSL_FEATURE_SYSCON_HAS_FLASH_HIDING == 1)
564 /*!
565  * @brief Validates the given address range is loaded in the flash hiding region.
566  *
567  * @param config A pointer to the storage for the driver runtime state.
568  * @param startAddress The start address of the desired flash memory to be verified.
569  * @param lengthInBytes The length, given in bytes (not words or long-words),
570  *        to be verified.
571  *
572  * @retval #kStatus_FLASH_Success API was executed successfully.
573  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
574  * @retval #kStatus_FLASH_ReadHidingAreaDisallowed Flash hiding read is not allowed.
575  */
576 status_t FLASH_IsFlashAreaReadable(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes);
577 #endif
578 
579 #if defined(FSL_FEATURE_SYSCON_HAS_CDPA) && (FSL_FEATURE_SYSCON_HAS_CDPA == 1)
580 /*!
581  * @brief Validates the given address range is loaded in the Flash firewall page locked region.
582  *
583  * @param config A pointer to the storage for the driver runtime state.
584  * @param startAddress The start address of the desired flash memory to be verified.
585  * @param lengthInBytes The length, given in bytes (not words or long-words),
586  *        to be verified.
587  *
588  * @retval #kStatus_FLASH_Success API was executed successfully.
589  * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
590  * @retval #kStatus_FLASH_ModifyProtectedAreaDisallowed Flash hiding read is not allowed.
591  */
592 status_t FLASH_IsFlashAreaModifiable(flash_config_t *config, uint32_t startAddress, uint32_t lengthInBytes);
593 #endif
594 
595 /*@}*/
596 
597 /*!
598  * @name command status
599  * @{
600  */
601 /*!
602  * @brief Get flash command execute status.
603  *
604  * This function is used to obtain the status after the command "FLASH_EraseNonBlocking" is executed.
605  *
606  * @param config A pointer to the storage for the driver runtime state.
607  *
608  * @retval #kStatus_FLASH_CommandOperationInProgress Indicate that a flash command in progress.
609  * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
610  * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
611  * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
612  * @retval #kStatus_FLASH_RegulationLoss A loss of regulation during read.
613  * @retval #kStatus_FLASH_Success API was executed successfully.
614  */
615 status_t FLASH_GetCommandState(flash_config_t *config);
616 
617 /*@}*/
618 
619 #ifdef __cplusplus
620 }
621 #endif
622 
623 /*@}*/
624 
625 #endif /* _FLASH_FLASH_H_ */
626