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