drv_sdram.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /*
  2. * File : drv_sdram.c
  3. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Change Logs:
  20. * Date Author Notes
  21. * 2017-08-02 Yang the first version
  22. */
  23. #include "drv_sdram.h"
  24. #include <fsl_emc.h>
  25. #include "fsl_iocon.h"
  26. /*******************************************************************************************
  27. * @函数名:sdram_gpio_config()
  28. * @参数 :void
  29. * @返回值:void
  30. * @描述 :SDRAM管脚配置函数,内部调用
  31. *********************************************************************************************/
  32. static void sdram_gpio_config(void)
  33. {
  34. // CLOCK_EnableClock(kCLOCK_Iocon); /* Enables the clock for the IOCON block. 0 = Disable; 1 = Enable.: 0x01u */
  35. const uint32_t port0_pin15_config = (
  36. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_WEN */
  37. IOCON_PIO_MODE_INACT | /* No addition pin function */
  38. IOCON_PIO_INV_DI | /* Input function is not inverted */
  39. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  40. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  41. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  42. );
  43. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN15_IDX, port0_pin15_config); /* PORT0 PIN15 (coords: L4) is configured as EMC_WEN */
  44. const uint32_t port0_pin18_config = (
  45. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(0) */
  46. IOCON_PIO_MODE_INACT | /* No addition pin function */
  47. IOCON_PIO_INV_DI | /* Input function is not inverted */
  48. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  49. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  50. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  51. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  52. );
  53. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN18_IDX, port0_pin18_config); /* PORT0 PIN18 (coords: C14) is configured as EMC_A(0) */
  54. const uint32_t port0_pin19_config = (
  55. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(1) */
  56. IOCON_PIO_MODE_INACT | /* No addition pin function */
  57. IOCON_PIO_INV_DI | /* Input function is not inverted */
  58. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  59. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  60. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  61. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  62. );
  63. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN19_IDX, port0_pin19_config); /* PORT0 PIN19 (coords: C6) is configured as EMC_A(1) */
  64. const uint32_t port0_pin2_config = (
  65. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(0) */
  66. IOCON_PIO_MODE_INACT | /* No addition pin function */
  67. IOCON_PIO_INV_DI | /* Input function is not inverted */
  68. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  69. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  70. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  71. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  72. );
  73. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN2_IDX, port0_pin2_config); /* PORT0 PIN2 (coords: E9) is configured as EMC_D(0) */
  74. const uint32_t port0_pin20_config = (
  75. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(2) */
  76. IOCON_PIO_MODE_INACT | /* No addition pin function */
  77. IOCON_PIO_INV_DI | /* Input function is not inverted */
  78. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  79. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  80. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  81. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  82. );
  83. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN20_IDX, port0_pin20_config); /* PORT0 PIN20 (coords: D13) is configured as EMC_A(2) */
  84. const uint32_t port0_pin21_config = (
  85. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(3) */
  86. IOCON_PIO_MODE_INACT | /* No addition pin function */
  87. IOCON_PIO_INV_DI | /* Input function is not inverted */
  88. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  89. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  90. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  91. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  92. );
  93. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN21_IDX, port0_pin21_config); /* PORT0 PIN21 (coords: C13) is configured as EMC_A(3) */
  94. const uint32_t port0_pin3_config = (
  95. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(1) */
  96. IOCON_PIO_MODE_INACT | /* No addition pin function */
  97. IOCON_PIO_INV_DI | /* Input function is not inverted */
  98. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  99. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  100. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  101. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  102. );
  103. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN3_IDX, port0_pin3_config); /* PORT0 PIN3 (coords: A10) is configured as EMC_D(1) */
  104. const uint32_t port0_pin4_config = (
  105. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(2) */
  106. IOCON_PIO_MODE_INACT | /* No addition pin function */
  107. IOCON_PIO_INV_DI | /* Input function is not inverted */
  108. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  109. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  110. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  111. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  112. );
  113. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN4_IDX, port0_pin4_config); /* PORT0 PIN4 (coords: C8) is configured as EMC_D(2) */
  114. const uint32_t port0_pin5_config = (
  115. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(3) */
  116. IOCON_PIO_MODE_INACT | /* No addition pin function */
  117. IOCON_PIO_INV_DI | /* Input function is not inverted */
  118. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  119. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  120. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  121. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  122. );
  123. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN5_IDX, port0_pin5_config); /* PORT0 PIN5 (coords: E7) is configured as EMC_D(3) */
  124. const uint32_t port0_pin6_config = (
  125. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(4) */
  126. IOCON_PIO_MODE_INACT | /* No addition pin function */
  127. IOCON_PIO_INV_DI | /* Input function is not inverted */
  128. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  129. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  130. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  131. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  132. );
  133. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN6_IDX, port0_pin6_config); /* PORT0 PIN6 (coords: A5) is configured as EMC_D(4) */
  134. const uint32_t port0_pin7_config = (
  135. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(5) */
  136. IOCON_PIO_MODE_INACT | /* No addition pin function */
  137. IOCON_PIO_INV_DI | /* Input function is not inverted */
  138. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  139. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  140. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  141. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  142. );
  143. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN7_IDX, port0_pin7_config); /* PORT0 PIN7 (coords: H12) is configured as EMC_D(5) */
  144. const uint32_t port0_pin8_config = (
  145. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(6) */
  146. IOCON_PIO_MODE_INACT | /* No addition pin function */
  147. IOCON_PIO_INV_DI | /* Input function is not inverted */
  148. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  149. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  150. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  151. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  152. );
  153. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN8_IDX, port0_pin8_config); /* PORT0 PIN8 (coords: H10) is configured as EMC_D(6) */
  154. const uint32_t port0_pin9_config = (
  155. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(7) */
  156. IOCON_PIO_MODE_INACT | /* No addition pin function */
  157. IOCON_PIO_INV_DI | /* Input function is not inverted */
  158. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  159. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  160. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  161. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  162. );
  163. IOCON_PinMuxSet(IOCON, PORT0_IDX, PIN9_IDX, port0_pin9_config); /* PORT0 PIN9 (coords: G12) is configured as EMC_D(7) */
  164. const uint32_t port1_pin10_config = (
  165. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_RASN */
  166. IOCON_PIO_MODE_INACT | /* No addition pin function */
  167. IOCON_PIO_INV_DI | /* Input function is not inverted */
  168. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  169. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  170. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  171. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  172. );
  173. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN10_IDX, port1_pin10_config); /* PORT1 PIN10 (coords: N9) is configured as EMC_RASN */
  174. const uint32_t port1_pin11_config = (
  175. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_CLK(0) */
  176. IOCON_PIO_MODE_INACT | /* No addition pin function */
  177. IOCON_PIO_INV_DI | /* Input function is not inverted */
  178. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  179. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  180. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  181. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  182. );
  183. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN11_IDX, port1_pin11_config); /* PORT1 PIN11 (coords: B4) is configured as EMC_CLK(0) */
  184. const uint32_t port1_pin12_config = (
  185. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_DYCSN(0) */
  186. IOCON_PIO_MODE_INACT | /* No addition pin function */
  187. IOCON_PIO_INV_DI | /* Input function is not inverted */
  188. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  189. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  190. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  191. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  192. );
  193. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN12_IDX, port1_pin12_config); /* PORT1 PIN12 (coords: K9) is configured as EMC_DYCSN(0) */
  194. const uint32_t port1_pin13_config = (
  195. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_DQM(0) */
  196. IOCON_PIO_MODE_INACT | /* No addition pin function */
  197. IOCON_PIO_INV_DI | /* Input function is not inverted */
  198. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  199. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  200. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  201. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  202. );
  203. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN13_IDX, port1_pin13_config); /* PORT1 PIN13 (coords: G10) is configured as EMC_DQM(0) */
  204. const uint32_t port1_pin14_config = (
  205. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_DQM(1) */
  206. IOCON_PIO_MODE_INACT | /* No addition pin function */
  207. IOCON_PIO_INV_DI | /* Input function is not inverted */
  208. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  209. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  210. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  211. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  212. );
  213. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN14_IDX, port1_pin14_config); /* PORT1 PIN14 (coords: C12) is configured as EMC_DQM(1) */
  214. const uint32_t port1_pin15_config = (
  215. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_CKE(0) */
  216. IOCON_PIO_MODE_INACT | /* No addition pin function */
  217. IOCON_PIO_INV_DI | /* Input function is not inverted */
  218. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  219. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  220. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  221. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  222. );
  223. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN15_IDX, port1_pin15_config); /* PORT1 PIN15 (coords: A11) is configured as EMC_CKE(0) */
  224. const uint32_t port1_pin16_config = (
  225. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(10) */
  226. IOCON_PIO_MODE_INACT | /* No addition pin function */
  227. IOCON_PIO_INV_DI | /* Input function is not inverted */
  228. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  229. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  230. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  231. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  232. );
  233. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN16_IDX, port1_pin16_config); /* PORT1 PIN16 (coords: B7) is configured as EMC_A(10) */
  234. const uint32_t port1_pin19_config = (
  235. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(8) */
  236. IOCON_PIO_MODE_INACT | /* No addition pin function */
  237. IOCON_PIO_INV_DI | /* Input function is not inverted */
  238. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  239. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  240. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  241. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  242. );
  243. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN19_IDX, port1_pin19_config); /* PORT1 PIN19 (coords: L1) is configured as EMC_D(8) */
  244. const uint32_t port1_pin20_config = (
  245. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(9) */
  246. IOCON_PIO_MODE_INACT | /* No addition pin function */
  247. IOCON_PIO_INV_DI | /* Input function is not inverted */
  248. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  249. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  250. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  251. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  252. );
  253. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN20_IDX, port1_pin20_config); /* PORT1 PIN20 (coords: M1) is configured as EMC_D(9) */
  254. const uint32_t port1_pin21_config = (
  255. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(10) */
  256. IOCON_PIO_MODE_INACT | /* No addition pin function */
  257. IOCON_PIO_INV_DI | /* Input function is not inverted */
  258. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  259. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  260. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  261. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  262. );
  263. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN21_IDX, port1_pin21_config); /* PORT1 PIN21 (coords: N8) is configured as EMC_D(10) */
  264. const uint32_t port1_pin23_config = (
  265. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(11) */
  266. IOCON_PIO_MODE_INACT | /* No addition pin function */
  267. IOCON_PIO_INV_DI | /* Input function is not inverted */
  268. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  269. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  270. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  271. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  272. );
  273. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN23_IDX, port1_pin23_config); /* PORT1 PIN23 (coords: M10) is configured as EMC_A(11) */
  274. const uint32_t port1_pin24_config = (
  275. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(12) */
  276. IOCON_PIO_MODE_INACT | /* No addition pin function */
  277. IOCON_PIO_INV_DI | /* Input function is not inverted */
  278. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  279. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  280. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  281. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  282. );
  283. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN24_IDX, port1_pin24_config); /* PORT1 PIN24 (coords: N14) is configured as EMC_A(12) */
  284. const uint32_t port1_pin25_config = (
  285. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(13) */
  286. IOCON_PIO_MODE_INACT | /* No addition pin function */
  287. IOCON_PIO_INV_DI | /* Input function is not inverted */
  288. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  289. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  290. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  291. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  292. );
  293. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN25_IDX, port1_pin25_config); /* PORT1 PIN25 (coords: M12) is configured as EMC_A(13) */
  294. const uint32_t port1_pin26_config = (
  295. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(8) */
  296. IOCON_PIO_MODE_INACT | /* No addition pin function */
  297. IOCON_PIO_INV_DI | /* Input function is not inverted */
  298. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  299. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  300. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  301. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  302. );
  303. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN26_IDX, port1_pin26_config); /* PORT1 PIN26 (coords: J10) is configured as EMC_A(8) */
  304. const uint32_t port1_pin27_config = (
  305. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(9) */
  306. IOCON_PIO_MODE_INACT | /* No addition pin function */
  307. IOCON_PIO_INV_DI | /* Input function is not inverted */
  308. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  309. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  310. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  311. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  312. );
  313. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN27_IDX, port1_pin27_config); /* PORT1 PIN27 (coords: F10) is configured as EMC_A(9) */
  314. const uint32_t port1_pin28_config = (
  315. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(12) */
  316. IOCON_PIO_MODE_INACT | /* No addition pin function */
  317. IOCON_PIO_INV_DI | /* Input function is not inverted */
  318. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  319. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  320. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  321. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  322. );
  323. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN28_IDX, port1_pin28_config); /* PORT1 PIN28 (coords: E12) is configured as EMC_D(12) */
  324. const uint32_t port1_pin29_config = (
  325. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(13) */
  326. IOCON_PIO_MODE_INACT | /* No addition pin function */
  327. IOCON_PIO_INV_DI | /* Input function is not inverted */
  328. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  329. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  330. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  331. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  332. );
  333. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN29_IDX, port1_pin29_config); /* PORT1 PIN29 (coords: C11) is configured as EMC_D(13) */
  334. const uint32_t port1_pin30_config = (
  335. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(14) */
  336. IOCON_PIO_MODE_INACT | /* No addition pin function */
  337. IOCON_PIO_INV_DI | /* Input function is not inverted */
  338. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  339. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  340. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  341. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  342. );
  343. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN30_IDX, port1_pin30_config); /* PORT1 PIN30 (coords: A8) is configured as EMC_D(14) */
  344. const uint32_t port1_pin31_config = (
  345. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(15) */
  346. IOCON_PIO_MODE_INACT | /* No addition pin function */
  347. IOCON_PIO_INV_DI | /* Input function is not inverted */
  348. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  349. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  350. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  351. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  352. );
  353. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN31_IDX, port1_pin31_config); /* PORT1 PIN31 (coords: C5) is configured as EMC_D(15) */
  354. const uint32_t port1_pin4_config = (
  355. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_D(11) */
  356. IOCON_PIO_MODE_INACT | /* No addition pin function */
  357. IOCON_PIO_INV_DI | /* Input function is not inverted */
  358. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  359. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  360. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  361. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  362. );
  363. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN4_IDX, port1_pin4_config); /* PORT1 PIN4 (coords: D4) is configured as EMC_D(11) */
  364. const uint32_t port1_pin5_config = (
  365. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(4) */
  366. IOCON_PIO_MODE_INACT | /* No addition pin function */
  367. IOCON_PIO_INV_DI | /* Input function is not inverted */
  368. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  369. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  370. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  371. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  372. );
  373. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN5_IDX, port1_pin5_config); /* PORT1 PIN5 (coords: E4) is configured as EMC_A(4) */
  374. const uint32_t port1_pin6_config = (
  375. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(5) */
  376. IOCON_PIO_MODE_INACT | /* No addition pin function */
  377. IOCON_PIO_INV_DI | /* Input function is not inverted */
  378. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  379. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  380. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  381. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  382. );
  383. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN6_IDX, port1_pin6_config); /* PORT1 PIN6 (coords: G4) is configured as EMC_A(5) */
  384. const uint32_t port1_pin7_config = (
  385. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(6) */
  386. IOCON_PIO_MODE_INACT | /* No addition pin function */
  387. IOCON_PIO_INV_DI | /* Input function is not inverted */
  388. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  389. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  390. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  391. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  392. );
  393. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN7_IDX, port1_pin7_config); /* PORT1 PIN7 (coords: N1) is configured as EMC_A(6) */
  394. const uint32_t port1_pin8_config = (
  395. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(7) */
  396. IOCON_PIO_MODE_INACT | /* No addition pin function */
  397. IOCON_PIO_INV_DI | /* Input function is not inverted */
  398. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  399. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  400. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  401. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  402. );
  403. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN8_IDX, port1_pin8_config); /* PORT1 PIN8 (coords: P8) is configured as EMC_A(7) */
  404. const uint32_t port1_pin9_config = (
  405. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_CASN */
  406. IOCON_PIO_MODE_INACT | /* No addition pin function */
  407. IOCON_PIO_INV_DI | /* Input function is not inverted */
  408. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  409. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  410. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  411. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  412. );
  413. IOCON_PinMuxSet(IOCON, PORT1_IDX, PIN9_IDX, port1_pin9_config); /* PORT1 PIN9 (coords: K6) is configured as EMC_CASN */
  414. const uint32_t port3_pin25_config = (
  415. IOCON_PIO_FUNC6 | /* Pin is configured as EMC_A(14) */
  416. IOCON_PIO_MODE_INACT | /* No addition pin function */
  417. IOCON_PIO_INV_DI | /* Input function is not inverted */
  418. IOCON_PIO_DIGITAL_EN | /* Enables digital function */
  419. IOCON_PIO_INPFILT_OFF | /* Input filter disabled */
  420. IOCON_PIO_SLEW_FAST | /* Fast mode, slew rate control is disabled */
  421. IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */
  422. );
  423. IOCON_PinMuxSet(IOCON, PORT3_IDX, PIN25_IDX, port3_pin25_config); /* PORT3 PIN25 (coords: P9) is configured as EMC_A(14) */
  424. }
  425. void lpc_sdram_hw_init(void)
  426. {
  427. emc_basic_config_t basicConfig;
  428. emc_dynamic_timing_config_t dynTiming;
  429. emc_dynamic_chip_config_t dynChipConfig;
  430. sdram_gpio_config();
  431. /* Basic configuration. */
  432. basicConfig.endian = kEMC_LittleEndian;
  433. basicConfig.fbClkSrc = kEMC_IntloopbackEmcclk;
  434. /* EMC Clock = CPU FREQ/2 here can fit CPU freq from 12M ~ 180M.
  435. * If you change the divide to 0 and EMC clock is larger than 100M
  436. * please take refer to emc.dox to adjust EMC clock delay.
  437. */
  438. basicConfig.emcClkDiv = 1;
  439. /* Dynamic memory timing configuration. */
  440. dynTiming.readConfig = kEMC_Cmddelay;
  441. dynTiming.refreshPeriod_Nanosec = SDRAM_REFRESHPERIOD_NS;
  442. dynTiming.tRp_Ns = SDRAM_TRP_NS;
  443. dynTiming.tRas_Ns = SDRAM_TRAS_NS;
  444. dynTiming.tSrex_Ns = SDRAM_TSREX_NS;
  445. dynTiming.tApr_Ns = SDRAM_TAPR_NS;
  446. dynTiming.tWr_Ns = (1000000000 / CLOCK_GetFreq(kCLOCK_EMC) + SDRAM_TWRDELT_NS); /* one clk + 6ns */
  447. dynTiming.tDal_Ns = dynTiming.tWr_Ns + dynTiming.tRp_Ns;
  448. dynTiming.tRc_Ns = SDRAM_TRC_NS;
  449. dynTiming.tRfc_Ns = SDRAM_RFC_NS;
  450. dynTiming.tXsr_Ns = SDRAM_XSR_NS;
  451. dynTiming.tRrd_Ns = SDRAM_RRD_NS;
  452. dynTiming.tMrd_Nclk = SDRAM_MRD_NCLK;
  453. /* Dynamic memory chip specific configuration: Chip 0 - MTL48LC8M16A2B4-6A */
  454. dynChipConfig.chipIndex = 0;
  455. dynChipConfig.dynamicDevice = kEMC_Sdram;
  456. dynChipConfig.rAS_Nclk = SDRAM_RAS_NCLK;
  457. dynChipConfig.sdramModeReg = SDRAM_MODEREG_VALUE;
  458. dynChipConfig.sdramExtModeReg = 0; /* it has no use for normal sdram */
  459. dynChipConfig.devAddrMap = SDRAM_DEV_MEMORYMAP;
  460. /* EMC Basic configuration. */
  461. EMC_Init(EMC, &basicConfig);
  462. /* EMC Dynamc memory configuration. */
  463. EMC_DynamicMemInit(EMC, &dynTiming, &dynChipConfig, 1);
  464. }