board.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /***************************************************************************//**
  2. * @file board.h
  3. * @brief Board support of RT-Thread RTOS for EFM32
  4. * COPYRIGHT (C) 2012, RT-Thread Development Team
  5. * @author onelife
  6. * @version 1.0
  7. *******************************************************************************
  8. * @section License
  9. * The license and distribution terms for this file may be found in the file
  10. * LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
  11. *******************************************************************************
  12. * @section Change Logs
  13. * Date Author Notes
  14. * 2010-12-21 onelife Initial creation for EFM32
  15. * 2011-05-06 onelife Add EFM32 development kit and SPI Flash support
  16. * 2011-07-12 onelife Add prototype for SWO output enable and interrupt
  17. * context check functions
  18. * 2011-12-08 onelife Add giant gecko development kit support
  19. * 2011-12-09 onelife Add giant gecko support
  20. * 2011-12-09 onelife Add LEUART module support
  21. * 2011-12-14 onelife Add LFXO enabling routine in driver initialization
  22. * function
  23. * 2011-12-20 onelife Move SPI Auto-CS setting to "rtconfig.h"
  24. * 2012-05-15 onelife Modified to compatible with CMSIS v3
  25. ******************************************************************************/
  26. #ifndef __BOARD_H__
  27. #define __BOARD_H__
  28. #if defined(EFM32G890F128)
  29. #elif defined(EFM32G290F128)
  30. #elif defined(EFM32G230F128)
  31. #elif defined(EFM32GG990F1024)
  32. #else
  33. #error Unknown MCU type
  34. #endif
  35. /* Includes ------------------------------------------------------------------*/
  36. #include <efm32.h>
  37. #include <em_chip.h>
  38. #include <em_cmu.h>
  39. #include <em_rmu.h>
  40. #include <em_emu.h>
  41. #include <em_dma.h>
  42. #include <em_ebi.h>
  43. #include <em_rtc.h>
  44. #include <em_timer.h>
  45. #include <em_letimer.h>
  46. #include <em_gpio.h>
  47. #include <em_acmp.h>
  48. #include <em_adc.h>
  49. #include <em_usart.h>
  50. #include <em_leuart.h>
  51. #include <em_i2c.h>
  52. #include <rtthread.h>
  53. #if (defined(EFM32_GXXX_DK) || defined(EFM32GG_DK3750))
  54. #include <dvk.h>
  55. #endif
  56. #include "drv_emu.h"
  57. /* Exported types ------------------------------------------------------------*/
  58. /* Exported constants --------------------------------------------------------*/
  59. /* Exported variables --------------------------------------------------------*/
  60. extern volatile rt_uint32_t rt_system_status;
  61. /* Exported macro ------------------------------------------------------------*/
  62. #ifdef EFM32_DEBUG
  63. #define DEBUG_EFM
  64. #define DEBUG_EFM_USER
  65. #define EFM32_SWO_ENABLE
  66. #endif
  67. #define EFM32_NO_DATA (0)
  68. #define EFM32_NO_POINTER (RT_NULL)
  69. #define EFM32_NO_OFFSET (-1)
  70. #define EFM32_NO_DMA (-1)
  71. /* SECTION: SPI Flash */
  72. #if defined(EFM32_USING_SFLASH)
  73. #define SFLASH_CS_PORT (gpioPortC)
  74. #define SFLASH_CS_PIN (8)
  75. #endif
  76. /* SECTION: Micro SD */
  77. #if defined(EFM32_USING_SPISD)
  78. #if defined(EFM32_GXXX_DK)
  79. #define SD_CS_PORT (gpioPortC)
  80. #define SD_CS_PIN (8)
  81. #elif defined(EFM32GG_DK3750)
  82. #define SD_CS_PORT (gpioPortE)
  83. #define SD_CS_PIN (4)
  84. #endif
  85. #endif
  86. /* SECTION: Ethernet */
  87. #if defined(EFM32_USING_ETHERNET)
  88. #if defined(EFM32_GXXX_DK)
  89. #define ETH_CS_PORT (gpioPortB)
  90. #define ETH_CS_PIN (6)
  91. #elif defined(EFM32GG_DK3750)
  92. #define ETH_CS_PORT (gpioPortD)
  93. #define ETH_CS_PIN (3)
  94. #endif
  95. #endif
  96. /* SECTION: LCD */
  97. #if defined(EFM32_USING_LCD)
  98. #if defined(EFM32GG_DK3750)
  99. #define LCD_CS_PORT (gpioPortD)
  100. #define LCD_CS_PIN (3)
  101. #endif
  102. #endif
  103. /* SECTION: SYSTEM */
  104. #define EFM32_SRAM_END (SRAM_BASE + SRAM_SIZE)
  105. #define EFM32_BASE_PRI_DEFAULT (0x0UL << 5)
  106. #define EFM32_IRQ_PRI_DEFAULT (0x4UL << 5)
  107. /* SECTION: CLOCK */
  108. #define EFM32_USING_HFXO
  109. #define EFM32_USING_LFXO
  110. #if defined(EFM32_USING_HFXO)
  111. #if (defined(EFM32_G8XX_STK) || defined(EFM32_GXXX_DK))
  112. #define EFM32_HFXO_FREQUENCY (32000000)
  113. #elif defined(EFM32GG_DK3750)
  114. #define EFM32_HFXO_FREQUENCY (48000000)
  115. #else
  116. #define EFM32_HFXO_FREQUENCY (00000000)
  117. #endif
  118. #endif
  119. #if defined(EFM32_USING_LFXO)
  120. #if (defined(EFM32_G8XX_STK) || defined(EFM32_GXXX_DK))
  121. #define EFM32_LETIMER_TOP_100HZ (41)
  122. #elif defined(EFM32GG_DK3750)
  123. #define EFM32_LETIMER_TOP_100HZ (41)
  124. #else
  125. #define EFM32_LETIMER_TOP_100HZ (41)
  126. #endif
  127. #endif
  128. /* SECTION: USART */
  129. #define USART_RX_BUFFER_SIZE (64)
  130. #define LEUART_RX_BUFFER_SIZE (64)
  131. /* Location count (start from 0) */
  132. #if defined(_EFM32_GECKO_FAMILY)
  133. #define EFM32_USART_LOCATION_COUNT (3)
  134. #define EFM32_UART_LOCATION_COUNT (4)
  135. #define EFM32_LEUART_LOCATION_COUNT (3)
  136. #elif defined(_EFM32_GIANT_FAMILY)
  137. #define EFM32_USART_LOCATION_COUNT (6)
  138. #define EFM32_UART_LOCATION_COUNT (4)
  139. #define EFM32_LEUART_LOCATION_COUNT (5)
  140. #endif
  141. /* SUBSECTION: UART */
  142. #define UART_BAUDRATE (115200)
  143. /* SUBSECTION: SPI */
  144. /* Max SPI clock: HFPERCLK/2 for master, HFPERCLK/8 for slave */
  145. #define SPI_BAUDRATE (4000000)
  146. /* SECTION: I2C */
  147. #define IIC_RX_BUFFER_SIZE (32)
  148. #if defined(_EFM32_GECKO_FAMILY)
  149. #define EFM32_IIC_LOCATION_COUNT (4)
  150. #elif defined(_EFM32_GIANT_FAMILY)
  151. #define EFM32_IIC_LOCATION_COUNT (7)
  152. #endif
  153. /* SECTION: ADC */
  154. #define ADC_CALI_REF (adcRef2V5)
  155. #define ADC_CALI_CH (adcSingleInpCh5)
  156. #define ADC_CONVERT_FREQUENCY (7000000)
  157. #if (RT_CONSOLE_DEVICE == EFM_USART0)
  158. #define CONSOLE_DEVICE RT_USART0_NAME
  159. #elif (RT_CONSOLE_DEVICE == EFM_USART1)
  160. #define CONSOLE_DEVICE RT_USART1_NAME
  161. #elif (RT_CONSOLE_DEVICE == EFM_USART2)
  162. #define CONSOLE_DEVICE RT_USART2_NAME
  163. #elif (RT_CONSOLE_DEVICE == EFM_UART0)
  164. #define CONSOLE_DEVICE RT_UART0_NAME
  165. #elif (RT_CONSOLE_DEVICE == EFM_UART1)
  166. #define CONSOLE_DEVICE RT_UART1_NAME
  167. #elif (RT_CONSOLE_DEVICE == EFM_LEUART0)
  168. #define CONSOLE_DEVICE RT_LEUART0_NAME
  169. #elif (RT_CONSOLE_DEVICE == EFM_LEUART1)
  170. #define CONSOLE_DEVICE RT_LEUART1_NAME
  171. #else
  172. #define CONSOLE_DEVICE "NONE"
  173. #endif
  174. /* The following defines should be consistent with those in diskio.h */
  175. #define CTRL_SYNC 0
  176. #define GET_SECTOR_COUNT 1
  177. #define GET_SECTOR_SIZE 2
  178. #define GET_BLOCK_SIZE 3
  179. #define MMC_GET_TYPE 10
  180. #define MMC_GET_CSD 11
  181. #define MMC_GET_CID 12
  182. #define MMC_GET_OCR 13
  183. #define MMC_GET_SDSTAT 14
  184. /* The above defines should be consistent with those in diskio.h */
  185. /* I/O control options */
  186. #define RT_DEVICE_CTRL_SD_SYNC CTRL_SYNC
  187. #define RT_DEVICE_CTRL_SD_GET_SCOUNT GET_SECTOR_COUNT
  188. #define RT_DEVICE_CTRL_SD_GET_SSIZE GET_SECTOR_SIZE
  189. #define RT_DEVICE_CTRL_SD_GET_BSIZE GET_BLOCK_SIZE
  190. #define RT_DEVICE_CTRL_SD_GET_TYPE MMC_GET_TYPE
  191. #define RT_DEVICE_CTRL_SD_GET_CSD MMC_GET_CSD
  192. #define RT_DEVICE_CTRL_SD_GET_CID MMC_GET_CID
  193. #define RT_DEVICE_CTRL_SD_GET_OCR MMC_GET_OCR
  194. #define RT_DEVICE_CTRL_SD_GET_SDSTAT MMC_GET_SDSTAT
  195. /*! fixme: move the following define to Rtdef.h */
  196. #define RT_DEVICE_CTRL_USART_RBUFFER (0xF1) /*!< set USART/UART rx buffer */
  197. #define RT_DEVICE_CTRL_LEUART_RBUFFER (0xF2) /*!< set LEUART rx buffer */
  198. #define RT_DEVICE_CTRL_IIC_SETTING (0xF3) /*!< change IIC setting */
  199. #define RT_DEVICE_CTRL_TIMER_PERIOD (0xF4) /*!< set Timer timeout period */
  200. #define RT_DEVICE_CTRL_ADC_MODE (0xF5) /*!< change ADC mode */
  201. #define RT_DEVICE_CTRL_ADC_RESULT (0xF6) /*!< get ADC result */
  202. #define RT_DEVICE_CTRL_ACMP_INIT (0xF7) /*!< Initialize ACMP */
  203. #define RT_DEVICE_CTRL_ACMP_OUTPUT (0xF8) /*!< get ACMP output */
  204. /* Exported functions ------------------------------------------------------- */
  205. void rt_hw_board_init(void);
  206. void rt_hw_driver_init(void);
  207. rt_uint32_t rt_hw_interrupt_check(void);
  208. #endif /*__BOARD_H__ */