dvk_ebi.c 9.4 KB

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