gd32f10x_fmc.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*!
  2. \file gd32f10x_fmc.h
  3. \brief definitions for the FMC
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #ifndef GD32F10X_FMC_H
  33. #define GD32F10X_FMC_H
  34. #include "gd32f10x.h"
  35. /* FMC and option byte definition */
  36. #define FMC FMC_BASE /*!< FMC register base address */
  37. #define OB OB_BASE /*!< option bytes base address */
  38. /* registers definitions */
  39. #define FMC_WS REG32((FMC) + 0x00U) /*!< FMC wait state register */
  40. #define FMC_KEY0 REG32((FMC) + 0x04U) /*!< FMC unlock key register 0 */
  41. #define FMC_OBKEY REG32((FMC) + 0x08U) /*!< FMC option bytes unlock key register */
  42. #define FMC_STAT0 REG32((FMC) + 0x0CU) /*!< FMC status register 0 */
  43. #define FMC_CTL0 REG32((FMC) + 0x10U) /*!< FMC control register 0 */
  44. #define FMC_ADDR0 REG32((FMC) + 0x14U) /*!< FMC address register 0 */
  45. #define FMC_OBSTAT REG32((FMC) + 0x1CU) /*!< FMC option bytes status register */
  46. #define FMC_WP REG32((FMC) + 0x20U) /*!< FMC erase/program protection register */
  47. #define FMC_KEY1 REG32((FMC) + 0x44U) /*!< FMC unlock key register 1 */
  48. #define FMC_STAT1 REG32((FMC) + 0x4CU) /*!< FMC status register 1 */
  49. #define FMC_CTL1 REG32((FMC) + 0x50U) /*!< FMC control register 1 */
  50. #define FMC_ADDR1 REG32((FMC) + 0x54U) /*!< FMC address register 1 */
  51. #define FMC_WSEN REG32((FMC) + 0xFCU) /*!< FMC wait state enable register */
  52. #define FMC_PID REG32((FMC) + 0x100U) /*!< FMC product ID register */
  53. #define OB_SPC REG16((OB) + 0x00U) /*!< option byte security protection value */
  54. #define OB_USER REG16((OB) + 0x02U) /*!< option byte user value*/
  55. #define OB_WP0 REG16((OB) + 0x08U) /*!< option byte write protection 0 */
  56. #define OB_WP1 REG16((OB) + 0x0AU) /*!< option byte write protection 1 */
  57. #define OB_WP2 REG16((OB) + 0x0CU) /*!< option byte write protection 2 */
  58. #define OB_WP3 REG16((OB) + 0x0EU) /*!< option byte write protection 3 */
  59. /* bits definitions */
  60. /* FMC_WS */
  61. #define FMC_WS_WSCNT BITS(0,2) /*!< wait state counter */
  62. /* FMC_KEY0 */
  63. #define FMC_KEY0_KEY BITS(0,31) /*!< FMC_CTL0 unlock key bits */
  64. /* FMC_OBKEY */
  65. #define FMC_OBKEY_OBKEY BITS(0,31) /*!< option bytes unlock key bits */
  66. /* FMC_STAT0 */
  67. #define FMC_STAT0_BUSY BIT(0) /*!< flash busy flag bit */
  68. #define FMC_STAT0_PGERR BIT(2) /*!< flash program error flag bit */
  69. #define FMC_STAT0_WPERR BIT(4) /*!< erase/program protection error flag bit */
  70. #define FMC_STAT0_ENDF BIT(5) /*!< end of operation flag bit */
  71. /* FMC_CTL0 */
  72. #define FMC_CTL0_PG BIT(0) /*!< main flash program for bank0 command bit */
  73. #define FMC_CTL0_PER BIT(1) /*!< main flash page erase for bank0 command bit */
  74. #define FMC_CTL0_MER BIT(2) /*!< main flash mass erase for bank0 command bit */
  75. #define FMC_CTL0_OBPG BIT(4) /*!< option bytes program command bit */
  76. #define FMC_CTL0_OBER BIT(5) /*!< option bytes erase command bit */
  77. #define FMC_CTL0_START BIT(6) /*!< send erase command to FMC bit */
  78. #define FMC_CTL0_LK BIT(7) /*!< FMC_CTL0 lock bit */
  79. #define FMC_CTL0_OBWEN BIT(9) /*!< option bytes erase/program enable bit */
  80. #define FMC_CTL0_ERRIE BIT(10) /*!< error interrupt enable bit */
  81. #define FMC_CTL0_ENDIE BIT(12) /*!< end of operation interrupt enable bit */
  82. /* FMC_ADDR0 */
  83. #define FMC_ADDR0_ADDR BITS(0,31) /*!< flash erase/program command address bits */
  84. /* FMC_OBSTAT */
  85. #define FMC_OBSTAT_OBERR BIT(0) /*!< option bytes read error bit. */
  86. #define FMC_OBSTAT_SPC BIT(1) /*!< option bytes security protection code */
  87. #define FMC_OBSTAT_USER BITS(2,9) /*!< store USER of option bytes block after system reset */
  88. #define FMC_OBSTAT_DATA BITS(10,25) /*!< store DATA of option bytes block after system reset. */
  89. /* FMC_WP */
  90. #define FMC_WP_WP BITS(0,31) /*!< store WP of option bytes block after system reset */
  91. /* FMC_KEY1 */
  92. #define FMC_KEY1_KEY BITS(0,31) /*!< FMC_CTL1 unlock key bits */
  93. /* FMC_STAT1 */
  94. #define FMC_STAT1_BUSY BIT(0) /*!< flash busy flag bit */
  95. #define FMC_STAT1_PGERR BIT(2) /*!< flash program error flag bit */
  96. #define FMC_STAT1_WPERR BIT(4) /*!< erase/program protection error flag bit */
  97. #define FMC_STAT1_ENDF BIT(5) /*!< end of operation flag bit */
  98. /* FMC_CTL1 */
  99. #define FMC_CTL1_PG BIT(0) /*!< main flash program for bank1 command bit */
  100. #define FMC_CTL1_PER BIT(1) /*!< main flash page erase for bank1 command bit */
  101. #define FMC_CTL1_MER BIT(2) /*!< main flash mass erase for bank1 command bit */
  102. #define FMC_CTL1_START BIT(6) /*!< send erase command to FMC bit */
  103. #define FMC_CTL1_LK BIT(7) /*!< FMC_CTL1 lock bit */
  104. #define FMC_CTL1_ERRIE BIT(10) /*!< error interrupt enable bit */
  105. #define FMC_CTL1_ENDIE BIT(12) /*!< end of operation interrupt enable bit */
  106. /* FMC_ADDR1 */
  107. #define FMC_ADDR1_ADDR BITS(0,31) /*!< flash erase/program command address bits */
  108. /* FMC_WSEN */
  109. #define FMC_WSEN_WSEN BIT(0) /*!< FMC wait state enable bit */
  110. /* FMC_PID */
  111. #define FMC_PID_PID BITS(0,31) /*!< product ID bits */
  112. /* constants definitions */
  113. /* define the FMC bit position and its register index offset */
  114. #define FMC_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
  115. #define FMC_REG_VAL(offset) (REG32(FMC + ((uint32_t)(offset) >> 6)))
  116. #define FMC_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
  117. #define FMC_REGIDX_BITS(regidx, bitpos0, bitpos1) (((uint32_t)(regidx) << 12) | ((uint32_t)(bitpos0) << 6) | (uint32_t)(bitpos1))
  118. #define FMC_REG_VALS(offset) (REG32(FMC + ((uint32_t)(offset) >> 12)))
  119. #define FMC_BIT_POS0(val) (((uint32_t)(val) >> 6) & 0x1FU)
  120. #define FMC_BIT_POS1(val) ((uint32_t)(val) & 0x1FU)
  121. #define FMC_REG_OFFSET_GET(flag) ((uint32_t)(flag) >> 12)
  122. /* configuration register */
  123. #define FMC_STAT0_REG_OFFSET 0x0CU /*!< status register 0 offset */
  124. #define FMC_CTL0_REG_OFFSET 0x10U /*!< control register 0 offset */
  125. #define FMC_STAT1_REG_OFFSET 0x4CU /*!< status register 1 offset */
  126. #define FMC_CTL1_REG_OFFSET 0x50U /*!< control register 1 offset */
  127. #define FMC_OBSTAT_REG_OFFSET 0x1CU /*!< option byte status register offset */
  128. /* fmc state */
  129. typedef enum
  130. {
  131. FMC_READY, /*!< the operation has been completed */
  132. FMC_BUSY, /*!< the operation is in progress */
  133. FMC_PGERR, /*!< program error */
  134. FMC_WPERR, /*!< erase/program protection error */
  135. FMC_TOERR, /*!< timeout error */
  136. }fmc_state_enum;
  137. /* FMC interrupt enable */
  138. typedef enum
  139. {
  140. FMC_INT_BANK0_END = FMC_REGIDX_BIT(FMC_CTL0_REG_OFFSET, 12U), /*!< enable FMC end of program interrupt */
  141. FMC_INT_BANK0_ERR = FMC_REGIDX_BIT(FMC_CTL0_REG_OFFSET, 10U), /*!< enable FMC error interrupt */
  142. FMC_INT_BANK1_END = FMC_REGIDX_BIT(FMC_CTL1_REG_OFFSET, 12U), /*!< enable FMC bank1 end of program interrupt */
  143. FMC_INT_BANK1_ERR = FMC_REGIDX_BIT(FMC_CTL1_REG_OFFSET, 10U), /*!< enable FMC bank1 error interrupt */
  144. }fmc_int_enum;
  145. /* FMC flags */
  146. typedef enum
  147. {
  148. FMC_FLAG_BANK0_BUSY = FMC_REGIDX_BIT(FMC_STAT0_REG_OFFSET, 0U), /*!< FMC bank0 busy flag */
  149. FMC_FLAG_BANK0_PGERR = FMC_REGIDX_BIT(FMC_STAT0_REG_OFFSET, 2U), /*!< FMC bank0 operation error flag bit */
  150. FMC_FLAG_BANK0_WPERR = FMC_REGIDX_BIT(FMC_STAT0_REG_OFFSET, 4U), /*!< FMC bank0 erase/program protection error flag bit */
  151. FMC_FLAG_BANK0_END = FMC_REGIDX_BIT(FMC_STAT0_REG_OFFSET, 5U), /*!< FMC bank0 end of operation flag bit */
  152. FMC_FLAG_OBERR = FMC_REGIDX_BIT(FMC_OBSTAT_REG_OFFSET, 0U), /*!< FMC option bytes read error flag */
  153. FMC_FLAG_BANK1_BUSY = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 0U), /*!< FMC bank1 busy flag */
  154. FMC_FLAG_BANK1_PGERR = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 2U), /*!< FMC bank1 operation error flag bit */
  155. FMC_FLAG_BANK1_WPERR = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 4U), /*!< FMC bank1 erase/program protection error flag bit */
  156. FMC_FLAG_BANK1_END = FMC_REGIDX_BIT(FMC_STAT1_REG_OFFSET, 5U), /*!< FMC bank1 end of operation flag bit */
  157. }fmc_flag_enum;
  158. /* FMC interrupt flags */
  159. typedef enum
  160. {
  161. FMC_INT_FLAG_BANK0_PGERR = FMC_REGIDX_BITS(FMC_STAT0_REG_OFFSET, 2U, 10U), /*!< FMC bank0 operation error interrupt flag bit */
  162. FMC_INT_FLAG_BANK0_WPERR = FMC_REGIDX_BITS(FMC_STAT0_REG_OFFSET, 4U, 10U), /*!< FMC bank0 erase/program protection error interrupt flag bit */
  163. FMC_INT_FLAG_BANK0_END = FMC_REGIDX_BITS(FMC_STAT0_REG_OFFSET, 5U, 12U), /*!< FMC bank0 end of operation interrupt flag bit */
  164. FMC_INT_FLAG_BANK1_PGERR = FMC_REGIDX_BITS(FMC_STAT1_REG_OFFSET, 2U, 10U), /*!< FMC bank1 operation error interrupt flag bit */
  165. FMC_INT_FLAG_BANK1_WPERR = FMC_REGIDX_BITS(FMC_STAT1_REG_OFFSET, 4U, 10U), /*!< FMC bank1 erase/program protection error interrupt flag bit */
  166. FMC_INT_FLAG_BANK1_END = FMC_REGIDX_BITS(FMC_STAT1_REG_OFFSET, 5U, 12U), /*!< FMC bank1 end of operation interrupt flag bit */
  167. }fmc_interrupt_flag_enum;
  168. /* unlock key */
  169. #define UNLOCK_KEY0 ((uint32_t)0x45670123U) /*!< unlock key 0 */
  170. #define UNLOCK_KEY1 ((uint32_t)0xCDEF89ABU) /*!< unlock key 1 */
  171. /* FMC wait state counter */
  172. #define WS_WSCNT(regval) (BITS(0,2) & ((uint32_t)(regval)))
  173. #define WS_WSCNT_0 WS_WSCNT(0) /*!< FMC 0 wait */
  174. #define WS_WSCNT_1 WS_WSCNT(1) /*!< FMC 1 wait */
  175. #define WS_WSCNT_2 WS_WSCNT(2) /*!< FMC 2 wait */
  176. /* option bytes software/hardware free watch dog timer */
  177. #define OB_FWDGT_SW ((uint8_t)0x01U) /*!< software free watchdog */
  178. #define OB_FWDGT_HW ((uint8_t)0x00U) /*!< hardware free watchdog */
  179. /* option bytes reset or not entering deep sleep mode */
  180. #define OB_DEEPSLEEP_NRST ((uint8_t)0x02U) /*!< no reset when entering deepsleep mode */
  181. #define OB_DEEPSLEEP_RST ((uint8_t)0x00U) /*!< generate a reset instead of entering deepsleep mode */
  182. /* option bytes reset or not entering standby mode */
  183. #define OB_STDBY_NRST ((uint8_t)0x04U) /*!< no reset when entering deepsleep mode */
  184. #define OB_STDBY_RST ((uint8_t)0x00U) /*!< generate a reset instead of entering standby mode */
  185. /* option bytes boot bank value */
  186. #define OB_BOOT_B0 ((uint8_t)0x08U) /*!< boot from bank0 */
  187. #define OB_BOOT_B1 ((uint8_t)0x00U) /*!< boot from bank1 */
  188. #define OB_USER_MASK ((uint8_t)0xF0U) /*!< MASK value */
  189. /* read protect configure */
  190. #define FMC_NSPC ((uint8_t)0xA5U) /*!< no security protection */
  191. #define FMC_USPC ((uint8_t)0xBBU) /*!< under security protection */
  192. /* OB_SPC */
  193. #define OB_SPC_SPC ((uint32_t)0x000000FFU) /*!< option byte security protection value */
  194. #define OB_SPC_SPC_N ((uint32_t)0x0000FF00U) /*!< option byte security protection complement value */
  195. /* OB_USER */
  196. #define OB_USER_USER ((uint32_t)0x00FF0000U) /*!< user option value */
  197. #define OB_USER_USER_N ((uint32_t)0xFF000000U) /*!< user option complement value */
  198. /* OB_WP0 */
  199. #define OB_WP0_WP0 ((uint32_t)0x000000FFU) /*!< FMC write protection option value */
  200. /* OB_WP1 */
  201. #define OB_WP1_WP1 ((uint32_t)0x0000FF00U) /*!< FMC write protection option complement value */
  202. /* OB_WP2 */
  203. #define OB_WP2_WP2 ((uint32_t)0x00FF0000U) /*!< FMC write protection option value */
  204. /* OB_WP3 */
  205. #define OB_WP3_WP3 ((uint32_t)0xFF000000U) /*!< FMC write protection option complement value */
  206. /* option bytes write protection */
  207. #define OB_WP_0 ((uint32_t)0x00000001U) /*!< erase/program protection of sector 0 */
  208. #define OB_WP_1 ((uint32_t)0x00000002U) /*!< erase/program protection of sector 1 */
  209. #define OB_WP_2 ((uint32_t)0x00000004U) /*!< erase/program protection of sector 2 */
  210. #define OB_WP_3 ((uint32_t)0x00000008U) /*!< erase/program protection of sector 3 */
  211. #define OB_WP_4 ((uint32_t)0x00000010U) /*!< erase/program protection of sector 4 */
  212. #define OB_WP_5 ((uint32_t)0x00000020U) /*!< erase/program protection of sector 5 */
  213. #define OB_WP_6 ((uint32_t)0x00000040U) /*!< erase/program protection of sector 6 */
  214. #define OB_WP_7 ((uint32_t)0x00000080U) /*!< erase/program protection of sector 7 */
  215. #define OB_WP_8 ((uint32_t)0x00000100U) /*!< erase/program protection of sector 8 */
  216. #define OB_WP_9 ((uint32_t)0x00000200U) /*!< erase/program protection of sector 9 */
  217. #define OB_WP_10 ((uint32_t)0x00000400U) /*!< erase/program protection of sector 10 */
  218. #define OB_WP_11 ((uint32_t)0x00000800U) /*!< erase/program protection of sector 11 */
  219. #define OB_WP_12 ((uint32_t)0x00001000U) /*!< erase/program protection of sector 12 */
  220. #define OB_WP_13 ((uint32_t)0x00002000U) /*!< erase/program protection of sector 13 */
  221. #define OB_WP_14 ((uint32_t)0x00004000U) /*!< erase/program protection of sector 14 */
  222. #define OB_WP_15 ((uint32_t)0x00008000U) /*!< erase/program protection of sector 15 */
  223. #define OB_WP_16 ((uint32_t)0x00010000U) /*!< erase/program protection of sector 16 */
  224. #define OB_WP_17 ((uint32_t)0x00020000U) /*!< erase/program protection of sector 17 */
  225. #define OB_WP_18 ((uint32_t)0x00040000U) /*!< erase/program protection of sector 18 */
  226. #define OB_WP_19 ((uint32_t)0x00080000U) /*!< erase/program protection of sector 19 */
  227. #define OB_WP_20 ((uint32_t)0x00100000U) /*!< erase/program protection of sector 20 */
  228. #define OB_WP_21 ((uint32_t)0x00200000U) /*!< erase/program protection of sector 21 */
  229. #define OB_WP_22 ((uint32_t)0x00400000U) /*!< erase/program protection of sector 22 */
  230. #define OB_WP_23 ((uint32_t)0x00800000U) /*!< erase/program protection of sector 23 */
  231. #define OB_WP_24 ((uint32_t)0x01000000U) /*!< erase/program protection of sector 24 */
  232. #define OB_WP_25 ((uint32_t)0x02000000U) /*!< erase/program protection of sector 25 */
  233. #define OB_WP_26 ((uint32_t)0x04000000U) /*!< erase/program protection of sector 26 */
  234. #define OB_WP_27 ((uint32_t)0x08000000U) /*!< erase/program protection of sector 27 */
  235. #define OB_WP_28 ((uint32_t)0x10000000U) /*!< erase/program protection of sector 28 */
  236. #define OB_WP_29 ((uint32_t)0x20000000U) /*!< erase/program protection of sector 29 */
  237. #define OB_WP_30 ((uint32_t)0x40000000U) /*!< erase/program protection of sector 30 */
  238. #define OB_WP_31 ((uint32_t)0x80000000U) /*!< erase/program protection of sector 31 */
  239. #define OB_WP_ALL ((uint32_t)0xFFFFFFFFU) /*!< erase/program protection of all sectors */
  240. /* FMC timeout */
  241. #define FMC_TIMEOUT_COUNT ((uint32_t)0x000F0000U) /*!< FMC timeout count value */
  242. /* FMC BANK address */
  243. #define FMC_BANK0_END_ADDRESS ((uint32_t)0x0807FFFFU) /*!< FMC bank0 end address */
  244. #define FMC_BANK0_SIZE ((uint32_t)0x00000200U) /*!< FMC bank0 size */
  245. #define FMC_SIZE (*(uint16_t *)0x1FFFF7E0U) /*!< FMC size */
  246. /* function declarations */
  247. /* FMC main memory programming functions */
  248. /* set the FMC wait state counter */
  249. void fmc_wscnt_set(uint32_t wscnt);
  250. /* unlock the main FMC operation */
  251. void fmc_unlock(void);
  252. /* unlock the FMC bank0 operation */
  253. void fmc_bank0_unlock(void);
  254. /* unlock the FMC bank1 operation */
  255. void fmc_bank1_unlock(void);
  256. /* lock the main FMC operation */
  257. void fmc_lock(void);
  258. /* lock the bank0 FMC operation */
  259. void fmc_bank0_lock(void);
  260. /* lock the bank1 FMC operation */
  261. void fmc_bank1_lock(void);
  262. /* FMC erase page */
  263. fmc_state_enum fmc_page_erase(uint32_t page_address);
  264. /* FMC erase whole chip */
  265. fmc_state_enum fmc_mass_erase(void);
  266. /* FMC erase whole bank0 */
  267. fmc_state_enum fmc_bank0_erase(void);
  268. /* FMC erase whole bank1 */
  269. fmc_state_enum fmc_bank1_erase(void);
  270. /* FMC program a word at the corresponding address */
  271. fmc_state_enum fmc_word_program(uint32_t address, uint32_t data);
  272. /* FMC program a half word at the corresponding address */
  273. fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data);
  274. /* FMC option bytes programming functions */
  275. /* unlock the option byte operation */
  276. void ob_unlock(void);
  277. /* lock the option byte operation */
  278. void ob_lock(void);
  279. /* erase the option byte */
  280. fmc_state_enum ob_erase(void);
  281. /* enable write protect */
  282. fmc_state_enum ob_write_protection_enable(uint32_t ob_wp);
  283. /* configure the option byte security protection */
  284. fmc_state_enum ob_security_protection_config(uint8_t ob_spc);
  285. /* write the FMC option byte */
  286. fmc_state_enum ob_user_write(uint8_t ob_fwdgt, uint8_t ob_deepsleep, uint8_t ob_stdby, uint8_t ob_boot);
  287. /* program option bytes data */
  288. fmc_state_enum ob_data_program(uint32_t address, uint8_t data);
  289. /* get the FMC option byte user */
  290. uint8_t ob_user_get(void);
  291. /* get OB_DATA in register FMC_OBSTAT */
  292. uint16_t ob_data_get(void);
  293. /* get the FMC option byte write protection */
  294. uint32_t ob_write_protection_get(void);
  295. /* get option byte security protection code value */
  296. FlagStatus ob_spc_get(void);
  297. /* FMC interrupts and flags management functions */
  298. /* enable FMC interrupt */
  299. void fmc_interrupt_enable(uint32_t interrupt);
  300. /* disable FMC interrupt */
  301. void fmc_interrupt_disable(uint32_t interrupt);
  302. /* check flag is set or not */
  303. FlagStatus fmc_flag_get(uint32_t flag);
  304. /* clear the FMC flag */
  305. void fmc_flag_clear(uint32_t flag);
  306. /* get FMC interrupt flag state */
  307. FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum flag);
  308. /* clear FMC interrupt flag state */
  309. void fmc_interrupt_flag_clear(fmc_interrupt_flag_enum flag);
  310. /* return the FMC bank0 state */
  311. fmc_state_enum fmc_bank0_state_get(void);
  312. /* return the FMC bank1 state */
  313. fmc_state_enum fmc_bank1_state_get(void);
  314. /* check FMC bank0 ready or not */
  315. fmc_state_enum fmc_bank0_ready_wait(uint32_t timeout);
  316. /* check FMC bank1 ready or not */
  317. fmc_state_enum fmc_bank1_ready_wait(uint32_t timeout);
  318. #endif /* GD32F10X_FMC_H */