dvk_ebi.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /**************************************************************************//**
  2. * @file
  3. * @brief EFM32GG_DK3750 board support package EBI API implementation
  4. * @author Energy Micro AS
  5. * @version 1.2.2
  6. ******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2011 Energy Micro AS, http://www.energymicro.com</b>
  9. ******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. *****************************************************************************/
  28. /***************************************************************************//**
  29. * @addtogroup BSP
  30. * @{
  31. ******************************************************************************/
  32. #include "efm32.h"
  33. #include "efm32_gpio.h"
  34. #include "efm32_ebi.h"
  35. #include "efm32_cmu.h"
  36. #include "dvk.h"
  37. #include "dvk_bcregisters.h"
  38. #if defined(EBI_PRESENT)
  39. /**************************************************************************//**
  40. * @brief Configure EFM32GG_DK3750 EBI (external bus interface) access for
  41. * - 0x80000000: Board Control registers (Xilinx Spartan FPGA)
  42. * - 0x84000000: TFT memory mapped drive (URT/SSD2119 controller)
  43. * - 0x88000000: PSRAM external memory (Micron MT45W2MW16PGA-70 IT)
  44. * - 0x8c000000: NOR flash (Spansion flash S29GLxxx_FBGA)
  45. * @return true if successful, false if board controller access failed
  46. *****************************************************************************/
  47. bool DVK_EBI_init(void)
  48. {
  49. EBI_Init_TypeDef ebiConfig = EBI_INIT_DEFAULT;
  50. /* Enable clocks */
  51. CMU_ClockEnable(cmuClock_EBI, true);
  52. CMU_ClockEnable(cmuClock_GPIO, true);
  53. /* Configure GPIO pins as push pull */
  54. /* EBI AD9..15 */
  55. GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
  56. GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);
  57. GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 0);
  58. GPIO_PinModeSet(gpioPortA, 3, gpioModePushPull, 0);
  59. GPIO_PinModeSet(gpioPortA, 4, gpioModePushPull, 0);
  60. GPIO_PinModeSet(gpioPortA, 5, gpioModePushPull, 0);
  61. GPIO_PinModeSet(gpioPortA, 6, gpioModePushPull, 0);
  62. /* EBI AD8 */
  63. GPIO_PinModeSet(gpioPortA, 15, gpioModePushPull, 0);
  64. /* EBI A16-A22 */
  65. GPIO_PinModeSet(gpioPortB, 0, gpioModePushPull, 0);
  66. GPIO_PinModeSet(gpioPortB, 1, gpioModePushPull, 0);
  67. GPIO_PinModeSet(gpioPortB, 2, gpioModePushPull, 0);
  68. GPIO_PinModeSet(gpioPortB, 3, gpioModePushPull, 0);
  69. GPIO_PinModeSet(gpioPortB, 4, gpioModePushPull, 0);
  70. GPIO_PinModeSet(gpioPortB, 5, gpioModePushPull, 0);
  71. GPIO_PinModeSet(gpioPortB, 6, gpioModePushPull, 0);
  72. /* EBI CS0-CS3 */
  73. GPIO_PinModeSet(gpioPortD, 9, gpioModePushPull, 1);
  74. GPIO_PinModeSet(gpioPortD, 10, gpioModePushPull, 1);
  75. GPIO_PinModeSet(gpioPortD, 11, gpioModePushPull, 1);
  76. GPIO_PinModeSet(gpioPortD, 12, gpioModePushPull, 1);
  77. /* EBI AD0..7 */
  78. GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
  79. GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
  80. GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
  81. GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
  82. GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
  83. GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
  84. GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
  85. GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
  86. /* EBI ARDY/WEN/REN/ALE */
  87. /* ARDY on Port F Pin 2 is not used */
  88. /* GPIO_PinModeSet(gpioPortF, 2, gpioModeInput, 0); */
  89. GPIO_PinModeSet(gpioPortF, 8, gpioModePushPull, 0);
  90. GPIO_PinModeSet(gpioPortF, 9, gpioModePushPull, 0);
  91. GPIO_PinModeSet(gpioPortC, 11, gpioModePushPull, 0);
  92. /* EBI Byte Lane 0 support BL0/BL1 */
  93. GPIO_PinModeSet(gpioPortF, 6, gpioModePushPull, 0);
  94. GPIO_PinModeSet(gpioPortF, 7, gpioModePushPull, 0);
  95. /* ---------------------------------------------------- */
  96. /* External 4MB PSRAM, Bank 2, Base Address 0x88000000 */
  97. /* Micron MT45W2MW16PGA-70 IT, 32Mb Cellular RAM */
  98. /* ---------------------------------------------------- */
  99. ebiConfig.banks = EBI_BANK2;
  100. ebiConfig.csLines = EBI_CS2;
  101. ebiConfig.mode = ebiModeD16A16ALE;
  102. ebiConfig.alePolarity = ebiActiveHigh;
  103. ebiConfig.blEnable = true;
  104. ebiConfig.noIdle = true;
  105. ebiConfig.ardyEnable = false;
  106. ebiConfig.addrHalfALE = true;
  107. ebiConfig.readPrefetch = true;
  108. ebiConfig.aLow = ebiALowA16;
  109. ebiConfig.aHigh = ebiAHighA23;
  110. ebiConfig.location = ebiLocation1;
  111. /* Address Setup and hold time */
  112. ebiConfig.addrHoldCycles = 0;
  113. ebiConfig.addrSetupCycles = 0;
  114. /* Read cycle times */
  115. ebiConfig.readStrobeCycles = 4;
  116. ebiConfig.readHoldCycles = 0;
  117. ebiConfig.readSetupCycles = 0;
  118. /* Write cycle times */
  119. ebiConfig.writeStrobeCycles = 2;
  120. ebiConfig.writeHoldCycles = 0;
  121. ebiConfig.writeSetupCycles = 0;
  122. /* Configure EBI bank 2 - external PSRAM */
  123. EBI_Init(&ebiConfig);
  124. /* --------------------------------------------------------- */
  125. /* Board Control Registers, Bank 0, Base Address 0x80000000 */
  126. /* FPGA Xilinx Spartan XC6SLX9 CSG324 */
  127. /* --------------------------------------------------------- */
  128. ebiConfig.banks = EBI_BANK0;
  129. ebiConfig.csLines = EBI_CS0;
  130. ebiConfig.mode = ebiModeD16A16ALE;;
  131. ebiConfig.alePolarity = ebiActiveHigh;
  132. /* keep blEnable */
  133. /* ebiConfig.blEnable = false; - common setting needs to be true for PSRAM */
  134. ebiConfig.addrHalfALE = true;
  135. ebiConfig.readPrefetch = false;
  136. ebiConfig.noIdle = true;
  137. /* keep alow/ahigh configuration */
  138. /* ebiConfig.aLow = ebiALowA0; - needs to be set for PSRAM */
  139. /* ebiConfig.aHigh = ebiAHighA0; - needs to be set for PSRAM */
  140. /* Address Setup and hold time */
  141. ebiConfig.addrHoldCycles = 3;
  142. ebiConfig.addrSetupCycles = 3;
  143. /* Read cycle times */
  144. ebiConfig.readStrobeCycles = 7;
  145. ebiConfig.readHoldCycles = 3;
  146. ebiConfig.readSetupCycles = 3;
  147. /* Write cycle times */
  148. ebiConfig.writeStrobeCycles = 7;
  149. ebiConfig.writeHoldCycles = 3;
  150. ebiConfig.writeSetupCycles = 3;
  151. /* Configure EBI bank 0 */
  152. EBI_Init(&ebiConfig);
  153. /* ----------------------------------------------------- */
  154. /* TFT-LCD Registers, Bank1, Base Address 0x84000000 */
  155. /* URT USMH_8252MD_320X240_RGB */
  156. /* Solomon Systech SSD 2119 */
  157. /* ----------------------------------------------------- */
  158. ebiConfig.banks = EBI_BANK1;
  159. ebiConfig.csLines = EBI_CS1;
  160. /* Address Setup and hold time */
  161. ebiConfig.addrHoldCycles = 1;
  162. ebiConfig.addrSetupCycles = 1;
  163. /* Read cycle times */
  164. ebiConfig.readStrobeCycles = 7;
  165. ebiConfig.readHoldCycles = 3;
  166. ebiConfig.readSetupCycles = 3;
  167. /* Write cycle times */
  168. ebiConfig.writeStrobeCycles = 2;
  169. ebiConfig.writeHoldCycles = 1;
  170. ebiConfig.writeSetupCycles = 1;
  171. /* Configure EBI bank 1 */
  172. EBI_Init(&ebiConfig);
  173. /* ----------------------------------------- */
  174. /* NOR Flash, Bank3, Base Address 0x8c000000 */
  175. /* Spansion flash S29GLxxx_FBGA */
  176. /* ----------------------------------------- */
  177. ebiConfig.banks = EBI_BANK3;
  178. ebiConfig.csLines = EBI_CS3;
  179. ebiConfig.mode = ebiModeD16A16ALE;;
  180. ebiConfig.alePolarity = ebiActiveHigh;
  181. /* keep blEnable */
  182. /* ebiConfig.blEnable = false; */
  183. ebiConfig.addrHalfALE = true;
  184. ebiConfig.readPrefetch = false;
  185. ebiConfig.noIdle = true;
  186. /* Address Setup and hold time */
  187. ebiConfig.addrHoldCycles = 0;
  188. ebiConfig.addrSetupCycles = 0;
  189. /* Read cycle times */
  190. ebiConfig.readStrobeCycles = 7;
  191. ebiConfig.readHoldCycles = 0;
  192. ebiConfig.readSetupCycles = 0;
  193. /* Write cycle times */
  194. ebiConfig.writeStrobeCycles = 2;
  195. ebiConfig.writeHoldCycles = 0;
  196. ebiConfig.writeSetupCycles = 0;
  197. /* Configure EBI bank 3 */
  198. EBI_Init(&ebiConfig);
  199. /* Enable extended address range */
  200. DVK_EBI_extendedAddressRange(true);
  201. /* Verify connectivity to Board Control registers */
  202. if (BC_REGISTER->MAGIC != 0xef32)
  203. {
  204. return false;
  205. }
  206. else
  207. {
  208. return true;
  209. }
  210. }
  211. /**************************************************************************//**
  212. * @brief Disable EFM32GG_DK3750 EBI board support package functionality
  213. *****************************************************************************/
  214. void DVK_EBI_disable(void)
  215. {
  216. /* Configure GPIO pins as push pull */
  217. /* EBI AD9..15 */
  218. GPIO_PinModeSet(gpioPortA, 0, gpioModeDisabled, 0);
  219. GPIO_PinModeSet(gpioPortA, 1, gpioModeDisabled, 0);
  220. GPIO_PinModeSet(gpioPortA, 2, gpioModeDisabled, 0);
  221. GPIO_PinModeSet(gpioPortA, 3, gpioModeDisabled, 0);
  222. GPIO_PinModeSet(gpioPortA, 4, gpioModeDisabled, 0);
  223. GPIO_PinModeSet(gpioPortA, 5, gpioModeDisabled, 0);
  224. GPIO_PinModeSet(gpioPortA, 6, gpioModeDisabled, 0);
  225. /* EBI AD8 */
  226. GPIO_PinModeSet(gpioPortA, 15, gpioModeDisabled, 0);
  227. /* EBI A16-A22 */
  228. GPIO_PinModeSet(gpioPortB, 0, gpioModeDisabled, 0);
  229. GPIO_PinModeSet(gpioPortB, 1, gpioModeDisabled, 0);
  230. GPIO_PinModeSet(gpioPortB, 2, gpioModeDisabled, 0);
  231. GPIO_PinModeSet(gpioPortB, 3, gpioModeDisabled, 0);
  232. GPIO_PinModeSet(gpioPortB, 4, gpioModeDisabled, 0);
  233. GPIO_PinModeSet(gpioPortB, 5, gpioModeDisabled, 0);
  234. GPIO_PinModeSet(gpioPortB, 6, gpioModeDisabled, 0);
  235. /* EBI CS0-CS3 */
  236. GPIO_PinModeSet(gpioPortD, 9, gpioModeDisabled, 0);
  237. GPIO_PinModeSet(gpioPortD, 10, gpioModeDisabled, 0);
  238. GPIO_PinModeSet(gpioPortD, 11, gpioModeDisabled, 0);
  239. GPIO_PinModeSet(gpioPortD, 12, gpioModeDisabled, 0);
  240. /* EBI AD0..7 */
  241. GPIO_PinModeSet(gpioPortE, 8, gpioModeDisabled, 0);
  242. GPIO_PinModeSet(gpioPortE, 9, gpioModeDisabled, 0);
  243. GPIO_PinModeSet(gpioPortE, 10, gpioModeDisabled, 0);
  244. GPIO_PinModeSet(gpioPortE, 11, gpioModeDisabled, 0);
  245. GPIO_PinModeSet(gpioPortE, 12, gpioModeDisabled, 0);
  246. GPIO_PinModeSet(gpioPortE, 13, gpioModeDisabled, 0);
  247. GPIO_PinModeSet(gpioPortE, 14, gpioModeDisabled, 0);
  248. GPIO_PinModeSet(gpioPortE, 15, gpioModeDisabled, 0);
  249. /* EBI ARDY/WEN/REN/ALE */
  250. /* ARDY on Port F Pin 2 is not used */
  251. /* GPIO_PinModeSet(gpioPortF, 2, gpioModeDisabled, 0); */
  252. GPIO_PinModeSet(gpioPortF, 8, gpioModeDisabled, 0);
  253. GPIO_PinModeSet(gpioPortF, 9, gpioModeDisabled, 0);
  254. GPIO_PinModeSet(gpioPortC, 11, gpioModeDisabled, 0);
  255. /* EBI Byte Lane 0 support BL0/BL1 */
  256. GPIO_PinModeSet(gpioPortF, 6, gpioModeDisabled, 0);
  257. GPIO_PinModeSet(gpioPortF, 7, gpioModeDisabled, 0);
  258. /* Reset EBI configuration */
  259. EBI_Disable();
  260. /* Turn off EBI clock */
  261. CMU_ClockEnable(cmuClock_EBI, false);
  262. }
  263. /**************************************************************************//**
  264. * @brief Configure EBI extended Address Range
  265. *
  266. * @param[in] enable
  267. * Controls extended address range mode
  268. *****************************************************************************/
  269. void DVK_EBI_extendedAddressRange(bool enable)
  270. {
  271. if (enable)
  272. {
  273. BC_REGISTER->EBI_CTRL = 0x0001;
  274. }
  275. else
  276. {
  277. BC_REGISTER->EBI_CTRL = 0x0000;
  278. }
  279. }
  280. #endif
  281. /** @} (end group BSP) */