fsl_flash.h 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  1. /*
  2. * Copyright (c) 2013-2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_FLASH_H_
  31. #define _FSL_FLASH_H_
  32. #if (defined(BL_TARGET_FLASH) || defined(BL_TARGET_ROM) || defined(BL_TARGET_RAM))
  33. #include <assert.h>
  34. #include <string.h>
  35. #include "fsl_device_registers.h"
  36. #include "bootloader_common.h"
  37. #else
  38. #include "fsl_common.h"
  39. #endif
  40. /*******************************************************************************
  41. * Definitions
  42. ******************************************************************************/
  43. /*!
  44. * @addtogroup flash_driver
  45. * @{
  46. */
  47. /*!
  48. * @name Flash version
  49. * @{
  50. */
  51. /*! @brief Constructs the version number for drivers. */
  52. #if !defined(MAKE_VERSION)
  53. #define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
  54. #endif
  55. /*! @brief Flash driver version for SDK*/
  56. #define FSL_FLASH_DRIVER_VERSION (MAKE_VERSION(2, 3, 1)) /*!< Version 2.3.1. */
  57. /*! @brief Flash driver version for ROM*/
  58. enum _flash_driver_version_constants
  59. {
  60. kFLASH_DriverVersionName = 'F', /*!< Flash driver version name.*/
  61. kFLASH_DriverVersionMajor = 2, /*!< Major flash driver version.*/
  62. kFLASH_DriverVersionMinor = 3, /*!< Minor flash driver version.*/
  63. kFLASH_DriverVersionBugfix = 1 /*!< Bugfix for flash driver version.*/
  64. };
  65. /*@}*/
  66. /*!
  67. * @name Flash configuration
  68. * @{
  69. */
  70. /*! @brief Indicates whether to support FlexNVM in the Flash driver */
  71. #if !defined(FLASH_SSD_CONFIG_ENABLE_FLEXNVM_SUPPORT)
  72. #define FLASH_SSD_CONFIG_ENABLE_FLEXNVM_SUPPORT 1 /*!< Enables the FlexNVM support by default. */
  73. #endif
  74. /*! @brief Indicates whether the FlexNVM is enabled in the Flash driver */
  75. #define FLASH_SSD_IS_FLEXNVM_ENABLED (FLASH_SSD_CONFIG_ENABLE_FLEXNVM_SUPPORT && FSL_FEATURE_FLASH_HAS_FLEX_NVM)
  76. /*! @brief Indicates whether to support Secondary flash in the Flash driver */
  77. #if !defined(FLASH_SSD_CONFIG_ENABLE_SECONDARY_FLASH_SUPPORT)
  78. #define FLASH_SSD_CONFIG_ENABLE_SECONDARY_FLASH_SUPPORT 1 /*!< Enables the secondary flash support by default. */
  79. #endif
  80. /*! @brief Indicates whether the secondary flash is supported in the Flash driver */
  81. #if defined(FSL_FEATURE_FLASH_HAS_MULTIPLE_FLASH) || defined(FSL_FEATURE_FLASH_PFLASH_1_START_ADDRESS)
  82. #define FLASH_SSD_IS_SECONDARY_FLASH_ENABLED (FLASH_SSD_CONFIG_ENABLE_SECONDARY_FLASH_SUPPORT)
  83. #else
  84. #define FLASH_SSD_IS_SECONDARY_FLASH_ENABLED (0)
  85. #endif
  86. /*! @brief Flash driver location. */
  87. #if !defined(FLASH_DRIVER_IS_FLASH_RESIDENT)
  88. #if (!defined(BL_TARGET_ROM) && !defined(BL_TARGET_RAM))
  89. #define FLASH_DRIVER_IS_FLASH_RESIDENT 1 /*!< Used for the flash resident application. */
  90. #else
  91. #define FLASH_DRIVER_IS_FLASH_RESIDENT 0 /*!< Used for the non-flash resident application. */
  92. #endif
  93. #endif
  94. /*! @brief Flash Driver Export option */
  95. #if !defined(FLASH_DRIVER_IS_EXPORTED)
  96. #if (defined(BL_TARGET_ROM) || defined(BL_TARGET_FLASH))
  97. #define FLASH_DRIVER_IS_EXPORTED 1 /*!< Used for the ROM bootloader. */
  98. #else
  99. #define FLASH_DRIVER_IS_EXPORTED 0 /*!< Used for the MCUXpresso SDK application. */
  100. #endif
  101. #endif
  102. /*@}*/
  103. /*!
  104. * @name Flash status
  105. * @{
  106. */
  107. /*! @brief Flash driver status group. */
  108. #if defined(kStatusGroup_FlashDriver)
  109. #define kStatusGroupGeneric kStatusGroup_Generic
  110. #define kStatusGroupFlashDriver kStatusGroup_FlashDriver
  111. #elif defined(kStatusGroup_FLASH)
  112. #define kStatusGroupGeneric kStatusGroup_Generic
  113. #define kStatusGroupFlashDriver kStatusGroup_FLASH
  114. #else
  115. #define kStatusGroupGeneric 0
  116. #define kStatusGroupFlashDriver 1
  117. #endif
  118. /*! @brief Constructs a status code value from a group and a code number. */
  119. #if !defined(MAKE_STATUS)
  120. #define MAKE_STATUS(group, code) ((((group)*100) + (code)))
  121. #endif
  122. /*!
  123. * @brief Flash driver status codes.
  124. */
  125. enum _flash_status
  126. {
  127. kStatus_FLASH_Success = MAKE_STATUS(kStatusGroupGeneric, 0), /*!< API is executed successfully*/
  128. kStatus_FLASH_InvalidArgument = MAKE_STATUS(kStatusGroupGeneric, 4), /*!< Invalid argument*/
  129. kStatus_FLASH_SizeError = MAKE_STATUS(kStatusGroupFlashDriver, 0), /*!< Error size*/
  130. kStatus_FLASH_AlignmentError =
  131. MAKE_STATUS(kStatusGroupFlashDriver, 1), /*!< Parameter is not aligned with the specified baseline*/
  132. kStatus_FLASH_AddressError = MAKE_STATUS(kStatusGroupFlashDriver, 2), /*!< Address is out of range */
  133. kStatus_FLASH_AccessError =
  134. MAKE_STATUS(kStatusGroupFlashDriver, 3), /*!< Invalid instruction codes and out-of bound addresses */
  135. kStatus_FLASH_ProtectionViolation = MAKE_STATUS(
  136. kStatusGroupFlashDriver, 4), /*!< The program/erase operation is requested to execute on protected areas */
  137. kStatus_FLASH_CommandFailure =
  138. MAKE_STATUS(kStatusGroupFlashDriver, 5), /*!< Run-time error during command execution. */
  139. kStatus_FLASH_UnknownProperty = MAKE_STATUS(kStatusGroupFlashDriver, 6), /*!< Unknown property.*/
  140. kStatus_FLASH_EraseKeyError = MAKE_STATUS(kStatusGroupFlashDriver, 7), /*!< API erase key is invalid.*/
  141. kStatus_FLASH_RegionExecuteOnly =
  142. MAKE_STATUS(kStatusGroupFlashDriver, 8), /*!< The current region is execute-only.*/
  143. kStatus_FLASH_ExecuteInRamFunctionNotReady =
  144. MAKE_STATUS(kStatusGroupFlashDriver, 9), /*!< Execute-in-RAM function is not available.*/
  145. kStatus_FLASH_PartitionStatusUpdateFailure =
  146. MAKE_STATUS(kStatusGroupFlashDriver, 10), /*!< Failed to update partition status.*/
  147. kStatus_FLASH_SetFlexramAsEepromError =
  148. MAKE_STATUS(kStatusGroupFlashDriver, 11), /*!< Failed to set FlexRAM as EEPROM.*/
  149. kStatus_FLASH_RecoverFlexramAsRamError =
  150. MAKE_STATUS(kStatusGroupFlashDriver, 12), /*!< Failed to recover FlexRAM as RAM.*/
  151. kStatus_FLASH_SetFlexramAsRamError = MAKE_STATUS(kStatusGroupFlashDriver, 13), /*!< Failed to set FlexRAM as RAM.*/
  152. kStatus_FLASH_RecoverFlexramAsEepromError =
  153. MAKE_STATUS(kStatusGroupFlashDriver, 14), /*!< Failed to recover FlexRAM as EEPROM.*/
  154. kStatus_FLASH_CommandNotSupported = MAKE_STATUS(kStatusGroupFlashDriver, 15), /*!< Flash API is not supported.*/
  155. kStatus_FLASH_SwapSystemNotInUninitialized =
  156. MAKE_STATUS(kStatusGroupFlashDriver, 16), /*!< Swap system is not in an uninitialzed state.*/
  157. kStatus_FLASH_SwapIndicatorAddressError =
  158. MAKE_STATUS(kStatusGroupFlashDriver, 17), /*!< The swap indicator address is invalid.*/
  159. kStatus_FLASH_ReadOnlyProperty = MAKE_STATUS(kStatusGroupFlashDriver, 18), /*!< The flash property is read-only.*/
  160. kStatus_FLASH_InvalidPropertyValue =
  161. MAKE_STATUS(kStatusGroupFlashDriver, 19), /*!< The flash property value is out of range.*/
  162. kStatus_FLASH_InvalidSpeculationOption =
  163. MAKE_STATUS(kStatusGroupFlashDriver, 20), /*!< The option of flash prefetch speculation is invalid.*/
  164. };
  165. /*@}*/
  166. /*!
  167. * @name Flash API key
  168. * @{
  169. */
  170. /*! @brief Constructs the four character code for the Flash driver API key. */
  171. #if !defined(FOUR_CHAR_CODE)
  172. #define FOUR_CHAR_CODE(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | ((a)))
  173. #endif
  174. /*!
  175. * @brief Enumeration for Flash driver API keys.
  176. *
  177. * @note The resulting value is built with a byte order such that the string
  178. * being readable in expected order when viewed in a hex editor, if the value
  179. * is treated as a 32-bit little endian value.
  180. */
  181. enum _flash_driver_api_keys
  182. {
  183. kFLASH_ApiEraseKey = FOUR_CHAR_CODE('k', 'f', 'e', 'k') /*!< Key value used to validate all flash erase APIs.*/
  184. };
  185. /*@}*/
  186. /*!
  187. * @brief Enumeration for supported flash margin levels.
  188. */
  189. typedef enum _flash_margin_value
  190. {
  191. kFLASH_MarginValueNormal, /*!< Use the 'normal' read level for 1s.*/
  192. kFLASH_MarginValueUser, /*!< Apply the 'User' margin to the normal read-1 level.*/
  193. kFLASH_MarginValueFactory, /*!< Apply the 'Factory' margin to the normal read-1 level.*/
  194. kFLASH_MarginValueInvalid /*!< Not real margin level, Used to determine the range of valid margin level. */
  195. } flash_margin_value_t;
  196. /*!
  197. * @brief Enumeration for the three possible flash security states.
  198. */
  199. typedef enum _flash_security_state
  200. {
  201. kFLASH_SecurityStateNotSecure, /*!< Flash is not secure.*/
  202. kFLASH_SecurityStateBackdoorEnabled, /*!< Flash backdoor is enabled.*/
  203. kFLASH_SecurityStateBackdoorDisabled /*!< Flash backdoor is disabled.*/
  204. } flash_security_state_t;
  205. /*!
  206. * @brief Enumeration for the three possible flash protection levels.
  207. */
  208. typedef enum _flash_protection_state
  209. {
  210. kFLASH_ProtectionStateUnprotected, /*!< Flash region is not protected.*/
  211. kFLASH_ProtectionStateProtected, /*!< Flash region is protected.*/
  212. kFLASH_ProtectionStateMixed /*!< Flash is mixed with protected and unprotected region.*/
  213. } flash_protection_state_t;
  214. /*!
  215. * @brief Enumeration for the three possible flash execute access levels.
  216. */
  217. typedef enum _flash_execute_only_access_state
  218. {
  219. kFLASH_AccessStateUnLimited, /*!< Flash region is unlimited.*/
  220. kFLASH_AccessStateExecuteOnly, /*!< Flash region is execute only.*/
  221. kFLASH_AccessStateMixed /*!< Flash is mixed with unlimited and execute only region.*/
  222. } flash_execute_only_access_state_t;
  223. /*!
  224. * @brief Enumeration for various flash properties.
  225. */
  226. typedef enum _flash_property_tag
  227. {
  228. kFLASH_PropertyPflashSectorSize = 0x00U, /*!< Pflash sector size property.*/
  229. kFLASH_PropertyPflashTotalSize = 0x01U, /*!< Pflash total size property.*/
  230. kFLASH_PropertyPflashBlockSize = 0x02U, /*!< Pflash block size property.*/
  231. kFLASH_PropertyPflashBlockCount = 0x03U, /*!< Pflash block count property.*/
  232. kFLASH_PropertyPflashBlockBaseAddr = 0x04U, /*!< Pflash block base address property.*/
  233. kFLASH_PropertyPflashFacSupport = 0x05U, /*!< Pflash fac support property.*/
  234. kFLASH_PropertyPflashAccessSegmentSize = 0x06U, /*!< Pflash access segment size property.*/
  235. kFLASH_PropertyPflashAccessSegmentCount = 0x07U, /*!< Pflash access segment count property.*/
  236. kFLASH_PropertyFlexRamBlockBaseAddr = 0x08U, /*!< FlexRam block base address property.*/
  237. kFLASH_PropertyFlexRamTotalSize = 0x09U, /*!< FlexRam total size property.*/
  238. kFLASH_PropertyDflashSectorSize = 0x10U, /*!< Dflash sector size property.*/
  239. kFLASH_PropertyDflashTotalSize = 0x11U, /*!< Dflash total size property.*/
  240. kFLASH_PropertyDflashBlockSize = 0x12U, /*!< Dflash block size property.*/
  241. kFLASH_PropertyDflashBlockCount = 0x13U, /*!< Dflash block count property.*/
  242. kFLASH_PropertyDflashBlockBaseAddr = 0x14U, /*!< Dflash block base address property.*/
  243. kFLASH_PropertyEepromTotalSize = 0x15U, /*!< EEPROM total size property.*/
  244. kFLASH_PropertyFlashMemoryIndex = 0x20U, /*!< Flash memory index property.*/
  245. kFLASH_PropertyFlashCacheControllerIndex = 0x21U /*!< Flash cache controller index property.*/
  246. } flash_property_tag_t;
  247. /*!
  248. * @brief Constants for execute-in-RAM flash function.
  249. */
  250. enum _flash_execute_in_ram_function_constants
  251. {
  252. kFLASH_ExecuteInRamFunctionMaxSizeInWords = 16U, /*!< The maximum size of execute-in-RAM function.*/
  253. kFLASH_ExecuteInRamFunctionTotalNum = 2U /*!< Total number of execute-in-RAM functions.*/
  254. };
  255. /*!
  256. * @brief Flash execute-in-RAM function information.
  257. */
  258. typedef struct _flash_execute_in_ram_function_config
  259. {
  260. uint32_t activeFunctionCount; /*!< Number of available execute-in-RAM functions.*/
  261. uint32_t *flashRunCommand; /*!< Execute-in-RAM function: flash_run_command.*/
  262. uint32_t *flashCommonBitOperation; /*!< Execute-in-RAM function: flash_common_bit_operation.*/
  263. } flash_execute_in_ram_function_config_t;
  264. /*!
  265. * @brief Enumeration for the two possible options of flash read resource command.
  266. */
  267. typedef enum _flash_read_resource_option
  268. {
  269. kFLASH_ResourceOptionFlashIfr =
  270. 0x00U, /*!< Select code for Program flash 0 IFR, Program flash swap 0 IFR, Data flash 0 IFR */
  271. kFLASH_ResourceOptionVersionId = 0x01U /*!< Select code for the version ID*/
  272. } flash_read_resource_option_t;
  273. /*!
  274. * @brief Enumeration for the range of special-purpose flash resource
  275. */
  276. enum _flash_read_resource_range
  277. {
  278. #if (FSL_FEATURE_FLASH_IS_FTFE == 1)
  279. kFLASH_ResourceRangePflashIfrSizeInBytes = 1024U, /*!< Pflash IFR size in byte.*/
  280. kFLASH_ResourceRangeVersionIdSizeInBytes = 8U, /*!< Version ID IFR size in byte.*/
  281. kFLASH_ResourceRangeVersionIdStart = 0x08U, /*!< Version ID IFR start address.*/
  282. kFLASH_ResourceRangeVersionIdEnd = 0x0FU, /*!< Version ID IFR end address.*/
  283. kFLASH_ResourceRangePflashSwapIfrStart = 0x40000U, /*!< Pflash swap IFR start address.*/
  284. kFLASH_ResourceRangePflashSwapIfrEnd =
  285. (kFLASH_ResourceRangePflashSwapIfrStart + 0x3FFU), /*!< Pflash swap IFR end address.*/
  286. #else /* FSL_FEATURE_FLASH_IS_FTFL == 1 or FSL_FEATURE_FLASH_IS_FTFA = =1 */
  287. kFLASH_ResourceRangePflashIfrSizeInBytes = 256U, /*!< Pflash IFR size in byte.*/
  288. kFLASH_ResourceRangeVersionIdSizeInBytes = 8U, /*!< Version ID IFR size in byte.*/
  289. kFLASH_ResourceRangeVersionIdStart = 0x00U, /*!< Version ID IFR start address.*/
  290. kFLASH_ResourceRangeVersionIdEnd = 0x07U, /*!< Version ID IFR end address.*/
  291. #if 0x20000U == (FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT * FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE)
  292. kFLASH_ResourceRangePflashSwapIfrStart = 0x8000U, /*!< Pflash swap IFR start address.*/
  293. #elif 0x40000U == (FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT * FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE)
  294. kFLASH_ResourceRangePflashSwapIfrStart = 0x10000U, /*!< Pflash swap IFR start address.*/
  295. #elif 0x80000U == (FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT * FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE)
  296. kFLASH_ResourceRangePflashSwapIfrStart = 0x20000U, /*!< Pflash swap IFR start address.*/
  297. #else
  298. kFLASH_ResourceRangePflashSwapIfrStart = 0,
  299. #endif
  300. kFLASH_ResourceRangePflashSwapIfrEnd =
  301. (kFLASH_ResourceRangePflashSwapIfrStart + 0xFFU), /*!< Pflash swap IFR end address.*/
  302. #endif
  303. kFLASH_ResourceRangeDflashIfrStart = 0x800000U, /*!< Dflash IFR start address.*/
  304. kFLASH_ResourceRangeDflashIfrEnd = 0x8003FFU, /*!< Dflash IFR end address.*/
  305. };
  306. /*!
  307. * @brief Enumeration for the index of read/program once record
  308. */
  309. enum _k3_flash_read_once_index
  310. {
  311. kFLASH_RecordIndexSwapAddr = 0xA1U, /*!< Index of Swap indicator address.*/
  312. kFLASH_RecordIndexSwapEnable = 0xA2U, /*!< Index of Swap system enable.*/
  313. kFLASH_RecordIndexSwapDisable = 0xA3U, /*!< Index of Swap system disable.*/
  314. };
  315. /*!
  316. * @brief Enumeration for the two possilbe options of set FlexRAM function command.
  317. */
  318. typedef enum _flash_flexram_function_option
  319. {
  320. kFLASH_FlexramFunctionOptionAvailableAsRam = 0xFFU, /*!< An option used to make FlexRAM available as RAM */
  321. kFLASH_FlexramFunctionOptionAvailableForEeprom = 0x00U /*!< An option used to make FlexRAM available for EEPROM */
  322. } flash_flexram_function_option_t;
  323. /*!
  324. * @brief Enumeration for acceleration RAM property.
  325. */
  326. enum _flash_acceleration_ram_property
  327. {
  328. kFLASH_AccelerationRamSize = 0x400U
  329. };
  330. /*!
  331. * @brief Enumeration for the possible options of Swap function
  332. */
  333. typedef enum _flash_swap_function_option
  334. {
  335. kFLASH_SwapFunctionOptionEnable = 0x00U, /*!< An option used to enable the Swap function */
  336. kFLASH_SwapFunctionOptionDisable = 0x01U /*!< An option used to disable the Swap function */
  337. } flash_swap_function_option_t;
  338. /*!
  339. * @brief Enumeration for the possible options of Swap control commands
  340. */
  341. typedef enum _flash_swap_control_option
  342. {
  343. kFLASH_SwapControlOptionIntializeSystem = 0x01U, /*!< An option used to initialize the Swap system */
  344. kFLASH_SwapControlOptionSetInUpdateState = 0x02U, /*!< An option used to set the Swap in an update state */
  345. kFLASH_SwapControlOptionSetInCompleteState = 0x04U, /*!< An option used to set the Swap in a complete state */
  346. kFLASH_SwapControlOptionReportStatus = 0x08U, /*!< An option used to report the Swap status */
  347. kFLASH_SwapControlOptionDisableSystem = 0x10U /*!< An option used to disable the Swap status */
  348. } flash_swap_control_option_t;
  349. /*!
  350. * @brief Enumeration for the possible flash Swap status.
  351. */
  352. typedef enum _flash_swap_state
  353. {
  354. kFLASH_SwapStateUninitialized = 0x00U, /*!< Flash Swap system is in an uninitialized state.*/
  355. kFLASH_SwapStateReady = 0x01U, /*!< Flash Swap system is in a ready state.*/
  356. kFLASH_SwapStateUpdate = 0x02U, /*!< Flash Swap system is in an update state.*/
  357. kFLASH_SwapStateUpdateErased = 0x03U, /*!< Flash Swap system is in an updateErased state.*/
  358. kFLASH_SwapStateComplete = 0x04U, /*!< Flash Swap system is in a complete state.*/
  359. kFLASH_SwapStateDisabled = 0x05U /*!< Flash Swap system is in a disabled state.*/
  360. } flash_swap_state_t;
  361. /*!
  362. * @breif Enumeration for the possible flash Swap block status
  363. */
  364. typedef enum _flash_swap_block_status
  365. {
  366. kFLASH_SwapBlockStatusLowerHalfProgramBlocksAtZero =
  367. 0x00U, /*!< Swap block status is that lower half program block at zero.*/
  368. kFLASH_SwapBlockStatusUpperHalfProgramBlocksAtZero =
  369. 0x01U, /*!< Swap block status is that upper half program block at zero.*/
  370. } flash_swap_block_status_t;
  371. /*!
  372. * @brief Flash Swap information
  373. */
  374. typedef struct _flash_swap_state_config
  375. {
  376. flash_swap_state_t flashSwapState; /*!<The current Swap system status.*/
  377. flash_swap_block_status_t currentSwapBlockStatus; /*!< The current Swap block status.*/
  378. flash_swap_block_status_t nextSwapBlockStatus; /*!< The next Swap block status.*/
  379. } flash_swap_state_config_t;
  380. /*!
  381. * @brief Flash Swap IFR fields
  382. */
  383. typedef struct _flash_swap_ifr_field_config
  384. {
  385. uint16_t swapIndicatorAddress; /*!< A Swap indicator address field.*/
  386. uint16_t swapEnableWord; /*!< A Swap enable word field.*/
  387. uint8_t reserved0[4]; /*!< A reserved field.*/
  388. #if (FSL_FEATURE_FLASH_IS_FTFE == 1)
  389. uint8_t reserved1[2]; /*!< A reserved field.*/
  390. uint16_t swapDisableWord; /*!< A Swap disable word field.*/
  391. uint8_t reserved2[4]; /*!< A reserved field.*/
  392. #endif
  393. } flash_swap_ifr_field_config_t;
  394. /*!
  395. * @brief Flash Swap IFR field data
  396. */
  397. typedef union _flash_swap_ifr_field_data
  398. {
  399. uint32_t flashSwapIfrData[2]; /*!< A flash Swap IFR field data .*/
  400. flash_swap_ifr_field_config_t flashSwapIfrField; /*!< A flash Swap IFR field structure.*/
  401. } flash_swap_ifr_field_data_t;
  402. /*!
  403. * @brief PFlash protection status - low 32bit
  404. */
  405. typedef union _pflash_protection_status_low
  406. {
  407. uint32_t protl32b; /*!< PROT[31:0] .*/
  408. struct
  409. {
  410. uint8_t protsl; /*!< PROTS[7:0] .*/
  411. uint8_t protsh; /*!< PROTS[15:8] .*/
  412. uint8_t reserved[2];
  413. } prots16b;
  414. } pflash_protection_status_low_t;
  415. /*!
  416. * @brief PFlash protection status - full
  417. */
  418. typedef struct _pflash_protection_status
  419. {
  420. pflash_protection_status_low_t valueLow32b; /*!< PROT[31:0] or PROTS[15:0].*/
  421. #if ((FSL_FEATURE_FLASH_IS_FTFA == 1) && (defined(FTFA_FPROTH0_PROT_MASK))) || \
  422. ((FSL_FEATURE_FLASH_IS_FTFE == 1) && (defined(FTFE_FPROTH0_PROT_MASK))) || \
  423. ((FSL_FEATURE_FLASH_IS_FTFL == 1) && (defined(FTFL_FPROTH0_PROT_MASK)))
  424. // uint32_t protHigh; /*!< PROT[63:32].*/
  425. struct
  426. {
  427. uint32_t proth32b;
  428. } valueHigh32b;
  429. #endif
  430. } pflash_protection_status_t;
  431. /*!
  432. * @brief Enumeration for the FlexRAM load during reset option.
  433. */
  434. typedef enum _flash_partition_flexram_load_option
  435. {
  436. kFLASH_PartitionFlexramLoadOptionLoadedWithValidEepromData =
  437. 0x00U, /*!< FlexRAM is loaded with valid EEPROM data during reset sequence.*/
  438. kFLASH_PartitionFlexramLoadOptionNotLoaded = 0x01U /*!< FlexRAM is not loaded during reset sequence.*/
  439. } flash_partition_flexram_load_option_t;
  440. /*!
  441. * @brief Enumeration for the flash memory index.
  442. */
  443. typedef enum _flash_memory_index
  444. {
  445. kFLASH_MemoryIndexPrimaryFlash = 0x00U, /*!< Current flash memory is primary flash.*/
  446. kFLASH_MemoryIndexSecondaryFlash = 0x01U, /*!< Current flash memory is secondary flash.*/
  447. } flash_memory_index_t;
  448. /*!
  449. * @brief Enumeration for the flash cache controller index.
  450. */
  451. typedef enum _flash_cache_controller_index
  452. {
  453. kFLASH_CacheControllerIndexForCore0 = 0x00U, /*!< Current flash cache controller is for core 0.*/
  454. kFLASH_CacheControllerIndexForCore1 = 0x01U, /*!< Current flash cache controller is for core 1.*/
  455. } flash_cache_controller_index_t;
  456. /*! @brief A callback type used for the Pflash block*/
  457. typedef void (*flash_callback_t)(void);
  458. /*!
  459. * @brief Enumeration for the two possible options of flash prefetch speculation.
  460. */
  461. typedef enum _flash_prefetch_speculation_option
  462. {
  463. kFLASH_prefetchSpeculationOptionEnable = 0x00U,
  464. kFLASH_prefetchSpeculationOptionDisable = 0x01U
  465. } flash_prefetch_speculation_option_t;
  466. /*!
  467. * @brief Flash prefetch speculation status.
  468. */
  469. typedef struct _flash_prefetch_speculation_status
  470. {
  471. flash_prefetch_speculation_option_t instructionOption; /*!< Instruction speculation.*/
  472. flash_prefetch_speculation_option_t dataOption; /*!< Data speculation.*/
  473. } flash_prefetch_speculation_status_t;
  474. /*!
  475. * @brief Flash cache clear process code.
  476. */
  477. typedef enum _flash_cache_clear_process
  478. {
  479. kFLASH_CacheClearProcessPre = 0x00U, /*!< Pre flash cache clear process.*/
  480. kFLASH_CacheClearProcessPost = 0x01U, /*!< Post flash cache clear process.*/
  481. } flash_cache_clear_process_t;
  482. /*!
  483. * @brief Active flash protection information for the current operation.
  484. */
  485. typedef struct _flash_protection_config
  486. {
  487. uint32_t regionBase; /*!< Base address of flash protection region.*/
  488. uint32_t regionSize; /*!< size of flash protection region.*/
  489. uint32_t regionCount; /*!< flash protection region count.*/
  490. } flash_protection_config_t;
  491. /*!
  492. * @brief Active flash Execute-Only access information for the current operation.
  493. */
  494. typedef struct _flash_access_config
  495. {
  496. uint32_t SegmentBase; /*!< Base address of flash Execute-Only segment.*/
  497. uint32_t SegmentSize; /*!< size of flash Execute-Only segment.*/
  498. uint32_t SegmentCount; /*!< flash Execute-Only segment count.*/
  499. } flash_access_config_t;
  500. /*!
  501. * @brief Active flash information for the current operation.
  502. */
  503. typedef struct _flash_operation_config
  504. {
  505. uint32_t convertedAddress; /*!< A converted address for the current flash type.*/
  506. uint32_t activeSectorSize; /*!< A sector size of the current flash type.*/
  507. uint32_t activeBlockSize; /*!< A block size of the current flash type.*/
  508. uint32_t blockWriteUnitSize; /*!< The write unit size.*/
  509. uint32_t sectorCmdAddressAligment; /*!< An erase sector command address alignment.*/
  510. uint32_t sectionCmdAddressAligment; /*!< A program/verify section command address alignment.*/
  511. uint32_t resourceCmdAddressAligment; /*!< A read resource command address alignment.*/
  512. uint32_t checkCmdAddressAligment; /*!< A program check command address alignment.*/
  513. } flash_operation_config_t;
  514. /*! @brief Flash driver state information.
  515. *
  516. * An instance of this structure is allocated by the user of the flash driver and
  517. * passed into each of the driver APIs.
  518. */
  519. typedef struct _flash_config
  520. {
  521. uint32_t PFlashBlockBase; /*!< A base address of the first PFlash block */
  522. uint32_t PFlashTotalSize; /*!< The size of the combined PFlash block. */
  523. uint8_t PFlashBlockCount; /*!< A number of PFlash blocks. */
  524. uint8_t FlashMemoryIndex; /*!< 0 - primary flash; 1 - secondary flash*/
  525. uint8_t FlashCacheControllerIndex; /*!< 0 - Controller for core 0; 1 - Controller for core 1 */
  526. uint8_t Reserved0; /*!< Reserved field 0 */
  527. uint32_t PFlashSectorSize; /*!< The size in bytes of a sector of PFlash. */
  528. flash_callback_t PFlashCallback; /*!< The callback function for the flash API. */
  529. uint32_t PFlashAccessSegmentSize; /*!< A size in bytes of an access segment of PFlash. */
  530. uint32_t PFlashAccessSegmentCount; /*!< A number of PFlash access segments. */
  531. uint32_t *flashExecuteInRamFunctionInfo; /*!< An information structure of the flash execute-in-RAM function. */
  532. uint32_t FlexRAMBlockBase; /*!< For the FlexNVM device, this is the base address of the FlexRAM */
  533. /*!< For the non-FlexNVM device, this is the base address of the acceleration RAM memory */
  534. uint32_t FlexRAMTotalSize; /*!< For the FlexNVM device, this is the size of the FlexRAM */
  535. /*!< For the non-FlexNVM device, this is the size of the acceleration RAM memory */
  536. uint32_t
  537. DFlashBlockBase; /*!< For the FlexNVM device, this is the base address of the D-Flash memory (FlexNVM memory) */
  538. /*!< For the non-FlexNVM device, this field is unused */
  539. uint32_t DFlashTotalSize; /*!< For the FlexNVM device, this is the total size of the FlexNVM memory; */
  540. /*!< For the non-FlexNVM device, this field is unused */
  541. uint32_t EEpromTotalSize; /*!< For the FlexNVM device, this is the size in bytes of the EEPROM area which was
  542. partitioned from FlexRAM */
  543. /*!< For the non-FlexNVM device, this field is unused */
  544. } flash_config_t;
  545. /*******************************************************************************
  546. * API
  547. ******************************************************************************/
  548. #if defined(__cplusplus)
  549. extern "C" {
  550. #endif
  551. /*!
  552. * @name Initialization
  553. * @{
  554. */
  555. /*!
  556. * @brief Initializes the global flash properties structure members.
  557. *
  558. * This function checks and initializes the Flash module for the other Flash APIs.
  559. *
  560. * @param config Pointer to the storage for the driver runtime state.
  561. *
  562. * @retval #kStatus_FLASH_Success API was executed successfully.
  563. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  564. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  565. * @retval #kStatus_FLASH_PartitionStatusUpdateFailure Failed to update the partition status.
  566. */
  567. status_t FLASH_Init(flash_config_t *config);
  568. /*!
  569. * @brief Sets the desired flash callback function.
  570. *
  571. * @param config Pointer to the storage for the driver runtime state.
  572. * @param callback A callback function to be stored in the driver.
  573. *
  574. * @retval #kStatus_FLASH_Success API was executed successfully.
  575. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  576. */
  577. status_t FLASH_SetCallback(flash_config_t *config, flash_callback_t callback);
  578. /*!
  579. * @brief Prepares flash execute-in-RAM functions.
  580. *
  581. * @param config Pointer to the storage for the driver runtime state.
  582. *
  583. * @retval #kStatus_FLASH_Success API was executed successfully.
  584. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  585. */
  586. #if FLASH_DRIVER_IS_FLASH_RESIDENT
  587. status_t FLASH_PrepareExecuteInRamFunctions(flash_config_t *config);
  588. #endif
  589. /*@}*/
  590. /*!
  591. * @name Erasing
  592. * @{
  593. */
  594. /*!
  595. * @brief Erases entire flash
  596. *
  597. * @param config Pointer to the storage for the driver runtime state.
  598. * @param key A value used to validate all flash erase APIs.
  599. *
  600. * @retval #kStatus_FLASH_Success API was executed successfully.
  601. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  602. * @retval #kStatus_FLASH_EraseKeyError API erase key is invalid.
  603. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  604. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  605. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  606. * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution.
  607. * @retval #kStatus_FLASH_PartitionStatusUpdateFailure Failed to update the partition status.
  608. */
  609. status_t FLASH_EraseAll(flash_config_t *config, uint32_t key);
  610. /*!
  611. * @brief Erases the flash sectors encompassed by parameters passed into function.
  612. *
  613. * This function erases the appropriate number of flash sectors based on the
  614. * desired start address and length.
  615. *
  616. * @param config The pointer to the storage for the driver runtime state.
  617. * @param start The start address of the desired flash memory to be erased.
  618. * The start address does not need to be sector-aligned but must be word-aligned.
  619. * @param lengthInBytes The length, given in bytes (not words or long-words)
  620. * to be erased. Must be word-aligned.
  621. * @param key The value used to validate all flash erase APIs.
  622. *
  623. * @retval #kStatus_FLASH_Success API was executed successfully.
  624. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  625. * @retval #kStatus_FLASH_AlignmentError The parameter is not aligned with the specified baseline.
  626. * @retval #kStatus_FLASH_AddressError The address is out of range.
  627. * @retval #kStatus_FLASH_EraseKeyError The API erase key is invalid.
  628. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  629. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  630. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  631. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  632. */
  633. status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
  634. /*!
  635. * @brief Erases the entire flash, including protected sectors.
  636. *
  637. * @param config Pointer to the storage for the driver runtime state.
  638. * @param key A value used to validate all flash erase APIs.
  639. *
  640. * @retval #kStatus_FLASH_Success API was executed successfully.
  641. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  642. * @retval #kStatus_FLASH_EraseKeyError API erase key is invalid.
  643. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  644. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  645. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  646. * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution.
  647. * @retval #kStatus_FLASH_PartitionStatusUpdateFailure Failed to update the partition status.
  648. */
  649. #if defined(FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD) && FSL_FEATURE_FLASH_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
  650. status_t FLASH_EraseAllUnsecure(flash_config_t *config, uint32_t key);
  651. #endif
  652. /*!
  653. * @brief Erases all program flash execute-only segments defined by the FXACC registers.
  654. *
  655. * @param config Pointer to the storage for the driver runtime state.
  656. * @param key A value used to validate all flash erase APIs.
  657. *
  658. * @retval #kStatus_FLASH_Success API was executed successfully.
  659. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  660. * @retval #kStatus_FLASH_EraseKeyError API erase key is invalid.
  661. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  662. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  663. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  664. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  665. */
  666. status_t FLASH_EraseAllExecuteOnlySegments(flash_config_t *config, uint32_t key);
  667. /*@}*/
  668. /*!
  669. * @name Programming
  670. * @{
  671. */
  672. /*!
  673. * @brief Programs flash with data at locations passed in through parameters.
  674. *
  675. * This function programs the flash memory with the desired data for a given
  676. * flash area as determined by the start address and the length.
  677. *
  678. * @param config A pointer to the storage for the driver runtime state.
  679. * @param start The start address of the desired flash memory to be programmed. Must be
  680. * word-aligned.
  681. * @param src A pointer to the source buffer of data that is to be programmed
  682. * into the flash.
  683. * @param lengthInBytes The length, given in bytes (not words or long-words),
  684. * to be programmed. Must be word-aligned.
  685. *
  686. * @retval #kStatus_FLASH_Success API was executed successfully.
  687. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  688. * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline.
  689. * @retval #kStatus_FLASH_AddressError Address is out of range.
  690. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  691. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  692. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  693. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  694. */
  695. status_t FLASH_Program(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes);
  696. /*!
  697. * @brief Programs Program Once Field through parameters.
  698. *
  699. * This function programs the Program Once Field with the desired data for a given
  700. * flash area as determined by the index and length.
  701. *
  702. * @param config A pointer to the storage for the driver runtime state.
  703. * @param index The index indicating which area of the Program Once Field to be programmed.
  704. * @param src A pointer to the source buffer of data that is to be programmed
  705. * into the Program Once Field.
  706. * @param lengthInBytes The length, given in bytes (not words or long-words),
  707. * to be programmed. Must be word-aligned.
  708. *
  709. * @retval #kStatus_FLASH_Success API was executed successfully.
  710. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  711. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  712. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  713. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  714. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  715. */
  716. status_t FLASH_ProgramOnce(flash_config_t *config, uint32_t index, uint32_t *src, uint32_t lengthInBytes);
  717. /*!
  718. * @brief Programs flash with data at locations passed in through parameters via the Program Section command.
  719. *
  720. * This function programs the flash memory with the desired data for a given
  721. * flash area as determined by the start address and length.
  722. *
  723. * @param config A pointer to the storage for the driver runtime state.
  724. * @param start The start address of the desired flash memory to be programmed. Must be
  725. * word-aligned.
  726. * @param src A pointer to the source buffer of data that is to be programmed
  727. * into the flash.
  728. * @param lengthInBytes The length, given in bytes (not words or long-words),
  729. * to be programmed. Must be word-aligned.
  730. *
  731. * @retval #kStatus_FLASH_Success API was executed successfully.
  732. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  733. * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
  734. * @retval #kStatus_FLASH_AddressError Address is out of range.
  735. * @retval #kStatus_FLASH_SetFlexramAsRamError Failed to set flexram as RAM.
  736. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  737. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  738. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  739. * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution.
  740. * @retval #kStatus_FLASH_RecoverFlexramAsEepromError Failed to recover FlexRAM as EEPROM.
  741. */
  742. #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_SECTION_CMD
  743. status_t FLASH_ProgramSection(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes);
  744. #endif
  745. /*!
  746. * @brief Programs the EEPROM with data at locations passed in through parameters.
  747. *
  748. * This function programs the emulated EEPROM with the desired data for a given
  749. * flash area as determined by the start address and length.
  750. *
  751. * @param config A pointer to the storage for the driver runtime state.
  752. * @param start The start address of the desired flash memory to be programmed. Must be
  753. * word-aligned.
  754. * @param src A pointer to the source buffer of data that is to be programmed
  755. * into the flash.
  756. * @param lengthInBytes The length, given in bytes (not words or long-words),
  757. * to be programmed. Must be word-aligned.
  758. *
  759. * @retval #kStatus_FLASH_Success API was executed successfully.
  760. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  761. * @retval #kStatus_FLASH_AddressError Address is out of range.
  762. * @retval #kStatus_FLASH_SetFlexramAsEepromError Failed to set flexram as eeprom.
  763. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  764. * @retval #kStatus_FLASH_RecoverFlexramAsRamError Failed to recover the FlexRAM as RAM.
  765. */
  766. #if FLASH_SSD_IS_FLEXNVM_ENABLED
  767. status_t FLASH_EepromWrite(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
  768. #endif
  769. /*@}*/
  770. /*!
  771. * @name Reading
  772. * @{
  773. */
  774. /*!
  775. * @brief Reads the resource with data at locations passed in through parameters.
  776. *
  777. * This function reads the flash memory with the desired location for a given
  778. * flash area as determined by the start address and length.
  779. *
  780. * @param config A pointer to the storage for the driver runtime state.
  781. * @param start The start address of the desired flash memory to be programmed. Must be
  782. * word-aligned.
  783. * @param dst A pointer to the destination buffer of data that is used to store
  784. * data to be read.
  785. * @param lengthInBytes The length, given in bytes (not words or long-words),
  786. * to be read. Must be word-aligned.
  787. * @param option The resource option which indicates which area should be read back.
  788. *
  789. * @retval #kStatus_FLASH_Success API was executed successfully.
  790. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  791. * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline.
  792. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  793. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  794. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  795. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  796. */
  797. #if defined(FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD) && FSL_FEATURE_FLASH_HAS_READ_RESOURCE_CMD
  798. status_t FLASH_ReadResource(
  799. flash_config_t *config, uint32_t start, uint32_t *dst, uint32_t lengthInBytes, flash_read_resource_option_t option);
  800. #endif
  801. /*!
  802. * @brief Reads the Program Once Field through parameters.
  803. *
  804. * This function reads the read once feild with given index and length.
  805. *
  806. * @param config A pointer to the storage for the driver runtime state.
  807. * @param index The index indicating the area of program once field to be read.
  808. * @param dst A pointer to the destination buffer of data that is used to store
  809. * data to be read.
  810. * @param lengthInBytes The length, given in bytes (not words or long-words),
  811. * to be programmed. Must be word-aligned.
  812. *
  813. * @retval #kStatus_FLASH_Success API was executed successfully.
  814. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  815. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  816. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  817. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  818. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  819. */
  820. status_t FLASH_ReadOnce(flash_config_t *config, uint32_t index, uint32_t *dst, uint32_t lengthInBytes);
  821. /*@}*/
  822. /*!
  823. * @name Security
  824. * @{
  825. */
  826. /*!
  827. * @brief Returns the security state via the pointer passed into the function.
  828. *
  829. * This function retrieves the current flash security status, including the
  830. * security enabling state and the backdoor key enabling state.
  831. *
  832. * @param config A pointer to storage for the driver runtime state.
  833. * @param state A pointer to the value returned for the current security status code:
  834. *
  835. * @retval #kStatus_FLASH_Success API was executed successfully.
  836. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  837. */
  838. status_t FLASH_GetSecurityState(flash_config_t *config, flash_security_state_t *state);
  839. /*!
  840. * @brief Allows users to bypass security with a backdoor key.
  841. *
  842. * If the MCU is in secured state, this function unsecures the MCU by
  843. * comparing the provided backdoor key with ones in the flash configuration
  844. * field.
  845. *
  846. * @param config A pointer to the storage for the driver runtime state.
  847. * @param backdoorKey A pointer to the user buffer containing the backdoor key.
  848. *
  849. * @retval #kStatus_FLASH_Success API was executed successfully.
  850. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  851. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  852. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  853. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  854. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  855. */
  856. status_t FLASH_SecurityBypass(flash_config_t *config, const uint8_t *backdoorKey);
  857. /*@}*/
  858. /*!
  859. * @name Verification
  860. * @{
  861. */
  862. /*!
  863. * @brief Verifies erasure of the entire flash at a specified margin level.
  864. *
  865. * This function checks whether the flash is erased to the
  866. * specified read margin level.
  867. *
  868. * @param config A pointer to the storage for the driver runtime state.
  869. * @param margin Read margin choice.
  870. *
  871. * @retval #kStatus_FLASH_Success API was executed successfully.
  872. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  873. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  874. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  875. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  876. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  877. */
  878. status_t FLASH_VerifyEraseAll(flash_config_t *config, flash_margin_value_t margin);
  879. /*!
  880. * @brief Verifies an erasure of the desired flash area at a specified margin level.
  881. *
  882. * This function checks the appropriate number of flash sectors based on
  883. * the desired start address and length to check whether the flash is erased
  884. * to the specified read margin level.
  885. *
  886. * @param config A pointer to the storage for the driver runtime state.
  887. * @param start The start address of the desired flash memory to be verified.
  888. * The start address does not need to be sector-aligned but must be word-aligned.
  889. * @param lengthInBytes The length, given in bytes (not words or long-words),
  890. * to be verified. Must be word-aligned.
  891. * @param margin Read margin choice.
  892. *
  893. * @retval #kStatus_FLASH_Success API was executed successfully.
  894. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  895. * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
  896. * @retval #kStatus_FLASH_AddressError Address is out of range.
  897. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  898. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  899. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  900. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  901. */
  902. status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, flash_margin_value_t margin);
  903. /*!
  904. * @brief Verifies programming of the desired flash area at a specified margin level.
  905. *
  906. * This function verifies the data programed in the flash memory using the
  907. * Flash Program Check Command and compares it to the expected data for a given
  908. * flash area as determined by the start address and length.
  909. *
  910. * @param config A pointer to the storage for the driver runtime state.
  911. * @param start The start address of the desired flash memory to be verified. Must be word-aligned.
  912. * @param lengthInBytes The length, given in bytes (not words or long-words),
  913. * to be verified. Must be word-aligned.
  914. * @param expectedData A pointer to the expected data that is to be
  915. * verified against.
  916. * @param margin Read margin choice.
  917. * @param failedAddress A pointer to the returned failing address.
  918. * @param failedData A pointer to the returned failing data. Some derivatives do
  919. * not include failed data as part of the FCCOBx registers. In this
  920. * case, zeros are returned upon failure.
  921. *
  922. * @retval #kStatus_FLASH_Success API was executed successfully.
  923. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  924. * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
  925. * @retval #kStatus_FLASH_AddressError Address is out of range.
  926. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  927. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  928. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  929. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  930. */
  931. status_t FLASH_VerifyProgram(flash_config_t *config,
  932. uint32_t start,
  933. uint32_t lengthInBytes,
  934. const uint32_t *expectedData,
  935. flash_margin_value_t margin,
  936. uint32_t *failedAddress,
  937. uint32_t *failedData);
  938. /*!
  939. * @brief Verifies whether the program flash execute-only segments have been erased to
  940. * the specified read margin level.
  941. *
  942. * @param config A pointer to the storage for the driver runtime state.
  943. * @param margin Read margin choice.
  944. *
  945. * @retval #kStatus_FLASH_Success API was executed successfully.
  946. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  947. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  948. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  949. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  950. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  951. */
  952. status_t FLASH_VerifyEraseAllExecuteOnlySegments(flash_config_t *config, flash_margin_value_t margin);
  953. /*@}*/
  954. /*!
  955. * @name Protection
  956. * @{
  957. */
  958. /*!
  959. * @brief Returns the protection state of the desired flash area via the pointer passed into the function.
  960. *
  961. * This function retrieves the current flash protect status for a given
  962. * flash area as determined by the start address and length.
  963. *
  964. * @param config A pointer to the storage for the driver runtime state.
  965. * @param start The start address of the desired flash memory to be checked. Must be word-aligned.
  966. * @param lengthInBytes The length, given in bytes (not words or long-words)
  967. * to be checked. Must be word-aligned.
  968. * @param protection_state A pointer to the value returned for the current
  969. * protection status code for the desired flash area.
  970. *
  971. * @retval #kStatus_FLASH_Success API was executed successfully.
  972. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  973. * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
  974. * @retval #kStatus_FLASH_AddressError The address is out of range.
  975. */
  976. status_t FLASH_IsProtected(flash_config_t *config,
  977. uint32_t start,
  978. uint32_t lengthInBytes,
  979. flash_protection_state_t *protection_state);
  980. /*!
  981. * @brief Returns the access state of the desired flash area via the pointer passed into the function.
  982. *
  983. * This function retrieves the current flash access status for a given
  984. * flash area as determined by the start address and length.
  985. *
  986. * @param config A pointer to the storage for the driver runtime state.
  987. * @param start The start address of the desired flash memory to be checked. Must be word-aligned.
  988. * @param lengthInBytes The length, given in bytes (not words or long-words),
  989. * to be checked. Must be word-aligned.
  990. * @param access_state A pointer to the value returned for the current
  991. * access status code for the desired flash area.
  992. *
  993. * @retval #kStatus_FLASH_Success API was executed successfully.
  994. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  995. * @retval #kStatus_FLASH_AlignmentError The parameter is not aligned to the specified baseline.
  996. * @retval #kStatus_FLASH_AddressError The address is out of range.
  997. */
  998. status_t FLASH_IsExecuteOnly(flash_config_t *config,
  999. uint32_t start,
  1000. uint32_t lengthInBytes,
  1001. flash_execute_only_access_state_t *access_state);
  1002. /*@}*/
  1003. /*!
  1004. * @name Properties
  1005. * @{
  1006. */
  1007. /*!
  1008. * @brief Returns the desired flash property.
  1009. *
  1010. * @param config A pointer to the storage for the driver runtime state.
  1011. * @param whichProperty The desired property from the list of properties in
  1012. * enum flash_property_tag_t
  1013. * @param value A pointer to the value returned for the desired flash property.
  1014. *
  1015. * @retval #kStatus_FLASH_Success API was executed successfully.
  1016. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1017. * @retval #kStatus_FLASH_UnknownProperty An unknown property tag.
  1018. */
  1019. status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value);
  1020. /*!
  1021. * @brief Sets the desired flash property.
  1022. *
  1023. * @param config A pointer to the storage for the driver runtime state.
  1024. * @param whichProperty The desired property from the list of properties in
  1025. * enum flash_property_tag_t
  1026. * @param value A to set for the desired flash property.
  1027. *
  1028. * @retval #kStatus_FLASH_Success API was executed successfully.
  1029. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1030. * @retval #kStatus_FLASH_UnknownProperty An unknown property tag.
  1031. * @retval #kStatus_FLASH_InvalidPropertyValue An invalid property value.
  1032. * @retval #kStatus_FLASH_ReadOnlyProperty An read-only property tag.
  1033. */
  1034. status_t FLASH_SetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t value);
  1035. /*@}*/
  1036. /*!
  1037. * @name FlexRAM
  1038. * @{
  1039. */
  1040. /*!
  1041. * @brief Sets the FlexRAM function command.
  1042. *
  1043. * @param config A pointer to the storage for the driver runtime state.
  1044. * @param option The option used to set the work mode of FlexRAM.
  1045. *
  1046. * @retval #kStatus_FLASH_Success API was executed successfully.
  1047. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1048. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  1049. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  1050. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  1051. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  1052. */
  1053. #if defined(FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD) && FSL_FEATURE_FLASH_HAS_SET_FLEXRAM_FUNCTION_CMD
  1054. status_t FLASH_SetFlexramFunction(flash_config_t *config, flash_flexram_function_option_t option);
  1055. #endif
  1056. /*@}*/
  1057. /*!
  1058. * @name Swap
  1059. * @{
  1060. */
  1061. /*!
  1062. * @brief Configures the Swap function or checks the the swap state of the Flash module.
  1063. *
  1064. * @param config A pointer to the storage for the driver runtime state.
  1065. * @param address Address used to configure the flash Swap function.
  1066. * @param option The possible option used to configure Flash Swap function or check the flash Swap status
  1067. * @param returnInfo A pointer to the data which is used to return the information of flash Swap.
  1068. *
  1069. * @retval #kStatus_FLASH_Success API was executed successfully.
  1070. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1071. * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
  1072. * @retval #kStatus_FLASH_SwapIndicatorAddressError Swap indicator address is invalid.
  1073. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  1074. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  1075. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  1076. * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
  1077. */
  1078. #if defined(FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD) && FSL_FEATURE_FLASH_HAS_SWAP_CONTROL_CMD
  1079. status_t FLASH_SwapControl(flash_config_t *config,
  1080. uint32_t address,
  1081. flash_swap_control_option_t option,
  1082. flash_swap_state_config_t *returnInfo);
  1083. #endif
  1084. /*!
  1085. * @brief Swaps the lower half flash with the higher half flash.
  1086. *
  1087. * @param config A pointer to the storage for the driver runtime state.
  1088. * @param address Address used to configure the flash swap function
  1089. * @param option The possible option used to configure the Flash Swap function or check the flash Swap status.
  1090. *
  1091. * @retval #kStatus_FLASH_Success API was executed successfully.
  1092. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1093. * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
  1094. * @retval #kStatus_FLASH_SwapIndicatorAddressError Swap indicator address is invalid.
  1095. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  1096. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  1097. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  1098. * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution.
  1099. * @retval #kStatus_FLASH_SwapSystemNotInUninitialized Swap system is not in an uninitialzed state.
  1100. */
  1101. #if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
  1102. status_t FLASH_Swap(flash_config_t *config, uint32_t address, flash_swap_function_option_t option);
  1103. #endif
  1104. /*!
  1105. * @name FlexNVM
  1106. * @{
  1107. */
  1108. /*!
  1109. * @brief Prepares the FlexNVM block for use as data flash, EEPROM backup, or a combination of both and initializes the
  1110. * FlexRAM.
  1111. *
  1112. * @param config Pointer to storage for the driver runtime state.
  1113. * @param option The option used to set FlexRAM load behavior during reset.
  1114. * @param eepromDataSizeCode Determines the amount of FlexRAM used in each of the available EEPROM subsystems.
  1115. * @param flexnvmPartitionCode Specifies how to split the FlexNVM block between data flash memory and EEPROM backup
  1116. * memory supporting EEPROM functions.
  1117. *
  1118. * @retval #kStatus_FLASH_Success API was executed successfully.
  1119. * @retval #kStatus_FLASH_InvalidArgument Invalid argument is provided.
  1120. * @retval #kStatus_FLASH_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
  1121. * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
  1122. * @retval #kStatus_FLASH_ProtectionViolation The program/erase operation is requested to execute on protected areas.
  1123. * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution.
  1124. */
  1125. #if defined(FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD) && FSL_FEATURE_FLASH_HAS_PROGRAM_PARTITION_CMD
  1126. status_t FLASH_ProgramPartition(flash_config_t *config,
  1127. flash_partition_flexram_load_option_t option,
  1128. uint32_t eepromDataSizeCode,
  1129. uint32_t flexnvmPartitionCode);
  1130. #endif
  1131. /*@}*/
  1132. /*!
  1133. * @name Flash Protection Utilities
  1134. * @{
  1135. */
  1136. /*!
  1137. * @brief Sets the PFlash Protection to the intended protection status.
  1138. *
  1139. * @param config A pointer to storage for the driver runtime state.
  1140. * @param protectStatus The expected protect status to set to the PFlash protection register. Each bit is
  1141. * corresponding to protection of 1/32(64) of the total PFlash. The least significant bit is corresponding to the lowest
  1142. * address area of PFlash. The most significant bit is corresponding to the highest address area of PFlash. There are
  1143. * two possible cases as shown below:
  1144. * 0: this area is protected.
  1145. * 1: this area is unprotected.
  1146. *
  1147. * @retval #kStatus_FLASH_Success API was executed successfully.
  1148. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1149. * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution.
  1150. */
  1151. status_t FLASH_PflashSetProtection(flash_config_t *config, pflash_protection_status_t *protectStatus);
  1152. /*!
  1153. * @brief Gets the PFlash protection status.
  1154. *
  1155. * @param config A pointer to the storage for the driver runtime state.
  1156. * @param protectStatus Protect status returned by the PFlash IP. Each bit is corresponding to the protection of
  1157. * 1/32(64)
  1158. * of the
  1159. * total PFlash. The least significant bit corresponds to the lowest address area of the PFlash. The most significant
  1160. * bit corresponds to the highest address area of PFlash. There are two possible cases as shown below:
  1161. * 0: this area is protected.
  1162. * 1: this area is unprotected.
  1163. *
  1164. * @retval #kStatus_FLASH_Success API was executed successfully.
  1165. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1166. */
  1167. status_t FLASH_PflashGetProtection(flash_config_t *config, pflash_protection_status_t *protectStatus);
  1168. /*!
  1169. * @brief Sets the DFlash protection to the intended protection status.
  1170. *
  1171. * @param config A pointer to the storage for the driver runtime state.
  1172. * @param protectStatus The expected protect status to set to the DFlash protection register. Each bit
  1173. * corresponds to the protection of the 1/8 of the total DFlash. The least significant bit corresponds to the lowest
  1174. * address area of the DFlash. The most significant bit corresponds to the highest address area of the DFlash. There
  1175. * are
  1176. * two possible cases as shown below:
  1177. * 0: this area is protected.
  1178. * 1: this area is unprotected.
  1179. *
  1180. * @retval #kStatus_FLASH_Success API was executed successfully.
  1181. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1182. * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
  1183. * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution.
  1184. */
  1185. #if FLASH_SSD_IS_FLEXNVM_ENABLED
  1186. status_t FLASH_DflashSetProtection(flash_config_t *config, uint8_t protectStatus);
  1187. #endif
  1188. /*!
  1189. * @brief Gets the DFlash protection status.
  1190. *
  1191. * @param config A pointer to the storage for the driver runtime state.
  1192. * @param protectStatus DFlash Protect status returned by the PFlash IP. Each bit corresponds to the protection of the
  1193. * 1/8 of
  1194. * the total DFlash. The least significant bit corresponds to the lowest address area of the DFlash. The most
  1195. * significant bit corresponds to the highest address area of the DFlash, and so on. There are two possible cases as
  1196. * below:
  1197. * 0: this area is protected.
  1198. * 1: this area is unprotected.
  1199. *
  1200. * @retval #kStatus_FLASH_Success API was executed successfully.
  1201. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1202. * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
  1203. */
  1204. #if FLASH_SSD_IS_FLEXNVM_ENABLED
  1205. status_t FLASH_DflashGetProtection(flash_config_t *config, uint8_t *protectStatus);
  1206. #endif
  1207. /*!
  1208. * @brief Sets the EEPROM protection to the intended protection status.
  1209. *
  1210. * @param config A pointer to the storage for the driver runtime state.
  1211. * @param protectStatus The expected protect status to set to the EEPROM protection register. Each bit
  1212. * corresponds to the protection of the 1/8 of the total EEPROM. The least significant bit corresponds to the lowest
  1213. * address area of the EEPROM. The most significant bit corresponds to the highest address area of EEPROM, and so on.
  1214. * There are two possible cases as shown below:
  1215. * 0: this area is protected.
  1216. * 1: this area is unprotected.
  1217. *
  1218. * @retval #kStatus_FLASH_Success API was executed successfully.
  1219. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1220. * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
  1221. * @retval #kStatus_FLASH_CommandFailure Run-time error during command execution.
  1222. */
  1223. #if FLASH_SSD_IS_FLEXNVM_ENABLED
  1224. status_t FLASH_EepromSetProtection(flash_config_t *config, uint8_t protectStatus);
  1225. #endif
  1226. /*!
  1227. * @brief Gets the DFlash protection status.
  1228. *
  1229. * @param config A pointer to the storage for the driver runtime state.
  1230. * @param protectStatus DFlash Protect status returned by the PFlash IP. Each bit corresponds to the protection of the
  1231. * 1/8 of
  1232. * the total EEPROM. The least significant bit corresponds to the lowest address area of the EEPROM. The most
  1233. * significant bit corresponds to the highest address area of the EEPROM. There are two possible cases as below:
  1234. * 0: this area is protected.
  1235. * 1: this area is unprotected.
  1236. *
  1237. * @retval #kStatus_FLASH_Success API was executed successfully.
  1238. * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
  1239. * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
  1240. */
  1241. #if FLASH_SSD_IS_FLEXNVM_ENABLED
  1242. status_t FLASH_EepromGetProtection(flash_config_t *config, uint8_t *protectStatus);
  1243. #endif
  1244. /*@}*/
  1245. /*@}*/
  1246. /*!
  1247. * @name Flash Speculation Utilities
  1248. * @{
  1249. */
  1250. /*!
  1251. * @brief Sets the PFlash prefetch speculation to the intended speculation status.
  1252. *
  1253. * @param speculationStatus The expected protect status to set to the PFlash protection register. Each bit is
  1254. * @retval #kStatus_FLASH_Success API was executed successfully.
  1255. * @retval #kStatus_FLASH_InvalidSpeculationOption An invalid speculation option argument is provided.
  1256. */
  1257. status_t FLASH_PflashSetPrefetchSpeculation(flash_prefetch_speculation_status_t *speculationStatus);
  1258. /*!
  1259. * @brief Gets the PFlash prefetch speculation status.
  1260. *
  1261. * @param speculationStatus Speculation status returned by the PFlash IP.
  1262. * @retval #kStatus_FLASH_Success API was executed successfully.
  1263. */
  1264. status_t FLASH_PflashGetPrefetchSpeculation(flash_prefetch_speculation_status_t *speculationStatus);
  1265. /*@}*/
  1266. #if defined(__cplusplus)
  1267. }
  1268. #endif
  1269. /*! @}*/
  1270. #endif /* _FSL_FLASH_H_ */