Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

823 строки
36 KiB

  1. /*
  2. * Copyright 2013-2016 Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. *
  8. */
  9. #ifndef FSL_FTFX_CONTROLLER_H
  10. #define FSL_FTFX_CONTROLLER_H
  11. #include "fsl_ftfx_features.h"
  12. #include "fsl_ftfx_utilities.h"
  13. /*!
  14. * @addtogroup ftfx_controller
  15. * @{
  16. */
  17. /*******************************************************************************
  18. * Definitions
  19. ******************************************************************************/
  20. /* Component ID definition, used by tools. */
  21. #ifndef FSL_COMPONENT_ID
  22. #define FSL_COMPONENT_ID "platform.drivers.flash"
  23. #endif
  24. /*!
  25. * @name FTFx status
  26. * @{
  27. */
  28. /*! @brief FTFx driver status group. */
  29. #if defined(kStatusGroup_FlashDriver)
  30. #define kStatusGroupGeneric kStatusGroup_Generic
  31. #define kStatusGroupFtfxDriver kStatusGroup_FlashDriver
  32. #elif defined(kStatusGroup_FLASH)
  33. #define kStatusGroupGeneric kStatusGroup_Generic
  34. #define kStatusGroupFtfxDriver kStatusGroup_FLASH
  35. #else
  36. #define kStatusGroupGeneric 0
  37. #define kStatusGroupFtfxDriver 1
  38. #endif
  39. /*!
  40. * @brief FTFx driver status codes.
  41. */
  42. enum
  43. {
  44. kStatus_FTFx_Success = MAKE_STATUS(kStatusGroupGeneric, 0), /*!< API is executed successfully*/
  45. kStatus_FTFx_InvalidArgument = MAKE_STATUS(kStatusGroupGeneric, 4), /*!< Invalid argument*/
  46. kStatus_FTFx_SizeError = MAKE_STATUS(kStatusGroupFtfxDriver, 0), /*!< Error size*/
  47. kStatus_FTFx_AlignmentError =
  48. MAKE_STATUS(kStatusGroupFtfxDriver, 1), /*!< Parameter is not aligned with the specified baseline*/
  49. kStatus_FTFx_AddressError = MAKE_STATUS(kStatusGroupFtfxDriver, 2), /*!< Address is out of range */
  50. kStatus_FTFx_AccessError =
  51. MAKE_STATUS(kStatusGroupFtfxDriver, 3), /*!< Invalid instruction codes and out-of bound addresses */
  52. kStatus_FTFx_ProtectionViolation = MAKE_STATUS(
  53. kStatusGroupFtfxDriver, 4), /*!< The program/erase operation is requested to execute on protected areas */
  54. kStatus_FTFx_CommandFailure =
  55. MAKE_STATUS(kStatusGroupFtfxDriver, 5), /*!< Run-time error during command execution. */
  56. kStatus_FTFx_UnknownProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 6), /*!< Unknown property.*/
  57. kStatus_FTFx_EraseKeyError = MAKE_STATUS(kStatusGroupFtfxDriver, 7), /*!< API erase key is invalid.*/
  58. kStatus_FTFx_RegionExecuteOnly = MAKE_STATUS(kStatusGroupFtfxDriver, 8), /*!< The current region is execute-only.*/
  59. kStatus_FTFx_ExecuteInRamFunctionNotReady =
  60. MAKE_STATUS(kStatusGroupFtfxDriver, 9), /*!< Execute-in-RAM function is not available.*/
  61. kStatus_FTFx_PartitionStatusUpdateFailure =
  62. MAKE_STATUS(kStatusGroupFtfxDriver, 10), /*!< Failed to update partition status.*/
  63. kStatus_FTFx_SetFlexramAsEepromError =
  64. MAKE_STATUS(kStatusGroupFtfxDriver, 11), /*!< Failed to set FlexRAM as EEPROM.*/
  65. kStatus_FTFx_RecoverFlexramAsRamError =
  66. MAKE_STATUS(kStatusGroupFtfxDriver, 12), /*!< Failed to recover FlexRAM as RAM.*/
  67. kStatus_FTFx_SetFlexramAsRamError = MAKE_STATUS(kStatusGroupFtfxDriver, 13), /*!< Failed to set FlexRAM as RAM.*/
  68. kStatus_FTFx_RecoverFlexramAsEepromError =
  69. MAKE_STATUS(kStatusGroupFtfxDriver, 14), /*!< Failed to recover FlexRAM as EEPROM.*/
  70. kStatus_FTFx_CommandNotSupported = MAKE_STATUS(kStatusGroupFtfxDriver, 15), /*!< Flash API is not supported.*/
  71. kStatus_FTFx_SwapSystemNotInUninitialized =
  72. MAKE_STATUS(kStatusGroupFtfxDriver, 16), /*!< Swap system is not in an uninitialzed state.*/
  73. kStatus_FTFx_SwapIndicatorAddressError =
  74. MAKE_STATUS(kStatusGroupFtfxDriver, 17), /*!< The swap indicator address is invalid.*/
  75. kStatus_FTFx_ReadOnlyProperty = MAKE_STATUS(kStatusGroupFtfxDriver, 18), /*!< The flash property is read-only.*/
  76. kStatus_FTFx_InvalidPropertyValue =
  77. MAKE_STATUS(kStatusGroupFtfxDriver, 19), /*!< The flash property value is out of range.*/
  78. kStatus_FTFx_InvalidSpeculationOption =
  79. MAKE_STATUS(kStatusGroupFtfxDriver, 20), /*!< The option of flash prefetch speculation is invalid.*/
  80. };
  81. /*@}*/
  82. /*!
  83. * @name FTFx API key
  84. * @{
  85. */
  86. /*!
  87. * @brief Enumeration for FTFx driver API keys.
  88. *
  89. * @note The resulting value is built with a byte order such that the string
  90. * being readable in expected order when viewed in a hex editor, if the value
  91. * is treated as a 32-bit little endian value.
  92. */
  93. enum _ftfx_driver_api_keys
  94. {
  95. kFTFx_ApiEraseKey = FOUR_CHAR_CODE('k', 'f', 'e', 'k') /*!< Key value used to validate all FTFx erase APIs.*/
  96. };
  97. /*@}*/
  98. /*!
  99. * @brief Enumeration for the FlexRAM load during reset option.
  100. */
  101. typedef enum _ftfx_partition_flexram_load_option
  102. {
  103. kFTFx_PartitionFlexramLoadOptLoadedWithValidEepromData =
  104. 0x00U, /*!< FlexRAM is loaded with valid EEPROM data during reset sequence.*/
  105. kFTFx_PartitionFlexramLoadOptNotLoaded = 0x01U /*!< FlexRAM is not loaded during reset sequence.*/
  106. } ftfx_partition_flexram_load_opt_t;
  107. /*!
  108. * @brief Enumeration for the two possible options of flash read resource command.
  109. */
  110. typedef enum _ftfx_read_resource_opt
  111. {
  112. kFTFx_ResourceOptionFlashIfr =
  113. 0x00U, /*!< Select code for Program flash 0 IFR, Program flash swap 0 IFR, Data flash 0 IFR */
  114. kFTFx_ResourceOptionVersionId = 0x01U /*!< Select code for the version ID*/
  115. } ftfx_read_resource_opt_t;
  116. /*!
  117. * @brief Enumeration for supported FTFx margin levels.
  118. */
  119. typedef enum _ftfx_margin_value
  120. {
  121. kFTFx_MarginValueNormal, /*!< Use the 'normal' read level for 1s.*/
  122. kFTFx_MarginValueUser, /*!< Apply the 'User' margin to the normal read-1 level.*/
  123. kFTFx_MarginValueFactory, /*!< Apply the 'Factory' margin to the normal read-1 level.*/
  124. kFTFx_MarginValueInvalid /*!< Not real margin level, Used to determine the range of valid margin level. */
  125. } ftfx_margin_value_t;
  126. /*!
  127. * @brief Enumeration for the three possible FTFx security states.
  128. */
  129. typedef enum _ftfx_security_state
  130. {
  131. kFTFx_SecurityStateNotSecure = (int)0xc33cc33cu, /*!< Flash is not secure.*/
  132. kFTFx_SecurityStateBackdoorEnabled = (int)0x5aa55aa5u, /*!< Flash backdoor is enabled.*/
  133. kFTFx_SecurityStateBackdoorDisabled = (int)0x5ac33ca5u /*!< Flash backdoor is disabled.*/
  134. } ftfx_security_state_t;
  135. /*!
  136. * @brief Enumeration for the two possilbe options of set FlexRAM function command.
  137. */
  138. typedef enum _ftfx_flexram_function_option
  139. {
  140. kFTFx_FlexramFuncOptAvailableAsRam = 0xFFU, /*!< An option used to make FlexRAM available as RAM */
  141. kFTFx_FlexramFuncOptAvailableForEeprom = 0x00U /*!< An option used to make FlexRAM available for EEPROM */
  142. } ftfx_flexram_func_opt_t;
  143. #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
  144. /*!
  145. * @brief Enumeration for the possible options of Swap control commands
  146. */
  147. typedef enum _ftfx_swap_control_option
  148. {
  149. kFTFx_SwapControlOptionIntializeSystem = 0x01U, /*!< An option used to initialize the Swap system */
  150. kFTFx_SwapControlOptionSetInUpdateState = 0x02U, /*!< An option used to set the Swap in an update state */
  151. kFTFx_SwapControlOptionSetInCompleteState = 0x04U, /*!< An option used to set the Swap in a complete state */
  152. kFTFx_SwapControlOptionReportStatus = 0x08U, /*!< An option used to report the Swap status */
  153. kFTFx_SwapControlOptionDisableSystem = 0x10U /*!< An option used to disable the Swap status */
  154. } ftfx_swap_control_opt_t;
  155. #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
  156. /*!
  157. * @brief Enumeration for the possible flash Swap status.
  158. */
  159. typedef enum _ftfx_swap_state
  160. {
  161. kFTFx_SwapStateUninitialized = 0x00U, /*!< Flash Swap system is in an uninitialized state.*/
  162. kFTFx_SwapStateReady = 0x01U, /*!< Flash Swap system is in a ready state.*/
  163. kFTFx_SwapStateUpdate = 0x02U, /*!< Flash Swap system is in an update state.*/
  164. kFTFx_SwapStateUpdateErased = 0x03U, /*!< Flash Swap system is in an updateErased state.*/
  165. kFTFx_SwapStateComplete = 0x04U, /*!< Flash Swap system is in a complete state.*/
  166. kFTFx_SwapStateDisabled = 0x05U /*!< Flash Swap system is in a disabled state.*/
  167. } ftfx_swap_state_t;
  168. #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
  169. /*!
  170. * @brief Enumeration for the possible flash Swap block status
  171. */
  172. typedef enum _ftfx_swap_block_status
  173. {
  174. kFTFx_SwapBlockStatusLowerHalfProgramBlocksAtZero =
  175. 0x00U, /*!< Swap block status is that lower half program block at zero.*/
  176. kFTFx_SwapBlockStatusUpperHalfProgramBlocksAtZero =
  177. 0x01U, /*!< Swap block status is that upper half program block at zero.*/
  178. } ftfx_swap_block_status_t;
  179. /*!
  180. * @brief Flash Swap information
  181. */
  182. typedef struct _ftfx_swap_state_config
  183. {
  184. ftfx_swap_state_t flashSwapState; /*!<The current Swap system status.*/
  185. ftfx_swap_block_status_t currentSwapBlockStatus; /*!< The current Swap block status.*/
  186. ftfx_swap_block_status_t nextSwapBlockStatus; /*!< The next Swap block status.*/
  187. } ftfx_swap_state_config_t;
  188. #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
  189. /*!
  190. * @brief Enumeration for FTFx memory type.
  191. */
  192. enum _ftfx_memory_type
  193. {
  194. kFTFx_MemTypePflash = 0x00U,
  195. kFTFx_MemTypeFlexnvm = 0x01U
  196. };
  197. /*!
  198. * @brief ftfx special memory access information.
  199. */
  200. typedef struct _ftfx_special_mem
  201. {
  202. uint32_t base; /*!< Base address of flash special memory.*/
  203. uint32_t size; /*!< size of flash special memory.*/
  204. uint32_t count; /*!< flash special memory count.*/
  205. } ftfx_spec_mem_t;
  206. #if defined(__CC_ARM)
  207. #pragma anon_unions
  208. #endif
  209. /*!
  210. * @brief Flash memory descriptor.
  211. */
  212. typedef struct _ftfx_mem_descriptor
  213. {
  214. struct
  215. {
  216. uint8_t type; /*!< Type of flash block.*/
  217. uint8_t index; /*!< Index of flash block.*/
  218. uint8_t reserved[2];
  219. };
  220. struct
  221. {
  222. uint32_t isIndBlock : 1;
  223. uint32_t hasIndPfsizeReg : 1;
  224. uint32_t hasProtControl : 1;
  225. uint32_t hasIndProtReg : 1;
  226. uint32_t hasXaccControl : 1;
  227. uint32_t hasIndXaccReg : 1;
  228. uint32_t : 18;
  229. uint32_t ProtRegBits : 8;
  230. } feature;
  231. uint32_t blockBase; /*!< A base address of the flash block */
  232. #if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS) && FSL_FEATURE_FLASH_HAS_FLEX_NVM_ALIAS
  233. uint32_t aliasBlockBase; /*!< A base address of the alias flash block */
  234. #endif
  235. uint32_t totalSize; /*!< The size of the flash block. */
  236. uint32_t sectorSize; /*!< The size in bytes of a sector of flash. */
  237. uint32_t blockCount; /*!< A number of flash blocks. */
  238. ftfx_spec_mem_t accessSegmentMem;
  239. ftfx_spec_mem_t protectRegionMem;
  240. } ftfx_mem_desc_t;
  241. /*!
  242. * @brief Active FTFx information for the current operation.
  243. */
  244. typedef struct _ftfx_ops_config
  245. {
  246. uint32_t convertedAddress; /*!< A converted address for the current flash type.*/
  247. struct
  248. {
  249. uint8_t sectorCmd;
  250. uint8_t sectionCmd;
  251. uint8_t resourceCmd;
  252. uint8_t checkCmd;
  253. uint8_t swapCtrlCmd;
  254. uint8_t blockWriteUnitSize;
  255. uint8_t reserved[2];
  256. } addrAligment;
  257. } ftfx_ops_config_t;
  258. /*!
  259. * @brief Flash IFR memory descriptor.
  260. */
  261. typedef struct _ftfx_ifr_descriptor
  262. {
  263. struct
  264. {
  265. uint32_t has4ByteIdxSupport : 1;
  266. uint32_t has8ByteIdxSupport : 1;
  267. uint32_t : 30;
  268. } feature;
  269. struct
  270. {
  271. uint8_t versionIdStart; /*!< Version ID start address */
  272. uint8_t versionIdSize;
  273. uint16_t ifrMemSize;
  274. uint32_t pflashIfrStart; /*!< Program Flash 0 IFR start address */
  275. uint32_t dflashIfrStart; /*!< Data Flash 0 IFR start address */
  276. uint32_t pflashSwapIfrStart; /*!< Program Flash Swap IFR start address*/
  277. } resRange;
  278. struct
  279. {
  280. uint16_t mix8byteIdxStart;
  281. uint16_t mix8byteIdxEnd;
  282. } idxInfo;
  283. } ftfx_ifr_desc_t;
  284. typedef union
  285. {
  286. uint32_t commadAddr;
  287. void (*callFlashCommand)(FTFx_REG8_ACCESS_TYPE FTMRx_fstat);
  288. } function_ptr_t;
  289. /*! @brief Flash driver state information.
  290. *
  291. * An instance of this structure is allocated by the user of the flash driver and
  292. * passed into each of the driver APIs.
  293. */
  294. typedef struct _ftfx_config
  295. {
  296. ftfx_mem_desc_t flashDesc;
  297. ftfx_ops_config_t opsConfig;
  298. uint32_t flexramBlockBase; /*!< The base address of the FlexRAM/acceleration RAM */
  299. uint32_t flexramTotalSize; /*!< The size of the FlexRAM/acceleration RAM */
  300. uint16_t eepromTotalSize; /*!< The size of EEPROM area which was partitioned from FlexRAM */
  301. uint16_t reserved;
  302. function_ptr_t runCmdFuncAddr; /*!< An buffer point to the flash execute-in-RAM function. */
  303. ftfx_ifr_desc_t ifrDesc;
  304. } ftfx_config_t;
  305. /*******************************************************************************
  306. * API
  307. ******************************************************************************/
  308. #if defined(__cplusplus)
  309. extern "C" {
  310. #endif
  311. /*!
  312. * @name Initialization
  313. * @{
  314. */
  315. /*!
  316. * @brief Initializes the global flash properties structure members.
  317. *
  318. * This function checks and initializes the Flash module for the other Flash APIs.
  319. *
  320. * @param config Pointer to the storage for the driver runtime state.
  321. *
  322. */
  323. void FTFx_API_Init(ftfx_config_t *config);
  324. #if defined(FSL_FEATURE_FLASH_HAS_FLEX_NVM) && FSL_FEATURE_FLASH_HAS_FLEX_NVM
  325. /*!
  326. * @brief Updates FlexNVM memory partition status according to data flash 0 IFR.
  327. *
  328. * This function updates FlexNVM memory partition status.
  329. *
  330. * @param config Pointer to the storage for the driver runtime state.
  331. *
  332. * @retval #kStatus_FTFx_Success API was executed successfully.
  333. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  334. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  335. */
  336. status_t FTFx_API_UpdateFlexnvmPartitionStatus(ftfx_config_t *config);
  337. #endif /* FSL_FEATURE_FLASH_HAS_FLEX_NVM */
  338. /*@}*/
  339. /*!
  340. * @name Erasing
  341. * @{
  342. */
  343. /*!
  344. * @brief Erases the flash sectors encompassed by parameters passed into function.
  345. *
  346. * This function erases the appropriate number of flash sectors based on the
  347. * desired start address and length.
  348. *
  349. * @param config The pointer to the storage for the driver runtime state.
  350. * @param start The start address of the desired flash memory to be erased.
  351. * The start address does not need to be sector-aligned but must be word-aligned.
  352. * @param lengthInBytes The length, given in bytes (not words or long-words)
  353. * to be erased. Must be word-aligned.
  354. * @param key The value used to validate all flash erase APIs.
  355. *
  356. * @retval #kStatus_FTFx_Success API was executed successfully.
  357. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  358. * @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
  359. * @retval #kStatus_FTFx_AddressError The address is out of range.
  360. * @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
  361. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  362. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  363. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  364. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  365. */
  366. status_t FTFx_CMD_Erase(ftfx_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
  367. /*!
  368. * @brief Erases entire flash
  369. *
  370. * @param config Pointer to the storage for the driver runtime state.
  371. * @param key A value used to validate all flash erase APIs.
  372. *
  373. * @retval #kStatus_FTFx_Success API was executed successfully.
  374. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  375. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  376. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  377. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  378. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  379. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  380. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  381. */
  382. status_t FTFx_CMD_EraseAll(ftfx_config_t *config, uint32_t key);
  383. #if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
  384. /*!
  385. * @brief Erases the entire flash, including protected sectors.
  386. *
  387. * @param config Pointer to the storage for the driver runtime state.
  388. * @param key A value used to validate all flash erase APIs.
  389. *
  390. * @retval #kStatus_FTFx_Success API was executed successfully.
  391. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  392. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  393. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  394. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  395. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  396. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  397. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  398. */
  399. status_t FTFx_CMD_EraseAllUnsecure(ftfx_config_t *config, uint32_t key);
  400. #endif /* FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD */
  401. /*!
  402. * @brief Erases all program flash execute-only segments defined by the FXACC registers.
  403. *
  404. * @param config Pointer to the storage for the driver runtime state.
  405. * @param key A value used to validate all flash erase APIs.
  406. *
  407. * @retval #kStatus_FTFx_Success API was executed successfully.
  408. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  409. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  410. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  411. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  412. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  413. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  414. */
  415. status_t FTFx_CMD_EraseAllExecuteOnlySegments(ftfx_config_t *config, uint32_t key);
  416. /*@}*/
  417. /*!
  418. * @name Programming
  419. * @{
  420. */
  421. /*!
  422. * @brief Programs flash with data at locations passed in through parameters.
  423. *
  424. * This function programs the flash memory with the desired data for a given
  425. * flash area as determined by the start address and the length.
  426. *
  427. * @param config A pointer to the storage for the driver runtime state.
  428. * @param start The start address of the desired flash memory to be programmed. Must be
  429. * word-aligned.
  430. * @param src A pointer to the source buffer of data that is to be programmed
  431. * into the flash.
  432. * @param lengthInBytes The length, given in bytes (not words or long-words),
  433. * to be programmed. Must be word-aligned.
  434. *
  435. * @retval #kStatus_FTFx_Success API was executed successfully.
  436. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  437. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
  438. * @retval #kStatus_FTFx_AddressError Address is out of range.
  439. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  440. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  441. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  442. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  443. */
  444. status_t FTFx_CMD_Program(ftfx_config_t *config, uint32_t start, const uint8_t *src, uint32_t lengthInBytes);
  445. /*!
  446. * @brief Programs Program Once Field through parameters.
  447. *
  448. * This function programs the Program Once Field with the desired data for a given
  449. * flash area as determined by the index and length.
  450. *
  451. * @param config A pointer to the storage for the driver runtime state.
  452. * @param index The index indicating which area of the Program Once Field to be programmed.
  453. * @param src A pointer to the source buffer of data that is to be programmed
  454. * into the Program Once Field.
  455. * @param lengthInBytes The length, given in bytes (not words or long-words),
  456. * to be programmed. Must be word-aligned.
  457. *
  458. * @retval #kStatus_FTFx_Success API was executed successfully.
  459. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  460. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  461. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  462. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  463. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  464. */
  465. status_t FTFx_CMD_ProgramOnce(ftfx_config_t *config, uint32_t index, const uint8_t *src, uint32_t lengthInBytes);
  466. #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
  467. /*!
  468. * @brief Programs flash with data at locations passed in through parameters via the Program Section command.
  469. *
  470. * This function programs the flash memory with the desired data for a given
  471. * flash area as determined by the start address and length.
  472. *
  473. * @param config A pointer to the storage for the driver runtime state.
  474. * @param start The start address of the desired flash memory to be programmed. Must be
  475. * word-aligned.
  476. * @param src A pointer to the source buffer of data that is to be programmed
  477. * into the flash.
  478. * @param lengthInBytes The length, given in bytes (not words or long-words),
  479. * to be programmed. Must be word-aligned.
  480. *
  481. * @retval #kStatus_FTFx_Success API was executed successfully.
  482. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  483. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  484. * @retval #kStatus_FTFx_AddressError Address is out of range.
  485. * @retval #kStatus_FTFx_SetFlexramAsRamError Failed to set flexram as RAM.
  486. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  487. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  488. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  489. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  490. * @retval #kStatus_FTFx_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
  491. */
  492. status_t FTFx_CMD_ProgramSection(ftfx_config_t *config, uint32_t start, const uint8_t *src, uint32_t lengthInBytes);
  493. #endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD */
  494. #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD
  495. /*!
  496. * @brief Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination of both and initializes the
  497. * FlexRAM.
  498. *
  499. * @param config Pointer to storage for the driver runtime state.
  500. * @param option The option used to set FlexRAM load behavior during reset.
  501. * @param eepromDataSizeCode Determines the amount of FlexRAM used in each of the available EEPROM subsystems.
  502. * @param flexnvmPartitionCode Specifies how to split the FlexNVM block between data flash memory and EEPROM backup
  503. * memory supporting EEPROM functions.
  504. *
  505. * @retval #kStatus_FTFx_Success API was executed successfully.
  506. * @retval #kStatus_FTFx_InvalidArgument Invalid argument is provided.
  507. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  508. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  509. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  510. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  511. */
  512. status_t FTFx_CMD_ProgramPartition(ftfx_config_t *config,
  513. ftfx_partition_flexram_load_opt_t option,
  514. uint32_t eepromDataSizeCode,
  515. uint32_t flexnvmPartitionCode);
  516. #endif /* FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD */
  517. /*@}*/
  518. /*!
  519. * @name Reading
  520. * @{
  521. */
  522. /*!
  523. * @brief Reads the Program Once Field through parameters.
  524. *
  525. * This function reads the read once feild with given index and length.
  526. *
  527. * @param config A pointer to the storage for the driver runtime state.
  528. * @param index The index indicating the area of program once field to be read.
  529. * @param dst A pointer to the destination buffer of data that is used to store
  530. * data to be read.
  531. * @param lengthInBytes The length, given in bytes (not words or long-words),
  532. * to be programmed. Must be word-aligned.
  533. *
  534. * @retval #kStatus_FTFx_Success API was executed successfully.
  535. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  536. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  537. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  538. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  539. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  540. */
  541. status_t FTFx_CMD_ReadOnce(ftfx_config_t *config, uint32_t index, uint8_t *dst, uint32_t lengthInBytes);
  542. #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
  543. /*!
  544. * @brief Reads the resource with data at locations passed in through parameters.
  545. *
  546. * This function reads the flash memory with the desired location for a given
  547. * flash area as determined by the start address and length.
  548. *
  549. * @param config A pointer to the storage for the driver runtime state.
  550. * @param start The start address of the desired flash memory to be programmed. Must be
  551. * word-aligned.
  552. * @param dst A pointer to the destination buffer of data that is used to store
  553. * data to be read.
  554. * @param lengthInBytes The length, given in bytes (not words or long-words),
  555. * to be read. Must be word-aligned.
  556. * @param option The resource option which indicates which area should be read back.
  557. *
  558. * @retval #kStatus_FTFx_Success API was executed successfully.
  559. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  560. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
  561. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  562. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  563. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  564. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  565. */
  566. status_t FTFx_CMD_ReadResource(
  567. ftfx_config_t *config, uint32_t start, uint8_t *dst, uint32_t lengthInBytes, ftfx_read_resource_opt_t option);
  568. #endif /* FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD */
  569. /*@}*/
  570. /*!
  571. * @name Verification
  572. * @{
  573. */
  574. /*!
  575. * @brief Verifies an erasure of the desired flash area at a specified margin level.
  576. *
  577. * This function checks the appropriate number of flash sectors based on
  578. * the desired start address and length to check whether the flash is erased
  579. * to the specified read margin level.
  580. *
  581. * @param config A pointer to the storage for the driver runtime state.
  582. * @param start The start address of the desired flash memory to be verified.
  583. * The start address does not need to be sector-aligned but must be word-aligned.
  584. * @param lengthInBytes The length, given in bytes (not words or long-words),
  585. * to be verified. Must be word-aligned.
  586. * @param margin Read margin choice.
  587. *
  588. * @retval #kStatus_FTFx_Success API was executed successfully.
  589. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  590. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  591. * @retval #kStatus_FTFx_AddressError Address is out of range.
  592. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  593. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  594. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  595. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  596. */
  597. status_t FTFx_CMD_VerifyErase(ftfx_config_t *config,
  598. uint32_t start,
  599. uint32_t lengthInBytes,
  600. ftfx_margin_value_t margin);
  601. /*!
  602. * @brief Verifies erasure of the entire flash at a specified margin level.
  603. *
  604. * This function checks whether the flash is erased to the
  605. * specified read margin level.
  606. *
  607. * @param config A pointer to the storage for the driver runtime state.
  608. * @param margin Read margin choice.
  609. *
  610. * @retval #kStatus_FTFx_Success API was executed successfully.
  611. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  612. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  613. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  614. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  615. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  616. */
  617. status_t FTFx_CMD_VerifyEraseAll(ftfx_config_t *config, ftfx_margin_value_t margin);
  618. /*!
  619. * @brief Verifies whether the program flash execute-only segments have been erased to
  620. * the specified read margin level.
  621. *
  622. * @param config A pointer to the storage for the driver runtime state.
  623. * @param margin Read margin choice.
  624. *
  625. * @retval #kStatus_FTFx_Success API was executed successfully.
  626. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  627. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  628. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  629. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  630. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  631. */
  632. status_t FTFx_CMD_VerifyEraseAllExecuteOnlySegments(ftfx_config_t *config, ftfx_margin_value_t margin);
  633. /*!
  634. * @brief Verifies programming of the desired flash area at a specified margin level.
  635. *
  636. * This function verifies the data programed in the flash memory using the
  637. * Flash Program Check Command and compares it to the expected data for a given
  638. * flash area as determined by the start address and length.
  639. *
  640. * @param config A pointer to the storage for the driver runtime state.
  641. * @param start The start address of the desired flash memory to be verified. Must be word-aligned.
  642. * @param lengthInBytes The length, given in bytes (not words or long-words),
  643. * to be verified. Must be word-aligned.
  644. * @param expectedData A pointer to the expected data that is to be
  645. * verified against.
  646. * @param margin Read margin choice.
  647. * @param failedAddress A pointer to the returned failing address.
  648. * @param failedData A pointer to the returned failing data. Some derivatives do
  649. * not include failed data as part of the FCCOBx registers. In this
  650. * case, zeros are returned upon failure.
  651. *
  652. * @retval #kStatus_FTFx_Success API was executed successfully.
  653. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  654. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  655. * @retval #kStatus_FTFx_AddressError Address is out of range.
  656. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  657. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  658. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  659. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  660. */
  661. status_t FTFx_CMD_VerifyProgram(ftfx_config_t *config,
  662. uint32_t start,
  663. uint32_t lengthInBytes,
  664. const uint8_t *expectedData,
  665. ftfx_margin_value_t margin,
  666. uint32_t *failedAddress,
  667. uint32_t *failedData);
  668. /*@}*/
  669. /*!
  670. * @name Security
  671. * @{
  672. */
  673. /*!
  674. * @brief Returns the security state via the pointer passed into the function.
  675. *
  676. * This function retrieves the current flash security status, including the
  677. * security enabling state and the backdoor key enabling state.
  678. *
  679. * @param config A pointer to storage for the driver runtime state.
  680. * @param state A pointer to the value returned for the current security status code:
  681. *
  682. * @retval #kStatus_FTFx_Success API was executed successfully.
  683. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  684. */
  685. status_t FTFx_REG_GetSecurityState(ftfx_config_t *config, ftfx_security_state_t *state);
  686. /*!
  687. * @brief Allows users to bypass security with a backdoor key.
  688. *
  689. * If the MCU is in secured state, this function unsecures the MCU by
  690. * comparing the provided backdoor key with ones in the flash configuration
  691. * field.
  692. *
  693. * @param config A pointer to the storage for the driver runtime state.
  694. * @param backdoorKey A pointer to the user buffer containing the backdoor key.
  695. *
  696. * @retval #kStatus_FTFx_Success API was executed successfully.
  697. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  698. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  699. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  700. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  701. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  702. */
  703. status_t FTFx_CMD_SecurityBypass(ftfx_config_t *config, const uint8_t *backdoorKey);
  704. /*@}*/
  705. /*!
  706. * @name FlexRAM
  707. * @{
  708. */
  709. #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
  710. /*!
  711. * @brief Sets the FlexRAM function command.
  712. *
  713. * @param config A pointer to the storage for the driver runtime state.
  714. * @param option The option used to set the work mode of FlexRAM.
  715. *
  716. * @retval #kStatus_FTFx_Success API was executed successfully.
  717. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  718. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  719. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  720. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  721. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  722. */
  723. status_t FTFx_CMD_SetFlexramFunction(ftfx_config_t *config, ftfx_flexram_func_opt_t option);
  724. #endif /* FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD */
  725. /*@}*/
  726. /*!
  727. * @name Swap
  728. * @{
  729. */
  730. #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
  731. /*!
  732. * @brief Configures the Swap function or checks the swap state of the Flash module.
  733. *
  734. * @param config A pointer to the storage for the driver runtime state.
  735. * @param address Address used to configure the flash Swap function.
  736. * @param option The possible option used to configure Flash Swap function or check the flash Swap status
  737. * @param returnInfo A pointer to the data which is used to return the information of flash Swap.
  738. *
  739. * @retval #kStatus_FTFx_Success API was executed successfully.
  740. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  741. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  742. * @retval #kStatus_FTFx_SwapIndicatorAddressError Swap indicator address is invalid.
  743. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  744. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  745. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  746. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  747. */
  748. status_t FTFx_CMD_SwapControl(ftfx_config_t *config,
  749. uint32_t address,
  750. ftfx_swap_control_opt_t option,
  751. ftfx_swap_state_config_t *returnInfo);
  752. #endif /* FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD */
  753. /*@}*/
  754. #if defined(__cplusplus)
  755. }
  756. #endif
  757. /*! @}*/
  758. #endif /* FSL_FTFX_CONTROLLER_H */