gd32f10x_exmc.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /**
  2. ******************************************************************************
  3. * @brief EXMC functions of the firmware library.
  4. ******************************************************************************
  5. */
  6. /* Includes ------------------------------------------------------------------*/
  7. #include "gd32f10x_exmc.h"
  8. #include "gd32f10x_rcc.h"
  9. /** @addtogroup GD32F10x_Firmware
  10. * @{
  11. */
  12. /** @defgroup EXMC
  13. * @brief EXMC driver modules
  14. * @{
  15. */
  16. /** @defgroup EXMC_Private_Defines
  17. * @{
  18. */
  19. /* EXMC Bank1 SCTLRx_BAKEN and SCTLRx_NORAEN Mask */
  20. #define SCTLR_BAKEN_SET ((uint32_t)0x00000001)
  21. #define SCTLR_BAKEN_RESET ((uint32_t)0x000FFFFE)
  22. /* EXMC Bank1 SCTLRx_NOREN Mask */
  23. #define SCTLR_NOREN_SET ((uint32_t)0x00000040)
  24. /* EXMC Bank2/3/4 CTLRx_BAKEN Mask */
  25. #define CTLR_BAKEN_SET ((uint32_t)0x00000004)
  26. #define CTLR_BAKEN_RESET ((uint32_t)0x000FFFFB)
  27. /* EXMC Bank2/3/4 CTLRx_ECCEN Mask */
  28. #define CTLR_ECCEN_SET ((uint32_t)0x00000040)
  29. #define CTLR_ECCEN_RESET ((uint32_t)0x000FFFBF)
  30. /* EXMC Bank2/3/4 CTLRx_MTYPE Mask */
  31. #define CTLR_EMTYP_NAND ((uint32_t)0x00000008)
  32. /* EXMC Bank1 Register Reset mask*/
  33. #define BANK1_SCTLR1_RESET ((uint32_t)0x000030DB)
  34. #define BANK1_SCTLR_RESET ((uint32_t)0x000030D2)
  35. #define BANK1_STR_RESET ((uint32_t)0x0FFFFFFF)
  36. #define BANK1_SWTR_RESET ((uint32_t)0x0FFFFFFF)
  37. /* EXMC Bank2/3 Register Reset mask*/
  38. #define BANK2_3_CTLR_RESET ((uint32_t)0x00000018)
  39. #define BANK2_3_SIR_RESET ((uint32_t)0x00000040)
  40. #define BANK2_3_COMTR_RESET ((uint32_t)0xFCFCFCFC)
  41. #define BANK2_3_ATTR_RESET ((uint32_t)0xFCFCFCFC)
  42. /* EXMC Bank4 Register Reset mask*/
  43. #define BANK4_CTLR_RESET ((uint32_t)0x00000018)
  44. #define BANK4_SIR_RESET ((uint32_t)0x00000000)
  45. #define BANK4_COMTR_RESET ((uint32_t)0xFCFCFCFC)
  46. #define BANK4_ATTR_RESET ((uint32_t)0xFCFCFCFC)
  47. #define BANK4_IOTR_RESET ((uint32_t)0xFCFCFCFC)
  48. /* EXMC register bit offset */
  49. #define STR_AHT_OFFSET ((uint32_t)0x00000004)
  50. #define STR_DST_OFFSET ((uint32_t)0x00000008)
  51. #define STR_BUSLAT_OFFSET ((uint32_t)0x00000010)
  52. #define STR_CDIV_OFFSET ((uint32_t)0x00000014)
  53. #define STR_DLAT_OFFSET ((uint32_t)0x00000018)
  54. #define SWTR_AHT_OFFSET ((uint32_t)0x00000004)
  55. #define SWTR_DST_OFFSET ((uint32_t)0x00000008)
  56. #define SWTR_CDIV_OFFSET ((uint32_t)0x00000014)
  57. #define SWTR_DLAT_OFFSET ((uint32_t)0x00000018)
  58. #define CTLR_CTR_OFFSET ((uint32_t)0x00000009)
  59. #define CTLR_ATR_OFFSET ((uint32_t)0x0000000D)
  60. #define COMTR_COMWT_OFFSET ((uint32_t)0x00000008)
  61. #define COMTR_COMHT_OFFSET ((uint32_t)0x00000010)
  62. #define COMTR_COMHIZT_OFFSET ((uint32_t)0x00000018)
  63. #define ATTR_ATTWT_OFFSET ((uint32_t)0x00000008)
  64. #define ATTR_ATTHT_OFFSET ((uint32_t)0x00000010)
  65. #define ATTR_ATTHIZT_OFFSET ((uint32_t)0x00000018)
  66. #define IOTR_IOTWT_OFFSET ((uint32_t)0x00000008)
  67. #define IOTR_IOHT_OFFSET ((uint32_t)0x00000010)
  68. #define IOTR_IOHIZT_OFFSET ((uint32_t)0x00000018)
  69. #define SIR_INTEN_OFFSET ((uint32_t)0x00000003)
  70. /**
  71. * @}
  72. */
  73. /** @defgroup EXMC_Private_Functions
  74. * @{
  75. */
  76. /**
  77. * @brief Reset the Bank1 NOR/SRAM registers.
  78. * @param EXMC_NORSRAMBank: specifies the Region of Bank1.
  79. * This parameter can be one of the following values:
  80. * @arg EXMC_BANK1_NORSRAM1: the Region1 of Bank1
  81. * @arg EXMC_BANK1_NORSRAM2: the Region2 of Bank1
  82. * @arg EXMC_BANK1_NORSRAM3: the Region3 of Bank1
  83. * @arg EXMC_BANK1_NORSRAM4: the Region4 of Bank1
  84. * @retval None
  85. */
  86. void EXMC_NORSRAM_DeInit(uint32_t EXMC_NORSRAMBank)
  87. {
  88. switch (EXMC_NORSRAMBank) {
  89. case EXMC_BANK1_NORSRAM1: {
  90. /* the Region1 of Bank1 */
  91. EXMC_BANK1->SCTLR1 = BANK1_SCTLR1_RESET;
  92. EXMC_BANK1->STR1 = BANK1_STR_RESET;
  93. EXMC_BANK1_WT->SWTR1 = BANK1_SWTR_RESET;
  94. break;
  95. }
  96. case EXMC_BANK1_NORSRAM2: {
  97. /* the Region2 of Bank1 */
  98. EXMC_BANK1->SCTLR2 = BANK1_SCTLR_RESET;
  99. EXMC_BANK1->STR2 = BANK1_STR_RESET;
  100. EXMC_BANK1_WT->SWTR2 = BANK1_SWTR_RESET;
  101. break;
  102. }
  103. case EXMC_BANK1_NORSRAM3: {
  104. /* the Region3 of Bank1 */
  105. EXMC_BANK1->SCTLR3 = BANK1_SCTLR_RESET;
  106. EXMC_BANK1->STR3 = BANK1_STR_RESET;
  107. EXMC_BANK1_WT->SWTR3 = BANK1_SWTR_RESET;
  108. break;
  109. }
  110. case EXMC_BANK1_NORSRAM4: {
  111. /* the Region4 of Bank1 */
  112. EXMC_BANK1->SCTLR4 = BANK1_SCTLR_RESET;
  113. EXMC_BANK1->STR4 = BANK1_STR_RESET;
  114. EXMC_BANK1_WT->SWTR4 = BANK1_SWTR_RESET;
  115. break;
  116. }
  117. default:
  118. break;
  119. }
  120. }
  121. /**
  122. * @brief Reset the Bank2 or Bank3 NAND registers.
  123. * @param EXMC_NANDBank: specifies the Bank2 or Bank3 to be used.
  124. * This parameter can be one of the following values:
  125. * @arg EXMC_BANK2_NAND: Bank2
  126. * @arg EXMC_BANK3_NAND: Bank3
  127. * @retval None
  128. */
  129. void EXMC_NAND_DeInit(uint32_t EXMC_NANDBank)
  130. {
  131. if (EXMC_NANDBank == EXMC_BANK2_NAND) {
  132. /* Reset the Bank2 NAND registers */
  133. EXMC_BANK2->CTLR2 = BANK2_3_CTLR_RESET;
  134. EXMC_BANK2->SIR2 = BANK2_3_SIR_RESET;
  135. EXMC_BANK2->COMTR2 = BANK2_3_COMTR_RESET;
  136. EXMC_BANK2->ATTR2 = BANK2_3_ATTR_RESET;
  137. }
  138. /* EXMC_Bank3_NAND */
  139. else {
  140. /* Reset the Bank3 NAND registers */
  141. EXMC_BANK3->CTLR3 = BANK2_3_CTLR_RESET;
  142. EXMC_BANK3->SIR3 = BANK2_3_SIR_RESET;
  143. EXMC_BANK3->COMTR3 = BANK2_3_COMTR_RESET;
  144. EXMC_BANK3->ATTR3 = BANK2_3_ATTR_RESET;
  145. }
  146. }
  147. /**
  148. * @brief Reset the Bank4 PCCARD registers.
  149. * @param None
  150. * @retval None
  151. */
  152. void EXMC_PCCARD_DeInit(void)
  153. {
  154. /* Reset EXMC Bank4 PCCARD registers */
  155. EXMC_BANK4->CTLR4 = BANK4_CTLR_RESET;
  156. EXMC_BANK4->SIR4 = BANK4_SIR_RESET;
  157. EXMC_BANK4->COMTR4 = BANK4_COMTR_RESET;
  158. EXMC_BANK4->ATTR4 = BANK4_ATTR_RESET;
  159. EXMC_BANK4->IOTR4 = BANK4_IOTR_RESET;
  160. }
  161. /**
  162. * @brief Initializes the EXMC Bank1 NOR/SRAM parameters.
  163. * @param EXMC_NORSRAMInitParaStruct : the struct EXMC_NORSRAMInitPara pointer
  164. * @retval None
  165. */
  166. void EXMC_NORSRAM_Init(EXMC_NORSRAMInitPara *EXMC_NORSRAMInitParaStruct)
  167. {
  168. uint32_t temp_SCTLR = 0x00000000, temp_STR = 0x00000000, temp_SWTR = 0x00000000;
  169. temp_SCTLR = (uint32_t)EXMC_NORSRAMInitParaStruct->EXMC_AddressDataMux |
  170. EXMC_NORSRAMInitParaStruct->EXMC_MemoryType |
  171. EXMC_NORSRAMInitParaStruct->EXMC_DatabusWidth |
  172. EXMC_NORSRAMInitParaStruct->EXMC_BurstMode |
  173. EXMC_NORSRAMInitParaStruct->EXMC_NWAITPolarity |
  174. EXMC_NORSRAMInitParaStruct->EXMC_WrapBurstMode |
  175. EXMC_NORSRAMInitParaStruct->EXMC_NWAITConfig |
  176. EXMC_NORSRAMInitParaStruct->EXMC_MemoryWrite |
  177. EXMC_NORSRAMInitParaStruct->EXMC_NWAITSignal |
  178. EXMC_NORSRAMInitParaStruct->EXMC_ExtendedMode |
  179. EXMC_NORSRAMInitParaStruct->EXMC_AsynWait |
  180. EXMC_NORSRAMInitParaStruct->EXMC_WriteMode;
  181. temp_STR = (uint32_t)EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_AsynAddressSetupTime |
  182. (EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_AsynAddressHoldTime << STR_AHT_OFFSET) |
  183. (EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_AsynDataSetupTime << STR_DST_OFFSET) |
  184. (EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_BusLatency << STR_BUSLAT_OFFSET) |
  185. (EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_SynCLKDivision << STR_CDIV_OFFSET) |
  186. (EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_SynDataLatency << STR_DLAT_OFFSET) |
  187. EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_AsynAccessMode;
  188. if (EXMC_NORSRAMInitParaStruct->EXMC_MemoryType == EXMC_MEMORY_TYPE_NOR) {
  189. temp_SCTLR |= (uint32_t)SCTLR_NOREN_SET;
  190. }
  191. if (EXMC_NORSRAMInitParaStruct->EXMC_ExtendedMode == EXMC_EXTENDED_MODE_ENABLE) {
  192. temp_SWTR = (uint32_t)EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_AsynAddressSetupTime |
  193. (EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_AsynAddressHoldTime << SWTR_AHT_OFFSET) |
  194. (EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_AsynDataSetupTime << SWTR_DST_OFFSET) |
  195. (EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_SynCLKDivision << SWTR_CDIV_OFFSET) |
  196. (EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_SynDataLatency << SWTR_DLAT_OFFSET) |
  197. EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_AsynAccessMode;
  198. } else {
  199. temp_SWTR = BANK1_SWTR_RESET;
  200. }
  201. switch (EXMC_NORSRAMInitParaStruct->EXMC_NORSRAMBank) {
  202. case EXMC_BANK1_NORSRAM1: {
  203. /* Bank1 NOR/SRAM Region1 registers configuration */
  204. EXMC_BANK1->SCTLR1 = temp_SCTLR;
  205. EXMC_BANK1->STR1 = temp_STR;
  206. EXMC_BANK1_WT->SWTR1 = temp_SWTR;
  207. break;
  208. }
  209. case EXMC_BANK1_NORSRAM2: {
  210. /* Bank1 NOR/SRAM Region2 registers configuration */
  211. EXMC_BANK1->SCTLR2 = temp_SCTLR;
  212. EXMC_BANK1->STR2 = temp_STR;
  213. EXMC_BANK1_WT->SWTR2 = temp_SWTR;
  214. break;
  215. }
  216. case EXMC_BANK1_NORSRAM3: {
  217. /* Bank1 NOR/SRAM Region3 registers configuration */
  218. EXMC_BANK1->SCTLR3 = temp_SCTLR;
  219. EXMC_BANK1->STR3 = temp_STR;
  220. EXMC_BANK1_WT->SWTR3 = temp_SWTR;
  221. break;
  222. }
  223. case EXMC_BANK1_NORSRAM4: {
  224. /* Bank1 NOR/SRAM Region4 registers configuration */
  225. EXMC_BANK1->SCTLR4 = temp_SCTLR;
  226. EXMC_BANK1->STR4 = temp_STR;
  227. EXMC_BANK1_WT->SWTR4 = temp_SWTR;
  228. break;
  229. }
  230. default:
  231. break;
  232. }
  233. }
  234. /**
  235. * @brief Initialize the EXMC Bank2 or Bank3 NAND parameters.
  236. * @param EXMC_NANDInitParaStruct : the struct EXMC_NANDInitPara pointer
  237. * @retval None
  238. */
  239. void EXMC_NAND_Init(EXMC_NANDInitPara *EXMC_NANDInitParaStruct)
  240. {
  241. uint32_t temp_CTLR = 0x00000000, temp_COMTR = 0x00000000, temp_ATTR = 0x00000000;
  242. temp_CTLR = (uint32_t)EXMC_NANDInitParaStruct->EXMC_WaitFeature |
  243. CTLR_EMTYP_NAND |
  244. EXMC_NANDInitParaStruct->EXMC_DatabusWidth |
  245. EXMC_NANDInitParaStruct->EXMC_ECCLogic |
  246. EXMC_NANDInitParaStruct->EXMC_ECCSize |
  247. (EXMC_NANDInitParaStruct->EXMC_CTRLatency << CTLR_CTR_OFFSET) |
  248. (EXMC_NANDInitParaStruct->EXMC_ATRLatency << CTLR_ATR_OFFSET);
  249. temp_COMTR = (uint32_t)EXMC_NANDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_SetupTime |
  250. (EXMC_NANDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_WaitTime << COMTR_COMWT_OFFSET) |
  251. (EXMC_NANDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_HoldTime << COMTR_COMHT_OFFSET) |
  252. (EXMC_NANDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_DatabusHiZTime << COMTR_COMHIZT_OFFSET);
  253. temp_ATTR = (uint32_t)EXMC_NANDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_SetupTime |
  254. (EXMC_NANDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_WaitTime << ATTR_ATTWT_OFFSET) |
  255. (EXMC_NANDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_HoldTime << ATTR_ATTHT_OFFSET) |
  256. (EXMC_NANDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_DatabusHiZTime << ATTR_ATTHIZT_OFFSET);
  257. if (EXMC_NANDInitParaStruct->EXMC_NANDBank == EXMC_BANK2_NAND) {
  258. /* Configure the EXMC_Bank2 NAND registers using the value of parameters */
  259. EXMC_BANK2->CTLR2 = temp_CTLR;
  260. EXMC_BANK2->COMTR2 = temp_COMTR;
  261. EXMC_BANK2->ATTR2 = temp_ATTR;
  262. } else {
  263. /* EXMC_Bank3_NAND registers configuration */
  264. EXMC_BANK3->CTLR3 = temp_CTLR;
  265. EXMC_BANK3->COMTR3 = temp_COMTR;
  266. EXMC_BANK3->ATTR3 = temp_ATTR;
  267. }
  268. }
  269. /**
  270. * @brief Initialize the EXMC Bank4 PCCARD parameters.
  271. * @param EXMC_PCCARDInitParaStruct : the struct EXMC_PCCARDInitPara pointer.
  272. * @retval None
  273. */
  274. void EXMC_PCCARD_Init(EXMC_PCCARDInitPara *EXMC_PCCARDInitParaStruct)
  275. {
  276. /* Configure the EXMC_Bank4_PCCARD CTLR4 register using the value of parameters */
  277. EXMC_BANK4->CTLR4 = (uint32_t)EXMC_PCCARDInitParaStruct->EXMC_WaitFeature |
  278. EXMC_DATABUS_WIDTH_16B |
  279. (EXMC_PCCARDInitParaStruct->EXMC_CTRLatency << CTLR_CTR_OFFSET) |
  280. (EXMC_PCCARDInitParaStruct->EXMC_ATRLatency << CTLR_ATR_OFFSET);
  281. /* Configure the EXMC_Bank4_PCCARD COMTR4 register using the value of parameters */
  282. EXMC_BANK4->COMTR4 = (uint32_t)EXMC_PCCARDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_SetupTime |
  283. (EXMC_PCCARDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_WaitTime << COMTR_COMWT_OFFSET) |
  284. (EXMC_PCCARDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_HoldTime << COMTR_COMHT_OFFSET) |
  285. (EXMC_PCCARDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_DatabusHiZTime << COMTR_COMHIZT_OFFSET);
  286. /* Configure the EXMC_Bank4_PCCARD ATTR4 register using the value of parameters */
  287. EXMC_BANK4->ATTR4 = (uint32_t)EXMC_PCCARDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_SetupTime |
  288. (EXMC_PCCARDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_WaitTime << ATTR_ATTWT_OFFSET) |
  289. (EXMC_PCCARDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_HoldTime << ATTR_ATTHT_OFFSET) |
  290. (EXMC_PCCARDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_DatabusHiZTime << ATTR_ATTHIZT_OFFSET);
  291. /* Configure the EXMC_Bank4_PCCARD IOTR4 register using the value of parameters */
  292. EXMC_BANK4->IOTR4 = (uint32_t)EXMC_PCCARDInitParaStruct->EXMC_IOSpaceTimingParaStruct->EXMC_SetupTime |
  293. (EXMC_PCCARDInitParaStruct->EXMC_IOSpaceTimingParaStruct->EXMC_WaitTime << IOTR_IOTWT_OFFSET) |
  294. (EXMC_PCCARDInitParaStruct->EXMC_IOSpaceTimingParaStruct->EXMC_HoldTime << IOTR_IOHT_OFFSET) |
  295. (EXMC_PCCARDInitParaStruct->EXMC_IOSpaceTimingParaStruct->EXMC_DatabusHiZTime << IOTR_IOHIZT_OFFSET);
  296. }
  297. /**
  298. * @brief Initialize the struct EXMC_NORSRAMInitPara
  299. * @param EXMC_NORSRAMInitParaStruct: the struct EXMC_NORSRAMInitPara pointer
  300. * @retval None
  301. */
  302. void EXMC_NORSRAMStruct_Init(EXMC_NORSRAMInitPara *EXMC_NORSRAMInitParaStruct)
  303. {
  304. EXMC_NORSRAMInitParaStruct->EXMC_NORSRAMBank = EXMC_BANK1_NORSRAM1;
  305. EXMC_NORSRAMInitParaStruct->EXMC_AddressDataMux = EXMC_ADDRESS_DATA_MUX_ENABLE;
  306. EXMC_NORSRAMInitParaStruct->EXMC_MemoryType = EXMC_MEMORY_TYPE_SRAM;
  307. EXMC_NORSRAMInitParaStruct->EXMC_DatabusWidth = EXMC_DATABUS_WIDTH_8B;
  308. EXMC_NORSRAMInitParaStruct->EXMC_BurstMode = EXMC_BURST_MODE_DISABLE;
  309. EXMC_NORSRAMInitParaStruct->EXMC_NWAITPolarity = EXMC_NWAIT_POLARITY_LOW;
  310. EXMC_NORSRAMInitParaStruct->EXMC_WrapBurstMode = EXMC_WRAP_BURST_MODE_DISABLE;
  311. EXMC_NORSRAMInitParaStruct->EXMC_NWAITConfig = EXMC_NWAIT_CONFIG_BEFORE;
  312. EXMC_NORSRAMInitParaStruct->EXMC_MemoryWrite = EXMC_MEMORY_WRITE_ENABLE;
  313. EXMC_NORSRAMInitParaStruct->EXMC_NWAITSignal = EXMC_NWAIT_SIGNAL_ENABLE;
  314. EXMC_NORSRAMInitParaStruct->EXMC_ExtendedMode = EXMC_EXTENDED_MODE_DISABLE;
  315. EXMC_NORSRAMInitParaStruct->EXMC_AsynWait = EXMC_ASYN_WAIT_DISABLE;
  316. EXMC_NORSRAMInitParaStruct->EXMC_WriteMode = EXMC_ASYN_WRITE;
  317. EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_AsynAddressSetupTime = 0xF;
  318. EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_AsynAddressHoldTime = 0xF;
  319. EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_AsynDataSetupTime = 0xFF;
  320. EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_BusLatency = 0xF;
  321. EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_SynCLKDivision = 0xF;
  322. EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_SynDataLatency = 0xF;
  323. EXMC_NORSRAMInitParaStruct->EXMC_ReadWriteTimingParaStruct->EXMC_AsynAccessMode = EXMC_ACCESS_MODE_A;
  324. EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_AsynAddressSetupTime = 0xF;
  325. EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_AsynAddressHoldTime = 0xF;
  326. EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_AsynDataSetupTime = 0xFF;
  327. EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_BusLatency = 0xF;
  328. EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_SynCLKDivision = 0xF;
  329. EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_SynDataLatency = 0xF;
  330. EXMC_NORSRAMInitParaStruct->EXMC_WriteTimingParaStruct->EXMC_AsynAccessMode = EXMC_ACCESS_MODE_A;
  331. }
  332. /**
  333. * @brief Initialize the struct EXMC_NANDInitPara
  334. * @param EXMC_NANDInitParaStruct: the struct EXMC_NANDInitPara pointer.
  335. * @retval None
  336. */
  337. void EXMC_NANDStruct_Init(EXMC_NANDInitPara *EXMC_NANDInitParaStruct)
  338. {
  339. EXMC_NANDInitParaStruct->EXMC_NANDBank = EXMC_BANK2_NAND;
  340. EXMC_NANDInitParaStruct->EXMC_WaitFeature = EXMC_WAIT_FEATURE_DISABLE;
  341. EXMC_NANDInitParaStruct->EXMC_DatabusWidth = EXMC_DATABUS_WIDTH_8B;
  342. EXMC_NANDInitParaStruct->EXMC_ECCLogic = EXMC_ECC_LOGIC_DISABLE;
  343. EXMC_NANDInitParaStruct->EXMC_ECCSize = EXMC_ECC_SIZE_256BYTES;
  344. EXMC_NANDInitParaStruct->EXMC_CTRLatency = 0x0;
  345. EXMC_NANDInitParaStruct->EXMC_ATRLatency = 0x0;
  346. EXMC_NANDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_SetupTime = 0xFC;
  347. EXMC_NANDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_WaitTime = 0xFC;
  348. EXMC_NANDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_HoldTime = 0xFC;
  349. EXMC_NANDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_DatabusHiZTime = 0xFC;
  350. EXMC_NANDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_SetupTime = 0xFC;
  351. EXMC_NANDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_WaitTime = 0xFC;
  352. EXMC_NANDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_HoldTime = 0xFC;
  353. EXMC_NANDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_DatabusHiZTime = 0xFC;
  354. }
  355. /**
  356. * @brief Initialize the struct EXMC_PCCARDInitParaStruct
  357. * @param EXMC_PCCARDInitPara: the struct EXMC_PCCARDInitParaStruct pointer.
  358. * @retval None
  359. */
  360. void EXMC_PCCARDStruct_Init(EXMC_PCCARDInitPara *EXMC_PCCARDInitParaStruct)
  361. {
  362. EXMC_PCCARDInitParaStruct->EXMC_WaitFeature = EXMC_WAIT_FEATURE_DISABLE;
  363. EXMC_PCCARDInitParaStruct->EXMC_CTRLatency = 0x0;
  364. EXMC_PCCARDInitParaStruct->EXMC_ATRLatency = 0x0;
  365. EXMC_PCCARDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_SetupTime = 0xFC;
  366. EXMC_PCCARDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_WaitTime = 0xFC;
  367. EXMC_PCCARDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_HoldTime = 0xFC;
  368. EXMC_PCCARDInitParaStruct->EXMC_CommonSpaceTimingParaStruct->EXMC_DatabusHiZTime = 0xFC;
  369. EXMC_PCCARDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_SetupTime = 0xFC;
  370. EXMC_PCCARDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_WaitTime = 0xFC;
  371. EXMC_PCCARDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_HoldTime = 0xFC;
  372. EXMC_PCCARDInitParaStruct->EXMC_AttributeSpaceTimingParaStruct->EXMC_DatabusHiZTime = 0xFC;
  373. EXMC_PCCARDInitParaStruct->EXMC_IOSpaceTimingParaStruct->EXMC_SetupTime = 0xFC;
  374. EXMC_PCCARDInitParaStruct->EXMC_IOSpaceTimingParaStruct->EXMC_WaitTime = 0xFC;
  375. EXMC_PCCARDInitParaStruct->EXMC_IOSpaceTimingParaStruct->EXMC_HoldTime = 0xFC;
  376. EXMC_PCCARDInitParaStruct->EXMC_IOSpaceTimingParaStruct->EXMC_DatabusHiZTime = 0xFC;
  377. }
  378. /**
  379. * @brief Enable or disable the specified Region of Bank1.
  380. * @param EXMC_NORSRAMBank: specifies the Region of Bank1.
  381. * This parameter can be one of the following values:
  382. * @arg EXMC_BANK1_NORSRAM1: the Region1 of Bank1
  383. * @arg EXMC_BANK1_NORSRAM2: the Region2 of Bank1
  384. * @arg EXMC_BANK1_NORSRAM3: the Region3 of Bank1
  385. * @arg EXMC_BANK1_NORSRAM4: the Region4 of Bank1
  386. * @param NewValue: new value of the specified Region of Bank1.
  387. * This parameter can be: ENABLE or DISABLE.
  388. * @retval None
  389. */
  390. void EXMC_NORSRAM_Enable(uint32_t EXMC_NORSRAMBank, TypeState NewValue)
  391. {
  392. if (NewValue != DISABLE) {
  393. /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */
  394. switch (EXMC_NORSRAMBank) {
  395. case EXMC_BANK1_NORSRAM1:
  396. EXMC_BANK1->SCTLR1 |= SCTLR_BAKEN_SET;
  397. break;
  398. case EXMC_BANK1_NORSRAM2:
  399. EXMC_BANK1->SCTLR2 |= SCTLR_BAKEN_SET;
  400. break;
  401. case EXMC_BANK1_NORSRAM3:
  402. EXMC_BANK1->SCTLR3 |= SCTLR_BAKEN_SET;
  403. break;
  404. case EXMC_BANK1_NORSRAM4:
  405. EXMC_BANK1->SCTLR4 |= SCTLR_BAKEN_SET;
  406. break;
  407. default:
  408. break;
  409. }
  410. } else {
  411. /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */
  412. switch (EXMC_NORSRAMBank) {
  413. case EXMC_BANK1_NORSRAM1:
  414. EXMC_BANK1->SCTLR1 &= SCTLR_BAKEN_RESET;
  415. break;
  416. case EXMC_BANK1_NORSRAM2:
  417. EXMC_BANK1->SCTLR2 &= SCTLR_BAKEN_RESET;
  418. break;
  419. case EXMC_BANK1_NORSRAM3:
  420. EXMC_BANK1->SCTLR3 &= SCTLR_BAKEN_RESET;
  421. break;
  422. case EXMC_BANK1_NORSRAM4:
  423. EXMC_BANK1->SCTLR4 &= SCTLR_BAKEN_RESET;
  424. break;
  425. default:
  426. break;
  427. }
  428. }
  429. }
  430. /**
  431. * @brief Enable or disable the specified NAND Bank2 or Bank3.
  432. * @param EXMC_NANDBank: specifies the NAND Bank.
  433. * This parameter can be one of the following values:
  434. * @arg EXMC_BANK2_NAND: the NAND Bank2
  435. * @arg EXMC_BANK3_NAND: the NAND Bank3
  436. * @param NewValue: new value of the specified Bank.
  437. * This parameter can be: ENABLE or DISABLE.
  438. * @retval None
  439. */
  440. void EXMC_NAND_Enable(uint32_t EXMC_NANDBank, TypeState NewValue)
  441. {
  442. if (NewValue != DISABLE) {
  443. /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */
  444. if (EXMC_NANDBank == EXMC_BANK2_NAND) {
  445. EXMC_BANK2->CTLR2 |= CTLR_BAKEN_SET;
  446. } else {
  447. EXMC_BANK3->CTLR3 |= CTLR_BAKEN_SET;
  448. }
  449. } else {
  450. /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */
  451. if (EXMC_NANDBank == EXMC_BANK2_NAND) {
  452. EXMC_BANK2->CTLR2 &= CTLR_BAKEN_RESET;
  453. } else {
  454. EXMC_BANK3->CTLR3 &= CTLR_BAKEN_RESET;
  455. }
  456. }
  457. }
  458. /**
  459. * @brief Enable or disable the Bank4 of PCCARD.
  460. * @param NewValue: new value of the PCCARD Bank.
  461. * This parameter can be: ENABLE or DISABLE.
  462. * @retval None
  463. */
  464. void EXMC_PCCARD_Enable(TypeState NewValue)
  465. {
  466. if (NewValue != DISABLE) {
  467. /* Enable the PCCARD Bank */
  468. EXMC_BANK4->CTLR4 |= CTLR_BAKEN_SET;
  469. } else {
  470. /* Disable the PCCARD Bank */
  471. EXMC_BANK4->CTLR4 &= CTLR_BAKEN_RESET;
  472. }
  473. }
  474. /**
  475. * @brief Enable or disable the EXMC_CTLR1_ECCEN control bit.
  476. * @param EXMC_NANDBank: specifies the NAND Bank.
  477. * This parameter can be one of the following values:
  478. * @arg EXMC_BANK2_NAND: the NAND Bank2
  479. * @arg EXMC_BANK3_NAND: the NAND Bank3
  480. * @param NewValue: new value of the EXMC Bank2 or Bank3 ECC calculation.
  481. * This parameter can be: ENABLE or DISABLE.
  482. * @retval None
  483. */
  484. void EXMC_NANDECC_Enable(uint32_t EXMC_NANDBank, TypeState NewValue)
  485. {
  486. if (NewValue != DISABLE) {
  487. /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */
  488. if (EXMC_NANDBank == EXMC_BANK2_NAND) {
  489. EXMC_BANK2->CTLR2 |= CTLR_ECCEN_SET;
  490. } else {
  491. EXMC_BANK3->CTLR3 |= CTLR_ECCEN_SET;
  492. }
  493. } else {
  494. /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
  495. if (EXMC_NANDBank == EXMC_BANK2_NAND) {
  496. EXMC_BANK2->CTLR2 &= CTLR_ECCEN_RESET;
  497. } else {
  498. EXMC_BANK3->CTLR3 &= CTLR_ECCEN_RESET;
  499. }
  500. }
  501. }
  502. /**
  503. * @brief Get the EXMC_ECCR value.
  504. * @param EXMC_NANDBank: specifies the NAND Bank.
  505. * This parameter can be one of the following values:
  506. * @arg EXMC_BANK2_NAND: the NAND Bank2
  507. * @arg EXMC_BANK3_NAND: the NAND Bank3
  508. * @retval The Error Correction Code (ECC) value.
  509. */
  510. uint32_t EXMC_GetECC(uint32_t EXMC_NANDBank)
  511. {
  512. if (EXMC_NANDBank == EXMC_BANK2_NAND) {
  513. return (EXMC_BANK2->ECCR2);
  514. } else {
  515. return (EXMC_BANK3->ECCR3);
  516. }
  517. }
  518. /**
  519. * @brief Enable or disable the specified EXMC Bank2/3/4 interrupts.
  520. * @param EXMC_PCNANDBank: specifies the NAND Bank or PCCARD Bank.
  521. * This parameter can be one of the following values:
  522. * @arg EXMC_BANK2_NAND: the NAND Bank2
  523. * @arg EXMC_BANK3_NAND: the NAND Bank3
  524. * @arg EXMC_BANK4_PCCARD: the PCCARD Bank4
  525. * @param EXMC_INT: the EXMC interrupt sources.
  526. * This parameter can be any combination of the following values:
  527. * @arg EXMC_INT_RISE: Rising edge detection interrupt
  528. * @arg EXMC_INT_LEVEL: Level edge detection interrupt
  529. * @arg EXMC_INT_FALL: Falling edge detection interrupt
  530. * @param NewValue: new value of the specified EXMC interrupts.
  531. * This parameter can be: ENABLE or DISABLE.
  532. * @retval None
  533. */
  534. void EXMC_INTConfig(uint32_t EXMC_PCNANDBank, uint32_t EXMC_INT, TypeState NewValue)
  535. {
  536. if (NewValue != DISABLE) {
  537. /* Enable the specified EXMC_Bank2 interrupts */
  538. if (EXMC_PCNANDBank == EXMC_BANK2_NAND) {
  539. EXMC_BANK2->SIR2 |= EXMC_INT;
  540. }
  541. /* Enable the specified EXMC_Bank3 interrupts */
  542. else if (EXMC_PCNANDBank == EXMC_BANK3_NAND) {
  543. EXMC_BANK3->SIR3 |= EXMC_INT;
  544. }
  545. /* Enable the specified EXMC_Bank4 interrupts */
  546. else {
  547. EXMC_BANK4->SIR4 |= EXMC_INT;
  548. }
  549. } else {
  550. /* Disable the specified EXMC_Bank2 interrupts */
  551. if (EXMC_PCNANDBank == EXMC_BANK2_NAND) {
  552. EXMC_BANK2->SIR2 &= ~((uint32_t)EXMC_INT);
  553. }
  554. /* Disable the specified EXMC_Bank3 interrupts */
  555. else if (EXMC_PCNANDBank == EXMC_BANK3_NAND) {
  556. EXMC_BANK3->SIR3 &= ~((uint32_t)EXMC_INT);
  557. }
  558. /* Disable the specified EXMC_Bank4 interrupts */
  559. else {
  560. EXMC_BANK4->SIR4 &= ~((uint32_t)EXMC_INT);
  561. }
  562. }
  563. }
  564. /**
  565. * @brief Get the bit flag of EXMC_SIRx register.
  566. * @param EXMC_PCNANDBank: specifies the NAND Bank or PCCARD Bank.
  567. * This parameter can be one of the following values:
  568. * @arg EXMC_BANK2_NAND: the NAND Bank2
  569. * @arg EXMC_BANK3_NAND: the NAND Bank3
  570. * @arg EXMC_BANK4_PCCARD: the PCCARD Bank4
  571. * @param EXMC_FLAG: the flag of EXMC_SIRx register.
  572. * This parameter can be one of the following values:
  573. * @arg EXMC_FLAG_RISE: Rising egde detection Flag
  574. * @arg EXMC_FLAG_LEVEL: Level detection Flag
  575. * @arg EXMC_FLAG_FALL: Falling egde detection Flag
  576. * @arg EXMC_FLAG_FIFOE: FIFO empty Flag
  577. * @retval The new value of EXMC_FLAG (SET or RESET).
  578. */
  579. TypeState EXMC_GetBitState(uint32_t EXMC_PCNANDBank, uint32_t EXMC_FLAG)
  580. {
  581. uint32_t temp_SIR = 0x00000000;
  582. /* the NAND Bank2 */
  583. if (EXMC_PCNANDBank == EXMC_BANK2_NAND) {
  584. temp_SIR = EXMC_BANK2->SIR2;
  585. }
  586. /* the NAND Bank3 */
  587. else if (EXMC_PCNANDBank == EXMC_BANK3_NAND) {
  588. temp_SIR = EXMC_BANK3->SIR3;
  589. }
  590. /* the PCCARD Bank4 */
  591. else {
  592. temp_SIR = EXMC_BANK4->SIR4;
  593. }
  594. if ((temp_SIR & EXMC_FLAG) != (uint16_t)RESET) {
  595. /* EXMC_FLAG is set */
  596. return SET;
  597. } else {
  598. /* EXMC_FLAG is reset */
  599. return RESET;
  600. }
  601. }
  602. /**
  603. * @brief Clear the bit flag of EXMC_SIRx register.
  604. * @param EXMC_PCNANDBank: specifies the NAND Bank or PCCARD Bank.
  605. * This parameter can be one of the following values:
  606. * @arg EXMC_BANK2_NAND: the NAND Bank2
  607. * @arg EXMC_BANK3_NAND: the NAND Bank3
  608. * @arg EXMC_BANK4_PCCARD: the PCCARD Bank4
  609. * @param EXMC_FLAG: the flag of EXMC_SIRx register.
  610. * This parameter can be any combination of the following values:
  611. * @arg EXMC_FLAG_RISE: Rising egde detection Flag
  612. * @arg EXMC_FLAG_LEVEL: Level detection Flag
  613. * @arg EXMC_FLAG_FALL: Falling egde detection Flag
  614. * @retval None
  615. */
  616. void EXMC_ClearBitState(uint32_t EXMC_PCNANDBank, uint32_t EXMC_FLAG)
  617. {
  618. if (EXMC_PCNANDBank == EXMC_BANK2_NAND) {
  619. EXMC_BANK2->SIR2 &= ~EXMC_FLAG;
  620. } else if (EXMC_PCNANDBank == EXMC_BANK3_NAND) {
  621. EXMC_BANK3->SIR3 &= ~EXMC_FLAG;
  622. }
  623. /* EXMC_Bank4_PCCARD*/
  624. else {
  625. EXMC_BANK4->SIR4 &= ~EXMC_FLAG;
  626. }
  627. }
  628. /**
  629. * @brief Get the interrupt bit flag.
  630. * @param EXMC_PCNANDBank: specifies the NAND Bank or PCCARD Bank.
  631. * This parameter can be one of the following values:
  632. * @arg EXMC_BANK2_NAND: the NAND Bank2
  633. * @arg EXMC_BANK3_NAND: the NAND Bank3
  634. * @arg EXMC_BANK4_PCCARD: the PCCARD Bank4
  635. * @param EXMC_INT: the interrupt bit flag.
  636. * This parameter can be one of the following values:
  637. * @arg EXMC_INT_RISE: Rising edge detection interrupt
  638. * @arg EXMC_INT_LEVEL: Level edge detection interrupt
  639. * @arg EXMC_INT_FALL: Falling edge detection interrupt
  640. * @retval The new value of EXMC_INT (SET or RESET).
  641. */
  642. TypeState EXMC_GetIntBitState(uint32_t EXMC_PCNANDBank, uint32_t EXMC_INT)
  643. {
  644. uint32_t temp_SIR = 0x00000000, temp_INTState = 0x00000000, temp_INTEnable = 0x00000000;
  645. if (EXMC_PCNANDBank == EXMC_BANK2_NAND) {
  646. temp_SIR = EXMC_BANK2->SIR2;
  647. } else if (EXMC_PCNANDBank == EXMC_BANK3_NAND) {
  648. temp_SIR = EXMC_BANK3->SIR3;
  649. }
  650. /* EXMC_Bank4_PCCARD*/
  651. else {
  652. temp_SIR = EXMC_BANK4->SIR4;
  653. }
  654. temp_INTState = temp_SIR & EXMC_INT;
  655. temp_INTEnable = temp_SIR & (EXMC_INT >> SIR_INTEN_OFFSET);
  656. if ((temp_INTState != (uint32_t)RESET) && (temp_INTEnable != (uint32_t)RESET)) {
  657. return SET;
  658. } else {
  659. return RESET;
  660. }
  661. }
  662. /**
  663. * @brief Clear the interrupt bit flag.
  664. * @param EXMC_PCNANDBank: specifies the NAND Bank or PCCARD Bank.
  665. * This parameter can be one of the following values:
  666. * @arg EXMC_BANK2_NAND: the NAND Bank2
  667. * @arg EXMC_BANK3_NAND: the NAND Bank3
  668. * @arg EXMC_BANK4_PCCARD: the PCCARD Bank4
  669. * @param EXMC_INT: the interrupt bit flag.
  670. * This parameter can be any combination of the following values:
  671. * @arg EXMC_FLAG_RISE: Rising edge detection interrupt
  672. * @arg EXMC_FLAG_LEVEL: Level edge detection interrupt
  673. * @arg EXMC_FLAG_FALL: Falling edge detection interrupt
  674. * @retval None
  675. */
  676. void EXMC_ClearIntBitState(uint32_t EXMC_PCNANDBank, uint32_t EXMC_INT)
  677. {
  678. if (EXMC_PCNANDBank == EXMC_BANK2_NAND) {
  679. EXMC_BANK2->SIR2 &= ~(EXMC_INT >> SIR_INTEN_OFFSET);
  680. } else if (EXMC_PCNANDBank == EXMC_BANK3_NAND) {
  681. EXMC_BANK3->SIR3 &= ~(EXMC_INT >> SIR_INTEN_OFFSET);
  682. }
  683. /* EXMC_Bank4_PCCARD*/
  684. else {
  685. EXMC_BANK4->SIR4 &= ~(EXMC_INT >> SIR_INTEN_OFFSET);
  686. }
  687. }
  688. /**
  689. * @}
  690. */
  691. /**
  692. * @}
  693. */
  694. /**
  695. * @}
  696. */