dvk_ebi.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /**************************************************************************//**
  2. * @file
  3. * @brief EBI implementation of Board Control interface
  4. * This implementation works for devices w/o LCD display on the
  5. * MCU module, specifically the EFM32_G2xx_DK development board
  6. * @author Energy Micro AS
  7. * @version 1.7.3
  8. ******************************************************************************
  9. * @section License
  10. * <b>(C) Copyright 2010 Energy Micro AS, http://www.energymicro.com</b>
  11. ******************************************************************************
  12. *
  13. * This source code is the property of Energy Micro AS. The source and compiled
  14. * code may only be used on Energy Micro "EFM32" microcontrollers.
  15. *
  16. * This copyright notice may not be removed from the source code nor changed.
  17. *
  18. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  19. * obligation to support this Software. Energy Micro AS is providing the
  20. * Software "AS IS", with no express or implied warranties of any kind,
  21. * including, but not limited to, any implied warranties of merchantability
  22. * or fitness for any particular purpose or warranties against infringement
  23. * of any proprietary rights of a third party.
  24. *
  25. * Energy Micro AS will not be liable for any consequential, incidental, or
  26. * special damages, or any other relief, or for any claim by any third party,
  27. * arising from your use of this Software.
  28. *
  29. *****************************************************************************/
  30. #include "efm32.h"
  31. #include "efm32_ebi.h"
  32. #include "efm32_cmu.h"
  33. #include "efm32_gpio.h"
  34. #include "dvk.h"
  35. #include "dvk_bcregisters.h"
  36. /***************************************************************************//**
  37. * @addtogroup BSP
  38. * @{
  39. ******************************************************************************/
  40. #if defined(EBI_PRESENT)
  41. /**************************************************************************//**
  42. * @brief Configure EBI (external bus interface) for Board Control register
  43. * access
  44. *****************************************************************************/
  45. void DVK_EBI_configure(void)
  46. {
  47. EBI_Init_TypeDef ebiConfig = EBI_INIT_DEFAULT;
  48. /* Run time check if we have EBI on-chip capability on this device */
  49. switch ((DEVINFO->PART & _DEVINFO_PART_DEVICE_NUMBER_MASK) >>
  50. _DEVINFO_PART_DEVICE_NUMBER_SHIFT)
  51. {
  52. /* Only device types EFM32G 280/290/880 and 890 have EBI capability */
  53. case 280:
  54. case 290:
  55. case 880:
  56. case 890:
  57. break;
  58. default:
  59. /* This device do not have EBI capability - use SPI to interface DVK */
  60. /* With high probability your project has been configured for an */
  61. /* incorrect part number. */
  62. while (1) ;
  63. }
  64. /* Enable clocks */
  65. CMU_ClockEnable(cmuClock_EBI, true);
  66. CMU_ClockEnable(cmuClock_GPIO, true);
  67. /* Configure mode - disable SPI, enable EBI */
  68. GPIO_PinModeSet(gpioPortC, 13, gpioModePushPull, 1);
  69. GPIO_PinModeSet(gpioPortC, 12, gpioModePushPull, 0);
  70. /* Configure GPIO pins as push pull */
  71. /* EBI AD9..15 */
  72. GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
  73. GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);
  74. GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 0);
  75. GPIO_PinModeSet(gpioPortA, 3, gpioModePushPull, 0);
  76. GPIO_PinModeSet(gpioPortA, 4, gpioModePushPull, 0);
  77. GPIO_PinModeSet(gpioPortA, 5, gpioModePushPull, 0);
  78. GPIO_PinModeSet(gpioPortA, 6, gpioModePushPull, 0);
  79. /* EBI AD8 */
  80. GPIO_PinModeSet(gpioPortA, 15, gpioModePushPull, 0);
  81. /* EBI CS0-CS3 */
  82. GPIO_PinModeSet(gpioPortD, 9, gpioModePushPull, 0);
  83. GPIO_PinModeSet(gpioPortD, 10, gpioModePushPull, 0);
  84. GPIO_PinModeSet(gpioPortD, 11, gpioModePushPull, 0);
  85. GPIO_PinModeSet(gpioPortD, 12, gpioModePushPull, 0);
  86. /* EBI AD0..7 */
  87. GPIO_PinModeSet(gpioPortE, 8, gpioModePushPull, 0);
  88. GPIO_PinModeSet(gpioPortE, 9, gpioModePushPull, 0);
  89. GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0);
  90. GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
  91. GPIO_PinModeSet(gpioPortE, 12, gpioModePushPull, 0);
  92. GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
  93. GPIO_PinModeSet(gpioPortE, 14, gpioModePushPull, 0);
  94. GPIO_PinModeSet(gpioPortE, 15, gpioModePushPull, 0);
  95. /* EBI ARDY/ALEN/Wen/Ren */
  96. GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 0);
  97. GPIO_PinModeSet(gpioPortF, 3, gpioModePushPull, 0);
  98. GPIO_PinModeSet(gpioPortF, 4, gpioModePushPull, 0);
  99. GPIO_PinModeSet(gpioPortF, 5, gpioModePushPull, 0);
  100. /* Configure EBI controller, changing default values */
  101. ebiConfig.mode = ebiModeD16A16ALE;
  102. /* Enable bank 0 address map 0x80000000, FPGA Flash */
  103. /* Enable bank 1 address map 0x84000000, FPGA SRAM */
  104. /* Enable bank 2 address map 0x88000000, FPGA TFT Display (SSD2119) */
  105. /* Enable bank 3 address map 0x8c000000, FPGA Board Control Registers */
  106. ebiConfig.banks = EBI_BANK0|EBI_BANK1|EBI_BANK2|EBI_BANK3;
  107. ebiConfig.csLines = EBI_CS0|EBI_CS1|EBI_CS2|EBI_CS3;
  108. /* Address Setup and hold time */
  109. ebiConfig.addrHoldCycles = 3;
  110. ebiConfig.addrSetupCycles = 3;
  111. /* Read cycle times */
  112. ebiConfig.readStrobeCycles = 7;
  113. ebiConfig.readHoldCycles = 3;
  114. ebiConfig.readSetupCycles = 3;
  115. /* Write cycle times */
  116. ebiConfig.writeStrobeCycles = 7;
  117. ebiConfig.writeHoldCycles = 3;
  118. ebiConfig.writeSetupCycles = 3;
  119. /* Polarity values are default */
  120. /* Configure EBI */
  121. EBI_Init(&ebiConfig);
  122. }
  123. /**************************************************************************//**
  124. * @brief Initialize EBI
  125. * access
  126. * @return true on success, false on failure
  127. *****************************************************************************/
  128. bool DVK_EBI_init(void)
  129. {
  130. uint16_t ebiMagic;
  131. int retry = 10;
  132. /* Disable all GPIO pins and register */
  133. DVK_EBI_disable();
  134. /* Configure EBI */
  135. DVK_EBI_configure();
  136. /* Verify that EBI access is working, if not kit is in SPI mode and needs to
  137. * be configured for EBI access */
  138. ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
  139. while ((ebiMagic != BC_MAGIC_VALUE) && retry)
  140. {
  141. DVK_EBI_disable();
  142. /* Enable SPI interface */
  143. DVK_SPI_init();
  144. /* Set EBI mode - after this SPI access will no longer be available */
  145. ebiMagic = DVK_SPI_readRegister(BC_MAGIC);
  146. DVK_SPI_writeRegister(BC_CFG, BC_CFG_EBI);
  147. /* Disable SPI */
  148. DVK_SPI_disable();
  149. /* Now setup EBI again */
  150. DVK_EBI_configure();
  151. /* Wait until ready */
  152. ebiMagic = DVK_EBI_readRegister(BC_MAGIC);
  153. if (ebiMagic == BC_MAGIC_VALUE) break;
  154. retry--;
  155. }
  156. if ( ! retry ) return false;
  157. DVK_EBI_writeRegister(BC_LED, retry);
  158. return true;
  159. }
  160. /**************************************************************************//**
  161. * @brief Disable EBI interface, free all GPIO pins
  162. *****************************************************************************/
  163. void DVK_EBI_disable(void)
  164. {
  165. /* Disable EBI and SPI _BC_BUS_CONNECT */
  166. GPIO_PinModeSet(gpioPortC, 12, gpioModeDisabled, 0);
  167. GPIO_PinModeSet(gpioPortC, 13, gpioModeDisabled, 0);
  168. /* Configure GPIO pins as disabled */
  169. GPIO_PinModeSet(gpioPortA, 0, gpioModeDisabled, 0);
  170. GPIO_PinModeSet(gpioPortA, 1, gpioModeDisabled, 0);
  171. GPIO_PinModeSet(gpioPortA, 2, gpioModeDisabled, 0);
  172. GPIO_PinModeSet(gpioPortA, 3, gpioModeDisabled, 0);
  173. GPIO_PinModeSet(gpioPortA, 4, gpioModeDisabled, 0);
  174. GPIO_PinModeSet(gpioPortA, 5, gpioModeDisabled, 0);
  175. GPIO_PinModeSet(gpioPortA, 6, gpioModeDisabled, 0);
  176. GPIO_PinModeSet(gpioPortA, 15, gpioModeDisabled, 0);
  177. GPIO_PinModeSet(gpioPortD, 9, gpioModeDisabled, 0);
  178. GPIO_PinModeSet(gpioPortD, 10, gpioModeDisabled, 0);
  179. GPIO_PinModeSet(gpioPortD, 11, gpioModeDisabled, 0);
  180. GPIO_PinModeSet(gpioPortD, 12, gpioModeDisabled, 0);
  181. GPIO_PinModeSet(gpioPortE, 8, gpioModeDisabled, 0);
  182. GPIO_PinModeSet(gpioPortE, 9, gpioModeDisabled, 0);
  183. GPIO_PinModeSet(gpioPortE, 10, gpioModeDisabled, 0);
  184. GPIO_PinModeSet(gpioPortE, 11, gpioModeDisabled, 0);
  185. GPIO_PinModeSet(gpioPortE, 12, gpioModeDisabled, 0);
  186. GPIO_PinModeSet(gpioPortE, 13, gpioModeDisabled, 0);
  187. GPIO_PinModeSet(gpioPortE, 14, gpioModeDisabled, 0);
  188. GPIO_PinModeSet(gpioPortE, 15, gpioModeDisabled, 0);
  189. GPIO_PinModeSet(gpioPortF, 2, gpioModeDisabled, 0);
  190. GPIO_PinModeSet(gpioPortF, 3, gpioModeDisabled, 0);
  191. GPIO_PinModeSet(gpioPortF, 4, gpioModeDisabled, 0);
  192. GPIO_PinModeSet(gpioPortF, 5, gpioModeDisabled, 0);
  193. /* Disable EBI controller */
  194. #if 0
  195. EBI_Disable();
  196. #endif
  197. /* Disable EBI clock in CMU */
  198. CMU_ClockEnable(cmuClock_EBI, false);
  199. }
  200. /**************************************************************************//**
  201. * @brief Write data into 16-bit board control register
  202. * @param addr Address to board control register
  203. * @param data Data to write into register
  204. *****************************************************************************/
  205. void DVK_EBI_writeRegister(volatile uint16_t *addr, uint16_t data)
  206. {
  207. *addr = data;
  208. }
  209. /**************************************************************************//**
  210. * @brief Write data into 16-bit board control register
  211. * @param addr Register to read from
  212. *****************************************************************************/
  213. uint16_t DVK_EBI_readRegister(volatile uint16_t *addr)
  214. {
  215. return *addr;
  216. }
  217. #endif
  218. /** @} (end group BSP) */