gd32f4xx_exmc.h 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /*!
  2. \file gd32f4xx_exmc.h
  3. \brief definitions for the EXMC
  4. */
  5. /*
  6. Copyright (C) 2016 GigaDevice
  7. 2016-08-15, V1.0.0, firmware for GD32F4xx
  8. */
  9. #ifndef GD32F4XX_EXMC_H
  10. #define GD32F4XX_EXMC_H
  11. #include "gd32f4xx.h"
  12. /* EXMC definitions */
  13. #define EXMC (EXMC_BASE) /*!< EXMC register base address */
  14. #define EXMC_NOR_PSRAM (EXMC_BASE - 0x40000000) /*!< EXMC NOR/PSRAM base address */
  15. #define EXMC_NAND (EXMC_BASE - 0x30000000) /*!< EXMC NAND base address */
  16. #define EXMC_PCCARD (EXMC_BASE - 0x10000000) /*!< EXMC PC card base address */
  17. #define EXMC_SDRAM (EXMC_BASE + 0x20000000) /*!< EXMC SDRAM base address */
  18. /* registers definitions */
  19. /* NOR/PSRAM */
  20. #define EXMC_SNCTL0 REG32(EXMC + 0x00U) /*!< EXMC SRAM/NOR flash control register */
  21. #define EXMC_SNTCFG0 REG32(EXMC + 0x04U) /*!< EXMC SRAM/NOR flash timing configuration register */
  22. #define EXMC_SNWTCFG0 REG32(EXMC + 0x104U) /*!< EXMC SRAM/NOR flash write timing configuration register */
  23. #define EXMC_SNCTL1 REG32(EXMC + 0x08U) /*!< EXMC SRAM/NOR flash control register */
  24. #define EXMC_SNTCFG1 REG32(EXMC + 0x0CU) /*!< EXMC SRAM/NOR flash timing configuration register */
  25. #define EXMC_SNWTCFG1 REG32(EXMC + 0x10CU) /*!< EXMC SRAM/NOR flash write timing configuration register */
  26. #define EXMC_SNCTL2 REG32(EXMC + 0x10U) /*!< EXMC SRAM/NOR flash control register */
  27. #define EXMC_SNTCFG2 REG32(EXMC + 0x14U) /*!< EXMC SRAM/NOR flash timing configuration register */
  28. #define EXMC_SNWTCFG2 REG32(EXMC + 0x114U) /*!< EXMC SRAM/NOR flash write timing configuration register */
  29. #define EXMC_SNCTL3 REG32(EXMC + 0x18U) /*!< EXMC SRAM/NOR flash control register */
  30. #define EXMC_SNTCFG3 REG32(EXMC + 0x1CU) /*!< EXMC SRAM/NOR flash timing configuration register */
  31. #define EXMC_SNWTCFG3 REG32(EXMC + 0x11CU) /*!< EXMC SRAM/NOR flash write timing configuration register */
  32. /* NAND/PC card */
  33. #define EXMC_NPCTL1 REG32(EXMC + 0x40U) /*!< EXMC NAND/PC card control register */
  34. #define EXMC_NPINTEN1 REG32(EXMC + 0x44U) /*!< EXMC NAND/PC card interrupt enable register */
  35. #define EXMC_NPCTCFG1 REG32(EXMC + 0x48U) /*!< EXMC NAND/PC card common space timing configuration register */
  36. #define EXMC_NPATCFG1 REG32(EXMC + 0x4CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
  37. #define EXMC_NECC1 REG32(EXMC + 0x54U) /*!< EXMC NAND ECC register */
  38. #define EXMC_NPCTL2 REG32(EXMC + 0x60U) /*!< EXMC NAND/PC card control register */
  39. #define EXMC_NPINTEN2 REG32(EXMC + 0x64U) /*!< EXMC NAND/PC card interrupt enable register */
  40. #define EXMC_NPCTCFG2 REG32(EXMC + 0x68U) /*!< EXMC NAND/PC card common space timing configuration register */
  41. #define EXMC_NPATCFG2 REG32(EXMC + 0x6CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
  42. #define EXMC_NECC2 REG32(EXMC + 0x74U) /*!< EXMC NAND ECC register */
  43. #define EXMC_NPCTL3 REG32(EXMC + 0x80U) /*!< EXMC NAND/PC card control register */
  44. #define EXMC_NPINTEN3 REG32(EXMC + 0x84U) /*!< EXMC NAND/PC card interrupt enable register */
  45. #define EXMC_NPCTCFG3 REG32(EXMC + 0x88U) /*!< EXMC NAND/PC card common space timing configuration register */
  46. #define EXMC_NPATCFG3 REG32(EXMC + 0x8CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
  47. #define EXMC_PIOTCFG3 REG32(EXMC + 0xB0U) /*!< EXMC PC card I/O space timing configuration register */
  48. /* SDRAM */
  49. #define EXMC_SDCTL0 REG32(EXMC + 0x140U) /*!< EXMC SDRAM control register */
  50. #define EXMC_SDTCFG0 REG32(EXMC + 0x148U) /*!< EXMC SDRAM timing configuration register register */
  51. #define EXMC_SDCTL1 REG32(EXMC + 0x144U) /*!< EXMC SDRAM control register */
  52. #define EXMC_SDTCFG1 REG32(EXMC + 0x14CU) /*!< EXMC SDRAM timing configuration register register */
  53. #define EXMC_SDCMD REG32(EXMC + 0x150U) /*!< EXMC SDRAM command register */
  54. #define EXMC_SDARI REG32(EXMC + 0x154U) /*!< EXMC SDRAM auto-refresh interval register */
  55. #define EXMC_SDSTAT REG32(EXMC + 0x158U) /*!< EXMC SDRAM status register */
  56. #define EXMC_SDRSCTL REG32(EXMC + 0x180U) /*!< EXMC SDRAM read sample control register */
  57. /* SQPI PSRAM */
  58. #define EXMC_SINIT REG32(EXMC + 0x310U) /*!< EXMC SPI initialization register */
  59. #define EXMC_SRCMD REG32(EXMC + 0x320U) /*!< EXMC SPI read command register */
  60. #define EXMC_SWCMD REG32(EXMC + 0x330U) /*!< EXMC SPI write command register */
  61. #define EXMC_SIDL REG32(EXMC + 0x340U) /*!< EXMC SPI ID low register */
  62. #define EXMC_SIDH REG32(EXMC + 0x350U) /*!< EXMC SPI ID high register */
  63. /* bits definitions */
  64. /* EXMC_SNCTLx,x=0..3 */
  65. #define EXMC_SNCTL_NRBKEN BIT(0) /*!< NOR bank enable */
  66. #define EXMC_SNCTL_NRMUX BIT(1) /*!< NOR bank memory address/data multiplexing */
  67. #define EXMC_SNCTL_NRTP BITS(2,3) /*!< NOR bank memory type */
  68. #define EXMC_SNCTL_NRW BITS(4,5) /*!< NOR bank memory data bus width */
  69. #define EXMC_SNCTL_NREN BIT(6) /*!< NOR flash access enable */
  70. #define EXMC_SNCTL_SBRSTEN BIT(8) /*!< synchronous burst enable */
  71. #define EXMC_SNCTL_NRWTPOL BIT(9) /*!< NWAIT signal polarity */
  72. #define EXMC_SNCTL_WRAPEN BIT(10) /*!< wrapped burst mode enable */
  73. #define EXMC_SNCTL_NRWTCFG BIT(11) /*!< NWAIT signal configuration, only work in synchronous mode */
  74. #define EXMC_SNCTL_WREN BIT(12) /*!< write enable */
  75. #define EXMC_SNCTL_NRWTEN BIT(13) /*!< NWAIT signal enable */
  76. #define EXMC_SNCTL_EXMODEN BIT(14) /*!< extended mode enable */
  77. #define EXMC_SNCTL_ASYNCWAIT BIT(15) /*!< asynchronous wait */
  78. #define EXMC_SNCTL_CPS BITS(16,18) /*!< CRAM page size */
  79. #define EXMC_SNCTL_SYNCWR BIT(19) /*!< synchronous write */
  80. #define EXMC_SNCTL_CCK BIT(20) /*!< consecutive clock */
  81. /* EXMC_SNTCFGx,x=0..3 */
  82. #define EXMC_SNTCFG_ASET BITS(0,3) /*!< address setup time */
  83. #define EXMC_SNTCFG_AHLD BITS(4,7) /*!< address hold time */
  84. #define EXMC_SNTCFG_DSET BITS(8,15) /*!< data setup time */
  85. #define EXMC_SNTCFG_BUSLAT BITS(16,19) /*!< bus latency */
  86. #define EXMC_SNTCFG_CKDIV BITS(20,23) /*!< synchronous clock divide ratio */
  87. #define EXMC_SNTCFG_DLAT BITS(24,27) /*!< data latency for NOR flash */
  88. #define EXMC_SNTCFG_ASYNCMOD BITS(28,29) /*!< asynchronous access mode */
  89. /* EXMC_SNWTCFGx,x=0..3 */
  90. #define EXMC_SNWTCFG_WASET BITS(0,3) /*!< address setup time */
  91. #define EXMC_SNWTCFG_WAHLD BITS(4,7) /*!< address hold time */
  92. #define EXMC_SNWTCFG_WDSET BITS(8,15) /*!< data setup time */
  93. #define EXMC_SNWTCFG_WBUSLAT BITS(16,19) /*!< bus latency */
  94. #define EXMC_SNWTCFG_WASYNCMOD BITS(28,29) /*!< asynchronous access mode */
  95. /* EXMC_NPCTLx,x=1..3 */
  96. #define EXMC_NPCTL_NDWTEN BIT(1) /*!< wait feature enable */
  97. #define EXMC_NPCTL_NDBKEN BIT(2) /*!< NAND bank enable */
  98. #define EXMC_NPCTL_NDTP BIT(3) /*!< NAND bank memory type */
  99. #define EXMC_NPCTL_NDW BITS(4,5) /*!< NAND bank memory data bus width */
  100. #define EXMC_NPCTL_ECCEN BIT(6) /*!< ECC enable */
  101. #define EXMC_NPCTL_CTR BITS(9,12) /*!< CLE to RE delay */
  102. #define EXMC_NPCTL_ATR BITS(13,16) /*!< ALE to RE delay */
  103. #define EXMC_NPCTL_ECCSZ BITS(17,19) /*!< ECC size */
  104. /* EXMC_NPINTENx,x=1..3 */
  105. #define EXMC_NPINTEN_INTRS BIT(0) /*!< interrupt rising edge status */
  106. #define EXMC_NPINTEN_INTHS BIT(1) /*!< interrupt high-level status */
  107. #define EXMC_NPINTEN_INTFS BIT(2) /*!< interrupt falling edge status */
  108. #define EXMC_NPINTEN_INTREN BIT(3) /*!< interrupt rising edge detection enable */
  109. #define EXMC_NPINTEN_INTHEN BIT(4) /*!< interrupt high-level detection enable */
  110. #define EXMC_NPINTEN_INTFEN BIT(5) /*!< interrupt falling edge detection enable */
  111. #define EXMC_NPINTEN_INTEPT BIT(6) /*!< FIFO empty flag */
  112. /* EXMC_NPCTCFGx,x=1..3 */
  113. #define EXMC_NPCTCFG_COMSET BITS(0,7) /*!< common memory data bus HiZ time */
  114. #define EXMC_NPCTCFG_COMWAIT BITS(8,15) /*!< common memory hold time */
  115. #define EXMC_NPCTCFG_COMHLD BITS(16,23) /*!< common memory wait time */
  116. #define EXMC_NPCTCFG_COMHIZ BITS(24,31) /*!< common memory setup time */
  117. /* EXMC_NPATCFGx,x=1..3 */
  118. #define EXMC_NPATCFG_ATTSET BITS(0,7) /*!< attribute memory data bus HiZ time */
  119. #define EXMC_NPATCFG_ATTWAIT BITS(8,15) /*!< attribute memory hold time */
  120. #define EXMC_NPATCFG_ATTHLD BITS(16,23) /*!< attribute memory wait time */
  121. #define EXMC_NPATCFG_ATTHIZ BITS(24,31) /*!< attribute memory setup time */
  122. /* EXMC_PIOTCFG3 */
  123. #define EXMC_PIOTCFG3_IOSET BITS(0,7) /*!< IO space data bus HiZ time */
  124. #define EXMC_PIOTCFG3_IOWAIT BITS(8,15) /*!< IO space hold time */
  125. #define EXMC_PIOTCFG3_IOHLD BITS(16,23) /*!< IO space wait time */
  126. #define EXMC_PIOTCFG3_IOHIZ BITS(24,31) /*!< IO space setup time */
  127. /* EXMC_NECCx,x=1..2 */
  128. #define EXMC_NECC_ECC BITS(0,31) /*!< ECC result */
  129. /* EXMC_SDCTLx,x=0..1 */
  130. #define EXMC_SDCTL_CAW BITS(0,1) /*!< column address bit width */
  131. #define EXMC_SDCTL_RAW BITS(2,3) /*!< row address bit width */
  132. #define EXMC_SDCTL_SDW BITS(4,5) /*!< SDRAM data bus width */
  133. #define EXMC_SDCTL_NBK BIT(6) /*!< number of banks */
  134. #define EXMC_SDCTL_CL BIT(7,8) /*!< CAS Latency */
  135. #define EXMC_SDCTL_WPEN BIT(9) /*!< write protection enable */
  136. #define EXMC_SDCTL_SDCLK BITS(10,11) /*!< SDRAM clock configuration */
  137. #define EXMC_SDCTL_BRSTRD BIT(12) /*!< burst read */
  138. #define EXMC_SDCTL_PIPED BITS(13,14) /*!< pipeline delay */
  139. /* EXMC_SDTCFGx,x=0..1 */
  140. #define EXMC_SDTCFG_LMRD BITS(0,3) /*!< load mode register delay */
  141. #define EXMC_SDTCFG_XSRD BITS(4,7) /*!< exit self-refresh delay */
  142. #define EXMC_SDTCFG_RASD BITS(8,11) /*!< row address select delay */
  143. #define EXMC_SDTCFG_ARFD BITS(12,15) /*!< auto refresh delay */
  144. #define EXMC_SDTCFG_WRD BITS(16,19) /*!< write recovery delay */
  145. #define EXMC_SDTCFG_RPD BITS(20,23) /*!< row precharge delay */
  146. #define EXMC_SDTCFG_RCD BITS(24,27) /*!< row to column delay */
  147. /* EXMC_SDCMD */
  148. #define EXMC_SDCMD_CMD BITS(0,2) /*!< command */
  149. #define EXMC_SDCMD_DS1 BIT(3) /*!< device select 1 */
  150. #define EXMC_SDCMD_DS0 BIT(4) /*!< device select 0 */
  151. #define EXMC_SDCMD_NARF BITS(5,8) /*!< number of successive auto-refresh */
  152. #define EXMC_SDCMD_MRC BITS(9,21) /*!< mode register content */
  153. /* EXMC_SDARI */
  154. #define EXMC_SDARI_REC BIT(0) /*!< refresh error flag clear */
  155. #define EXMC_SDARI_ARINTV BITS(1,13) /*!< auto-refresh interval */
  156. #define EXMC_SDARI_REIE BIT(14) /*!< interrupt refresh error enable */
  157. /* EXMC_SDSTAT */
  158. #define EXMC_SDSDAT_REIF BIT(0) /*!< refresh error interrupt flag */
  159. #define EXMC_SDSDAT_STA0 BITS(1,2) /*!< device 0 status */
  160. #define EXMC_SDSDAT_STA1 BITS(3,4) /*!< device 1 status */
  161. #define EXMC_SDSDAT_NRDY BIT(5) /*!< not ready status */
  162. /* EXMC_SDRSCTL */
  163. #define EXMC_SDRSCTL_RSEN BIT(0) /*!< read sample enable */
  164. #define EXMC_SDRSCTL_SSCR BIT(1) /*!< select sample cycle of read data */
  165. #define EXMC_SDRSCTL_SDSC BITS(4,7) /*!< select the delayed sample clock of read data */
  166. /* EXMC_SINIT */
  167. #define EXMC_SINIT_CMDBIT BITS(16,17) /*!< bit number of SPI PSRAM command phase */
  168. #define EXMC_SINIT_ARDBIT BITS(24,28) /*!< bit number of SPI PSRAM address phase */
  169. #define EXMC_SINIT_IDL BITS(29,30) /*!< SPI PSRAM ID length */
  170. #define EXMC_SINIT_POL BIT(31) /*!< read data sample polarity */
  171. /* EXMC_SRCMD */
  172. #define EXMC_SRCMD_RCMD BITS(0,15) /*!< SPI read command for AHB read transfer */
  173. #define EXMC_SRCMD_RWAITCYCLE BITS(16,19) /*!< SPI read wait cycle number after address phase */
  174. #define EXMC_SRCMD_RMODE BITS(20,21) /*!< SPI PSRAM read command mode */
  175. #define EXMC_SRCMD_RDID BIT(31) /*!< send SPI read ID command */
  176. /* EXMC_SWCMD */
  177. #define EXMC_SWCMD_WCMD BITS(0,15) /*!< send SPI special command */
  178. #define EXMC_SWCMD_WWAITCYCLE BITS(16,19) /*!< SPI PSRAM write command mode */
  179. #define EXMC_SWCMD_WMODE BITS(20,21) /*!< SPI write wait cycle number after address phase */
  180. #define EXMC_SWCMD_SC BIT(31) /*!< SPI write command for AHB write transfer */
  181. /* EXMC_SIDL */
  182. #define EXMC_SIDL_SIDL BITS(0,31) /*!< ID low data saved for SPI read ID command */
  183. /* EXMC_SIDH */
  184. #define EXMC_SIDL_SIDH BITS(0,31) /*!< ID high Data saved for SPI read ID command */
  185. /* constants definitions */
  186. /* EXMC NOR/SRAM timing initialize struct */
  187. typedef struct
  188. {
  189. uint32_t asyn_access_mode; /*!< asynchronous access mode */
  190. uint32_t syn_data_latency; /*!< configure the data latency */
  191. uint32_t syn_clk_division; /*!< configure the clock divide ratio */
  192. uint32_t bus_latency; /*!< configure the bus latency */
  193. uint32_t asyn_data_setuptime; /*!< configure the data setup time,asynchronous access mode valid */
  194. uint32_t asyn_address_holdtime; /*!< configure the address hold time,asynchronous access mode valid */
  195. uint32_t asyn_address_setuptime; /*!< configure the data setup time,asynchronous access mode valid */
  196. }exmc_norsram_timing_parameter_struct;
  197. /* EXMC NOR/SRAM initialize struct */
  198. typedef struct
  199. {
  200. uint32_t norsram_region; /*!< select the region of EXMC NOR/SRAM bank */
  201. uint32_t write_mode; /*!< the write mode, synchronous mode or asynchronous mode */
  202. uint32_t extended_mode; /*!< enable or disable the extended mode */
  203. uint32_t asyn_wait; /*!< enable or disable the asynchronous wait function */
  204. uint32_t nwait_signal; /*!< enable or disable the NWAIT signal while in synchronous bust mode */
  205. uint32_t memory_write; /*!< enable or disable the write operation */
  206. uint32_t nwait_config; /*!< NWAIT signal configuration */
  207. uint32_t wrap_burst_mode; /*!< enable or disable the wrap burst mode */
  208. uint32_t nwait_polarity; /*!< specifies the polarity of NWAIT signal from memory */
  209. uint32_t burst_mode; /*!< enable or disable the burst mode */
  210. uint32_t databus_width; /*!< specifies the databus width of external memory */
  211. uint32_t memory_type; /*!< specifies the type of external memory */
  212. uint32_t address_data_mux; /*!< specifies whether the data bus and address bus are multiplexed */
  213. exmc_norsram_timing_parameter_struct* read_write_timing; /*!< timing parameters for read and write if the extendedmode is not used or the timing
  214. parameters for read if the extendedmode is used. */
  215. exmc_norsram_timing_parameter_struct* write_timing; /*!< timing parameters for write when the extendedmode is used. */
  216. }exmc_norsram_parameter_struct;
  217. /* EXMC NAND/PC card timing initialize struct */
  218. typedef struct
  219. {
  220. uint32_t databus_hiztime; /*!< configure the dadtabus HiZ time for write operation */
  221. uint32_t holdtime; /*!< configure the address hold time(or the data hold time for write operation) */
  222. uint32_t waittime; /*!< configure the minimum wait time */
  223. uint32_t setuptime; /*!< configure the address setup time */
  224. }exmc_nand_pccard_timing_parameter_struct;
  225. /* EXMC NAND initialize struct */
  226. typedef struct
  227. {
  228. uint32_t nand_bank; /*!< select the bank of NAND */
  229. uint32_t ecc_size; /*!< the page size for the ECC calculation */
  230. uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
  231. uint32_t ctr_latency; /*!< configure the latency of CLE low to RB low */
  232. uint32_t ecc_logic; /*!< enable or disable the ECC calculation logic */
  233. uint32_t databus_width; /*!< the NAND flash databus width */
  234. uint32_t wait_feature; /*!< enables or disables the wait feature */
  235. exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for NAND flash Common Space */
  236. exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for NAND flash Attribute Space */
  237. }exmc_nand_parameter_struct;
  238. /* EXMC PC card initialize struct */
  239. typedef struct
  240. {
  241. uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
  242. uint32_t ctr_latency; /*!< configure the latency of CLE low to RB low */
  243. uint32_t wait_feature; /*!< enables or disables the Wait feature */
  244. exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for NAND flash Common Space */
  245. exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for NAND flash Attribute Space */
  246. exmc_nand_pccard_timing_parameter_struct* io_space_timing; /*!< the timing parameters for NAND flash IO Space */
  247. }exmc_pccard_parameter_struct;;
  248. /* EXMC SDRAM timing initialize struct */
  249. typedef struct
  250. {
  251. uint32_t row_to_column_delay; /*!< configure the row to column delay */
  252. uint32_t row_precharge_delay; /*!< configure the row precharge delay */
  253. uint32_t write_recovery_delay; /*!< configure the write recovery delay */
  254. uint32_t auto_refresh_delay; /*!< configure the auto refresh delay */
  255. uint32_t row_address_select_delay; /*!< configure the row address select delay */
  256. uint32_t exit_selfrefresh_delay; /*!< configure the exit self-refresh delay */
  257. uint32_t load_mode_register_delay; /*!< configure the load mode register delay */
  258. }exmc_sdram_timing_parameter_struct;
  259. /* EXMC SDRAM initialize struct */
  260. typedef struct
  261. {
  262. uint32_t sdram_device; /*!< device of SDRAM */
  263. uint32_t pipeline_read_delay; /*!< the delay for reading data after CAS latency in HCLK clock cycles */
  264. uint32_t brust_read_switch; /*!< enable or disable the burst read */
  265. uint32_t sdclock_config; /*!< the SDCLK memory clock for both SDRAM banks */
  266. uint32_t write_protection; /*!< enable or disable SDRAM bank write protection function */
  267. uint32_t cas_latency; /*!< configure the SDRAM CAS latency */
  268. uint32_t internal_bank_number; /*!< the number internal banks */
  269. uint32_t data_width; /*!< the databus width of SDRAM memory */
  270. uint32_t row_address_width; /*!< the bit width of a row address */
  271. uint32_t column_address_width; /*!< the bit width of a column address */
  272. exmc_sdram_timing_parameter_struct* timing; /*!< the timing parameters for write and read SDRAM */
  273. }exmc_sdram_parameter_struct;
  274. /* EXMC SDRAM command initialize struct */
  275. typedef struct
  276. {
  277. uint32_t mode_register_content; /*!< the SDRAM mode register content */
  278. uint32_t auto_refresh_number; /*!< the number of successive auto-refresh cycles will be send when CMD = 011 */
  279. uint32_t bank_select; /*!< the bank which command will be sent to */
  280. uint32_t command; /*!< the commands that will be sent to SDRAM */
  281. }exmc_sdram_command_parameter_struct;
  282. /* EXMC SQPISRAM initialize struct */
  283. typedef struct{
  284. uint32_t sample_polarity; /*!< read data sample polarity */
  285. uint32_t id_length; /*!< SPI PSRAM ID length */
  286. uint32_t address_bits; /*!< bit number of SPI PSRAM address phase */
  287. uint32_t command_bits; /*!< bit number of SPI PSRAM command phase */
  288. }exmc_sqpipsram_parameter_struct;
  289. /* EXMC_register address */
  290. #define EXMC_SNCTL(bank) REG32(EXMC + 0x08U*((uint32_t)(bank))) /*!< EXMC SRAM/NOR flash control register */
  291. #define EXMC_SNTCFG(bank) REG32(EXMC + 0x04U + 0x08U*(bank)) /*!< EXMC SRAM/NOR flash timing configuration register */
  292. #define EXMC_SNWTCFG(bank) REG32(EXMC + 0x104U + 0x08U*(bank)) /*!< EXMC SRAM/NOR flash write timing configuration register */
  293. #define EXMC_NPCTL(bank) REG32(EXMC + 0x40U + 0x20U*(bank)) /*!< EXMC NAND/PC card control register */
  294. #define EXMC_NPINTEN(bank) REG32(EXMC + 0x44U + 0x20U*(bank)) /*!< EXMC NAND/PC card interrupt enable register */
  295. #define EXMC_NPCTCFG(bank) REG32(EXMC + 0x48U + 0x20U*(bank)) /*!< EXMC NAND/PC card common space timing configuration register */
  296. #define EXMC_NPATCFG(bank) REG32(EXMC + 0x4CU + 0x20U*(bank)) /*!< EXMC NAND/PC card attribute space timing configuration register */
  297. #define EXMC_NECC(bank) REG32(EXMC + 0x54U + 0x20U*(bank)) /*!< EXMC NAND ECC register */
  298. #define EXMC_SDCTL(bank) REG32(EXMC + 0x140U + 0x4U*((bank) - 0x4U)) /*!< EXMC SDRAM control register */
  299. #define EXMC_SDTCFG(bank) REG32(EXMC + 0x148U + 0x4U*((bank) - 0x4U)) /*!< EXMC SDRAM timing configuration register */
  300. /* CRAM page size */
  301. #define SNCTL_CPS(regval) (BITS(16,18) & ((uint32_t)(regval) << 16))
  302. #define EXMC_CRAM_AUTO_SPLIT SNCTL_CPS(0) /*!< automatic burst split on page boundary crossing */
  303. #define EXMC_CRAM_PAGE_SIZE_128_BYTES SNCTL_CPS(1) /*!< page size is 128 bytes */
  304. #define EXMC_CRAM_PAGE_SIZE_256_BYTES SNCTL_CPS(2) /*!< page size is 256 bytes */
  305. #define EXMC_CRAM_PAGE_SIZE_512_BYTES SNCTL_CPS(3) /*!< page size is 512 bytes */
  306. #define EXMC_CRAM_PAGE_SIZE_1024_BYTES SNCTL_CPS(4) /*!< page size is 1024 bytes */
  307. /* NOR bank memory data bus width */
  308. #define SNCTL_NRW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
  309. #define EXMC_NOR_DATABUS_WIDTH_8B SNCTL_NRW(0) /*!< NOR data width 8 bits */
  310. #define EXMC_NOR_DATABUS_WIDTH_16B SNCTL_NRW(1) /*!< NOR data width 16 bits */
  311. /* NOR bank memory type */
  312. #define SNCTL_NRTP(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
  313. #define EXMC_MEMORY_TYPE_SRAM SNCTL_NRTP(0) /*!< SRAM,ROM */
  314. #define EXMC_MEMORY_TYPE_PSRAM SNCTL_NRTP(1) /*!< PSRAM,CRAM */
  315. #define EXMC_MEMORY_TYPE_NOR SNCTL_NRTP(2) /*!< NOR flash */
  316. /* asynchronous access mode */
  317. #define SNTCFG_ASYNCMOD(regval) (BITS(28,29) & ((uint32_t)(regval) << 28))
  318. #define EXMC_ACCESS_MODE_A SNTCFG_ASYNCMOD(0) /*!< mode A access */
  319. #define EXMC_ACCESS_MODE_B SNTCFG_ASYNCMOD(1) /*!< mode B access */
  320. #define EXMC_ACCESS_MODE_C SNTCFG_ASYNCMOD(2) /*!< mode C access */
  321. #define EXMC_ACCESS_MODE_D SNTCFG_ASYNCMOD(3) /*!< mode D access */
  322. /* data latency for NOR flash */
  323. #define SNTCFG_DLAT(regval) (BITS(24,27) & ((uint32_t)(regval) << 24))
  324. #define EXMC_DATALAT_2_CLK SNTCFG_DLAT(0) /*!< data latency 2 EXMC_CLK */
  325. #define EXMC_DATALAT_3_CLK SNTCFG_DLAT(1) /*!< data latency 3 EXMC_CLK */
  326. #define EXMC_DATALAT_4_CLK SNTCFG_DLAT(2) /*!< data latency 4 EXMC_CLK */
  327. #define EXMC_DATALAT_5_CLK SNTCFG_DLAT(3) /*!< data latency 5 EXMC_CLK */
  328. #define EXMC_DATALAT_6_CLK SNTCFG_DLAT(4) /*!< data latency 6 EXMC_CLK */
  329. #define EXMC_DATALAT_7_CLK SNTCFG_DLAT(5) /*!< data latency 7 EXMC_CLK */
  330. #define EXMC_DATALAT_8_CLK SNTCFG_DLAT(6) /*!< data latency 8 EXMC_CLK */
  331. #define EXMC_DATALAT_9_CLK SNTCFG_DLAT(7) /*!< data latency 9 EXMC_CLK */
  332. #define EXMC_DATALAT_10_CLK SNTCFG_DLAT(8) /*!< data latency 10 EXMC_CLK */
  333. #define EXMC_DATALAT_11_CLK SNTCFG_DLAT(9) /*!< data latency 11 EXMC_CLK */
  334. #define EXMC_DATALAT_12_CLK SNTCFG_DLAT(10) /*!< data latency 12 EXMC_CLK */
  335. #define EXMC_DATALAT_13_CLK SNTCFG_DLAT(11) /*!< data latency 13 EXMC_CLK */
  336. #define EXMC_DATALAT_14_CLK SNTCFG_DLAT(12) /*!< data latency 14 EXMC_CLK */
  337. #define EXMC_DATALAT_15_CLK SNTCFG_DLAT(13) /*!< data latency 15 EXMC_CLK */
  338. #define EXMC_DATALAT_16_CLK SNTCFG_DLAT(14) /*!< data latency 16 EXMC_CLK */
  339. #define EXMC_DATALAT_17_CLK SNTCFG_DLAT(15) /*!< data latency 17 EXMC_CLK */
  340. /* synchronous clock divide ratio */
  341. #define SNTCFG_CKDIV(regval) (BITS(20,23) & ((uint32_t)(regval) << 20))
  342. #define EXMC_SYN_CLOCK_RATIO_DISABLE SNTCFG_CKDIV(0) /*!< EXMC_CLK disable */
  343. #define EXMC_SYN_CLOCK_RATIO_2_CLK SNTCFG_CKDIV(1) /*!< EXMC_CLK = 2*HCLK */
  344. #define EXMC_SYN_CLOCK_RATIO_3_CLK SNTCFG_CKDIV(2) /*!< EXMC_CLK = 3*HCLK */
  345. #define EXMC_SYN_CLOCK_RATIO_4_CLK SNTCFG_CKDIV(3) /*!< EXMC_CLK = 4*HCLK */
  346. #define EXMC_SYN_CLOCK_RATIO_5_CLK SNTCFG_CKDIV(4) /*!< EXMC_CLK = 5*HCLK */
  347. #define EXMC_SYN_CLOCK_RATIO_6_CLK SNTCFG_CKDIV(5) /*!< EXMC_CLK = 6*HCLK */
  348. #define EXMC_SYN_CLOCK_RATIO_7_CLK SNTCFG_CKDIV(6) /*!< EXMC_CLK = 7*HCLK */
  349. #define EXMC_SYN_CLOCK_RATIO_8_CLK SNTCFG_CKDIV(7) /*!< EXMC_CLK = 8*HCLK */
  350. #define EXMC_SYN_CLOCK_RATIO_9_CLK SNTCFG_CKDIV(8) /*!< EXMC_CLK = 9*HCLK */
  351. #define EXMC_SYN_CLOCK_RATIO_10_CLK SNTCFG_CKDIV(9) /*!< EXMC_CLK = 10*HCLK */
  352. #define EXMC_SYN_CLOCK_RATIO_11_CLK SNTCFG_CKDIV(10) /*!< EXMC_CLK = 11*HCLK */
  353. #define EXMC_SYN_CLOCK_RATIO_12_CLK SNTCFG_CKDIV(11) /*!< EXMC_CLK = 12*HCLK */
  354. #define EXMC_SYN_CLOCK_RATIO_13_CLK SNTCFG_CKDIV(12) /*!< EXMC_CLK = 13*HCLK */
  355. #define EXMC_SYN_CLOCK_RATIO_14_CLK SNTCFG_CKDIV(13) /*!< EXMC_CLK = 14*HCLK */
  356. #define EXMC_SYN_CLOCK_RATIO_15_CLK SNTCFG_CKDIV(14) /*!< EXMC_CLK = 15*HCLK */
  357. #define EXMC_SYN_CLOCK_RATIO_16_CLK SNTCFG_CKDIV(15) /*!< EXMC_CLK = 16*HCLK */
  358. /* ECC size */
  359. #define NPCTL_ECCSZ(regval) (BITS(17,19) & ((uint32_t)(regval) << 17))
  360. #define EXMC_ECC_SIZE_256BYTES NPCTL_ECCSZ(0) /* 256 bytes */
  361. #define EXMC_ECC_SIZE_512BYTES NPCTL_ECCSZ(1) /* 512 bytes */
  362. #define EXMC_ECC_SIZE_1024BYTES NPCTL_ECCSZ(2) /* 1024 bytes */
  363. #define EXMC_ECC_SIZE_2048BYTES NPCTL_ECCSZ(3) /* 2048 bytes */
  364. #define EXMC_ECC_SIZE_4096BYTES NPCTL_ECCSZ(4) /* 4096 bytes */
  365. #define EXMC_ECC_SIZE_8192BYTES NPCTL_ECCSZ(5) /* 8192 bytes */
  366. /* ALE to RE delay */
  367. #define NPCTL_ATR(regval) (BITS(13,16) & ((uint32_t)(regval) << 13))
  368. #define EXMC_ALE_RE_DELAY_1_HCLK NPCTL_ATR(0) /* ALE to RE delay = 1*HCLK */
  369. #define EXMC_ALE_RE_DELAY_2_HCLK NPCTL_ATR(1) /* ALE to RE delay = 2*HCLK */
  370. #define EXMC_ALE_RE_DELAY_3_HCLK NPCTL_ATR(2) /* ALE to RE delay = 3*HCLK */
  371. #define EXMC_ALE_RE_DELAY_4_HCLK NPCTL_ATR(3) /* ALE to RE delay = 4*HCLK */
  372. #define EXMC_ALE_RE_DELAY_5_HCLK NPCTL_ATR(4) /* ALE to RE delay = 5*HCLK */
  373. #define EXMC_ALE_RE_DELAY_6_HCLK NPCTL_ATR(5) /* ALE to RE delay = 6*HCLK */
  374. #define EXMC_ALE_RE_DELAY_7_HCLK NPCTL_ATR(6) /* ALE to RE delay = 7*HCLK */
  375. #define EXMC_ALE_RE_DELAY_8_HCLK NPCTL_ATR(7) /* ALE to RE delay = 8*HCLK */
  376. #define EXMC_ALE_RE_DELAY_9_HCLK NPCTL_ATR(8) /* ALE to RE delay = 9*HCLK */
  377. #define EXMC_ALE_RE_DELAY_10_HCLK NPCTL_ATR(9) /* ALE to RE delay = 10*HCLK */
  378. #define EXMC_ALE_RE_DELAY_11_HCLK NPCTL_ATR(10) /* ALE to RE delay = 11*HCLK */
  379. #define EXMC_ALE_RE_DELAY_12_HCLK NPCTL_ATR(11) /* ALE to RE delay = 12*HCLK */
  380. #define EXMC_ALE_RE_DELAY_13_HCLK NPCTL_ATR(12) /* ALE to RE delay = 13*HCLK */
  381. #define EXMC_ALE_RE_DELAY_14_HCLK NPCTL_ATR(13) /* ALE to RE delay = 14*HCLK */
  382. #define EXMC_ALE_RE_DELAY_15_HCLK NPCTL_ATR(14) /* ALE to RE delay = 15*HCLK */
  383. #define EXMC_ALE_RE_DELAY_16_HCLK NPCTL_ATR(15) /* ALE to RE delay = 16*HCLK */
  384. /* CLE to RE delay */
  385. #define NPCTL_CTR(regval) (BITS(9,12) & ((uint32_t)(regval) << 9))
  386. #define EXMC_CLE_RE_DELAY_1_HCLK NPCTL_CTR(0) /* CLE to RE delay = 1*HCLK */
  387. #define EXMC_CLE_RE_DELAY_2_HCLK NPCTL_CTR(1) /* CLE to RE delay = 2*HCLK */
  388. #define EXMC_CLE_RE_DELAY_3_HCLK NPCTL_CTR(2) /* CLE to RE delay = 3*HCLK */
  389. #define EXMC_CLE_RE_DELAY_4_HCLK NPCTL_CTR(3) /* CLE to RE delay = 4*HCLK */
  390. #define EXMC_CLE_RE_DELAY_5_HCLK NPCTL_CTR(4) /* CLE to RE delay = 5*HCLK */
  391. #define EXMC_CLE_RE_DELAY_6_HCLK NPCTL_CTR(5) /* CLE to RE delay = 6*HCLK */
  392. #define EXMC_CLE_RE_DELAY_7_HCLK NPCTL_CTR(6) /* CLE to RE delay = 7*HCLK */
  393. #define EXMC_CLE_RE_DELAY_8_HCLK NPCTL_CTR(7) /* CLE to RE delay = 8*HCLK */
  394. #define EXMC_CLE_RE_DELAY_9_HCLK NPCTL_CTR(8) /* CLE to RE delay = 9*HCLK */
  395. #define EXMC_CLE_RE_DELAY_10_HCLK NPCTL_CTR(9) /* CLE to RE delay = 10*HCLK */
  396. #define EXMC_CLE_RE_DELAY_11_HCLK NPCTL_CTR(10) /* CLE to RE delay = 11*HCLK */
  397. #define EXMC_CLE_RE_DELAY_12_HCLK NPCTL_CTR(11) /* CLE to RE delay = 12*HCLK */
  398. #define EXMC_CLE_RE_DELAY_13_HCLK NPCTL_CTR(12) /* CLE to RE delay = 13*HCLK */
  399. #define EXMC_CLE_RE_DELAY_14_HCLK NPCTL_CTR(13) /* CLE to RE delay = 14*HCLK */
  400. #define EXMC_CLE_RE_DELAY_15_HCLK NPCTL_CTR(14) /* CLE to RE delay = 15*HCLK */
  401. #define EXMC_CLE_RE_DELAY_16_HCLK NPCTL_CTR(15) /* CLE to RE delay = 16*HCLK */
  402. /* NAND bank memory data bus width */
  403. #define NPCTL_NDW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
  404. #define EXMC_NAND_DATABUS_WIDTH_8B NPCTL_NDW(0) /*!< NAND data width 8 bits */
  405. #define EXMC_NAND_DATABUS_WIDTH_16B NPCTL_NDW(1) /*!< NAND data width 16 bits */
  406. /* SDRAM pipeline delay */
  407. #define SDCTL_PIPED(regval) (BITS(13,14) & ((uint32_t)(regval) << 13))
  408. #define EXMC_PIPELINE_DELAY_0_HCLK SDCTL_PIPED(0) /*!< 0 HCLK clock cycle delay */
  409. #define EXMC_PIPELINE_DELAY_1_HCLK SDCTL_PIPED(1) /*!< 1 HCLK clock cycle delay */
  410. #define EXMC_PIPELINE_DELAY_2_HCLK SDCTL_PIPED(2) /*!< 2 HCLK clock cycle delay */
  411. /* SDRAM clock configuration */
  412. #define SDCTL_SDCLK(regval) (BITS(10,11) & ((uint32_t)(regval) << 10))
  413. #define EXMC_SDCLK_DISABLE SDCTL_SDCLK(0) /*!< SDCLK memory clock disabled */
  414. #define EXMC_SDCLK_PERIODS_2_HCLK SDCTL_SDCLK(2) /*!< SDCLK memory period = 2*HCLK */
  415. #define EXMC_SDCLK_PERIODS_3_HCLK SDCTL_SDCLK(3) /*!< SDCLK memory period = 3*HCLK */
  416. /* CAS latency */
  417. #define SDCTL_CL(regval) (BITS(7,8) & ((uint32_t)(regval) << 7))
  418. #define EXMC_CAS_LATENCY_1_SDCLK SDCTL_CL(1) /*!< CAS latency is 1 memory clock cycle */
  419. #define EXMC_CAS_LATENCY_2_SDCLK SDCTL_CL(2) /*!< CAS latency is 2 memory clock cycle */
  420. #define EXMC_CAS_LATENCY_3_SDCLK SDCTL_CL(3) /*!< CAS latency is 3 memory clock cycle */
  421. /* SDRAM data bus width */
  422. #define SDCTL_SDW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
  423. #define EXMC_SDRAM_DATABUS_WIDTH_8B SDCTL_SDW(0) /*!< SDRAM data width 8 bits */
  424. #define EXMC_SDRAM_DATABUS_WIDTH_16B SDCTL_SDW(1) /*!< SDRAM data width 16 bits */
  425. #define EXMC_SDRAM_DATABUS_WIDTH_32B SDCTL_SDW(2) /*!< SDRAM data width 32 bits */
  426. /* SDRAM row address bit width */
  427. #define SDCTL_RAW(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
  428. #define EXMC_SDRAM_ROW_ADDRESS_11 SDCTL_RAW(0) /*!< row address bit width is 11 bits */
  429. #define EXMC_SDRAM_ROW_ADDRESS_12 SDCTL_RAW(1) /*!< row address bit width is 12 bits */
  430. #define EXMC_SDRAM_ROW_ADDRESS_13 SDCTL_RAW(2) /*!< row address bit width is 13 bits */
  431. /* SDRAM column address bit width */
  432. #define SDCTL_CAW(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
  433. #define EXMC_SDRAM_COW_ADDRESS_8 SDCTL_CAW(0) /*!< column address bit width is 8 bits */
  434. #define EXMC_SDRAM_COW_ADDRESS_9 SDCTL_CAW(1) /*!< column address bit width is 9 bits */
  435. #define EXMC_SDRAM_COW_ADDRESS_10 SDCTL_CAW(2) /*!< column address bit width is 10 bits */
  436. #define EXMC_SDRAM_COW_ADDRESS_11 SDCTL_CAW(3) /*!< column address bit width is 11 bits */
  437. /* SDRAM number of successive auto-refresh */
  438. #define SDCMD_NARF(regval) (BITS(5,8) & ((uint32_t)(regval) << 5))
  439. #define EXMC_SDRAM_AUTO_REFLESH_1_SDCLK SDCMD_NARF(0) /*!< 1 auto-refresh cycle */
  440. #define EXMC_SDRAM_AUTO_REFLESH_2_SDCLK SDCMD_NARF(1) /*!< 2 auto-refresh cycles */
  441. #define EXMC_SDRAM_AUTO_REFLESH_3_SDCLK SDCMD_NARF(2) /*!< 3 auto-refresh cycles */
  442. #define EXMC_SDRAM_AUTO_REFLESH_4_SDCLK SDCMD_NARF(3) /*!< 4 auto-refresh cycles */
  443. #define EXMC_SDRAM_AUTO_REFLESH_5_SDCLK SDCMD_NARF(4) /*!< 5 auto-refresh cycles */
  444. #define EXMC_SDRAM_AUTO_REFLESH_6_SDCLK SDCMD_NARF(5) /*!< 6 auto-refresh cycles */
  445. #define EXMC_SDRAM_AUTO_REFLESH_7_SDCLK SDCMD_NARF(6) /*!< 7 auto-refresh cycles */
  446. #define EXMC_SDRAM_AUTO_REFLESH_8_SDCLK SDCMD_NARF(7) /*!< 8 auto-refresh cycles */
  447. #define EXMC_SDRAM_AUTO_REFLESH_9_SDCLK SDCMD_NARF(8) /*!< 9 auto-refresh cycles */
  448. #define EXMC_SDRAM_AUTO_REFLESH_10_SDCLK SDCMD_NARF(9) /*!< 10 auto-refresh cycles */
  449. #define EXMC_SDRAM_AUTO_REFLESH_11_SDCLK SDCMD_NARF(10) /*!< 11 auto-refresh cycles */
  450. #define EXMC_SDRAM_AUTO_REFLESH_12_SDCLK SDCMD_NARF(11) /*!< 12 auto-refresh cycles */
  451. #define EXMC_SDRAM_AUTO_REFLESH_13_SDCLK SDCMD_NARF(12) /*!< 13 auto-refresh cycles */
  452. #define EXMC_SDRAM_AUTO_REFLESH_14_SDCLK SDCMD_NARF(13) /*!< 14 auto-refresh cycles */
  453. #define EXMC_SDRAM_AUTO_REFLESH_15_SDCLK SDCMD_NARF(14) /*!< 15 auto-refresh cycles */
  454. /* SDRAM command select */
  455. #define SDCMD_CMD(regval) (BITS(0,2) & ((uint32_t)(regval) << 0))
  456. #define EXMC_SDRAM_NORMAL_OPERATION SDCMD_CMD(0) /*!< normal operation command */
  457. #define EXMC_SDRAM_CLOCK_ENABLE SDCMD_CMD(1) /*!< clock enable command */
  458. #define EXMC_SDRAM_PRECHARGE_ALL SDCMD_CMD(2) /*!< precharge all command */
  459. #define EXMC_SDRAM_AUTO_REFRESH SDCMD_CMD(3) /*!< auto-refresh command */
  460. #define EXMC_SDRAM_LOAD_MODE_REGISTER SDCMD_CMD(4) /*!< load mode register command */
  461. #define EXMC_SDRAM_SELF_REFRESH SDCMD_CMD(5) /*!< self-refresh command */
  462. #define EXMC_SDRAM_POWERDOWN_ENTRY SDCMD_CMD(6) /*!< power-down entry command */
  463. /* SDRAM the delayed sample clock of read data */
  464. #define SDRSCTL_SDSC(regval) (BITS(4,7) & ((uint32_t)(regval) << 4))
  465. #define EXMC_SDRAM_0_DELAY_CELL SDRSCTL_SDSC(0) /*!< select the clock after 0 delay cell */
  466. #define EXMC_SDRAM_1_DELAY_CELL SDRSCTL_SDSC(1) /*!< select the clock after 1 delay cell */
  467. #define EXMC_SDRAM_2_DELAY_CELL SDRSCTL_SDSC(2) /*!< select the clock after 2 delay cell */
  468. #define EXMC_SDRAM_3_DELAY_CELL SDRSCTL_SDSC(3) /*!< select the clock after 3 delay cell */
  469. #define EXMC_SDRAM_4_DELAY_CELL SDRSCTL_SDSC(4) /*!< select the clock after 4 delay cell */
  470. #define EXMC_SDRAM_5_DELAY_CELL SDRSCTL_SDSC(5) /*!< select the clock after 5 delay cell */
  471. #define EXMC_SDRAM_6_DELAY_CELL SDRSCTL_SDSC(6) /*!< select the clock after 6 delay cell */
  472. #define EXMC_SDRAM_7_DELAY_CELL SDRSCTL_SDSC(7) /*!< select the clock after 7 delay cell */
  473. #define EXMC_SDRAM_8_DELAY_CELL SDRSCTL_SDSC(8) /*!< select the clock after 8 delay cell */
  474. #define EXMC_SDRAM_9_DELAY_CELL SDRSCTL_SDSC(9) /*!< select the clock after 9 delay cell */
  475. #define EXMC_SDRAM_10_DELAY_CELL SDRSCTL_SDSC(10) /*!< select the clock after 10 delay cell */
  476. #define EXMC_SDRAM_11_DELAY_CELL SDRSCTL_SDSC(11) /*!< select the clock after 11 delay cell */
  477. #define EXMC_SDRAM_12_DELAY_CELL SDRSCTL_SDSC(12) /*!< select the clock after 12 delay cell */
  478. #define EXMC_SDRAM_13_DELAY_CELL SDRSCTL_SDSC(13) /*!< select the clock after 13 delay cell */
  479. #define EXMC_SDRAM_14_DELAY_CELL SDRSCTL_SDSC(14) /*!< select the clock after 14 delay cell */
  480. #define EXMC_SDRAM_15_DELAY_CELL SDRSCTL_SDSC(15) /*!< select the clock after 15 delay cell */
  481. /* SPI PSRAM ID length */
  482. #define SINIT_IDL(regval) (BITS(29,30) & ((uint32_t)(regval) << 29))
  483. #define EXMC_SQPIPSRAM_ID_LENGTH_64B SINIT_IDL(0) /*!< SPI PSRAM ID length is 64 bits */
  484. #define EXMC_SQPIPSRAM_ID_LENGTH_32B SINIT_IDL(1) /*!< SPI PSRAM ID length is 32 bits */
  485. #define EXMC_SQPIPSRAM_ID_LENGTH_16B SINIT_IDL(2) /*!< SPI PSRAM ID length is 16 bits */
  486. #define EXMC_SQPIPSRAM_ID_LENGTH_8B SINIT_IDL(3) /*!< SPI PSRAM ID length is 8 bits */
  487. /* SPI PSRAM bit number of address phase */
  488. #define SINIT_ADRBIT(regval) (BITS(24,28) & ((uint32_t)(regval) << 24))
  489. #define EXMC_SQPIPSRAM_ADDR_LENGTH_1B SINIT_ADRBIT(1) /*!< SPI PSRAM address is 1 bit */
  490. #define EXMC_SQPIPSRAM_ADDR_LENGTH_2B SINIT_ADRBIT(2) /*!< SPI PSRAM address is 2 bits */
  491. #define EXMC_SQPIPSRAM_ADDR_LENGTH_3B SINIT_ADRBIT(3) /*!< SPI PSRAM address is 3 bits */
  492. #define EXMC_SQPIPSRAM_ADDR_LENGTH_4B SINIT_ADRBIT(4) /*!< SPI PSRAM address is 4 bits */
  493. #define EXMC_SQPIPSRAM_ADDR_LENGTH_5B SINIT_ADRBIT(5) /*!< SPI PSRAM address is 5 bits */
  494. #define EXMC_SQPIPSRAM_ADDR_LENGTH_6B SINIT_ADRBIT(6) /*!< SPI PSRAM address is 6 bits */
  495. #define EXMC_SQPIPSRAM_ADDR_LENGTH_7B SINIT_ADRBIT(7) /*!< SPI PSRAM address is 7 bits */
  496. #define EXMC_SQPIPSRAM_ADDR_LENGTH_8B SINIT_ADRBIT(8) /*!< SPI PSRAM address is 8 bits */
  497. #define EXMC_SQPIPSRAM_ADDR_LENGTH_9B SINIT_ADRBIT(9) /*!< SPI PSRAM address is 9 bits */
  498. #define EXMC_SQPIPSRAM_ADDR_LENGTH_10B SINIT_ADRBIT(10) /*!< SPI PSRAM address is 10 bits */
  499. #define EXMC_SQPIPSRAM_ADDR_LENGTH_11B SINIT_ADRBIT(11) /*!< SPI PSRAM address is 11 bits */
  500. #define EXMC_SQPIPSRAM_ADDR_LENGTH_12B SINIT_ADRBIT(12) /*!< SPI PSRAM address is 12 bits */
  501. #define EXMC_SQPIPSRAM_ADDR_LENGTH_13B SINIT_ADRBIT(13) /*!< SPI PSRAM address is 13 bits */
  502. #define EXMC_SQPIPSRAM_ADDR_LENGTH_14B SINIT_ADRBIT(14) /*!< SPI PSRAM address is 14 bits */
  503. #define EXMC_SQPIPSRAM_ADDR_LENGTH_15B SINIT_ADRBIT(15) /*!< SPI PSRAM address is 15 bits */
  504. #define EXMC_SQPIPSRAM_ADDR_LENGTH_16B SINIT_ADRBIT(16) /*!< SPI PSRAM address is 16 bits */
  505. #define EXMC_SQPIPSRAM_ADDR_LENGTH_17B SINIT_ADRBIT(17) /*!< SPI PSRAM address is 17 bits */
  506. #define EXMC_SQPIPSRAM_ADDR_LENGTH_18B SINIT_ADRBIT(18) /*!< SPI PSRAM address is 18 bits */
  507. #define EXMC_SQPIPSRAM_ADDR_LENGTH_19B SINIT_ADRBIT(19) /*!< SPI PSRAM address is 19 bits */
  508. #define EXMC_SQPIPSRAM_ADDR_LENGTH_20B SINIT_ADRBIT(20) /*!< SPI PSRAM address is 20 bits */
  509. #define EXMC_SQPIPSRAM_ADDR_LENGTH_21B SINIT_ADRBIT(21) /*!< SPI PSRAM address is 21 bits */
  510. #define EXMC_SQPIPSRAM_ADDR_LENGTH_22B SINIT_ADRBIT(22) /*!< SPI PSRAM address is 22 bits */
  511. #define EXMC_SQPIPSRAM_ADDR_LENGTH_23B SINIT_ADRBIT(23) /*!< SPI PSRAM address is 23 bits */
  512. #define EXMC_SQPIPSRAM_ADDR_LENGTH_24B SINIT_ADRBIT(24) /*!< SPI PSRAM address is 24 bits */
  513. #define EXMC_SQPIPSRAM_ADDR_LENGTH_25B SINIT_ADRBIT(25) /*!< SPI PSRAM address is 25 bits */
  514. #define EXMC_SQPIPSRAM_ADDR_LENGTH_26B SINIT_ADRBIT(26) /*!< SPI PSRAM address is 26 bits */
  515. /* SPI PSRAM bit number of command phase */
  516. #define SINIT_CMDBIT(regval) (BITS(16,17) & ((uint32_t)(regval) << 16))
  517. #define EXMC_SQPIPSRAM_COMMAND_LENGTH_4B SINIT_CMDBIT(0) /*!< SPI PSRAM command is 4 bits */
  518. #define EXMC_SQPIPSRAM_COMMAND_LENGTH_8B SINIT_CMDBIT(1) /*!< SPI PSRAM command is 8 bits */
  519. #define EXMC_SQPIPSRAM_COMMAND_LENGTH_16B SINIT_CMDBIT(2) /*!< SPI PSRAM command is 16 bits */
  520. /* SPI PSRAM read command mode */
  521. #define SRCMD_RMODE(regval) (BITS(20,21) & ((uint32_t)(regval) << 20))
  522. #define EXMC_SQPIPSRAM_READ_MODE_DISABLE SRCMD_RMODE(0) /*!< not SPI mode */
  523. #define EXMC_SQPIPSRAM_READ_MODE_SPI SRCMD_RMODE(1) /*!< SPI mode */
  524. #define EXMC_SQPIPSRAM_READ_MODE_SQPI SRCMD_RMODE(2) /*!< SQPI mode */
  525. #define EXMC_SQPIPSRAM_READ_MODE_QPI SRCMD_RMODE(3) /*!< QPI mode */
  526. /* SPI PSRAM write command mode */
  527. #define SRCMD_WMODE(regval) (BITS(20,21) & ((uint32_t)(regval) << 20))
  528. #define EXMC_SQPIPSRAM_WRITE_MODE_DISABLE SRCMD_WMODE(0) /*!< not SPI mode */
  529. #define EXMC_SQPIPSRAM_WRITE_MODE_SPI SRCMD_WMODE(1) /*!< SPI mode */
  530. #define EXMC_SQPIPSRAM_WRITE_MODE_SQPI SRCMD_WMODE(2) /*!< SQPI mode */
  531. #define EXMC_SQPIPSRAM_WRITE_MODE_QPI SRCMD_WMODE(3) /*!< QPI mode */
  532. /* EXMC NOR/SRAM bank region definition */
  533. #define EXMC_BANK0_NORSRAM_REGION0 ((uint32_t)0x00000000U) /*!< bank0 NOR/SRAM region0 */
  534. #define EXMC_BANK0_NORSRAM_REGION1 ((uint32_t)0x00000001U) /*!< bank0 NOR/SRAM region1 */
  535. #define EXMC_BANK0_NORSRAM_REGION2 ((uint32_t)0x00000002U) /*!< bank0 NOR/SRAM region2 */
  536. #define EXMC_BANK0_NORSRAM_REGION3 ((uint32_t)0x00000003U) /*!< bank0 NOR/SRAM region3 */
  537. /* EXMC consecutive clock */
  538. #define EXMC_CLOCK_SYN_MODE ((uint32_t)0x00000000U) /*!< EXMC_CLK is generated only during synchronous access */
  539. #define EXMC_CLOCK_UNCONDITIONALLY ((uint32_t)0x00010000U) /*!< EXMC_CLK is generated unconditionally */
  540. /* EXMC NOR/SRAM write mode */
  541. #define EXMC_ASYN_WRITE ((uint32_t)0x00000000U) /*!< asynchronous write mode */
  542. #define EXMC_SYN_WRITE ((uint32_t)0x00008000U) /*!< synchronous write mode */
  543. /* EXMC NWAIT signal configuration */
  544. #define EXMC_NWAIT_CONFIG_BEFORE ((uint32_t)0x00000000U) /*!< NWAIT signal is active one data cycle before wait state */
  545. #define EXMC_NWAIT_CONFIG_DURING ((uint32_t)0x00000800U) /*!< NWAIT signal is active during wait state */
  546. /* EXMC NWAIT signal polarity configuration */
  547. #define EXMC_NWAIT_POLARITY_LOW ((uint32_t)0x00000000U) /*!< low level is active of NWAIT */
  548. #define EXMC_NWAIT_POLARITY_HIGH ((uint32_t)0x00000200U) /*!< high level is active of NWAIT */
  549. /* EXMC NAND/PC card bank definition */
  550. #define EXMC_BANK1_NAND ((uint32_t)0x00000001U) /*!< bank1 NAND flash */
  551. #define EXMC_BANK2_NAND ((uint32_t)0x00000002U) /*!< bank2 NAND flash */
  552. #define EXMC_BANK3_PCCARD ((uint32_t)0x00000003U) /*!< bank3 PC card */
  553. /* EXMC SDRAM bank definition */
  554. #define EXMC_SDRAM_DEVICE0 ((uint32_t)0x00000004U) /*!< SDRAM device0 */
  555. #define EXMC_SDRAM_DEVICE1 ((uint32_t)0x00000005U) /*!< SDRAM device1 */
  556. /* EXMC SDRAM internal banks */
  557. #define EXMC_SDRAM_2_INTER_BANK ((uint32_t)0x00000000U) /*!< 2 internal banks */
  558. #define EXMC_SDRAM_4_INTER_BANK ((uint32_t)0x00000040U) /*!< 4 internal banks */
  559. /* SDRAM device0 select */
  560. #define EXMC_SDRAM_DEVICE0_UNSELECT ((uint32_t)0x00000000U) /*!< NAND data width 8 bits */
  561. #define EXMC_SDRAM_DEVICE0_SELECT ((uint32_t)0x00000010U) /*!< NAND data width 16 bits */
  562. /* SDRAM device1 select */
  563. #define EXMC_SDRAM_DEVICE1_UNSELECT ((uint32_t)0x00000000U) /*!< NAND data width 8 bits */
  564. #define EXMC_SDRAM_DEVICE1_SELECT ((uint32_t)0x00000008U) /*!< NAND data width 16 bits */
  565. /* SDRAM device status */
  566. #define EXMC_SDRAM_DEVICE_NORMAL ((uint32_t)0x00000000U) /*!< normal status */
  567. #define EXMC_SDRAM_DEVICE_SELF_REFRESH ((uint32_t)0x00000001U) /*!< self refresh status */
  568. #define EXMC_SDRAM_DEVICE_POWER_DOWN ((uint32_t)0x00000002U) /*!< power down status */
  569. /* sample cycle of read data */
  570. #define EXMC_SDRAM_READSAMPLE_0_EXTRAHCLK ((uint32_t)0x00000000U) /*!< add 0 extra HCLK cycle to the read data sample clock besides the delay chain */
  571. #define EXMC_SDRAM_READSAMPLE_1_EXTRAHCLK ((uint32_t)0x00000002U) /*!< add 1 extra HCLK cycle to the read data sample clock besides the delay chain */
  572. /* read data sample polarity */
  573. #define EXMC_SDRAM_SAMPLE_RISING_EDGE ((uint32_t)0x00000000U) /*!< sample data at rising edge */
  574. #define EXMC_SDRAM_SAMPLE_FALLING_EDGE ((uint32_t)0x80000000U) /*!< sample data at falling edge */
  575. /* SQPI SRAM command flag */
  576. #define EXMC_SEND_COMMAND_FLAG_RDID EXMC_SRCMD_RDID /*!< EXMC_SRCMD_RDID flag bit */
  577. #define EXMC_SEND_COMMAND_FLAG_SC EXMC_SWCMD_SC /*!< EXMC_SWCMD_SC flag bit */
  578. /* EXMC flag bits */
  579. #define EXMC_NAND_PCCARD_FLAG_RISE EXMC_NPINTENx_INTRS /*!< interrupt rising edge status */
  580. #define EXMC_NAND_PCCARD_FLAG_LEVEL EXMC_NPINTENx_INTHS /*!< interrupt high-level status */
  581. #define EXMC_NAND_PCCARD_FLAG_FALL EXMC_NPINTENx_INTFS /*!< interrupt falling edge status */
  582. #define EXMC_NAND_PCCARD_FLAG_FIFOE EXMC_NPINTENx_INTEPT /*!< FIFO empty flag */
  583. #define EXMC_SDRAM_FLAG_REFRESH EXMC_SDSDAT_REIF /*!< refresh error interrupt flag */
  584. #define EXMC_SDRAM_FLAG_NREADY EXMC_SDSDAT_NRDY /*!< not ready status */
  585. /* EXMC interrupt flag bits */
  586. #define EXMC_NAND_PCCARD_INT_RISE EXMC_NPINTENx_INTREN /*!< interrupt rising edge detection enable */
  587. #define EXMC_NAND_PCCARD_INT_LEVEL EXMC_NPINTENx_INTHEN /*!< interrupt high-level detection enable */
  588. #define EXMC_NAND_PCCARD_INT_FALL EXMC_NPINTENx_INTFEN /*!< interrupt falling edge detection enable */
  589. #define EXMC_SDRAM_INT_REFRESH EXMC_SDARI_REIE /*!< interrupt refresh error enable */
  590. /* function declarations */
  591. /* deinitialize EXMC NOR/SRAM region */
  592. void exmc_norsram_deinit(uint32_t exmc_norsram_region);
  593. /* initialize EXMC NOR/SRAM region */
  594. void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
  595. /* exmc_norsram_parameter_struct parameter initialize */
  596. void exmc_norsram_parameter_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
  597. /* consecutive clock configure */
  598. void exmc_norsram_consecutive_clock_config(uint32_t clock_mode);
  599. /* CRAM page size configure */
  600. void exmc_norsram_page_size_config(uint32_t page_size);
  601. /* EXMC NOR/SRAM bank enable */
  602. void exmc_norsram_enable(uint32_t exmc_norsram_region);
  603. /* EXMC NOR/SRAM bank disable */
  604. void exmc_norsram_disable(uint32_t exmc_norsram_region);
  605. /* deinitialize EXMC NAND bank */
  606. void exmc_nand_deinit(uint32_t exmc_nand_bank);
  607. /* initialize EXMC NAND bank */
  608. void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
  609. /* exmc_norsram_parameter_struct parameter initialize */
  610. void exmc_nand_parameter_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
  611. /* EXMC NAND bank enable */
  612. void exmc_nand_enable(uint32_t exmc_nand_bank);
  613. /* EXMC NAND bank disable */
  614. void exmc_nand_disable(uint32_t exmc_nand_bank);
  615. /* enable or disable the EXMC NAND ECC function */
  616. void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue);
  617. /* get the EXMC ECC value */
  618. uint32_t exmc_ecc_get(uint32_t exmc_nand_bank);
  619. /* deinitialize EXMC PC card bank */
  620. void exmc_pccard_deinit(void);
  621. /* initialize EXMC PC card bank */
  622. void exmc_pccard_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
  623. /* exmc_pccard_parameter_struct parameter initialize */
  624. void exmc_pccard_parameter_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
  625. /* EXMC PC card bank enable */
  626. void exmc_pccard_enable(void);
  627. /* EXMC PC card bank disable */
  628. void exmc_pccard_disable(void);
  629. /* deinitialize EXMC SDRAM device */
  630. void exmc_sdram_deinit(uint32_t exmc_sdram_device);
  631. /* initialize EXMC SDRAM device */
  632. void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct);
  633. /* exmc_sdram_parameter_struct parameter initialize */
  634. void exmc_sdram_parameter_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct);
  635. /* configure the SDRAM memory command */
  636. void exmc_sdram_command_config(exmc_sdram_command_parameter_struct* exmc_sdram_command_init_struct);
  637. /* set auto-refresh interval */
  638. void exmc_sdram_refresh_count_set(uint32_t exmc_count);
  639. /* set the number of successive auto-refresh command */
  640. void exmc_sdram_autorefresh_number_set(uint32_t exmc_number);
  641. /* config the write protection function */
  642. void exmc_sdram_write_protection_config(uint32_t exmc_sdram_device, ControlStatus newvalue);
  643. /* get the status of SDRAM device0 or device1 */
  644. uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device);
  645. /* configure the delayed sample clock of read data */
  646. void exmc_sdram_readsample_config(uint32_t delay_cell, uint32_t extra_hclk);
  647. /* enable or disable read sample */
  648. void exmc_sdram_readsample_enable(ControlStatus newvalue);
  649. /* deinitialize EXMC SQPIPSRAM */
  650. void exmc_sqpipsram_deinit(void);
  651. /* initialize EXMC SQPIPSRAM */
  652. void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct);
  653. /* exmc_sqpipsram_parameter_struct parameter initialize */
  654. void exmc_sqpipsram_parameter_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct);
  655. /* set the read command */
  656. void exmc_sqpipsram_read_command_set(uint32_t read_command_mode,uint32_t read_wait_cycle,uint32_t read_command_code);
  657. /* set the write command */
  658. void exmc_sqpipsram_write_command_set(uint32_t write_command_mode,uint32_t write_wait_cycle,uint32_t write_command_code);
  659. /* send SPI read ID command */
  660. void exmc_sqpipsram_read_id_command_send(void);
  661. /* send SPI special command which does not have address and data phase */
  662. void exmc_sqpipsram_write_cmd_send(void);
  663. /* get the EXMC SPI ID low data */
  664. uint32_t exmc_sqpipsram_low_id_get(void);
  665. /* get the EXMC SPI ID high data */
  666. uint32_t exmc_sqpipsram_high_id_get(void);
  667. /* get the bit value of EXMC send write command bit or read ID command */
  668. FlagStatus exmc_sqpipsram_send_command_state_get(uint32_t send_command_flag);
  669. /* check EXMC flag is set or not */
  670. FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag);
  671. /* clear EXMC flag */
  672. void exmc_flag_clear(uint32_t exmc_bank,uint32_t flag);
  673. /* check EXMC flag is set or not */
  674. FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank,uint32_t interrupt_source);
  675. /* clear EXMC one channel flag */
  676. void exmc_interrupt_flag_clear(uint32_t exmc_bank,uint32_t interrupt_source);
  677. /* enable EXMC interrupt */
  678. void exmc_interrupt_enable(uint32_t exmc_bank,uint32_t interrupt_source);
  679. /* disable EXMC interrupt */
  680. void exmc_interrupt_disable(uint32_t exmc_bank,uint32_t interrupt_source);
  681. #endif /* GD32F4XX_EXMC_H */