fsl_ftfx_flexnvm.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * The Clear BSD License
  3. * Copyright 2013-2016 Freescale Semiconductor, Inc.
  4. * Copyright 2016-2018 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted (subject to the limitations in the
  9. * disclaimer below) provided that the following conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * * Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * * Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from
  20. * this software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  23. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  24. * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  25. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  26. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  31. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  32. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  33. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  34. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. */
  37. #ifndef _FSL_FTFX_FLEXNVM_H_
  38. #define _FSL_FTFX_FLEXNVM_H_
  39. #include "fsl_ftfx_controller.h"
  40. /*!
  41. * @addtogroup ftfx_flexnvm_driver
  42. * @{
  43. */
  44. /*******************************************************************************
  45. * Definitions
  46. ******************************************************************************/
  47. /*!
  48. * @name Flexnvm version
  49. * @{
  50. */
  51. /*! @brief Flexnvm driver version for SDK*/
  52. #define FSL_FLEXNVM_DRIVER_VERSION (MAKE_VERSION(3, 0, 0)) /*!< Version 1.0.0. */
  53. /*@}*/
  54. /*!
  55. * @brief Enumeration for various flexnvm properties.
  56. */
  57. typedef enum _flexnvm_property_tag
  58. {
  59. kFLEXNVM_PropertyDflashSectorSize = 0x00U, /*!< Dflash sector size property.*/
  60. kFLEXNVM_PropertyDflashTotalSize = 0x01U, /*!< Dflash total size property.*/
  61. kFLEXNVM_PropertyDflashBlockSize = 0x02U, /*!< Dflash block size property.*/
  62. kFLEXNVM_PropertyDflashBlockCount = 0x03U, /*!< Dflash block count property.*/
  63. kFLEXNVM_PropertyDflashBlockBaseAddr = 0x04U, /*!< Dflash block base address property.*/
  64. kFLEXNVM_PropertyFlexRamBlockBaseAddr = 0x05U, /*!< FlexRam block base address property.*/
  65. kFLEXNVM_PropertyFlexRamTotalSize = 0x06U, /*!< FlexRam total size property.*/
  66. kFLEXNVM_PropertyEepromTotalSize = 0x07U, /*!< EEPROM total size property.*/
  67. } flexnvm_property_tag_t;
  68. /*! @brief Flexnvm driver state information.
  69. *
  70. * An instance of this structure is allocated by the user of the Flexnvm driver and
  71. * passed into each of the driver APIs.
  72. */
  73. typedef struct _flexnvm_config
  74. {
  75. ftfx_config_t ftfxConfig;
  76. } flexnvm_config_t;
  77. /*******************************************************************************
  78. * API
  79. ******************************************************************************/
  80. #if defined(__cplusplus)
  81. extern "C" {
  82. #endif
  83. /*!
  84. * @name Initialization
  85. * @{
  86. */
  87. /*!
  88. * @brief Initializes the global flash properties structure members.
  89. *
  90. * This function checks and initializes the Flash module for the other Flash APIs.
  91. *
  92. * @param config Pointer to the storage for the driver runtime state.
  93. *
  94. * @retval #kStatus_FTFx_Success API was executed successfully.
  95. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  96. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  97. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  98. */
  99. status_t FLEXNVM_Init(flexnvm_config_t *config);
  100. /*@}*/
  101. /*!
  102. * @name Erasing
  103. * @{
  104. */
  105. /*!
  106. * @brief Erases the Dflash sectors encompassed by parameters passed into function.
  107. *
  108. * This function erases the appropriate number of flash sectors based on the
  109. * desired start address and length.
  110. *
  111. * @param config The pointer to the storage for the driver runtime state.
  112. * @param start The start address of the desired flash memory to be erased.
  113. * The start address does not need to be sector-aligned but must be word-aligned.
  114. * @param lengthInBytes The length, given in bytes (not words or long-words)
  115. * to be erased. Must be word-aligned.
  116. * @param key The value used to validate all flash erase APIs.
  117. *
  118. * @retval #kStatus_FTFx_Success API was executed successfully.
  119. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  120. * @retval #kStatus_FTFx_AlignmentError The parameter is not aligned with the specified baseline.
  121. * @retval #kStatus_FTFx_AddressError The address is out of range.
  122. * @retval #kStatus_FTFx_EraseKeyError The API erase key is invalid.
  123. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  124. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  125. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  126. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  127. */
  128. status_t FLEXNVM_DflashErase(flexnvm_config_t *config,
  129. uint32_t start,
  130. uint32_t lengthInBytes,
  131. uint32_t key);
  132. /*!
  133. * @brief Erases entire flexnvm
  134. *
  135. * @param config Pointer to the storage for the driver runtime state.
  136. * @param key A value used to validate all flash erase APIs.
  137. *
  138. * @retval #kStatus_FTFx_Success API was executed successfully.
  139. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  140. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  141. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  142. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  143. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  144. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  145. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  146. */
  147. status_t FLEXNVM_EraseAll(flexnvm_config_t *config, uint32_t key);
  148. /*!
  149. * @brief Erases the entire flexnvm, including protected sectors.
  150. *
  151. * @param config Pointer to the storage for the driver runtime state.
  152. * @param key A value used to validate all flash erase APIs.
  153. *
  154. * @retval #kStatus_FTFx_Success API was executed successfully.
  155. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  156. * @retval #kStatus_FTFx_EraseKeyError API erase key is invalid.
  157. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  158. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  159. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  160. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  161. * @retval #kStatus_FTFx_PartitionStatusUpdateFailure Failed to update the partition status.
  162. */
  163. #if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
  164. status_t FLEXNVM_EraseAllUnsecure(flexnvm_config_t *config, uint32_t key);
  165. #endif
  166. /*@}*/
  167. /*!
  168. * @name Programming
  169. * @{
  170. */
  171. /*!
  172. * @brief Programs flash with data at locations passed in through parameters.
  173. *
  174. * This function programs the flash memory with the desired data for a given
  175. * flash area as determined by the start address and the length.
  176. *
  177. * @param config A pointer to the storage for the driver runtime state.
  178. * @param start The start address of the desired flash memory to be programmed. Must be
  179. * word-aligned.
  180. * @param src A pointer to the source buffer of data that is to be programmed
  181. * into the flash.
  182. * @param lengthInBytes The length, given in bytes (not words or long-words),
  183. * to be programmed. Must be word-aligned.
  184. *
  185. * @retval #kStatus_FTFx_Success API was executed successfully.
  186. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  187. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
  188. * @retval #kStatus_FTFx_AddressError Address is out of range.
  189. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  190. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  191. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  192. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  193. */
  194. status_t FLEXNVM_DflashProgram(flexnvm_config_t *config,
  195. uint32_t start,
  196. uint8_t *src,
  197. uint32_t lengthInBytes);
  198. /*!
  199. * @brief Programs flash with data at locations passed in through parameters via the Program Section command.
  200. *
  201. * This function programs the flash memory with the desired data for a given
  202. * flash area as determined by the start address and length.
  203. *
  204. * @param config A pointer to the storage for the driver runtime state.
  205. * @param start The start address of the desired flash memory to be programmed. Must be
  206. * word-aligned.
  207. * @param src A pointer to the source buffer of data that is to be programmed
  208. * into the flash.
  209. * @param lengthInBytes The length, given in bytes (not words or long-words),
  210. * to be programmed. Must be word-aligned.
  211. *
  212. * @retval #kStatus_FTFx_Success API was executed successfully.
  213. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  214. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  215. * @retval #kStatus_FTFx_AddressError Address is out of range.
  216. * @retval #kStatus_FTFx_SetFlexramAsRamError Failed to set flexram as RAM.
  217. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  218. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  219. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  220. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  221. * @retval #kStatus_FTFx_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
  222. */
  223. #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
  224. status_t FLEXNVM_DflashProgramSection(flexnvm_config_t *config,
  225. uint32_t start,
  226. uint8_t *src,
  227. uint32_t lengthInBytes);
  228. #endif
  229. /*!
  230. * @brief Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination of both and initializes the
  231. * FlexRAM.
  232. *
  233. * @param config Pointer to storage for the driver runtime state.
  234. * @param option The option used to set FlexRAM load behavior during reset.
  235. * @param eepromDataSizeCode Determines the amount of FlexRAM used in each of the available EEPROM subsystems.
  236. * @param flexnvmPartitionCode Specifies how to split the FlexNVM block between data flash memory and EEPROM backup
  237. * memory supporting EEPROM functions.
  238. *
  239. * @retval #kStatus_FTFx_Success API was executed successfully.
  240. * @retval #kStatus_FTFx_InvalidArgument Invalid argument is provided.
  241. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  242. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  243. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  244. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  245. */
  246. status_t FLEXNVM_ProgramPartition(flexnvm_config_t *config,
  247. ftfx_partition_flexram_load_opt_t option,
  248. uint32_t eepromDataSizeCode,
  249. uint32_t flexnvmPartitionCode);
  250. /*@}*/
  251. /*!
  252. * @name Reading
  253. * @{
  254. */
  255. /*!
  256. * @brief Reads the resource with data at locations passed in through parameters.
  257. *
  258. * This function reads the flash memory with the desired location for a given
  259. * flash area as determined by the start address and length.
  260. *
  261. * @param config A pointer to the storage for the driver runtime state.
  262. * @param start The start address of the desired flash memory to be programmed. Must be
  263. * word-aligned.
  264. * @param dst A pointer to the destination buffer of data that is used to store
  265. * data to be read.
  266. * @param lengthInBytes The length, given in bytes (not words or long-words),
  267. * to be read. Must be word-aligned.
  268. * @param option The resource option which indicates which area should be read back.
  269. *
  270. * @retval #kStatus_FTFx_Success API was executed successfully.
  271. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  272. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with the specified baseline.
  273. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  274. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  275. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  276. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  277. */
  278. #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
  279. status_t FLEXNVM_ReadResource(flexnvm_config_t *config,
  280. uint32_t start,
  281. uint8_t *dst,
  282. uint32_t lengthInBytes,
  283. ftfx_read_resource_opt_t option);
  284. #endif
  285. /*@}*/
  286. /*!
  287. * @name Verification
  288. * @{
  289. */
  290. /*!
  291. * @brief Verifies an erasure of the desired flash area at a specified margin level.
  292. *
  293. * This function checks the appropriate number of flash sectors based on
  294. * the desired start address and length to check whether the flash is erased
  295. * to the specified read margin level.
  296. *
  297. * @param config A pointer to the storage for the driver runtime state.
  298. * @param start The start address of the desired flash memory to be verified.
  299. * The start address does not need to be sector-aligned but must be word-aligned.
  300. * @param lengthInBytes The length, given in bytes (not words or long-words),
  301. * to be verified. Must be word-aligned.
  302. * @param margin Read margin choice.
  303. *
  304. * @retval #kStatus_FTFx_Success API was executed successfully.
  305. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  306. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  307. * @retval #kStatus_FTFx_AddressError Address is out of range.
  308. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  309. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  310. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  311. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  312. */
  313. status_t FLEXNVM_DflashVerifyErase(flexnvm_config_t *config,
  314. uint32_t start,
  315. uint32_t lengthInBytes,
  316. ftfx_margin_value_t margin);
  317. /*!
  318. * @brief Verifies erasure of the entire flash at a specified margin level.
  319. *
  320. * This function checks whether the flash is erased to the
  321. * specified read margin level.
  322. *
  323. * @param config A pointer to the storage for the driver runtime state.
  324. * @param margin Read margin choice.
  325. *
  326. * @retval #kStatus_FTFx_Success API was executed successfully.
  327. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  328. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  329. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  330. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  331. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  332. */
  333. status_t FLEXNVM_VerifyEraseAll(flexnvm_config_t *config, ftfx_margin_value_t margin);
  334. /*!
  335. * @brief Verifies programming of the desired flash area at a specified margin level.
  336. *
  337. * This function verifies the data programed in the flash memory using the
  338. * Flash Program Check Command and compares it to the expected data for a given
  339. * flash area as determined by the start address and length.
  340. *
  341. * @param config A pointer to the storage for the driver runtime state.
  342. * @param start The start address of the desired flash memory to be verified. Must be word-aligned.
  343. * @param lengthInBytes The length, given in bytes (not words or long-words),
  344. * to be verified. Must be word-aligned.
  345. * @param expectedData A pointer to the expected data that is to be
  346. * verified against.
  347. * @param margin Read margin choice.
  348. * @param failedAddress A pointer to the returned failing address.
  349. * @param failedData A pointer to the returned failing data. Some derivatives do
  350. * not include failed data as part of the FCCOBx registers. In this
  351. * case, zeros are returned upon failure.
  352. *
  353. * @retval #kStatus_FTFx_Success API was executed successfully.
  354. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  355. * @retval #kStatus_FTFx_AlignmentError Parameter is not aligned with specified baseline.
  356. * @retval #kStatus_FTFx_AddressError Address is out of range.
  357. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  358. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  359. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  360. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  361. */
  362. status_t FLEXNVM_DflashVerifyProgram(flexnvm_config_t *config,
  363. uint32_t start,
  364. uint32_t lengthInBytes,
  365. const uint8_t *expectedData,
  366. ftfx_margin_value_t margin,
  367. uint32_t *failedAddress,
  368. uint32_t *failedData);
  369. /*@}*/
  370. /*!
  371. * @name Security
  372. * @{
  373. */
  374. /*!
  375. * @brief Returns the security state via the pointer passed into the function.
  376. *
  377. * This function retrieves the current flash security status, including the
  378. * security enabling state and the backdoor key enabling state.
  379. *
  380. * @param config A pointer to storage for the driver runtime state.
  381. * @param state A pointer to the value returned for the current security status code:
  382. *
  383. * @retval #kStatus_FTFx_Success API was executed successfully.
  384. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  385. */
  386. status_t FLEXNVM_GetSecurityState(flexnvm_config_t *config, ftfx_security_state_t *state);
  387. /*!
  388. * @brief Allows users to bypass security with a backdoor key.
  389. *
  390. * If the MCU is in secured state, this function unsecures the MCU by
  391. * comparing the provided backdoor key with ones in the flash configuration
  392. * field.
  393. *
  394. * @param config A pointer to the storage for the driver runtime state.
  395. * @param backdoorKey A pointer to the user buffer containing the backdoor key.
  396. *
  397. * @retval #kStatus_FTFx_Success API was executed successfully.
  398. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  399. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  400. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  401. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  402. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  403. */
  404. status_t FLEXNVM_SecurityBypass(flexnvm_config_t *config, const uint8_t *backdoorKey);
  405. /*@}*/
  406. /*!
  407. * @name FlexRAM
  408. * @{
  409. */
  410. /*!
  411. * @brief Sets the FlexRAM function command.
  412. *
  413. * @param config A pointer to the storage for the driver runtime state.
  414. * @param option The option used to set the work mode of FlexRAM.
  415. *
  416. * @retval #kStatus_FTFx_Success API was executed successfully.
  417. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  418. * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  419. * @retval #kStatus_FTFx_AccessError Invalid instruction codes and out-of bounds addresses.
  420. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  421. * @retval #kStatus_FTFx_CommandFailure Run-time error during the command execution.
  422. */
  423. #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
  424. status_t FLEXNVM_SetFlexramFunction(flexnvm_config_t *config, ftfx_flexram_func_opt_t option);
  425. #endif
  426. /*@}*/
  427. /*!
  428. * @brief Programs the EEPROM with data at locations passed in through parameters.
  429. *
  430. * This function programs the emulated EEPROM with the desired data for a given
  431. * flash area as determined by the start address and length.
  432. *
  433. * @param config A pointer to the storage for the driver runtime state.
  434. * @param start The start address of the desired flash memory to be programmed. Must be
  435. * word-aligned.
  436. * @param src A pointer to the source buffer of data that is to be programmed
  437. * into the flash.
  438. * @param lengthInBytes The length, given in bytes (not words or long-words),
  439. * to be programmed. Must be word-aligned.
  440. *
  441. * @retval #kStatus_FTFx_Success API was executed successfully.
  442. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  443. * @retval #kStatus_FTFx_AddressError Address is out of range.
  444. * @retval #kStatus_FTFx_SetFlexramAsEepromError Failed to set flexram as eeprom.
  445. * @retval #kStatus_FTFx_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  446. * @retval #kStatus_FTFx_RecoverFlexramAsRamError Failed to recover the FlexRAM as RAM.
  447. */
  448. status_t FLEXNVM_EepromWrite(flexnvm_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
  449. /*!
  450. * @name Flash Protection Utilities
  451. * @{
  452. */
  453. /*!
  454. * @brief Sets the DFlash protection to the intended protection status.
  455. *
  456. * @param config A pointer to the storage for the driver runtime state.
  457. * @param protectStatus The expected protect status to set to the DFlash protection register. Each bit
  458. * corresponds to the protection of the 1/8 of the total DFlash. The least significant bit corresponds to the lowest
  459. * address area of the DFlash. The most significant bit corresponds to the highest address area of the DFlash. There
  460. * are
  461. * two possible cases as shown below:
  462. * 0: this area is protected.
  463. * 1: this area is unprotected.
  464. *
  465. * @retval #kStatus_FTFx_Success API was executed successfully.
  466. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  467. * @retval #kStatus_FTFx_CommandNotSupported Flash API is not supported.
  468. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  469. */
  470. status_t FLEXNVM_DflashSetProtection(flexnvm_config_t *config, uint8_t protectStatus);
  471. /*!
  472. * @brief Gets the DFlash protection status.
  473. *
  474. * @param config A pointer to the storage for the driver runtime state.
  475. * @param protectStatus DFlash Protect status returned by the PFlash IP. Each bit corresponds to the protection of the
  476. * 1/8 of
  477. * the total DFlash. The least significant bit corresponds to the lowest address area of the DFlash. The most
  478. * significant bit corresponds to the highest address area of the DFlash, and so on. There are two possible cases as
  479. * below:
  480. * 0: this area is protected.
  481. * 1: this area is unprotected.
  482. *
  483. * @retval #kStatus_FTFx_Success API was executed successfully.
  484. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  485. * @retval #kStatus_FTFx_CommandNotSupported Flash API is not supported.
  486. */
  487. status_t FLEXNVM_DflashGetProtection(flexnvm_config_t *config, uint8_t *protectStatus);
  488. /*!
  489. * @brief Sets the EEPROM protection to the intended protection status.
  490. *
  491. * @param config A pointer to the storage for the driver runtime state.
  492. * @param protectStatus The expected protect status to set to the EEPROM protection register. Each bit
  493. * corresponds to the protection of the 1/8 of the total EEPROM. The least significant bit corresponds to the lowest
  494. * address area of the EEPROM. The most significant bit corresponds to the highest address area of EEPROM, and so on.
  495. * There are two possible cases as shown below:
  496. * 0: this area is protected.
  497. * 1: this area is unprotected.
  498. *
  499. * @retval #kStatus_FTFx_Success API was executed successfully.
  500. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  501. * @retval #kStatus_FTFx_CommandNotSupported Flash API is not supported.
  502. * @retval #kStatus_FTFx_CommandFailure Run-time error during command execution.
  503. */
  504. status_t FLEXNVM_EepromSetProtection(flexnvm_config_t *config, uint8_t protectStatus);
  505. /*!
  506. * @brief Gets the EEPROM protection status.
  507. *
  508. * @param config A pointer to the storage for the driver runtime state.
  509. * @param protectStatus DFlash Protect status returned by the PFlash IP. Each bit corresponds to the protection of the
  510. * 1/8 of
  511. * the total EEPROM. The least significant bit corresponds to the lowest address area of the EEPROM. The most
  512. * significant bit corresponds to the highest address area of the EEPROM. There are two possible cases as below:
  513. * 0: this area is protected.
  514. * 1: this area is unprotected.
  515. *
  516. * @retval #kStatus_FTFx_Success API was executed successfully.
  517. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  518. * @retval #kStatus_FTFx_CommandNotSupported Flash API is not supported.
  519. */
  520. status_t FLEXNVM_EepromGetProtection(flexnvm_config_t *config, uint8_t *protectStatus);
  521. /*@}*/
  522. /*!
  523. * @name Properties
  524. * @{
  525. */
  526. /*!
  527. * @brief Returns the desired flexnvm property.
  528. *
  529. * @param config A pointer to the storage for the driver runtime state.
  530. * @param whichProperty The desired property from the list of properties in
  531. * enum flexnvm_property_tag_t
  532. * @param value A pointer to the value returned for the desired flexnvm property.
  533. *
  534. * @retval #kStatus_FTFx_Success API was executed successfully.
  535. * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
  536. * @retval #kStatus_FTFx_UnknownProperty An unknown property tag.
  537. */
  538. status_t FLEXNVM_GetProperty(flexnvm_config_t *config, flexnvm_property_tag_t whichProperty, uint32_t *value);
  539. #if defined(__cplusplus)
  540. }
  541. #endif
  542. /*! @}*/
  543. #endif /* _FSL_FTFX_FLEXNVM_H_ */