dvk_ebi.c 12 KB

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