at32f423_xmc.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /**
  2. **************************************************************************
  3. * @file at32f423_xmc.h
  4. * @brief at32f423 xmc header file
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. /* Define to prevent recursive inclusion -------------------------------------*/
  25. #ifndef __AT32F423_XMC_H
  26. #define __AT32F423_XMC_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "at32f423.h"
  32. /** @addtogroup AT32F423_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup XMC
  36. * @{
  37. */
  38. /** @defgroup XMC_exported_types
  39. * @{
  40. */
  41. /**
  42. * @brief xmc data address bus multiplexing type
  43. */
  44. typedef enum
  45. {
  46. XMC_DATA_ADDR_MUX_DISABLE = 0x00000000, /*!< xmc address/data multiplexing disable */
  47. XMC_DATA_ADDR_MUX_ENABLE = 0x00000002 /*!< xmc address/data multiplexing enable */
  48. } xmc_data_addr_mux_type;
  49. /**
  50. * @brief xmc burst access mode type
  51. */
  52. typedef enum
  53. {
  54. XMC_BURST_MODE_DISABLE = 0x00000000, /*!< xmc burst mode disable */
  55. XMC_BURST_MODE_ENABLE = 0x00000100 /*!< xmc burst mode enable */
  56. } xmc_burst_access_mode_type;
  57. /**
  58. * @brief xmc asynchronous wait type
  59. */
  60. typedef enum
  61. {
  62. XMC_ASYN_WAIT_DISABLE = 0x00000000, /*!< xmc wait signal during asynchronous transfers disbale */
  63. XMC_ASYN_WAIT_ENABLE = 0x00008000 /*!< xmc wait signal during asynchronous transfers enable */
  64. } xmc_asyn_wait_type;
  65. /**
  66. * @brief xmc wrapped mode type
  67. */
  68. typedef enum
  69. {
  70. XMC_WRAPPED_MODE_DISABLE = 0x00000000, /*!< xmc direct wrapped burst is disbale */
  71. XMC_WRAPPED_MODE_ENABLE = 0x00000400 /*!< xmc direct wrapped burst is enable */
  72. } xmc_wrap_mode_type;
  73. /**
  74. * @brief xmc write operation type
  75. */
  76. typedef enum
  77. {
  78. XMC_WRITE_OPERATION_DISABLE = 0x00000000, /*!< xmc write operations is disable */
  79. XMC_WRITE_OPERATION_ENABLE = 0x00001000 /*!< xmc write operations is enable */
  80. } xmc_write_operation_type;
  81. /**
  82. * @brief xmc wait signal type
  83. */
  84. typedef enum
  85. {
  86. XMC_WAIT_SIGNAL_DISABLE = 0x00000000, /*!< xmc nwait signal is disable */
  87. XMC_WAIT_SIGNAL_ENABLE = 0x00002000 /*!< xmc nwait signal is enable */
  88. } xmc_wait_signal_type;
  89. /**
  90. * @brief xmc write burst type
  91. */
  92. typedef enum
  93. {
  94. XMC_WRITE_BURST_SYN_DISABLE = 0x00000000, /*!< xmc write operations are always performed in asynchronous mode */
  95. XMC_WRITE_BURST_SYN_ENABLE = 0x00080000 /*!< xmc write operations are performed in synchronous mode */
  96. } xmc_write_burst_type;
  97. /**
  98. * @brief xmc extended mode type
  99. */
  100. typedef enum
  101. {
  102. XMC_WRITE_TIMING_DISABLE = 0x00000000, /*!< xmc write timing disable */
  103. XMC_WRITE_TIMING_ENABLE = 0x00004000 /*!< xmc write timing enable */
  104. } xmc_extended_mode_type;
  105. /**
  106. * @brief xmc pccard wait type
  107. */
  108. typedef enum
  109. {
  110. XMC_WAIT_OPERATION_DISABLE = 0x00000000, /*!< xmc wait operation for the pc card/nand flash memory bank disable */
  111. XMC_WAIT_OPERATION_ENABLE = 0x00000002 /*!< xmc wait operation for the pc card/nand flash memory bank enable */
  112. } xmc_nand_pccard_wait_type;
  113. /**
  114. * @brief xmc ecc enable type
  115. */
  116. typedef enum
  117. {
  118. XMC_ECC_OPERATION_DISABLE = 0x00000000, /*!< xmc ecc module disable */
  119. XMC_ECC_OPERATION_ENABLE = 0x00000040 /*!< xmc ecc module enable */
  120. } xmc_ecc_enable_type;
  121. /**
  122. * @brief xmc nor/sram subbank type
  123. */
  124. typedef enum
  125. {
  126. XMC_BANK1_NOR_SRAM1 = 0x00000000, /*!< xmc nor/sram subbank1 */
  127. XMC_BANK1_NOR_SRAM2 = 0x00000001, /*!< xmc nor/sram subbank2 */
  128. XMC_BANK1_NOR_SRAM3 = 0x00000002, /*!< xmc nor/sram subbank3 */
  129. XMC_BANK1_NOR_SRAM4 = 0x00000003 /*!< xmc nor/sram subbank4 */
  130. } xmc_nor_sram_subbank_type;
  131. /**
  132. * @brief xmc memory type
  133. */
  134. typedef enum
  135. {
  136. XMC_DEVICE_SRAM = 0x00000000, /*!< xmc device choice sram */
  137. XMC_DEVICE_PSRAM = 0x00000004, /*!< xmc device choice psram */
  138. XMC_DEVICE_NOR = 0x00000008 /*!< xmc device choice nor flash */
  139. } xmc_memory_type;
  140. /**
  141. * @brief xmc data width type
  142. */
  143. typedef enum
  144. {
  145. XMC_BUSTYPE_8_BITS = 0x00000000, /*!< xmc databuss width 8bits */
  146. XMC_BUSTYPE_16_BITS = 0x00000010 /*!< xmc databuss width 16bits */
  147. } xmc_data_width_type;
  148. /**
  149. * @brief xmc wait signal polarity type
  150. */
  151. typedef enum
  152. {
  153. XMC_WAIT_SIGNAL_LEVEL_LOW = 0x00000000, /*!< xmc nwait active low */
  154. XMC_WAIT_SIGNAL_LEVEL_HIGH = 0x00000200 /*!< xmc nwait active high */
  155. } xmc_wait_signal_polarity_type;
  156. /**
  157. * @brief xmc wait timing type
  158. */
  159. typedef enum
  160. {
  161. XMC_WAIT_SIGNAL_SYN_BEFORE = 0x00000000, /*!< xmc nwait signal is active one data cycle before wait state */
  162. XMC_WAIT_SIGNAL_SYN_DURING = 0x00000800 /*!< xmc nwait signal is active during wait state */
  163. } xmc_wait_timing_type;
  164. /**
  165. * @brief xmc access mode type
  166. */
  167. typedef enum
  168. {
  169. XMC_ACCESS_MODE_A = 0x00000000, /*!< xmc access mode A */
  170. XMC_ACCESS_MODE_B = 0x10000000, /*!< xmc access mode B */
  171. XMC_ACCESS_MODE_C = 0x20000000, /*!< xmc access mode C */
  172. XMC_ACCESS_MODE_D = 0x30000000 /*!< xmc access mode D */
  173. } xmc_access_mode_type;
  174. /**
  175. * @brief nor/sram banks timing parameters
  176. */
  177. typedef struct
  178. {
  179. xmc_nor_sram_subbank_type subbank; /*!< xmc nor/sram subbank */
  180. xmc_extended_mode_type write_timing_enable; /*!< xmc nor/sram write timing enable */
  181. uint32_t addr_setup_time; /*!< xmc nor/sram address setup time */
  182. uint32_t addr_hold_time; /*!< xmc nor/sram address hold time */
  183. uint32_t data_setup_time; /*!< xmc nor/sram data setup time */
  184. uint32_t bus_latency_time; /*!< xmc nor/sram bus latency time */
  185. uint32_t clk_psc; /*!< xmc nor/sram clock prescale */
  186. uint32_t data_latency_time; /*!< xmc nor/sram data latency time */
  187. xmc_access_mode_type mode; /*!< xmc nor/sram access mode */
  188. } xmc_norsram_timing_init_type;
  189. /**
  190. * @brief xmc nor/sram init structure definition
  191. */
  192. typedef struct
  193. {
  194. xmc_nor_sram_subbank_type subbank; /*!< xmc nor/sram subbank */
  195. xmc_data_addr_mux_type data_addr_multiplex; /*!< xmc nor/sram address/data multiplexing enable */
  196. xmc_memory_type device; /*!< xmc nor/sram memory device */
  197. xmc_data_width_type bus_type; /*!< xmc nor/sram data bus width */
  198. xmc_burst_access_mode_type burst_mode_enable; /*!< xmc nor/sram burst mode enable */
  199. xmc_asyn_wait_type asynwait_enable; /*!< xmc nor/sram nwait in asynchronous transfer enable */
  200. xmc_wait_signal_polarity_type wait_signal_lv; /*!< xmc nor/sram nwait polarity */
  201. xmc_wrap_mode_type wrapped_mode_enable; /*!< xmc nor/sram wrapped enable */
  202. xmc_wait_timing_type wait_signal_config; /*!< xmc nor/sram nwait timing configuration */
  203. xmc_write_operation_type write_enable; /*!< xmc nor/sram write enable */
  204. xmc_wait_signal_type wait_signal_enable; /*!< xmc nor/sram nwait in synchronous transfer enable */
  205. xmc_extended_mode_type write_timing_enable; /*!< xmc nor/sram read-write timing different */
  206. xmc_write_burst_type write_burst_syn; /*!< xmc nor/sram memory write mode control */
  207. } xmc_norsram_init_type;
  208. typedef struct
  209. {
  210. /**
  211. * @brief xmc bank1 bk1ctrl register, offset:0x00+0x08*(x-1) x= 1...4
  212. */
  213. union
  214. {
  215. __IO uint32_t bk1ctrl;
  216. struct
  217. {
  218. __IO uint32_t en : 1; /* [0] */
  219. __IO uint32_t admuxen : 1; /* [1] */
  220. __IO uint32_t dev : 2; /* [3:2] */
  221. __IO uint32_t extmdbw : 2; /* [5:4] */
  222. __IO uint32_t noren : 1; /* [6] */
  223. __IO uint32_t reserved1 : 1; /* [7] */
  224. __IO uint32_t syncben : 1; /* [8] */
  225. __IO uint32_t nwpol : 1; /* [9] */
  226. __IO uint32_t wrapen : 1; /* [10] */
  227. __IO uint32_t nwtcfg : 1; /* [11] */
  228. __IO uint32_t wen : 1; /* [12] */
  229. __IO uint32_t nwsen : 1; /* [13] */
  230. __IO uint32_t rwtd : 1; /* [14] */
  231. __IO uint32_t nwasen : 1; /* [15] */
  232. __IO uint32_t crpgs : 3; /* [18:16] */
  233. __IO uint32_t mwmc : 1; /* [19] */
  234. __IO uint32_t reserved2 : 12;/* [31:20] */
  235. } bk1ctrl_bit;
  236. };
  237. /**
  238. * @brief xmc bank1 bk1tmg register, offset:0x04+0x08*(x-1) x= 1...4
  239. */
  240. union
  241. {
  242. __IO uint32_t bk1tmg;
  243. struct
  244. {
  245. __IO uint32_t addrst : 4; /* [3:0] */
  246. __IO uint32_t addrht : 4; /* [7:4] */
  247. __IO uint32_t dtst : 8; /* [15:8] */
  248. __IO uint32_t buslat : 4; /* [19:16] */
  249. __IO uint32_t clkpsc : 4; /* [23:20] */
  250. __IO uint32_t dtlat : 4; /* [27:24] */
  251. __IO uint32_t asyncm : 2; /* [29:28] */
  252. __IO uint32_t reserved1 : 2; /* [31:30] */
  253. } bk1tmg_bit;
  254. };
  255. } xmc_bank1_ctrl_tmg_reg_type;
  256. typedef struct
  257. {
  258. /**
  259. * @brief xmc bank1 bk1tmgwr register, offset:0x104+0x08*(x-1) x= 1...4
  260. */
  261. union
  262. {
  263. __IO uint32_t bk1tmgwr;
  264. struct
  265. {
  266. __IO uint32_t addrst : 4; /* [3:0] */
  267. __IO uint32_t addrht : 4; /* [7:4] */
  268. __IO uint32_t dtst : 8; /* [15:8] */
  269. __IO uint32_t buslat : 4; /* [19:16] */
  270. __IO uint32_t reserved1 : 8; /* [27:20] */
  271. __IO uint32_t asyncm : 2; /* [29:28] */
  272. __IO uint32_t reserved2 : 2; /* [31:30] */
  273. } bk1tmgwr_bit;
  274. };
  275. /**
  276. * @brief xmc bank1 reserved register
  277. */
  278. __IO uint32_t reserved1;
  279. } xmc_bank1_tmgwr_reg_type;
  280. /**
  281. * @brief xmc bank1 registers
  282. */
  283. typedef struct
  284. {
  285. /**
  286. * @brief xmc bank1 ctrl and tmg register, offset:0x00~0x1C
  287. */
  288. xmc_bank1_ctrl_tmg_reg_type ctrl_tmg_group[4];
  289. /**
  290. * @brief xmc bank1 reserved register, offset:0x20~0x100
  291. */
  292. __IO uint32_t reserved1[57];
  293. /**
  294. * @brief xmc bank1 tmgwr register, offset:0x104~0x11C
  295. */
  296. xmc_bank1_tmgwr_reg_type tmgwr_group[4];
  297. /**
  298. * @brief xmc bank1 reserved register, offset:0x120~0x21C
  299. */
  300. __IO uint32_t reserved2[63];
  301. /**
  302. * @brief xmc bank1 ext register, offset:0x220~0x22C
  303. */
  304. union
  305. {
  306. __IO uint32_t ext[4];
  307. struct
  308. {
  309. __IO uint32_t buslatw2w : 8; /* [7:0] */
  310. __IO uint32_t buslatr2r : 8; /* [15:8] */
  311. __IO uint32_t reserved1 : 16;/* [31:16] */
  312. } ext_bit[4];
  313. };
  314. } xmc_bank1_type;
  315. /**
  316. * @}
  317. */
  318. #define XMC_BANK1 ((xmc_bank1_type *) XMC_BANK1_REG_BASE)
  319. /** @defgroup XMC_exported_functions
  320. * @{
  321. */
  322. void xmc_nor_sram_reset(xmc_nor_sram_subbank_type xmc_subbank);
  323. void xmc_nor_sram_init(xmc_norsram_init_type* xmc_norsram_init_struct);
  324. void xmc_nor_sram_timing_config(xmc_norsram_timing_init_type* xmc_rw_timing_struct,
  325. xmc_norsram_timing_init_type* xmc_w_timing_struct);
  326. void xmc_norsram_default_para_init(xmc_norsram_init_type* xmc_nor_sram_init_struct);
  327. void xmc_norsram_timing_default_para_init(xmc_norsram_timing_init_type* xmc_rw_timing_struct,
  328. xmc_norsram_timing_init_type* xmc_w_timing_struct);
  329. void xmc_nor_sram_enable(xmc_nor_sram_subbank_type xmc_subbank, confirm_state new_state);
  330. void xmc_ext_timing_config(xmc_nor_sram_subbank_type xmc_sub_bank, uint16_t w2w_timing, uint16_t r2r_timing);
  331. /**
  332. * @}
  333. */
  334. /**
  335. * @}
  336. */
  337. /**
  338. * @}
  339. */
  340. #ifdef __cplusplus
  341. }
  342. #endif
  343. #endif