nu_fmc.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /**************************************************************************//**
  2. * @file nu_fmc.h
  3. * @version V3.0
  4. * $Revision: 2 $
  5. * $Date: 19/11/27 3:11p $
  6. * @brief M2355 Series Flash Memory Controller(FMC) driver header file
  7. *
  8. * @copyright SPDX-License-Identifier: Apache-2.0
  9. * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
  10. ******************************************************************************/
  11. #ifndef __NU_FMC_H__
  12. #define __NU_FMC_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup Standard_Driver Standard Driver
  18. @{
  19. */
  20. /** @addtogroup FMC_Driver FMC Driver
  21. @{
  22. */
  23. /** @addtogroup FMC_EXPORTED_CONSTANTS FMC Exported Constants
  24. @{
  25. */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. /* Global constant definitions */
  28. /*---------------------------------------------------------------------------------------------------------*/
  29. #define ISBEN 0UL
  30. #define FMC_ISP ( (__PC() & 0x10000000) ? FMC_NS : FMC)
  31. /*---------------------------------------------------------------------------------------------------------*/
  32. /* Define Base Address */
  33. /*---------------------------------------------------------------------------------------------------------*/
  34. #define FMC_APROM_BASE 0x00000000UL /*!< APROM Base Address */
  35. #define FMC_APROM_END 0x00100000UL /*!< APROM end address */
  36. #define FMC_APROM_BANK0_END (FMC_APROM_END/2UL) /*!< APROM bank0 end address */
  37. #define FMC_LDROM_BASE 0x00100000UL /*!< LDROM Base Address */
  38. #define FMC_LDROM_END 0x00104000UL /*!< LDROM end address */
  39. #define FMC_DTFSH_BASE 0x00110000UL /*!< LDROM Base Address */
  40. #define FMC_DTFSH_END 0x00112000UL /*!< LDROM end address */
  41. #define FMC_XOM_BASE 0x00200000UL /*!< XOM Base Address */
  42. #define FMC_XOMR0_BASE 0x00200000UL /*!< XOMR 0 Base Address */
  43. #define FMC_XOMR1_BASE 0x00200010UL /*!< XOMR 1 Base Address */
  44. #define FMC_XOMR2_BASE 0x00200020UL /*!< XOMR 2 Base Address */
  45. #define FMC_XOMR3_BASE 0x00200030UL /*!< XOMR 3 Base Address */
  46. #define FMC_NSCBA_BASE 0x00210800UL /*!< Non-Secure base address */
  47. #define FMC_SCRLOCK_BASE 0x00610000UL /*!< Secure Region Lock base address */
  48. #define FMC_ARLOCK_BASE 0x00610008UL /*!< All Region Lock base address */
  49. #define FMC_CONFIG_BASE 0x00300000UL /*!< CONFIG Base Address */
  50. #define FMC_USER_CONFIG_0 0x00300000UL /*!< CONFIG 0 Address */
  51. #define FMC_USER_CONFIG_1 0x00300004UL /*!< CONFIG 1 Address */
  52. #define FMC_USER_CONFIG_2 0x00300008UL /*!< CONFIG 2 Address */
  53. #define FMC_USER_CONFIG_3 0x0030000CUL /*!< CONFIG 3 Address */
  54. #define FMC_OTP_BASE 0x00310000UL /*!< OTP flash base address */
  55. #define FMC_FLASH_PAGE_SIZE 0x800UL /*!< Flash Page Size (2048 Bytes) */
  56. #define FMC_PAGE_ADDR_MASK 0xFFFFF800UL /*!< Flash page address mask */
  57. #define FMC_MULTI_WORD_PROG_LEN 512UL /*!< The maximum length of a multi-word program. */
  58. #define FMC_APROM_SIZE FMC_APROM_END /*!< APROM Size */
  59. #define FMC_BANK_SIZE (FMC_APROM_SIZE/2UL) /*!< APROM Bank Size */
  60. #define FMC_LDROM_SIZE 0x4000UL /*!< LDROM Size (4 Kbytes) */
  61. #define FMC_OTP_ENTRY_CNT 256UL /*!< OTP entry number */
  62. /*---------------------------------------------------------------------------------------------------------*/
  63. /* XOM region number constant definitions */
  64. /*---------------------------------------------------------------------------------------------------------*/
  65. #define XOMR0 0UL /*!< XOM region 0 */
  66. #define XOMR1 1UL /*!< XOM region 1 */
  67. #define XOMR2 2UL /*!< XOM region 2 */
  68. #define XOMR3 3UL /*!< XOM region 3 */
  69. /*---------------------------------------------------------------------------------------------------------*/
  70. /* ISPCTL constant definitions */
  71. /*---------------------------------------------------------------------------------------------------------*/
  72. #define IS_BOOT_FROM_LDROM 0x1UL /*!< ISPCTL setting to select to boot from LDROM */
  73. #define IS_BOOT_FROM_APROM 0x0UL /*!< ISPCTL setting to select to boot from APROM */
  74. /*---------------------------------------------------------------------------------------------------------*/
  75. /* ISPCMD constant definitions */
  76. /*---------------------------------------------------------------------------------------------------------*/
  77. #define FMC_ISPCMD_READ 0x00UL /*!< ISP Command: Read Flash */
  78. #define FMC_ISPCMD_READ_UID 0x04UL /*!< ISP Command: Read Unique ID */
  79. #define FMC_ISPCMD_READ_ALL1 0x08UL /*!< ISP Command: Read all-one result */
  80. #define FMC_ISPCMD_READ_CID 0x0BUL /*!< ISP Command: Read Company ID */
  81. #define FMC_ISPCMD_READ_DID 0x0CUL /*!< ISP Command: Read Device ID */
  82. #define FMC_ISPCMD_READ_CKS 0x0DUL /*!< ISP Command: Read Checksum */
  83. #define FMC_ISPCMD_PROGRAM 0x21UL /*!< ISP Command: 32-bit Program Flash */
  84. #define FMC_ISPCMD_PAGE_ERASE 0x22UL /*!< ISP Command: Page Erase Flash */
  85. #define FMC_ISPCMD_BANK_ERASE 0x23UL /*!< ISP Command: Erase Flash bank 0 or 1 */
  86. #define FMC_ISPCMD_PROGRAM_MUL 0x27UL /*!< ISP Command: Flash Multi-Word Program */
  87. #define FMC_ISPCMD_RUN_ALL1 0x28UL /*!< ISP Command: Run all-one verification */
  88. #define FMC_ISPCMD_BANK_REMAP 0x2CUL /*!< ISP Command: Bank Remap */
  89. #define FMC_ISPCMD_RUN_CKS 0x2DUL /*!< ISP Command: Run Check Calculation */
  90. #define FMC_ISPCMD_VECMAP 0x2EUL /*!< ISP Command: Set vector mapping */
  91. #define FMC_ISPCMD_READ_64 0x40UL /*!< ISP Command: 64-bit read Flash */
  92. #define FMC_ISPCMD_PROGRAM_64 0x61UL /*!< ISP Command: 64-bit program Flash */
  93. #define READ_ALLONE_YES 0xA11FFFFFUL /*!< Check-all-one result is all one. */
  94. #define READ_ALLONE_NOT 0xA1100000UL /*!< Check-all-one result is not all one. */
  95. #define READ_ALLONE_CMD_FAIL 0xFFFFFFFFUL /*!< Check-all-one command failed. */
  96. /**@}*/ /* end of group FMC_EXPORTED_CONSTANTS */
  97. /** @addtogroup FMC_EXPORTED_FUNCTIONS FMC Exported Functions
  98. @{
  99. */
  100. /*---------------------------------------------------------------------------------------------------------*/
  101. /* FMC Macro Definitions */
  102. /*---------------------------------------------------------------------------------------------------------*/
  103. /**
  104. * @brief Enable ISP Function
  105. *
  106. * @param None
  107. *
  108. * @return None
  109. *
  110. * @details This function will set ISPEN bit of ISPCTL control register to enable ISP function.
  111. *
  112. */
  113. #define FMC_ENABLE_ISP() (FMC_ISP->ISPCTL |= FMC_ISPCTL_ISPEN_Msk) /*!< Enable ISP Function */
  114. /**
  115. * @brief Disable ISP Function
  116. *
  117. * @param None
  118. *
  119. * @return None
  120. *
  121. * @details This function will clear ISPEN bit of ISPCTL control register to disable ISP function.
  122. *
  123. */
  124. #define FMC_DISABLE_ISP() (FMC_ISP->ISPCTL &= ~FMC_ISPCTL_ISPEN_Msk) /*!< Disable ISP Function */
  125. /**
  126. * @brief Disable Non Secure ISP Function
  127. *
  128. * @param None
  129. *
  130. * @return None
  131. *
  132. * @details This function will clear ISPEN bit of ISPCTL control register to disable Non Secure ISP function.
  133. *
  134. */
  135. #define FMC_ENABLE_LD_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_LDUEN_Msk) /*!< Enable LDROM Update Function */
  136. /**
  137. * @brief Disable LDROM Update Function
  138. *
  139. * @param None
  140. *
  141. * @return None
  142. *
  143. * @details This function will set ISPEN bit of ISPCTL control register to disable LDROM update function.
  144. *
  145. */
  146. #define FMC_DISABLE_LD_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_LDUEN_Msk) /*!< Disable LDROM Update Function */
  147. /**
  148. * @brief Enable User Configuration Update Function
  149. *
  150. * @param None
  151. *
  152. * @return None
  153. *
  154. * @details This function will set CFGUEN bit of ISPCTL control register to enable User Configuration update function.
  155. * User needs to set CFGUEN bit before they can update User Configuration area.
  156. *
  157. */
  158. #define FMC_ENABLE_CFG_UPDATE() (FMC->ISPCTL |= FMC_ISPCTL_CFGUEN_Msk) /*!< Enable CONFIG Update Function */
  159. /**
  160. * @brief Disable User Configuration Update Function
  161. *
  162. * @param None
  163. *
  164. * @return None
  165. *
  166. * @details This function will clear CFGUEN bit of ISPCTL control register to disable User Configuration update function.
  167. *
  168. */
  169. #define FMC_DISABLE_CFG_UPDATE() (FMC->ISPCTL &= ~FMC_ISPCTL_CFGUEN_Msk) /*!< Disable CONFIG Update Function */
  170. /**
  171. * @brief Enable APROM Update Function
  172. *
  173. * @param None
  174. *
  175. * @return None
  176. *
  177. * @details This function will set APUEN bit of ISPCTL control register to enable APROM update function.
  178. * User needs to set APUEN bit before they can update APROM in APROM boot mode.
  179. *
  180. */
  181. #define FMC_ENABLE_AP_UPDATE() (FMC_ISP->ISPCTL |= FMC_ISPCTL_APUEN_Msk) /*!< Enable APROM Update Function */
  182. /**
  183. * @brief Disable APROM Update Function
  184. *
  185. * @param None
  186. *
  187. * @return None
  188. *
  189. * @details This function will clear APUEN bit of ISPCTL control register to disable APROM update function.
  190. *
  191. */
  192. #define FMC_DISABLE_AP_UPDATE() (FMC_ISP->ISPCTL &= ~FMC_ISPCTL_APUEN_Msk) /*!< Disable APROM Update Function */
  193. /**
  194. * @brief Get ISP Fail Flag
  195. *
  196. * @param None
  197. *
  198. * @return None
  199. *
  200. * @details This function is used to get ISP fail flag when do ISP actoin.
  201. *
  202. */
  203. #define FMC_GET_FAIL_FLAG() ((FMC_ISP->ISPCTL & FMC_ISPCTL_ISPFF_Msk) ? 1UL : 0UL) /*!< Get ISP fail flag */
  204. /**
  205. * @brief Clear ISP Fail Flag
  206. *
  207. * @param None
  208. *
  209. * @return None
  210. *
  211. * @details This function is used to clear ISP fail flag when ISP fail flag set.
  212. *
  213. */
  214. #define FMC_CLR_FAIL_FLAG() (FMC_ISP->ISPCTL |= FMC_ISPCTL_ISPFF_Msk) /*!< Clear ISP fail flag */
  215. /**
  216. * @brief Enable ISP Interrupt
  217. *
  218. * @param None
  219. *
  220. * @return None
  221. *
  222. * @details This function will enable ISP action interrupt.
  223. *
  224. */
  225. #define FMC_ENABLE_ISP_INT() (FMC_ISP->ISPCTL |= FMC_ISPCTL_INTEN_Msk) /*!< Enable ISP interrupt */
  226. /**
  227. * @brief Disable ISP Interrupt
  228. *
  229. * @param None
  230. *
  231. * @return None
  232. *
  233. * @details This function will disable ISP action interrupt.
  234. *
  235. */
  236. #define FMC_DISABLE_ISP_INT() (FMC_ISP->ISPCTL &= ~FMC_ISPCTL_INTEN_Msk) /*!< Disable ISP interrupt */
  237. /**
  238. * @brief Get ISP Interrupt Flag
  239. *
  240. * @param None
  241. *
  242. * @return None
  243. *
  244. * @details This function will get ISP action interrupt status
  245. *
  246. */
  247. #define FMC_GET_ISP_INT_FLAG() ((FMC_ISP->ISPSTS & FMC_ISPSTS_INTFLAG_Msk) ? 1UL : 0UL) /*!< Get ISP interrupt flag Status */
  248. /**
  249. * @brief Clear ISP Interrupt Flag
  250. *
  251. * @param None
  252. *
  253. * @return None
  254. *
  255. * @details This function will clear ISP interrupt flag
  256. *
  257. */
  258. #define FMC_CLEAR_ISP_INT_FLAG() (FMC_ISP->ISPSTS = FMC_ISPSTS_INTFLAG_Msk) /*!< Clear ISP interrupt flag*/
  259. /**
  260. * @brief Enable Data Flash Scrambling Function
  261. *
  262. * @param None
  263. *
  264. * @return None
  265. *
  266. * @details This function will set SCRAMEN bit of DFCTL control register to enable Data Flash Scrambling Function.
  267. *
  268. */
  269. #define FMC_ENABLE_SCRAMBLE() (FMC->DFCTL |= FMC_DFCTL_SCRAMEN_Msk) /*!< Enable Data Flash Scrambling Function */
  270. /**
  271. * @brief Disable Data Flash Scrambling Function
  272. *
  273. * @param None
  274. *
  275. * @return None
  276. *
  277. * @details This function will clear SCRAMEN bit of DFCTL control register to disable Data Flash Scrambling Function.
  278. *
  279. */
  280. #define FMC_DISABLE_SCRAMBLE() (FMC->DFCTL &= ~FMC_DFCTL_SCRAMEN_Msk) /*!< Disable Data Flash Scrambling Function */
  281. /**
  282. * @brief Enable Data Flash Silent Access Function
  283. *
  284. * @param None
  285. *
  286. * @return None
  287. *
  288. * @details This function will set SILENTEN bit of DFCTL control register to enable Data Flash Silent Access Function.
  289. *
  290. */
  291. #define FMC_ENABLE_SILENT() (FMC->DFCTL |= FMC_DFCTL_SILENTEN_Msk) /*!< Enable Data Flash Silent Access Function */
  292. /**
  293. * @brief Disable Data Flash Silent Access Function
  294. *
  295. * @param None
  296. *
  297. * @return None
  298. *
  299. * @details This function will clear SILENTEN bit of DFCTL control register to disable Data Flash Silent Access Function.
  300. *
  301. */
  302. #define FMC_DISABLE_SILENT() (FMC->DFCTL &= ~FMC_DFCTL_SILENTEN_Msk) /*!< Disable Data Flash Silent Access Function */
  303. /**
  304. * @brief Enable Data Flash Temper Attack Program Function
  305. *
  306. * @param None
  307. *
  308. * @return None
  309. *
  310. * @details This function will set TMPCLR bit of DFCTL control register to enable Data Flash Temper Attack Program Function.
  311. *
  312. */
  313. #define FMC_ENABLE_TMPCLR() (FMC->DFCTL |= FMC_DFCTL_TMPCLR_Msk) /*!< Enable Data Flash Temper Attack Program Function */
  314. /**
  315. * @brief Disable Data Flash Temper Attack Program Function
  316. *
  317. * @param None
  318. *
  319. * @return None
  320. *
  321. * @details This function will clear TMPCLR bit of DFCTL control register to disable Data Flash Temper Attack Program Function.
  322. *
  323. */
  324. #define FMC_DISABLE_TMPCLR() (FMC->DFCTL &= ~FMC_DFCTL_TMPCLR_Msk) /*!< Disable Data Flash Temper Attack Program Function */
  325. /**
  326. * @brief Get Data Flash Temper Attack Programming Done Flag
  327. *
  328. * @param None
  329. *
  330. * @return None
  331. *
  332. * @details This function will get Data Flash Temper Attack Programming Done flag
  333. *
  334. */
  335. #define FMC_GET_TMPCLRDONE_FLAG() ((FMC->DFSTS & FMC_DFSTS_TMPCLRDONE_Msk) ? 1UL : 0UL) /*!< Get Data Flash Temper Attack Programming Done Flag */
  336. /**
  337. * @brief Get Data Flash Temper Attack Programming Busy Flag
  338. *
  339. * @param None
  340. *
  341. * @return None
  342. *
  343. * @details This function will get Data Flash Temper Attack Programming Busy flag
  344. *
  345. */
  346. #define FMC_GET_TMPCLRBUSY_FLAG() ((FMC->DFSTS & FMC_DFSTS_TMPCLRBUSY_Msk) ? 1UL : 0UL) /*!< Get Data Flash Temper Attack Programming Busy Flag */
  347. /**
  348. * @brief Clear Data Flash Temper Attack Programming Done Flag
  349. *
  350. * @param None
  351. *
  352. * @return None
  353. *
  354. * @details This function will clear Data Flash Temper Attack Programming Done flag
  355. *
  356. */
  357. #define FMC_CLEAR_TMPCLRDONE_FLAG() (FMC->DFSTS |= FMC_DFSTS_TMPCLRDONE_Msk) /*!< Clear Data Flash Temper Attack Programming Done Flag */
  358. /*---------------------------------------------------------------------------------------------------------*/
  359. /* inline functions */
  360. /*---------------------------------------------------------------------------------------------------------*/
  361. __STATIC_INLINE uint32_t FMC_ReadCID(void);
  362. __STATIC_INLINE uint32_t FMC_ReadPID(void);
  363. __STATIC_INLINE uint32_t FMC_ReadUID(uint8_t u8Index);
  364. __STATIC_INLINE uint32_t FMC_ReadUCID(uint32_t u32Index);
  365. __STATIC_INLINE void FMC_SetVectorPageAddr(uint32_t u32PageAddr);
  366. __STATIC_INLINE uint32_t FMC_GetVECMAP(void);
  367. __STATIC_INLINE void FMC_SetScrambleKey(uint32_t u32ScrambleKey);
  368. /**
  369. * @brief Get current vector mapping address.
  370. *
  371. * @param None
  372. *
  373. * @return The current vector mapping address.
  374. *
  375. * @details To get VECMAP value which is the page address for remapping to vector page (0x0).
  376. *
  377. */
  378. __STATIC_INLINE uint32_t FMC_GetVECMAP(void)
  379. {
  380. return (FMC->ISPSTS & FMC_ISPSTS_VECMAP_Msk);
  381. }
  382. /**
  383. * @brief Read company ID
  384. *
  385. * @param None
  386. *
  387. * @return The company ID (32-bit)
  388. *
  389. * @details The company ID of Nuvoton is fixed to be 0xDA
  390. */
  391. __STATIC_INLINE uint32_t FMC_ReadCID(void)
  392. {
  393. FMC_ISP->ISPCMD = FMC_ISPCMD_READ_CID; /* Set ISP Command Code */
  394. FMC_ISP->ISPADDR = 0x0u; /* Must keep 0x0 when read CID */
  395. FMC_ISP->ISPTRG = FMC_ISPTRG_ISPGO_Msk; /* Trigger to start ISP procedure */
  396. #if ISBEN
  397. __ISB();
  398. #endif /* To make sure ISP/CPU be Synchronized */
  399. while(FMC_ISP->ISPTRG & FMC_ISPTRG_ISPGO_Msk) {} /* Waiting for ISP Done */
  400. return FMC_ISP->ISPDAT;
  401. }
  402. /**
  403. * @brief Read product ID
  404. *
  405. * @param None
  406. *
  407. * @return The product ID (32-bit)
  408. *
  409. * @details This function is used to read product ID.
  410. */
  411. __STATIC_INLINE uint32_t FMC_ReadPID(void)
  412. {
  413. FMC_ISP->ISPCMD = FMC_ISPCMD_READ_DID; /* Set ISP Command Code */
  414. FMC_ISP->ISPADDR = 0x04u; /* Must keep 0x4 when read PID */
  415. FMC_ISP->ISPTRG = FMC_ISPTRG_ISPGO_Msk; /* Trigger to start ISP procedure */
  416. #if ISBEN
  417. __ISB();
  418. #endif /* To make sure ISP/CPU be Synchronized */
  419. while(FMC_ISP->ISPTRG & FMC_ISPTRG_ISPGO_Msk) {} /* Waiting for ISP Done */
  420. return FMC_ISP->ISPDAT;
  421. }
  422. /**
  423. * @brief Read Unique ID
  424. *
  425. * @param[in] u8Index UID index. 0 = UID[31:0], 1 = UID[63:32], 2 = UID[95:64]
  426. *
  427. * @return The 32-bit unique ID data of specified UID index.
  428. *
  429. * @details To read out 96-bit Unique ID.
  430. */
  431. __STATIC_INLINE uint32_t FMC_ReadUID(uint8_t u8Index)
  432. {
  433. FMC_ISP->ISPCMD = FMC_ISPCMD_READ_UID;
  434. FMC_ISP->ISPADDR = ((uint32_t)u8Index << 2u);
  435. FMC_ISP->ISPDAT = 0u;
  436. FMC_ISP->ISPTRG = 0x1u;
  437. #if ISBEN
  438. __ISB();
  439. #endif
  440. while(FMC_ISP->ISPTRG) {}
  441. return FMC_ISP->ISPDAT;
  442. }
  443. /**
  444. * @brief To read UCID
  445. *
  446. * @param[in] u32Index Index of the UCID to read. u32Index must be 0, 1, 2, or 3.
  447. *
  448. * @return The UCID of specified index
  449. *
  450. * @details This function is used to read unique chip ID (UCID).
  451. */
  452. __STATIC_INLINE uint32_t FMC_ReadUCID(uint32_t u32Index)
  453. {
  454. FMC_ISP->ISPCMD = FMC_ISPCMD_READ_UID; /* Set ISP Command Code */
  455. FMC_ISP->ISPADDR = (0x04u * u32Index) + 0x10u; /* The UCID is at offset 0x10 with word alignment. */
  456. FMC_ISP->ISPTRG = FMC_ISPTRG_ISPGO_Msk; /* Trigger to start ISP procedure */
  457. #if ISBEN
  458. __ISB();
  459. #endif /* To make sure ISP/CPU be Synchronized */
  460. while(FMC_ISP->ISPTRG & FMC_ISPTRG_ISPGO_Msk) {} /* Waiting for ISP Done */
  461. return FMC_ISP->ISPDAT;
  462. }
  463. /**
  464. * @brief Set vector mapping address
  465. *
  466. * @param[in] u32PageAddr The page address to remap to address 0x0. The address must be page alignment.
  467. *
  468. * @return To set VECMAP to remap specified page address to 0x0.
  469. *
  470. * @details This function is used to set VECMAP to map specified page to vector page (0x0).
  471. */
  472. __STATIC_INLINE void FMC_SetVectorPageAddr(uint32_t u32PageAddr)
  473. {
  474. FMC->ISPCMD = FMC_ISPCMD_VECMAP; /* Set ISP Command Code */
  475. FMC->ISPADDR = u32PageAddr; /* The address of specified page which will be map to address 0x0. It must be page alignment. */
  476. FMC->ISPTRG = 0x1u; /* Trigger to start ISP procedure */
  477. #if ISBEN
  478. __ISB();
  479. #endif /* To make sure ISP/CPU be Synchronized */
  480. while(FMC->ISPTRG) {} /* Waiting for ISP Done */
  481. }
  482. /**
  483. * @brief Set Data Flash scrambling key
  484. *
  485. * @param[in] u32ScramKey The value of scrambling key.
  486. *
  487. * @return NULL
  488. *
  489. * @details This function is used to set Data Flash scrambling key.
  490. */
  491. __STATIC_INLINE void FMC_SetScrambleKey(uint32_t u32ScrambleKey)
  492. {
  493. FMC->SCRKEY = u32ScrambleKey;
  494. }
  495. /*---------------------------------------------------------------------------------------------------------*/
  496. /* Functions */
  497. /*---------------------------------------------------------------------------------------------------------*/
  498. extern uint32_t FMC_CheckAllOne(uint32_t u32addr, uint32_t u32count);
  499. extern void FMC_Close(void);
  500. extern int32_t FMC_ConfigXOM(uint32_t xom_num, uint32_t xom_base, uint8_t xom_page);
  501. extern int32_t FMC_Erase(uint32_t u32PageAddr);
  502. extern int32_t FMC_EraseBank(uint32_t u32BankAddr);
  503. extern int32_t FMC_EraseXOM(uint32_t xom_num);
  504. extern uint32_t FMC_GetChkSum(uint32_t u32addr, uint32_t u32count);
  505. extern int32_t FMC_IsOTPLocked(uint32_t otp_num);
  506. extern int32_t FMC_GetXOMState(uint32_t xom_num);
  507. extern int32_t FMC_LockOTP(uint32_t otp_num);
  508. extern void FMC_Open(void);
  509. extern uint32_t FMC_Read(uint32_t u32Addr);
  510. extern int32_t FMC_Read64(uint32_t u32addr, uint32_t * u32data0, uint32_t * u32data1);
  511. extern int32_t FMC_ReadOTP(uint32_t otp_num, uint32_t *low_word, uint32_t *high_word);
  512. extern int32_t FMC_ReadConfig(uint32_t u32Config[], uint32_t u32Count);
  513. extern void FMC_Write(uint32_t u32Addr, uint32_t u32Data);
  514. extern int32_t FMC_Write8Bytes(uint32_t u32addr, uint32_t u32data0, uint32_t u32data1);
  515. extern int32_t FMC_WriteConfig(uint32_t au32Config[], uint32_t u32Count);
  516. extern int32_t FMC_WriteMultiple(uint32_t u32Addr, uint32_t pu32Buf[], uint32_t u32Len);
  517. extern int32_t FMC_WriteOTP(uint32_t otp_num, uint32_t low_word, uint32_t high_word);
  518. extern int32_t FMC_WriteMultipleA(uint32_t u32Addr, uint32_t pu32Buf[], uint32_t u32Len);
  519. extern int32_t FMC_RemapBank(uint32_t u32Bank);
  520. /**@}*/ /* end of group FMC_EXPORTED_FUNCTIONS */
  521. /**@}*/ /* end of group FMC_Driver */
  522. /**@}*/ /* end of group Standard_Driver */
  523. #ifdef __cplusplus
  524. }
  525. #endif
  526. #endif /* __NU_FMC_H__ */