gd32f30x_exmc.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*!
  2. \file gd32f30x_exmc.h
  3. \brief definitions for the EXMC
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. \version 2020-09-30, V2.1.0, firmware for GD32F30x
  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 GD32F30X_EXMC_H
  33. #define GD32F30X_EXMC_H
  34. #include "gd32f30x.h"
  35. /* EXMC definitions */
  36. #define EXMC (EXMC_BASE) /*!< EXMC register base address */
  37. /* registers definitions */
  38. /* NOR/PSRAM */
  39. #define EXMC_SNCTL0 REG32(EXMC + 0x00U) /*!< EXMC SRAM/NOR flash control register0 */
  40. #define EXMC_SNTCFG0 REG32(EXMC + 0x04U) /*!< EXMC SRAM/NOR flash timing configuration register0 */
  41. #define EXMC_SNWTCFG0 REG32(EXMC + 0x104U) /*!< EXMC SRAM/NOR flash write timing configuration register0 */
  42. #define EXMC_SNCTL1 REG32(EXMC + 0x08U) /*!< EXMC SRAM/NOR flash control register1 */
  43. #define EXMC_SNTCFG1 REG32(EXMC + 0x0CU) /*!< EXMC SRAM/NOR flash timing configuration register1 */
  44. #define EXMC_SNWTCFG1 REG32(EXMC + 0x10CU) /*!< EXMC SRAM/NOR flash write timing configuration register1 */
  45. #define EXMC_SNCTL2 REG32(EXMC + 0x10U) /*!< EXMC SRAM/NOR flash control register2 */
  46. #define EXMC_SNTCFG2 REG32(EXMC + 0x14U) /*!< EXMC SRAM/NOR flash timing configuration register2 */
  47. #define EXMC_SNWTCFG2 REG32(EXMC + 0x114U) /*!< EXMC SRAM/NOR flash write timing configuration register2 */
  48. #define EXMC_SNCTL3 REG32(EXMC + 0x18U) /*!< EXMC SRAM/NOR flash control register3 */
  49. #define EXMC_SNTCFG3 REG32(EXMC + 0x1CU) /*!< EXMC SRAM/NOR flash timing configuration register3 */
  50. #define EXMC_SNWTCFG3 REG32(EXMC + 0x11CU) /*!< EXMC SRAM/NOR flash write timing configuration register3 */
  51. /* NAND/PC card */
  52. #define EXMC_NPCTL1 REG32(EXMC + 0x60U) /*!< EXMC NAND/PC card control register1 */
  53. #define EXMC_NPINTEN1 REG32(EXMC + 0x64U) /*!< EXMC NAND/PC card interrupt enable register1 */
  54. #define EXMC_NPCTCFG1 REG32(EXMC + 0x68U) /*!< EXMC NAND/PC card common space timing configuration register1 */
  55. #define EXMC_NPATCFG1 REG32(EXMC + 0x6CU) /*!< EXMC NAND/PC card attribute space timing configuration register1 */
  56. #define EXMC_NECC1 REG32(EXMC + 0x74U) /*!< EXMC NAND ECC register1 */
  57. #define EXMC_NPCTL2 REG32(EXMC + 0x80U) /*!< EXMC NAND/PC card control register2 */
  58. #define EXMC_NPINTEN2 REG32(EXMC + 0x84U) /*!< EXMC NAND/PC card interrupt enable register2 */
  59. #define EXMC_NPCTCFG2 REG32(EXMC + 0x88U) /*!< EXMC NAND/PC card common space timing configuration register2 */
  60. #define EXMC_NPATCFG2 REG32(EXMC + 0x8CU) /*!< EXMC NAND/PC card attribute space timing configuration register2 */
  61. #define EXMC_NECC2 REG32(EXMC + 0x94U) /*!< EXMC NAND ECC register2 */
  62. #define EXMC_NPCTL3 REG32(EXMC + 0xA0U) /*!< EXMC NAND/PC card control register3 */
  63. #define EXMC_NPINTEN3 REG32(EXMC + 0xA4U) /*!< EXMC NAND/PC card interrupt enable register3 */
  64. #define EXMC_NPCTCFG3 REG32(EXMC + 0xA8U) /*!< EXMC NAND/PC card common space timing configuration register3 */
  65. #define EXMC_NPATCFG3 REG32(EXMC + 0xACU) /*!< EXMC NAND/PC card attribute space timing configuration register3 */
  66. #define EXMC_PIOTCFG3 REG32(EXMC + 0xB0U) /*!< EXMC PC card I/O space timing configuration register */
  67. /* bits definitions */
  68. /* EXMC_SNCTLx,x=0..3 */
  69. #define EXMC_SNCTL_NRBKEN BIT(0) /*!< NOR bank enable */
  70. #define EXMC_SNCTL_NRMUX BIT(1) /*!< NOR bank memory address/data multiplexing enable */
  71. #define EXMC_SNCTL_NRTP BITS(2,3) /*!< NOR bank memory type */
  72. #define EXMC_SNCTL_NRW BITS(4,5) /*!< NOR bank memory data bus width */
  73. #define EXMC_SNCTL_NREN BIT(6) /*!< NOR flash access enable */
  74. #define EXMC_SNCTL_SBRSTEN BIT(8) /*!< synchronous burst enable */
  75. #define EXMC_SNCTL_NRWTPOL BIT(9) /*!< NWAIT signal polarity */
  76. #define EXMC_SNCTL_WRAPEN BIT(10) /*!< wrapped burst mode enable */
  77. #define EXMC_SNCTL_NRWTCFG BIT(11) /*!< NWAIT signal configuration, only work in synchronous mode */
  78. #define EXMC_SNCTL_WREN BIT(12) /*!< write enable */
  79. #define EXMC_SNCTL_NRWTEN BIT(13) /*!< NWAIT signal enable */
  80. #define EXMC_SNCTL_EXMODEN BIT(14) /*!< extended mode enable */
  81. #define EXMC_SNCTL_ASYNCWAIT BIT(15) /*!< asynchronous wait enable */
  82. #define EXMC_SNCTL_CPS BITS(16,18) /*!< CRAM page size */
  83. #define EXMC_SNCTL_SYNCWR BIT(19) /*!< synchronous write config */
  84. /* EXMC_SNTCFGx,x=0..3 */
  85. #define EXMC_SNTCFG_ASET BITS(0,3) /*!< asynchronous address setup time */
  86. #define EXMC_SNTCFG_AHLD BITS(4,7) /*!< asynchronous address hold time */
  87. #define EXMC_SNTCFG_DSET BITS(8,15) /*!< asynchronous data setup time */
  88. #define EXMC_SNTCFG_BUSLAT BITS(16,19) /*!< bus latency */
  89. #define EXMC_SNTCFG_CKDIV BITS(20,23) /*!< synchronous clock divide ratio */
  90. #define EXMC_SNTCFG_DLAT BITS(24,27) /*!< synchronous data latency for NOR flash */
  91. #define EXMC_SNTCFG_ASYNCMOD BITS(28,29) /*!< asynchronous access mode */
  92. /* EXMC_SNWTCFGx,x=0..3 */
  93. #define EXMC_SNWTCFG_WASET BITS(0,3) /*!< asynchronous address setup time */
  94. #define EXMC_SNWTCFG_WAHLD BITS(4,7) /*!< asynchronous address hold time */
  95. #define EXMC_SNWTCFG_WDSET BITS(8,15) /*!< asynchronous data setup time */
  96. #define EXMC_SNWTCFG_WBUSLAT BITS(16,19) /*!< bus latency */
  97. #define EXMC_SNWTCFG_WASYNCMOD BITS(28,29) /*!< asynchronous access mode */
  98. /* EXMC_NPCTLx,x=1..3 */
  99. #define EXMC_NPCTL_NDWTEN BIT(1) /*!< wait feature enable */
  100. #define EXMC_NPCTL_NDBKEN BIT(2) /*!< NAND bank enable */
  101. #define EXMC_NPCTL_NDTP BIT(3) /*!< NAND bank memory type */
  102. #define EXMC_NPCTL_NDW BITS(4,5) /*!< NAND bank memory data bus width */
  103. #define EXMC_NPCTL_ECCEN BIT(6) /*!< ECC enable */
  104. #define EXMC_NPCTL_CTR BITS(9,12) /*!< CLE to RE delay */
  105. #define EXMC_NPCTL_ATR BITS(13,16) /*!< ALE to RE delay */
  106. #define EXMC_NPCTL_ECCSZ BITS(17,19) /*!< ECC size */
  107. /* EXMC_NPINTENx,x=1..3 */
  108. #define EXMC_NPINTEN_INTRS BIT(0) /*!< interrupt rising edge status */
  109. #define EXMC_NPINTEN_INTHS BIT(1) /*!< interrupt high-level status */
  110. #define EXMC_NPINTEN_INTFS BIT(2) /*!< interrupt falling edge status */
  111. #define EXMC_NPINTEN_INTREN BIT(3) /*!< interrupt rising edge detection enable */
  112. #define EXMC_NPINTEN_INTHEN BIT(4) /*!< interrupt high-level detection enable */
  113. #define EXMC_NPINTEN_INTFEN BIT(5) /*!< interrupt falling edge detection enable */
  114. #define EXMC_NPINTEN_FFEPT BIT(6) /*!< FIFO empty flag */
  115. /* EXMC_NPCTCFGx,x=1..3 */
  116. #define EXMC_NPCTCFG_COMSET BITS(0,7) /*!< common memory setup time */
  117. #define EXMC_NPCTCFG_COMWAIT BITS(8,15) /*!< common memory wait time */
  118. #define EXMC_NPCTCFG_COMHLD BITS(16,23) /*!< common memory hold time */
  119. #define EXMC_NPCTCFG_COMHIZ BITS(24,31) /*!< common memory data bus HiZ time */
  120. /* EXMC_NPATCFGx,x=1..3 */
  121. #define EXMC_NPATCFG_ATTSET BITS(0,7) /*!< attribute memory setup time */
  122. #define EXMC_NPATCFG_ATTWAIT BITS(8,15) /*!< attribute memory wait time */
  123. #define EXMC_NPATCFG_ATTHLD BITS(16,23) /*!< attribute memory hold time */
  124. #define EXMC_NPATCFG_ATTHIZ BITS(24,31) /*!< attribute memory data bus HiZ time */
  125. /* EXMC_PIOTCFG3 */
  126. #define EXMC_PIOTCFG3_IOSET BITS(0,7) /*!< IO space setup time */
  127. #define EXMC_PIOTCFG3_IOWAIT BITS(8,15) /*!< IO space wait time */
  128. #define EXMC_PIOTCFG3_IOHLD BITS(16,23) /*!< IO space hold time */
  129. #define EXMC_PIOTCFG3_IOHIZ BITS(24,31) /*!< IO space data bus HiZ time */
  130. /* EXMC_NECCx,x=1,2 */
  131. #define EXMC_NECC_ECC BITS(0,31) /*!< ECC result */
  132. /* constants definitions */
  133. /* EXMC NOR/SRAM timing initialize struct */
  134. typedef struct
  135. {
  136. uint32_t asyn_access_mode; /*!< asynchronous access mode */
  137. uint32_t syn_data_latency; /*!< configure the data latency */
  138. uint32_t syn_clk_division; /*!< configure the clock divide ratio */
  139. uint32_t bus_latency; /*!< configure the bus latency */
  140. uint32_t asyn_data_setuptime; /*!< configure the data setup time,asynchronous access mode valid */
  141. uint32_t asyn_address_holdtime; /*!< configure the address hold time,asynchronous access mode valid */
  142. uint32_t asyn_address_setuptime; /*!< configure the data setup time,asynchronous access mode valid */
  143. }exmc_norsram_timing_parameter_struct;
  144. /* EXMC NOR/SRAM initialize struct */
  145. typedef struct
  146. {
  147. uint32_t norsram_region; /*!< select the region of EXMC NOR/SRAM bank */
  148. uint32_t write_mode; /*!< the write mode, synchronous mode or asynchronous mode */
  149. uint32_t extended_mode; /*!< enable or disable the extended mode */
  150. uint32_t asyn_wait; /*!< enable or disable the asynchronous wait function */
  151. uint32_t nwait_signal; /*!< enable or disable the NWAIT signal while in synchronous bust mode */
  152. uint32_t memory_write; /*!< enable or disable the write operation */
  153. uint32_t nwait_config; /*!< NWAIT signal configuration */
  154. uint32_t wrap_burst_mode; /*!< enable or disable the wrap burst mode */
  155. uint32_t nwait_polarity; /*!< specifies the polarity of NWAIT signal from memory */
  156. uint32_t burst_mode; /*!< enable or disable the burst mode */
  157. uint32_t databus_width; /*!< specifies the databus width of external memory */
  158. uint32_t memory_type; /*!< specifies the type of external memory */
  159. uint32_t address_data_mux; /*!< specifies whether the data bus and address bus are multiplexed */
  160. exmc_norsram_timing_parameter_struct* read_write_timing; /*!< timing parameters for read and write if the extended mode is not used or the timing
  161. parameters for read if the extended mode is used */
  162. exmc_norsram_timing_parameter_struct* write_timing; /*!< timing parameters for write when the extended mode is used */
  163. }exmc_norsram_parameter_struct;
  164. /* EXMC NAND/PC card timing initialize struct */
  165. typedef struct
  166. {
  167. uint32_t databus_hiztime; /*!< configure the dadtabus HiZ time for write operation */
  168. uint32_t holdtime; /*!< configure the address hold time(or the data hold time for write operation) */
  169. uint32_t waittime; /*!< configure the minimum wait time */
  170. uint32_t setuptime; /*!< configure the address setup time */
  171. }exmc_nand_pccard_timing_parameter_struct;
  172. /* EXMC NAND initialize struct */
  173. typedef struct
  174. {
  175. uint32_t nand_bank; /*!< select the bank of NAND */
  176. uint32_t ecc_size; /*!< the page size for the ECC calculation */
  177. uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
  178. uint32_t ctr_latency; /*!< configure the latency of CLE low to RB low */
  179. uint32_t ecc_logic; /*!< enable or disable the ECC calculation logic */
  180. uint32_t databus_width; /*!< the NAND flash databus width */
  181. uint32_t wait_feature; /*!< enable or disable the wait feature */
  182. exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for NAND flash common space */
  183. exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for NAND flash attribute space */
  184. }exmc_nand_parameter_struct;
  185. /* EXMC PC card initialize struct */
  186. typedef struct
  187. {
  188. uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
  189. uint32_t ctr_latency; /*!< configure the latency of CLE low to RB low */
  190. uint32_t wait_feature; /*!< enable or disable the wait feature */
  191. exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for PC card common space */
  192. exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for PC card attribute space */
  193. exmc_nand_pccard_timing_parameter_struct* io_space_timing; /*!< the timing parameters for PC card IO space */
  194. }exmc_pccard_parameter_struct;
  195. /* EXMC_register address */
  196. #define EXMC_SNCTL(region) REG32(EXMC + 0x08U * (region)) /*!< EXMC SRAM/NOR flash control registers, region = 0,1,2,3 */
  197. #define EXMC_SNTCFG(region) REG32(EXMC + 0x04U + 0x08U * (region)) /*!< EXMC SRAM/NOR flash timing configuration registers, region = 0,1,2,3 */
  198. #define EXMC_SNWTCFG(region) REG32(EXMC + 0x104U + 0x08U * (region)) /*!< EXMC SRAM/NOR flash write timing configuration registers, region = 0,1,2,3 */
  199. #define EXMC_NPCTL(bank) REG32(EXMC + 0x40U + 0x20U * (bank)) /*!< EXMC NAND/PC card control registers, bank = 1,2,3 */
  200. #define EXMC_NPINTEN(bank) REG32(EXMC + 0x44U + 0x20U * (bank)) /*!< EXMC NAND/PC card interrupt enable registers, bank = 1,2,3 */
  201. #define EXMC_NPCTCFG(bank) REG32(EXMC + 0x48U + 0x20U * (bank)) /*!< EXMC NAND/PC card common space timing configuration registers, bank = 1,2,3 */
  202. #define EXMC_NPATCFG(bank) REG32(EXMC + 0x4CU + 0x20U * (bank)) /*!< EXMC NAND/PC card attribute space timing configuration registers, bank = 1,2,3 */
  203. #define EXMC_NECC(bank) REG32(EXMC + 0x54U + 0x20U * (bank)) /*!< EXMC NAND ECC registers, bank = 1,2 */
  204. /* CRAM page size */
  205. #define SNCTL_CPS(regval) (BITS(16,18) & ((uint32_t)(regval) << 16))
  206. #define EXMC_CRAM_AUTO_SPLIT SNCTL_CPS(0) /*!< automatic burst split on page boundary crossing */
  207. #define EXMC_CRAM_PAGE_SIZE_128_BYTES SNCTL_CPS(1) /*!< page size is 128 bytes */
  208. #define EXMC_CRAM_PAGE_SIZE_256_BYTES SNCTL_CPS(2) /*!< page size is 256 bytes */
  209. #define EXMC_CRAM_PAGE_SIZE_512_BYTES SNCTL_CPS(3) /*!< page size is 512 bytes */
  210. #define EXMC_CRAM_PAGE_SIZE_1024_BYTES SNCTL_CPS(4) /*!< page size is 1024 bytes */
  211. /* NOR bank memory data bus width */
  212. #define SNCTL_NRW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
  213. #define EXMC_NOR_DATABUS_WIDTH_8B SNCTL_NRW(0) /*!< NOR data width is 8 bits */
  214. #define EXMC_NOR_DATABUS_WIDTH_16B SNCTL_NRW(1) /*!< NOR data width is 16 bits */
  215. /* NOR bank memory type */
  216. #define SNCTL_NRTP(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
  217. #define EXMC_MEMORY_TYPE_SRAM SNCTL_NRTP(0) /*!< SRAM,ROM */
  218. #define EXMC_MEMORY_TYPE_PSRAM SNCTL_NRTP(1) /*!< PSRAM,CRAM */
  219. #define EXMC_MEMORY_TYPE_NOR SNCTL_NRTP(2) /*!< NOR flash */
  220. /* asynchronous access mode */
  221. #define SNTCFG_ASYNCMOD(regval) (BITS(28,29) & ((uint32_t)(regval) << 28))
  222. #define EXMC_ACCESS_MODE_A SNTCFG_ASYNCMOD(0) /*!< mode A access */
  223. #define EXMC_ACCESS_MODE_B SNTCFG_ASYNCMOD(1) /*!< mode B access */
  224. #define EXMC_ACCESS_MODE_C SNTCFG_ASYNCMOD(2) /*!< mode C access */
  225. #define EXMC_ACCESS_MODE_D SNTCFG_ASYNCMOD(3) /*!< mode D access */
  226. /* data latency for NOR flash */
  227. #define SNTCFG_DLAT(regval) (BITS(24,27) & ((uint32_t)(regval) << 24))
  228. #define EXMC_DATALAT_2_CLK SNTCFG_DLAT(0) /*!< data latency of first burst access is 2 EXMC_CLK */
  229. #define EXMC_DATALAT_3_CLK SNTCFG_DLAT(1) /*!< data latency of first burst access is 3 EXMC_CLK */
  230. #define EXMC_DATALAT_4_CLK SNTCFG_DLAT(2) /*!< data latency of first burst access is 4 EXMC_CLK */
  231. #define EXMC_DATALAT_5_CLK SNTCFG_DLAT(3) /*!< data latency of first burst access is 5 EXMC_CLK */
  232. #define EXMC_DATALAT_6_CLK SNTCFG_DLAT(4) /*!< data latency of first burst access is 6 EXMC_CLK */
  233. #define EXMC_DATALAT_7_CLK SNTCFG_DLAT(5) /*!< data latency of first burst access is 7 EXMC_CLK */
  234. #define EXMC_DATALAT_8_CLK SNTCFG_DLAT(6) /*!< data latency of first burst access is 8 EXMC_CLK */
  235. #define EXMC_DATALAT_9_CLK SNTCFG_DLAT(7) /*!< data latency of first burst access is 9 EXMC_CLK */
  236. #define EXMC_DATALAT_10_CLK SNTCFG_DLAT(8) /*!< data latency of first burst access is 10 EXMC_CLK */
  237. #define EXMC_DATALAT_11_CLK SNTCFG_DLAT(9) /*!< data latency of first burst access is 11 EXMC_CLK */
  238. #define EXMC_DATALAT_12_CLK SNTCFG_DLAT(10) /*!< data latency of first burst access is 12 EXMC_CLK */
  239. #define EXMC_DATALAT_13_CLK SNTCFG_DLAT(11) /*!< data latency of first burst access is 13 EXMC_CLK */
  240. #define EXMC_DATALAT_14_CLK SNTCFG_DLAT(12) /*!< data latency of first burst access is 14 EXMC_CLK */
  241. #define EXMC_DATALAT_15_CLK SNTCFG_DLAT(13) /*!< data latency of first burst access is 15 EXMC_CLK */
  242. #define EXMC_DATALAT_16_CLK SNTCFG_DLAT(14) /*!< data latency of first burst access is 16 EXMC_CLK */
  243. #define EXMC_DATALAT_17_CLK SNTCFG_DLAT(15) /*!< data latency of first burst access is 17 EXMC_CLK */
  244. /* synchronous clock divide ratio */
  245. #define SNTCFG_CKDIV(regval) (BITS(20,23) & ((uint32_t)(regval) << 20))
  246. #define EXMC_SYN_CLOCK_RATIO_DISABLE SNTCFG_CKDIV(0) /*!< EXMC_CLK disable */
  247. #define EXMC_SYN_CLOCK_RATIO_2_CLK SNTCFG_CKDIV(1) /*!< EXMC_CLK = HCLK/2 */
  248. #define EXMC_SYN_CLOCK_RATIO_3_CLK SNTCFG_CKDIV(2) /*!< EXMC_CLK = HCLK/3 */
  249. #define EXMC_SYN_CLOCK_RATIO_4_CLK SNTCFG_CKDIV(3) /*!< EXMC_CLK = HCLK/4 */
  250. #define EXMC_SYN_CLOCK_RATIO_5_CLK SNTCFG_CKDIV(4) /*!< EXMC_CLK = HCLK/5 */
  251. #define EXMC_SYN_CLOCK_RATIO_6_CLK SNTCFG_CKDIV(5) /*!< EXMC_CLK = HCLK/6 */
  252. #define EXMC_SYN_CLOCK_RATIO_7_CLK SNTCFG_CKDIV(6) /*!< EXMC_CLK = HCLK/7 */
  253. #define EXMC_SYN_CLOCK_RATIO_8_CLK SNTCFG_CKDIV(7) /*!< EXMC_CLK = HCLK/8 */
  254. #define EXMC_SYN_CLOCK_RATIO_9_CLK SNTCFG_CKDIV(8) /*!< EXMC_CLK = HCLK/9 */
  255. #define EXMC_SYN_CLOCK_RATIO_10_CLK SNTCFG_CKDIV(9) /*!< EXMC_CLK = HCLK/10 */
  256. #define EXMC_SYN_CLOCK_RATIO_11_CLK SNTCFG_CKDIV(10) /*!< EXMC_CLK = HCLK/11 */
  257. #define EXMC_SYN_CLOCK_RATIO_12_CLK SNTCFG_CKDIV(11) /*!< EXMC_CLK = HCLK/12 */
  258. #define EXMC_SYN_CLOCK_RATIO_13_CLK SNTCFG_CKDIV(12) /*!< EXMC_CLK = HCLK/13 */
  259. #define EXMC_SYN_CLOCK_RATIO_14_CLK SNTCFG_CKDIV(13) /*!< EXMC_CLK = HCLK/14 */
  260. #define EXMC_SYN_CLOCK_RATIO_15_CLK SNTCFG_CKDIV(14) /*!< EXMC_CLK = HCLK/15 */
  261. #define EXMC_SYN_CLOCK_RATIO_16_CLK SNTCFG_CKDIV(15) /*!< EXMC_CLK = HCLK/16 */
  262. /* ECC size */
  263. #define NPCTL_ECCSZ(regval) (BITS(17,19) & ((uint32_t)(regval) << 17))
  264. #define EXMC_ECC_SIZE_256BYTES NPCTL_ECCSZ(0) /* ECC size is 256 bytes */
  265. #define EXMC_ECC_SIZE_512BYTES NPCTL_ECCSZ(1) /* ECC size is 512 bytes */
  266. #define EXMC_ECC_SIZE_1024BYTES NPCTL_ECCSZ(2) /* ECC size is 1024 bytes */
  267. #define EXMC_ECC_SIZE_2048BYTES NPCTL_ECCSZ(3) /* ECC size is 2048 bytes */
  268. #define EXMC_ECC_SIZE_4096BYTES NPCTL_ECCSZ(4) /* ECC size is 4096 bytes */
  269. #define EXMC_ECC_SIZE_8192BYTES NPCTL_ECCSZ(5) /* ECC size is 8192 bytes */
  270. /* ALE to RE delay */
  271. #define NPCTL_ATR(regval) (BITS(13,16) & ((uint32_t)(regval) << 13))
  272. #define EXMC_ALE_RE_DELAY_1_HCLK NPCTL_ATR(0) /* ALE to RE delay = 1*HCLK */
  273. #define EXMC_ALE_RE_DELAY_2_HCLK NPCTL_ATR(1) /* ALE to RE delay = 2*HCLK */
  274. #define EXMC_ALE_RE_DELAY_3_HCLK NPCTL_ATR(2) /* ALE to RE delay = 3*HCLK */
  275. #define EXMC_ALE_RE_DELAY_4_HCLK NPCTL_ATR(3) /* ALE to RE delay = 4*HCLK */
  276. #define EXMC_ALE_RE_DELAY_5_HCLK NPCTL_ATR(4) /* ALE to RE delay = 5*HCLK */
  277. #define EXMC_ALE_RE_DELAY_6_HCLK NPCTL_ATR(5) /* ALE to RE delay = 6*HCLK */
  278. #define EXMC_ALE_RE_DELAY_7_HCLK NPCTL_ATR(6) /* ALE to RE delay = 7*HCLK */
  279. #define EXMC_ALE_RE_DELAY_8_HCLK NPCTL_ATR(7) /* ALE to RE delay = 8*HCLK */
  280. #define EXMC_ALE_RE_DELAY_9_HCLK NPCTL_ATR(8) /* ALE to RE delay = 9*HCLK */
  281. #define EXMC_ALE_RE_DELAY_10_HCLK NPCTL_ATR(9) /* ALE to RE delay = 10*HCLK */
  282. #define EXMC_ALE_RE_DELAY_11_HCLK NPCTL_ATR(10) /* ALE to RE delay = 11*HCLK */
  283. #define EXMC_ALE_RE_DELAY_12_HCLK NPCTL_ATR(11) /* ALE to RE delay = 12*HCLK */
  284. #define EXMC_ALE_RE_DELAY_13_HCLK NPCTL_ATR(12) /* ALE to RE delay = 13*HCLK */
  285. #define EXMC_ALE_RE_DELAY_14_HCLK NPCTL_ATR(13) /* ALE to RE delay = 14*HCLK */
  286. #define EXMC_ALE_RE_DELAY_15_HCLK NPCTL_ATR(14) /* ALE to RE delay = 15*HCLK */
  287. #define EXMC_ALE_RE_DELAY_16_HCLK NPCTL_ATR(15) /* ALE to RE delay = 16*HCLK */
  288. /* CLE to RE delay */
  289. #define NPCTL_CTR(regval) (BITS(9,12) & ((uint32_t)(regval) << 9))
  290. #define EXMC_CLE_RE_DELAY_1_HCLK NPCTL_CTR(0) /* CLE to RE delay = 1*HCLK */
  291. #define EXMC_CLE_RE_DELAY_2_HCLK NPCTL_CTR(1) /* CLE to RE delay = 2*HCLK */
  292. #define EXMC_CLE_RE_DELAY_3_HCLK NPCTL_CTR(2) /* CLE to RE delay = 3*HCLK */
  293. #define EXMC_CLE_RE_DELAY_4_HCLK NPCTL_CTR(3) /* CLE to RE delay = 4*HCLK */
  294. #define EXMC_CLE_RE_DELAY_5_HCLK NPCTL_CTR(4) /* CLE to RE delay = 5*HCLK */
  295. #define EXMC_CLE_RE_DELAY_6_HCLK NPCTL_CTR(5) /* CLE to RE delay = 6*HCLK */
  296. #define EXMC_CLE_RE_DELAY_7_HCLK NPCTL_CTR(6) /* CLE to RE delay = 7*HCLK */
  297. #define EXMC_CLE_RE_DELAY_8_HCLK NPCTL_CTR(7) /* CLE to RE delay = 8*HCLK */
  298. #define EXMC_CLE_RE_DELAY_9_HCLK NPCTL_CTR(8) /* CLE to RE delay = 9*HCLK */
  299. #define EXMC_CLE_RE_DELAY_10_HCLK NPCTL_CTR(9) /* CLE to RE delay = 10*HCLK */
  300. #define EXMC_CLE_RE_DELAY_11_HCLK NPCTL_CTR(10) /* CLE to RE delay = 11*HCLK */
  301. #define EXMC_CLE_RE_DELAY_12_HCLK NPCTL_CTR(11) /* CLE to RE delay = 12*HCLK */
  302. #define EXMC_CLE_RE_DELAY_13_HCLK NPCTL_CTR(12) /* CLE to RE delay = 13*HCLK */
  303. #define EXMC_CLE_RE_DELAY_14_HCLK NPCTL_CTR(13) /* CLE to RE delay = 14*HCLK */
  304. #define EXMC_CLE_RE_DELAY_15_HCLK NPCTL_CTR(14) /* CLE to RE delay = 15*HCLK */
  305. #define EXMC_CLE_RE_DELAY_16_HCLK NPCTL_CTR(15) /* CLE to RE delay = 16*HCLK */
  306. /* NAND bank memory data bus width */
  307. #define NPCTL_NDW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
  308. #define EXMC_NAND_DATABUS_WIDTH_8B NPCTL_NDW(0) /*!< NAND data width is 8 bits */
  309. #define EXMC_NAND_DATABUS_WIDTH_16B NPCTL_NDW(1) /*!< NAND data width is 16 bits */
  310. /* EXMC NOR/SRAM bank region definition */
  311. #define EXMC_BANK0_NORSRAM_REGION0 ((uint32_t)0x00000000U) /*!< bank0 NOR/SRAM region0 */
  312. #define EXMC_BANK0_NORSRAM_REGION1 ((uint32_t)0x00000001U) /*!< bank0 NOR/SRAM region1 */
  313. #define EXMC_BANK0_NORSRAM_REGION2 ((uint32_t)0x00000002U) /*!< bank0 NOR/SRAM region2 */
  314. #define EXMC_BANK0_NORSRAM_REGION3 ((uint32_t)0x00000003U) /*!< bank0 NOR/SRAM region3 */
  315. /* EXMC NOR/SRAM write mode */
  316. #define EXMC_ASYN_WRITE ((uint32_t)0x00000000U) /*!< asynchronous write mode */
  317. #define EXMC_SYN_WRITE EXMC_SNCTL_SYNCWR /*!< synchronous write mode */
  318. /* EXMC NWAIT signal configuration */
  319. #define EXMC_NWAIT_CONFIG_BEFORE ((uint32_t)0x00000000U) /*!< NWAIT signal is active one data cycle before wait state */
  320. #define EXMC_NWAIT_CONFIG_DURING EXMC_SNCTL_NRWTCFG /*!< NWAIT signal is active during wait state */
  321. /* EXMC NWAIT signal polarity configuration */
  322. #define EXMC_NWAIT_POLARITY_LOW ((uint32_t)0x00000000U) /*!< low level is active of NWAIT */
  323. #define EXMC_NWAIT_POLARITY_HIGH EXMC_SNCTL_NRWTPOL /*!< high level is active of NWAIT */
  324. /* EXMC NAND/PC card bank definition */
  325. #define EXMC_BANK1_NAND ((uint32_t)0x00000001U) /*!< bank1 NAND flash */
  326. #define EXMC_BANK2_NAND ((uint32_t)0x00000002U) /*!< bank2 NAND flash */
  327. #define EXMC_BANK3_PCCARD ((uint32_t)0x00000003U) /*!< bank3 PC card */
  328. /* EXMC flag bits */
  329. #define EXMC_NAND_PCCARD_FLAG_RISE EXMC_NPINTEN_INTRS /*!< interrupt rising edge status */
  330. #define EXMC_NAND_PCCARD_FLAG_LEVEL EXMC_NPINTEN_INTHS /*!< interrupt high-level status */
  331. #define EXMC_NAND_PCCARD_FLAG_FALL EXMC_NPINTEN_INTFS /*!< interrupt falling edge status */
  332. #define EXMC_NAND_PCCARD_FLAG_FIFOE EXMC_NPINTEN_FFEPT /*!< FIFO empty flag */
  333. /* EXMC interrupt flag bits */
  334. #define EXMC_NAND_PCCARD_INT_FLAG_RISE EXMC_NPINTEN_INTREN /*!< rising edge interrupt and flag */
  335. #define EXMC_NAND_PCCARD_INT_FLAG_LEVEL EXMC_NPINTEN_INTHEN /*!< high-level interrupt and flag */
  336. #define EXMC_NAND_PCCARD_INT_FLAG_FALL EXMC_NPINTEN_INTFEN /*!< falling edge interrupt and flag */
  337. /* function declarations */
  338. /* initialization functions */
  339. /* NOR/SRAM */
  340. /* deinitialize EXMC NOR/SRAM region */
  341. void exmc_norsram_deinit(uint32_t exmc_norsram_region);
  342. /* initialize exmc_norsram_parameter_struct with the default values */
  343. void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
  344. /* initialize EXMC NOR/SRAM region */
  345. void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
  346. /* enable EXMC NOR/SRAM region */
  347. void exmc_norsram_enable(uint32_t exmc_norsram_region);
  348. /* disable EXMC NOR/SRAM region */
  349. void exmc_norsram_disable(uint32_t exmc_norsram_region);
  350. /* NAND */
  351. /* deinitialize EXMC NAND bank */
  352. void exmc_nand_deinit(uint32_t exmc_nand_bank);
  353. /* initialize exmc_norsram_parameter_struct with the default values */
  354. void exmc_nand_struct_para_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
  355. /* initialize EXMC NAND bank */
  356. void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
  357. /* enable EXMC NAND bank */
  358. void exmc_nand_enable(uint32_t exmc_nand_bank);
  359. /* disable EXMC NAND bank */
  360. void exmc_nand_disable(uint32_t exmc_nand_bank);
  361. /* PC card */
  362. /* deinitialize EXMC PC card bank */
  363. void exmc_pccard_deinit(void);
  364. /* initialize exmc_pccard_parameter_struct parameter with the default values */
  365. void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
  366. /* initialize EXMC PC card bank */
  367. void exmc_pccard_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
  368. /* enable EXMC PC card bank */
  369. void exmc_pccard_enable(void);
  370. /* disable EXMC PC card bank */
  371. void exmc_pccard_disable(void);
  372. /* function configuration */
  373. /* NOR/SRAM */
  374. /* configure CRAM page size */
  375. void exmc_norsram_page_size_config(uint32_t exmc_norsram_region, uint32_t page_size);
  376. /* NAND */
  377. /* enable or disable the EXMC NAND ECC function */
  378. void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue);
  379. /* get the EXMC ECC value */
  380. uint32_t exmc_ecc_get(uint32_t exmc_nand_bank);
  381. /* interrupt & flag functions */
  382. /* enable EXMC interrupt */
  383. void exmc_interrupt_enable(uint32_t exmc_bank,uint32_t interrupt);
  384. /* disable EXMC interrupt */
  385. void exmc_interrupt_disable(uint32_t exmc_bank,uint32_t interrupt);
  386. /* get EXMC flag status */
  387. FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag);
  388. /* clear EXMC flag status */
  389. void exmc_flag_clear(uint32_t exmc_bank,uint32_t flag);
  390. /* get EXMC interrupt flag */
  391. FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank,uint32_t interrupt);
  392. /* clear EXMC interrupt flag */
  393. void exmc_interrupt_flag_clear(uint32_t exmc_bank,uint32_t interrupt);
  394. #endif /* GD32F30X_EXMC_H */