gd32f10x_exmc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /**
  2. ******************************************************************************
  3. * @brief EXMC header file of the firmware library.
  4. ******************************************************************************
  5. */
  6. /* Define to prevent recursive inclusion -------------------------------------*/
  7. #ifndef __GD32F10X_EXMC_H
  8. #define __GD32F10X_EXMC_H
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /* Includes ------------------------------------------------------------------*/
  13. #include "gd32f10x.h"
  14. /** @addtogroup GD32F10x_Firmware
  15. * @{
  16. */
  17. /** @addtogroup EXMC
  18. * @{
  19. */
  20. /** @defgroup EXMC_Exported_Types
  21. * @{
  22. */
  23. /**
  24. * @brief Initial Timing Parameters For NOR/SRAM Banks
  25. */
  26. typedef struct {
  27. uint32_t EXMC_AsynAccessMode; /*!< The asynchronous access mode, detailed in @ref EXMC_AsynAccess_Mode*/
  28. uint32_t EXMC_SynDataLatency; /*!< The number of CLK cycles to configure the data latency,
  29. which may assume a value between 0x0 and 0xF. */
  30. uint32_t EXMC_SynCLKDivision; /*!< The number of HCLK cycles to configure the clock divide ratio,
  31. which can be a value between 0x0 and 0xF. */
  32. uint32_t EXMC_BusLatency; /*!< The number of HCLK cycles to configure the bus latency,
  33. which can be a value between 0x0 and 0xF. */
  34. uint32_t EXMC_AsynDataSetupTime; /*!< The number of HCLK cycles to configure the data setup time
  35. while in the asynchronous access mode, which can be a value
  36. between 0x00 and 0xFF. */
  37. uint32_t EXMC_AsynAddressHoldTime; /*!< The number of HCLK cycles to configure the address hold time
  38. while in the asynchronous access mode, which can be a value
  39. between 0x0 and 0xF. */
  40. uint32_t EXMC_AsynAddressSetupTime; /*!< The number of HCLK cycles to configure the data setup time
  41. while in the asynchronous access mode, which can be a value
  42. between 0x0 and 0xF. */
  43. } EXMC_NORSRAMTimingInitPara;
  44. /**
  45. * @brief EXMC NOR/SRAM Init structure definition
  46. */
  47. typedef struct {
  48. uint32_t EXMC_NORSRAMBank; /*!< The specified region of NORSRAM Bank1,
  49. choose one from @ref EXMC_NORSRAMBank. */
  50. uint32_t EXMC_WriteMode; /*!< The write mode, details in @ref EXMC_WriteMode. */
  51. uint32_t EXMC_ExtendedMode; /*!< Enable or Disable the extended mode, details in
  52. @ref EXMC_ExtendedMode. */
  53. uint32_t EXMC_AsynWait; /*!< Enable or disable the asynchronous wait feature,detial
  54. in @ref EXMC_AsynWait. */
  55. uint32_t EXMC_NWAITSignal; /*!< Enable or Disable the NWAIT signal while in synchronous
  56. bust mode, details in @ref EXMC_NWAITSignal. */
  57. uint32_t EXMC_MemoryWrite; /*!< Enable or Disable the write operation, details in
  58. @ref EXMC_MemoryWrite. */
  59. uint32_t EXMC_NWAITConfig; /*!< NWAIT signal configuration, details in @ref EXMC_NWAITConfig */
  60. uint32_t EXMC_WrapBurstMode; /*!< Enable or Disable the wrap burst mode, details in
  61. @ref EXMC_WrapBurstMode. */
  62. uint32_t EXMC_NWAITPolarity; /*!< Specifies the polarity of NWAIT signal from memory,
  63. details in @ref EXMC_NWAITPolarity. */
  64. uint32_t EXMC_BurstMode; /*!< Enable or Disable the burst mode, details in
  65. @ref EXMC_BurstMode. */
  66. uint32_t EXMC_DatabusWidth; /*!< Specifies the databus width of external memory,
  67. details in @ref EXMC_DatabusWidth. */
  68. uint32_t EXMC_MemoryType; /*!< Specifies the type of external memory, details in
  69. @ref EXMC_MemoryType. */
  70. uint32_t EXMC_AddressDataMux; /*!< Specifies whether the data bus and address bus are multiplexed
  71. or not,details in @ref EXMC_AddressDataMux. */
  72. EXMC_NORSRAMTimingInitPara *EXMC_ReadWriteTimingParaStruct; /*!< The struct EXMC_NORSRAMTimingInitPara pointer,which is
  73. used to define the timing parameters for read and write
  74. if the ExtendedMode is not used or define the timing
  75. parameters for read if the ExtendedMode is used. */
  76. EXMC_NORSRAMTimingInitPara *EXMC_WriteTimingParaStruct; /*!< The struct EXMC_NORSRAMTimingInitPara pointer,which is
  77. only used to define the timing parameters for write when
  78. the ExtendedMode is used. */
  79. } EXMC_NORSRAMInitPara;
  80. /**
  81. * @brief Timing parameters For EXMC NAND and PCCARD Banks
  82. */
  83. typedef struct {
  84. uint32_t EXMC_DatabusHiZTime; /*!< The number of HCLK cycles to configure the dadtabus HiZ time
  85. for write operation, which can be a value between 0x00 and 0xFF. */
  86. uint32_t EXMC_HoldTime; /*!< The number of HCLK cycles to configure the address hold time
  87. (or the data hold time for write operation),which can be a value
  88. between 0x00 and 0xFF. */
  89. uint32_t EXMC_WaitTime; /*!< The number of HCLK cycles to configure the minimum wait time,
  90. which can be a value between 0x00 and 0xFF. */
  91. uint32_t EXMC_SetupTime; /*!< The number of HCLK cycles to configure the address setup time ,
  92. which can be a value between 0x00 and 0xFF. */
  93. } EXMC_NAND_PCCARDTimingInitPara;
  94. /**
  95. * @brief EXMC NAND Init structure definition
  96. */
  97. typedef struct {
  98. uint32_t EXMC_NANDBank; /*!< The specified Bank of NAND FLASH, choose one
  99. from @ref EXMC_NANDBank. */
  100. uint32_t EXMC_ECCSize; /*!< The page size for the ECC calculation,details
  101. in @ref EXMC_ECCSize. */
  102. uint32_t EXMC_ATRLatency; /*!< The number of HCLK cycles to configure the
  103. latency of ALE low to RB low, which can be a
  104. value between 0x0 and 0xF. */
  105. uint32_t EXMC_CTRLatency; /*!< The number of HCLK cycles to configure the
  106. latency of CLE low to RB low, which can be a
  107. value between 0x0 and 0xF. */
  108. uint32_t EXMC_ECCLogic; /*!< Enable or Disable the ECC calculation logic,
  109. details in @ref EXMC_ECCLogic. */
  110. uint32_t EXMC_DatabusWidth; /*!< the NAND flash databus width, details in
  111. @ref EXMC_DatabusWidth. */
  112. uint32_t EXMC_WaitFeature; /*!< Enables or Disables the Wait feature,details
  113. in @ref EXMC_WaitFeature. */
  114. EXMC_NAND_PCCARDTimingInitPara *EXMC_CommonSpaceTimingParaStruct; /*!< The struct EXMC_NAND_PCCARDTimingInitPara
  115. pointer, which is used to define the timing
  116. parameters for NAND flash Common Space. */
  117. EXMC_NAND_PCCARDTimingInitPara *EXMC_AttributeSpaceTimingParaStruct; /*!< The struct EXMC_NAND_PCCARDTimingInitPara
  118. pointer, which is used to define the timing
  119. parameters for NAND flash Attribute Space. */
  120. } EXMC_NANDInitPara;
  121. /**
  122. * @brief EXMC PCCARD Init structure definition
  123. */
  124. typedef struct {
  125. uint32_t EXMC_ATRLatency; /*!< The number of HCLK cycles to configure
  126. the latency of ALE low to RB low, which can
  127. be a value between 0x0 and 0xF. */
  128. uint32_t EXMC_CTRLatency; /*!< The number of HCLK cycles to configure
  129. the latency of CLE low to RB low, which can
  130. be a value between 0x0 and 0xF. */
  131. uint32_t EXMC_WaitFeature; /*!< Enables or Disables the Wait feature,details
  132. in @ref EXMC_WaitFeature. */
  133. EXMC_NAND_PCCARDTimingInitPara *EXMC_CommonSpaceTimingParaStruct; /*!< The struct EXMC_NAND_PCCARDTimingInitPara
  134. pointer, which is used to define the timing
  135. parameters for PC CARD Common Space. */
  136. EXMC_NAND_PCCARDTimingInitPara *EXMC_AttributeSpaceTimingParaStruct; /*!< The struct EXMC_NAND_PCCARDTimingInitPara
  137. pointer, which is used to define the timing
  138. parameters for PC CARD Attribute Space. */
  139. EXMC_NAND_PCCARDTimingInitPara *EXMC_IOSpaceTimingParaStruct; /*!< The struct EXMC_NAND_PCCARDTimingInitPara
  140. pointer, which is used to define the timing
  141. parameters for PC CARD I/O Space. */
  142. } EXMC_PCCARDInitPara;
  143. /**
  144. * @}
  145. */
  146. /** @defgroup EXMC_Exported_Constants
  147. * @{
  148. */
  149. /** @defgroup EXMC_NORSRAMBank
  150. * @{
  151. */
  152. #define EXMC_BANK1_NORSRAM1 ((uint32_t)0x00000001)
  153. #define EXMC_BANK1_NORSRAM2 ((uint32_t)0x00000002)
  154. #define EXMC_BANK1_NORSRAM3 ((uint32_t)0x00000003)
  155. #define EXMC_BANK1_NORSRAM4 ((uint32_t)0x00000004)
  156. /**
  157. * @}
  158. */
  159. /** @defgroup EXMC_NANDBank
  160. * @{
  161. */
  162. #define EXMC_BANK2_NAND ((uint32_t)0x00000010)
  163. #define EXMC_BANK3_NAND ((uint32_t)0x00000100)
  164. /**
  165. * @}
  166. */
  167. /** @defgroup EXMC_PCCARD_Bank
  168. * @{
  169. */
  170. #define EXMC_BANK4_PCCARD ((uint32_t)0x00001000)
  171. /**
  172. * @}
  173. */
  174. /** @defgroup NORSRAM_Controller
  175. * @{
  176. */
  177. /** @defgroup EXMC_AddressDataMux
  178. * @{
  179. */
  180. #define EXMC_ADDRESS_DATA_MUX_DISABLE ((uint32_t)0x00000000)
  181. #define EXMC_ADDRESS_DATA_MUX_ENABLE ((uint32_t)0x00000002)
  182. /**
  183. * @}
  184. */
  185. /** @defgroup EXMC_MemoryType
  186. * @{
  187. */
  188. #define EXMC_MEMORY_TYPE_SRAM ((uint32_t)0x00000000)
  189. #define EXMC_MEMORY_TYPE_PSRAM ((uint32_t)0x00000004)
  190. #define EXMC_MEMORY_TYPE_NOR ((uint32_t)0x00000008)
  191. /**
  192. * @}
  193. */
  194. /** @defgroup EXMC_DatabusWidth
  195. * @{
  196. */
  197. #define EXMC_DATABUS_WIDTH_8B ((uint32_t)0x00000000)
  198. #define EXMC_DATABUS_WIDTH_16B ((uint32_t)0x00000010)
  199. /**
  200. * @}
  201. */
  202. /** @defgroup EXMC_NORFlash_Access
  203. * @{
  204. */
  205. #define EXMC_NORFLASH_ACCESS_DISABLE ((uint32_t)0x00000000)
  206. #define EXMC_NORFLASH_ACCESS_ENABLE ((uint32_t)0x00000040)
  207. /**
  208. * @}
  209. */
  210. /** @defgroup EXMC_BurstMode
  211. * @{
  212. */
  213. #define EXMC_BURST_MODE_DISABLE ((uint32_t)0x00000000)
  214. #define EXMC_BURST_MODE_ENABLE ((uint32_t)0x00000100)
  215. /**
  216. * @}
  217. */
  218. /** @defgroup EXMC_AsynWait
  219. * @{
  220. */
  221. #define EXMC_ASYN_WAIT_DISABLE ((uint32_t)0x00000000)
  222. #define EXMC_ASYN_WAIT_ENABLE ((uint32_t)0x00008000)
  223. /**
  224. * @}
  225. */
  226. /** @defgroup EXMC_NWAITPolarity
  227. * @{
  228. */
  229. #define EXMC_NWAIT_POLARITY_LOW ((uint32_t)0x00000000)
  230. #define EXMC_NWAIT_POLARITY_HIGH ((uint32_t)0x00000200)
  231. /**
  232. * @}
  233. */
  234. /** @defgroup EXMC_WrapBurstMode
  235. * @{
  236. */
  237. #define EXMC_WRAP_BURST_MODE_DISABLE ((uint32_t)0x00000000)
  238. #define EXMC_WRAP_BURST_MODE_ENABLE ((uint32_t)0x00000400)
  239. /**
  240. * @}
  241. */
  242. /** @defgroup EXMC_NWAITConfig
  243. * @{
  244. */
  245. #define EXMC_NWAIT_CONFIG_BEFORE ((uint32_t)0x00000000)
  246. #define EXMC_NWAIT_CONFIG_DURING ((uint32_t)0x00000800)
  247. /**
  248. * @}
  249. */
  250. /** @defgroup EXMC_MemoryWrite
  251. * @{
  252. */
  253. #define EXMC_MEMORY_WRITE_DISABLE ((uint32_t)0x00000000)
  254. #define EXMC_MEMORY_WRITE_ENABLE ((uint32_t)0x00001000)
  255. /**
  256. * @}
  257. */
  258. /** @defgroup EXMC_NWAITSignal
  259. * @{
  260. */
  261. #define EXMC_NWAIT_SIGNAL_DISABLE ((uint32_t)0x00000000)
  262. #define EXMC_NWAIT_SIGNAL_ENABLE ((uint32_t)0x00002000)
  263. /**
  264. * @}
  265. */
  266. /** @defgroup EXMC_ExtendedMode
  267. * @{
  268. */
  269. #define EXMC_EXTENDED_MODE_DISABLE ((uint32_t)0x00000000)
  270. #define EXMC_EXTENDED_MODE_ENABLE ((uint32_t)0x00004000)
  271. /**
  272. * @}
  273. */
  274. /** @defgroup EXMC_WriteMode
  275. * @{
  276. */
  277. #define EXMC_ASYN_WRITE ((uint32_t)0x00000000)
  278. #define EXMC_SYN_WRITE ((uint32_t)0x00080000)
  279. /**
  280. * @}
  281. */
  282. /** @defgroup EXMC_AsynAccess_Mode
  283. * @{
  284. */
  285. #define EXMC_ACCESS_MODE_A ((uint32_t)0x00000000)
  286. #define EXMC_ACCESS_MODE_B ((uint32_t)0x10000000)
  287. #define EXMC_ACCESS_MODE_C ((uint32_t)0x20000000)
  288. #define EXMC_ACCESS_MODE_D ((uint32_t)0x30000000)
  289. /**
  290. * @}
  291. */
  292. /**
  293. * @}
  294. */
  295. /** @defgroup NAND_PCCARD_Controller
  296. * @{
  297. */
  298. /** @defgroup EXMC_WaitFeature
  299. * @{
  300. */
  301. #define EXMC_WAIT_FEATURE_DISABLE ((uint32_t)0x00000000)
  302. #define EXMC_WAIT_FEATURE_ENABLE ((uint32_t)0x00000002)
  303. /**
  304. * @}
  305. */
  306. /** @defgroup EXMC_ECCLogic
  307. * @{
  308. */
  309. #define EXMC_ECC_LOGIC_DISABLE ((uint32_t)0x00000000)
  310. #define EXMC_ECC_LOGIC_ENABLE ((uint32_t)0x00000040)
  311. /**
  312. * @}
  313. */
  314. /** @defgroup EXMC_ECCSize
  315. * @{
  316. */
  317. #define EXMC_ECC_SIZE_256BYTES ((uint32_t)0x00000000)
  318. #define EXMC_ECC_SIZE_512BYTES ((uint32_t)0x00020000)
  319. #define EXMC_ECC_SIZE_1024BYTES ((uint32_t)0x00040000)
  320. #define EXMC_ECC_SIZE_2048BYTES ((uint32_t)0x00060000)
  321. #define EXMC_ECC_SIZE_4096BYTES ((uint32_t)0x00080000)
  322. #define EXMC_ECC_SIZE_8192BYTES ((uint32_t)0x000A0000)
  323. /**
  324. * @}
  325. */
  326. /** @defgroup EXMC_Interrupt_Source
  327. * @{
  328. */
  329. #define EXMC_INT_RISE ((uint32_t)0x00000008)
  330. #define EXMC_INT_LEVEL ((uint32_t)0x00000010)
  331. #define EXMC_INT_FALL ((uint32_t)0x00000020)
  332. /**
  333. * @}
  334. */
  335. /** @defgroup EXMC_FLAG
  336. * @{
  337. */
  338. #define EXMC_FLAG_RISE ((uint32_t)0x00000001)
  339. #define EXMC_FLAG_LEVEL ((uint32_t)0x00000002)
  340. #define EXMC_FLAG_FALL ((uint32_t)0x00000004)
  341. #define EXMC_FLAG_FIFOE ((uint32_t)0x00000040)
  342. /**
  343. * @}
  344. */
  345. /**
  346. * @}
  347. */
  348. /**
  349. * @}
  350. */
  351. /** @defgroup EXMC_Exported_Functions
  352. * @{
  353. */
  354. void EXMC_NORSRAM_DeInit(uint32_t EXMC_NORSRAMBank);
  355. void EXMC_NAND_DeInit(uint32_t EXMC_NANDBank);
  356. void EXMC_PCCARD_DeInit(void);
  357. void EXMC_NORSRAM_Init(EXMC_NORSRAMInitPara *EXMC_NORSRAMInitParaStruct);
  358. void EXMC_NAND_Init(EXMC_NANDInitPara *EXMC_NANDInitParaStruct);
  359. void EXMC_PCCARD_Init(EXMC_PCCARDInitPara *EXMC_PCCARDInitParaStruct);
  360. void EXMC_NORSRAMStruct_Init(EXMC_NORSRAMInitPara *EXMC_NORSRAMInitParaStruct);
  361. void EXMC_NANDStruct_Init(EXMC_NANDInitPara *EXMC_NANDInitParaStruct);
  362. void EXMC_PCCARDStruct_Init(EXMC_PCCARDInitPara *EXMC_PCCARDInitParaStruct);
  363. void EXMC_NORSRAM_Enable(uint32_t EXMC_NORSRAMBank, TypeState NewValue);
  364. void EXMC_NAND_Enable(uint32_t EXMC_NANDBank, TypeState NewValue);
  365. void EXMC_PCCARD_Enable(TypeState NewValue);
  366. void EXMC_NANDECC_Enable(uint32_t EXMC_NANDBank, TypeState NewValue);
  367. uint32_t EXMC_GetECC(uint32_t EXMC_NANDBank);
  368. void EXMC_INTConfig(uint32_t EXMC_PCNANDBank, uint32_t EXMC_INT, TypeState NewValue);
  369. TypeState EXMC_GetBitState(uint32_t EXMC_PCNANDBank, uint32_t EXMC_FLAG);
  370. void EXMC_ClearBitState(uint32_t EXMC_PCNANDBank, uint32_t EXMC_FLAG);
  371. TypeState EXMC_GetIntBitState(uint32_t EXMC_PCNANDBank, uint32_t EXMC_INT);
  372. void EXMC_ClearIntBitState(uint32_t EXMC_PCNANDBank, uint32_t EXMC_INT);
  373. #ifdef __cplusplus
  374. }
  375. #endif
  376. #endif /*__GD32F10x_EXMC_H */
  377. /**
  378. * @}
  379. */
  380. /**
  381. * @}
  382. */
  383. /**
  384. * @}
  385. */