gd32f4xx_fmc.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*!
  2. \file gd32f4xx_fmc.h
  3. \brief definitions for the FMC
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #ifndef GD32F4XX_FMC_H
  10. #define GD32F4XX_FMC_H
  11. #include "gd32f4xx.h"
  12. /* FMC and option byte definition */
  13. #define FMC FMC_BASE /*!< FMC register base address */
  14. #define OB OB_BASE /*!< option byte base address */
  15. /* registers definitions */
  16. #define FMC_WS REG32((FMC) + 0x00U) /*!< FMC wait state register */
  17. #define FMC_KEY REG32((FMC) + 0x04U) /*!< FMC unlock key register */
  18. #define FMC_OBKEY REG32((FMC) + 0x08U) /*!< FMC option byte unlock key register */
  19. #define FMC_STAT REG32((FMC) + 0x0CU) /*!< FMC status register */
  20. #define FMC_CTL REG32((FMC) + 0x10U) /*!< FMC control register */
  21. #define FMC_OBCTL0 REG32((FMC) + 0x14U) /*!< FMC option byte control register 0 */
  22. #define FMC_OBCTL1 REG32((FMC) + 0x18U) /*!< FMC option byte control register 1 */
  23. #define FMC_WSEN REG32((FMC) + 0xFCU) /*!< FMC wait state enable register */
  24. #define FMC_PID REG32((FMC) + 0x100U) /*!< FMC product ID register */
  25. #define OB_WP1 REG32((OB) + 0x00000008U) /*!< option byte write protection 1 */
  26. #define OB_USER REG32((OB) + 0x00010000U) /*!< option byte user value*/
  27. #define OB_SPC REG32((OB) + 0x00010001U) /*!< option byte security protection value */
  28. #define OB_WP0 REG32((OB) + 0x00010008U) /*!< option byte write protection 0 */
  29. /* bits definitions */
  30. /* FMC_WS */
  31. #define FMC_WC_WSCNT BITS(0,3) /*!< wait state counter */
  32. /* FMC_KEY */
  33. #define FMC_KEY_KEY BITS(0,31) /*!< FMC main flash key bits */
  34. /* FMC_OBKEY */
  35. #define FMC_OBKEY_OBKEY BITS(0,31) /*!< option byte key bits */
  36. /* FMC_STAT */
  37. #define FMC_STAT_END BIT(0) /*!< end of operation flag bit */
  38. #define FMC_STAT_OPERR BIT(1) /*!< flash operation error flag bit */
  39. #define FMC_STAT_WPERR BIT(4) /*!< erase/Program protection error flag bit */
  40. #define FMC_STAT_PGMERR BIT(6) /*!< program size not match error flag bit */
  41. #define FMC_STAT_PGSERR BIT(7) /*!< program sequence error flag bit */
  42. #define FMC_STAT_RDDERR BIT(8) /*!< read D-bus protection error flag bit */
  43. #define FMC_STAT_BUSY BIT(16) /*!< flash busy flag bit */
  44. /* FMC_CTL */
  45. #define FMC_CTL_PG BIT(0) /*!< main flash program command bit */
  46. #define FMC_CTL_SER BIT(1) /*!< main flash sector erase command bit */
  47. #define FMC_CTL_MER0 BIT(2) /*!< main flash mass erase for bank0 command bit */
  48. #define FMC_CTL_SN BITS(3,7) /*!< select which sector number to be erased */
  49. #define FMC_CTL_PSZ BITS(8,9) /*!< program size bit */
  50. #define FMC_CTL_MER1 BIT(15) /*!< main flash mass erase for bank1 command bit */
  51. #define FMC_CTL_START BIT(16) /*!< send erase command to FMC bit */
  52. #define FMC_CTL_ENDIE BIT(24) /*!< end of operation interrupt enable bit */
  53. #define FMC_CTL_ERRIE BIT(25) /*!< error interrupt enable bit */
  54. #define FMC_CTL_LK BIT(31) /*!< FMC_CTL lock bit */
  55. /* FMC_OBCTL0 */
  56. #define FMC_OBCTL0_OB_LK BIT(0) /*!< FMC_OBCTL0 lock bit */
  57. #define FMC_OBCTL0_OB_START BIT(1) /*!< send option byte change command to FMC bit */
  58. #define FMC_OBCTL0_BOR_TH BITS(2,3) /*!< option byte BOR threshold value */
  59. #define FMC_OBCTL0_BB BIT(4) /*!< option byte boot bank value */
  60. #define FMC_OBCTL0_NWDG_HW BIT(5) /*!< option byte watchdog value */
  61. #define FMC_OBCTL0_NRST_DPSLP BIT(6) /*!< option byte deepsleep reset value */
  62. #define FMC_OBCTL0_NRST_STDBY BIT(7) /*!< option byte standby reset value */
  63. #define FMC_OBCTL0_SPC BITS(8,15) /*!< option byte Security Protection code */
  64. #define FMC_OBCTL0_WP0 BITS(16,27) /*!< erase/program protection of each sector when DRP is 0 */
  65. #define FMC_OBCTL0_DBS BIT(30) /*!< double banks or single bank selection when flash size is 1M bytes */
  66. #define FMC_OBCTL0_DRP BIT(31) /*!< D-bus read protection bit */
  67. /* FMC_OBCTL1 */
  68. #define FMC_OBCTL1_WP1 BITS(16,27) /*!< erase/program protection of each sector when DRP is 0 */
  69. /* FMC_WSEN */
  70. #define FMC_WSEN_WSEN BIT(0) /*!< FMC wait state enable bit */
  71. /* FMC_PID */
  72. #define FMC_PID_PID BITS(0,31) /*!< product ID bits */
  73. /* constants definitions */
  74. /* fmc state */
  75. typedef enum
  76. {
  77. FMC_READY, /*!< the operation has been completed */
  78. FMC_BUSY, /*!< the operation is in progress */
  79. FMC_RDDERR, /*!< read D-bus protection error */
  80. FMC_PGSERR, /*!< program sequence error */
  81. FMC_PGMERR, /*!< program size not match error */
  82. FMC_WPERR, /*!< erase/program protection error */
  83. FMC_OPERR, /*!< operation error */
  84. FMC_PGERR, /*!< program error */
  85. FMC_TOERR /*!< timeout error */
  86. }fmc_state_enum;
  87. /* unlock key */
  88. #define UNLOCK_KEY0 ((uint32_t)0x45670123U) /*!< unlock key 0 */
  89. #define UNLOCK_KEY1 ((uint32_t)0xCDEF89ABU) /*!< unlock key 1 */
  90. #define OB_UNLOCK_KEY0 ((uint32_t)0x08192A3BU) /*!< ob unlock key 0 */
  91. #define OB_UNLOCK_KEY1 ((uint32_t)0x4C5D6E7FU) /*!< ob unlock key 1 */
  92. /* FMC time out */
  93. #define FMC_TIMEOUT_COUNT ((uint32_t)0x000F0000) /*!< enable FMC error timeout */
  94. /* option byte write protection */
  95. #define OB_LWP ((uint32_t)0x000000FFU) /*!< write protection low bits */
  96. #define OB_HWP ((uint32_t)0x0000FF00U) /*!< write protection high bits */
  97. /* FMC wait state counter */
  98. #define WC_WSCNT(regval) (BITS(0,3) & ((uint32_t)(regval)))
  99. #define WS_WSCNT_0 WC_WSCNT(0) /*!< FMC 0 wait */
  100. #define WS_WSCNT_1 WC_WSCNT(1) /*!< FMC 1 wait */
  101. #define WS_WSCNT_2 WC_WSCNT(2) /*!< FMC 2 wait */
  102. #define WS_WSCNT_3 WC_WSCNT(3) /*!< FMC 3 wait */
  103. #define WS_WSCNT_4 WC_WSCNT(4) /*!< FMC 4 wait */
  104. #define WS_WSCNT_5 WC_WSCNT(5) /*!< FMC 5 wait */
  105. #define WS_WSCNT_6 WC_WSCNT(6) /*!< FMC 6 wait */
  106. #define WS_WSCNT_7 WC_WSCNT(7) /*!< FMC 7 wait */
  107. #define WS_WSCNT_8 WC_WSCNT(8) /*!< FMC 8 wait */
  108. #define WS_WSCNT_9 WC_WSCNT(9) /*!< FMC 9 wait */
  109. #define WS_WSCNT_10 WC_WSCNT(10) /*!< FMC 10 wait */
  110. #define WS_WSCNT_11 WC_WSCNT(11) /*!< FMC 11 wait */
  111. #define WS_WSCNT_12 WC_WSCNT(12) /*!< FMC 12 wait */
  112. #define WS_WSCNT_13 WC_WSCNT(13) /*!< FMC 13 wait */
  113. #define WS_WSCNT_14 WC_WSCNT(14) /*!< FMC 14 wait */
  114. #define WS_WSCNT_15 WC_WSCNT(15) /*!< FMC 15 wait */
  115. /* option byte BOR threshold value */
  116. #define OBCTL0_BOR_TH(regval) (BITS(2,3) & ((uint32_t)(regval))<< 2)
  117. #define OB_BOR_TH_VALUE3 OBCTL0_BOR_TH(0) /*!< BOR threshold value 3 */
  118. #define OB_BOR_TH_VALUE2 OBCTL0_BOR_TH(1) /*!< BOR threshold value 2 */
  119. #define OB_BOR_TH_VALUE1 OBCTL0_BOR_TH(2) /*!< BOR threshold value 1 */
  120. #define OB_BOR_TH_OFF OBCTL0_BOR_TH(3) /*!< no BOR function */
  121. /* option byte boot bank value */
  122. #define OBCTL0_BB(regval) (BIT(4) & ((uint32_t)(regval)<<4))
  123. #define OB_BB_DISABLE OBCTL0_BB(0) /*!< boot from bank0 */
  124. #define OB_BB_ENABLE OBCTL0_BB(1) /*!< boot from bank1 or bank0 if bank1 is void */
  125. /* option byte software/hardware free watch dog timer */
  126. #define OBCTL0_NWDG_HW(regval) (BIT(5) & ((uint32_t)(regval))<< 5)
  127. #define OB_FWDGT_SW OBCTL0_NWDG_HW(1) /*!< software free watchdog */
  128. #define OB_FWDGT_HW OBCTL0_NWDG_HW(0) /*!< hardware free watchdog */
  129. /* option byte reset or not entering deep sleep mode */
  130. #define OBCTL0_NRST_DPSLP(regval) (BIT(6) & ((uint32_t)(regval))<< 6)
  131. #define OB_DEEPSLEEP_NRST OBCTL0_NRST_DPSLP(1) /*!< no reset when entering deepsleep mode */
  132. #define OB_DEEPSLEEP_RST OBCTL0_NRST_DPSLP(0) /*!< generate a reset instead of entering deepsleep mode */
  133. /* option byte reset or not entering standby mode */
  134. #define OBCTL0_NRST_STDBY(regval) (BIT(7) & ((uint32_t)(regval))<< 7)
  135. #define OB_STDBY_NRST OBCTL0_NRST_STDBY(1) /*!< no reset when entering deepsleep mode */
  136. #define OB_STDBY_RST OBCTL0_NRST_STDBY(0) /*!< generate a reset instead of entering standby mode */
  137. /* read protect configure */
  138. #define FMC_NSPC ((uint8_t)0xAAU) /*!< no security protection */
  139. #define FMC_LSPC ((uint8_t)0xABU) /*!< low security protection */
  140. #define FMC_HSPC ((uint8_t)0xCCU) /*!< high security protection */
  141. /* option bytes write protection */
  142. #define OB_WP_0 ((uint32_t)0x00000001U) /*!< erase/program protection of sector 0 */
  143. #define OB_WP_1 ((uint32_t)0x00000002U) /*!< erase/program protection of sector 1 */
  144. #define OB_WP_2 ((uint32_t)0x00000004U) /*!< erase/program protection of sector 2 */
  145. #define OB_WP_3 ((uint32_t)0x00000008U) /*!< erase/program protection of sector 3 */
  146. #define OB_WP_4 ((uint32_t)0x00000010U) /*!< erase/program protection of sector 4 */
  147. #define OB_WP_5 ((uint32_t)0x00000020U) /*!< erase/program protection of sector 5 */
  148. #define OB_WP_6 ((uint32_t)0x00000040U) /*!< erase/program protection of sector 6 */
  149. #define OB_WP_7 ((uint32_t)0x00000080U) /*!< erase/program protection of sector 7 */
  150. #define OB_WP_8 ((uint32_t)0x00000100U) /*!< erase/program protection of sector 8 */
  151. #define OB_WP_9 ((uint32_t)0x00000200U) /*!< erase/program protection of sector 9 */
  152. #define OB_WP_10 ((uint32_t)0x00000400U) /*!< erase/program protection of sector 10 */
  153. #define OB_WP_11 ((uint32_t)0x00000800U) /*!< erase/program protection of sector 11 */
  154. #define OB_WP_12 ((uint32_t)0x00000001U) /*!< erase/program protection of sector 12 */
  155. #define OB_WP_13 ((uint32_t)0x00000002U) /*!< erase/program protection of sector 13 */
  156. #define OB_WP_14 ((uint32_t)0x00000004U) /*!< erase/program protection of sector 14 */
  157. #define OB_WP_15 ((uint32_t)0x00000008U) /*!< erase/program protection of sector 15 */
  158. #define OB_WP_16 ((uint32_t)0x00000010U) /*!< erase/program protection of sector 16 */
  159. #define OB_WP_17 ((uint32_t)0x00000020U) /*!< erase/program protection of sector 17 */
  160. #define OB_WP_18 ((uint32_t)0x00000040U) /*!< erase/program protection of sector 18 */
  161. #define OB_WP_19 ((uint32_t)0x00000080U) /*!< erase/program protection of sector 19 */
  162. #define OB_WP_20 ((uint32_t)0x00000100U) /*!< erase/program protection of sector 20 */
  163. #define OB_WP_21 ((uint32_t)0x00000200U) /*!< erase/program protection of sector 21 */
  164. #define OB_WP_22 ((uint32_t)0x00000400U) /*!< erase/program protection of sector 22 */
  165. #define OB_WP_23_30 ((uint32_t)0x00000800U) /*!< erase/program protection of sector 23~30 */
  166. #define OB_WP_ALL ((uint32_t)0x00000FFFU) /*!< erase/program protection of all sectors */
  167. /* option bytes D-bus read protection */
  168. #define OB_DRP_0 ((uint32_t)0x00000001U) /*!< D-bus read protection protection of sector 0 */
  169. #define OB_DRP_1 ((uint32_t)0x00000002U) /*!< D-bus read protection protection of sector 1 */
  170. #define OB_DRP_2 ((uint32_t)0x00000004U) /*!< D-bus read protection protection of sector 2 */
  171. #define OB_DRP_3 ((uint32_t)0x00000008U) /*!< D-bus read protection protection of sector 3 */
  172. #define OB_DRP_4 ((uint32_t)0x00000010U) /*!< D-bus read protection protection of sector 4 */
  173. #define OB_DRP_5 ((uint32_t)0x00000020U) /*!< D-bus read protection protection of sector 5 */
  174. #define OB_DRP_6 ((uint32_t)0x00000040U) /*!< D-bus read protection protection of sector 6 */
  175. #define OB_DRP_7 ((uint32_t)0x00000080U) /*!< D-bus read protection protection of sector 7 */
  176. #define OB_DRP_8 ((uint32_t)0x00000100U) /*!< D-bus read protection protection of sector 8 */
  177. #define OB_DRP_9 ((uint32_t)0x00000200U) /*!< D-bus read protection protection of sector 9 */
  178. #define OB_DRP_10 ((uint32_t)0x00000400U) /*!< D-bus read protection protection of sector 10 */
  179. #define OB_DRP_11 ((uint32_t)0x00000800U) /*!< D-bus read protection protection of sector 11 */
  180. #define OB_DRP_12 ((uint32_t)0x00000001U) /*!< D-bus read protection protection of sector 12 */
  181. #define OB_DRP_13 ((uint32_t)0x00000002U) /*!< D-bus read protection protection of sector 13 */
  182. #define OB_DRP_14 ((uint32_t)0x00000004U) /*!< D-bus read protection protection of sector 14 */
  183. #define OB_DRP_15 ((uint32_t)0x00000008U) /*!< D-bus read protection protection of sector 15 */
  184. #define OB_DRP_16 ((uint32_t)0x00000010U) /*!< D-bus read protection protection of sector 16 */
  185. #define OB_DRP_17 ((uint32_t)0x00000020U) /*!< D-bus read protection protection of sector 17 */
  186. #define OB_DRP_18 ((uint32_t)0x00000040U) /*!< D-bus read protection protection of sector 18 */
  187. #define OB_DRP_19 ((uint32_t)0x00000080U) /*!< D-bus read protection protection of sector 19 */
  188. #define OB_DRP_20 ((uint32_t)0x00000100U) /*!< D-bus read protection protection of sector 20 */
  189. #define OB_DRP_21 ((uint32_t)0x00000200U) /*!< D-bus read protection protection of sector 21 */
  190. #define OB_DRP_22 ((uint32_t)0x00000400U) /*!< D-bus read protection protection of sector 22 */
  191. #define OB_DRP_23_30 ((uint32_t)0x00000800U) /*!< D-bus read protection protection of sector 23~30 */
  192. #define OB_DRP_ALL ((uint32_t)0x00000FFFU) /*!< D-bus read protection protection of all sectors */
  193. /* double banks or single bank selection when flash size is 1M bytes */
  194. #define OBCTL0_DBS(regval) (BIT(30) & ((uint32_t)(regval)<<30))
  195. #define OB_DBS_DISABLE OBCTL0_DBS(0) /*!< single bank when flash size is 1M bytes */
  196. #define OB_DBS_ENABLE OBCTL0_DBS(1) /*!< double bank when flash size is 1M bytes */
  197. /* option bytes D-bus read protection mode */
  198. #define OBCTL0_DRP(regval) (BIT(31) & ((uint32_t)(regval)<<31))
  199. #define OB_DRP_DISABLE OBCTL0_DRP(0) /*!< the WPx bits used as erase/program protection of each sector */
  200. #define OB_DRP_ENABLE OBCTL0_DRP(1) /*!< the WPx bits used as erase/program protection and D-bus read protection of each sector */
  201. /* FMC sectors */
  202. #define CTL_SN(regval) (BITS(3,7) & ((uint32_t)(regval))<< 3)
  203. #define CTL_SECTOR_NUMBER_0 CTL_SN(0) /*!< sector 0 */
  204. #define CTL_SECTOR_NUMBER_1 CTL_SN(1) /*!< sector 1 */
  205. #define CTL_SECTOR_NUMBER_2 CTL_SN(2) /*!< sector 2 */
  206. #define CTL_SECTOR_NUMBER_3 CTL_SN(3) /*!< sector 3 */
  207. #define CTL_SECTOR_NUMBER_4 CTL_SN(4) /*!< sector 4 */
  208. #define CTL_SECTOR_NUMBER_5 CTL_SN(5) /*!< sector 5 */
  209. #define CTL_SECTOR_NUMBER_6 CTL_SN(6) /*!< sector 6 */
  210. #define CTL_SECTOR_NUMBER_7 CTL_SN(7) /*!< sector 7 */
  211. #define CTL_SECTOR_NUMBER_8 CTL_SN(8) /*!< sector 8 */
  212. #define CTL_SECTOR_NUMBER_9 CTL_SN(9) /*!< sector 9 */
  213. #define CTL_SECTOR_NUMBER_10 CTL_SN(10) /*!< sector 10 */
  214. #define CTL_SECTOR_NUMBER_11 CTL_SN(11) /*!< sector 11 */
  215. #define CTL_SECTOR_NUMBER_24 CTL_SN(12) /*!< sector 24 */
  216. #define CTL_SECTOR_NUMBER_25 CTL_SN(13) /*!< sector 25 */
  217. #define CTL_SECTOR_NUMBER_26 CTL_SN(14) /*!< sector 26 */
  218. #define CTL_SECTOR_NUMBER_27 CTL_SN(15) /*!< sector 27 */
  219. #define CTL_SECTOR_NUMBER_12 CTL_SN(16) /*!< sector 12 */
  220. #define CTL_SECTOR_NUMBER_13 CTL_SN(17) /*!< sector 13 */
  221. #define CTL_SECTOR_NUMBER_14 CTL_SN(18) /*!< sector 14 */
  222. #define CTL_SECTOR_NUMBER_15 CTL_SN(19) /*!< sector 15 */
  223. #define CTL_SECTOR_NUMBER_16 CTL_SN(20) /*!< sector 16 */
  224. #define CTL_SECTOR_NUMBER_17 CTL_SN(21) /*!< sector 17 */
  225. #define CTL_SECTOR_NUMBER_18 CTL_SN(22) /*!< sector 18 */
  226. #define CTL_SECTOR_NUMBER_19 CTL_SN(23) /*!< sector 19 */
  227. #define CTL_SECTOR_NUMBER_20 CTL_SN(24) /*!< sector 20 */
  228. #define CTL_SECTOR_NUMBER_21 CTL_SN(25) /*!< sector 21 */
  229. #define CTL_SECTOR_NUMBER_22 CTL_SN(26) /*!< sector 22 */
  230. #define CTL_SECTOR_NUMBER_23 CTL_SN(27) /*!< sector 23 */
  231. #define CTL_SECTOR_NUMBER_28 CTL_SN(28) /*!< sector 28 */
  232. #define CTL_SECTOR_NUMBER_29 CTL_SN(29) /*!< sector 29 */
  233. #define CTL_SECTOR_NUMBER_30 CTL_SN(30) /*!< sector 30 */
  234. /* FMC program size */
  235. #define CTL_PSZ(regval) (BITS(8,9) & ((uint32_t)(regval))<< 8)
  236. #define CTL_PSZ_BYTE CTL_PSZ(0) /*!< FMC program by byte access */
  237. #define CTL_PSZ_HALF_WORD CTL_PSZ(1) /*!< FMC program by half-word access */
  238. #define CTL_PSZ_WORD CTL_PSZ(2) /*!< FMC program by word access */
  239. /* FMC interrupt enable */
  240. #define FMC_INTEN_END ((uint32_t)0x01000000U) /*!< enable FMC end of program interrupt */
  241. #define FMC_INTEN_ERR ((uint32_t)0x02000000U) /*!< enable FMC error interrupt */
  242. /* FMC flags */
  243. #define FMC_FLAG_END ((uint32_t)0x00000001U) /*!< FMC end of operation flag bit */
  244. #define FMC_FLAG_OPERR ((uint32_t)0x00000002U) /*!< FMC operation error flag bit */
  245. #define FMC_FLAG_WPERR ((uint32_t)0x00000010U) /*!< FMC erase/program protection error flag bit */
  246. #define FMC_FLAG_PGMERR ((uint32_t)0x00000040U) /*!< FMC program size not match error flag bit */
  247. #define FMC_FLAG_PGSERR ((uint32_t)0x00000080U) /*!< FMC program sequence error flag bit */
  248. #define FMC_FLAG_RDDERR ((uint32_t)0x00000100U) /*!< FMC read D-bus protection error flag bit */
  249. #define FMC_FLAG_BUSY ((uint32_t)0x00010000U) /*!< FMC busy flag */
  250. /* function declarations */
  251. /* FMC main memory programming functions */
  252. /* set the FMC wait state counter */
  253. void fmc_wscnt_set(uint32_t wscnt);
  254. /* unlock the main FMC operation */
  255. void fmc_unlock(void);
  256. /* lock the main FMC operation */
  257. void fmc_lock(void);
  258. /* FMC erase sector */
  259. fmc_state_enum fmc_sector_erase(uint32_t fmc_sector);
  260. /* FMC erase whole chip */
  261. fmc_state_enum fmc_mass_erase(void);
  262. /* FMC erase whole bank0 */
  263. fmc_state_enum fmc_bank0_erase(void);
  264. /* FMC erase whole bank1 */
  265. fmc_state_enum fmc_bank1_erase(void);
  266. /* FMC program a word at the corresponding address */
  267. fmc_state_enum fmc_word_program(uint32_t address, uint32_t data);
  268. /* FMC program a half word at the corresponding address */
  269. fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data);
  270. /* FMC program a byte at the corresponding address */
  271. fmc_state_enum fmc_byte_program(uint32_t address, uint8_t data);
  272. /* FMC option bytes programming functions */
  273. /* unlock the option byte operation */
  274. void ob_unlock(void);
  275. /* lock the option byte operation */
  276. void ob_lock(void);
  277. /* send option byte change command */
  278. void ob_start(void);
  279. /* enable write protect */
  280. void ob_write_protection0_enable(uint32_t ob_wp);
  281. /* disable write protect */
  282. void ob_write_protection0_disable(uint32_t ob_wp);
  283. /* enable write protect */
  284. void ob_write_protection1_enable(uint32_t ob_wp);
  285. /* disable write protect */
  286. void ob_write_protection1_disable(uint32_t ob_wp);
  287. /* configure the erase/program protection mode */
  288. void ob_drp_config(uint32_t ob_drp);
  289. /* enable the erase/program protection mode */
  290. void ob_drp0_enable(uint32_t ob_drp);
  291. /* disable the erase/program protection mode */
  292. void ob_drp0_disable(uint32_t ob_drp);
  293. /* enable the erase/program protection mode */
  294. void ob_drp1_enable(uint32_t ob_drp);
  295. /* disable the erase/program protection mode */
  296. void ob_drp1_disable(uint32_t ob_drp);
  297. /* set the option byte security protection level */
  298. void ob_security_protection_config(uint8_t ob_spc);
  299. /* write the FMC option byte user */
  300. void ob_user_write(uint32_t ob_fwdgt, uint32_t ob_deepsleep, uint32_t ob_stdby);
  301. /* option byte BOR threshold value */
  302. void ob_user_bor_threshold(uint32_t ob_bor_th);
  303. /* configure the boot mode */
  304. void ob_boot_mode_config(uint32_t boot_mode);
  305. /* get the FMC option byte user */
  306. uint8_t ob_user_get(void);
  307. /* get the FMC option byte write protection */
  308. uint16_t ob_write_protection0_get(void);
  309. /* get the FMC option byte write protection */
  310. uint16_t ob_write_protection1_get(void);
  311. /* get the FMC erase/program protection and D-bus read protection option bytes value */
  312. uint16_t ob_drp0_get(void);
  313. /* get the FMC erase/program protection and D-bus read protection option bytes value */
  314. uint16_t ob_drp1_get(void);
  315. /* get option byte security protection code value */
  316. FlagStatus ob_spc_get(void);
  317. /* get the FMC threshold value */
  318. uint8_t ob_user_bor_threshold_get(void);
  319. /* FMC interrupts and flags management functions */
  320. /* enable FMC interrupt */
  321. void fmc_interrupt_enable(uint32_t fmc_int);
  322. /* disable FMC interrupt */
  323. void fmc_interrupt_disable(uint32_t fmc_int);
  324. /* get flag set or reset */
  325. FlagStatus fmc_flag_get(uint32_t fmc_flag);
  326. /* clear the FMC pending flag */
  327. void fmc_flag_clear(uint32_t fmc_flag);
  328. /* return the FMC state */
  329. fmc_state_enum fmc_state_get(void);
  330. /* check FMC ready or not */
  331. fmc_state_enum fmc_ready_wait(uint32_t count);
  332. #endif /* GD32F4XX_FMC_H */