board.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /************************************************************************************
  2. * configs/same70-xplained/include/board.h
  3. *
  4. * Copyright (C) 2015 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ************************************************************************************/
  35. #ifndef __CONFIGS_SAME70_XPLAINED_INCLUDE_BOARD_H
  36. #define __CONFIGS_SAME70_XPLAINED_INCLUDE_BOARD_H
  37. /************************************************************************************
  38. * Included Files
  39. ************************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <stdbool.h>
  42. /************************************************************************************
  43. * Pre-processor Definitions
  44. ************************************************************************************/
  45. /* Clocking *************************************************************************/
  46. /* After power-on reset, the SAME70Q device is running out of the Master Clock using
  47. * the Fast RC Oscillator running at 4 MHz.
  48. *
  49. * MAINOSC: Frequency = 12MHz (crystal)
  50. *
  51. * 300MHz Settings:
  52. * PLLA: PLL Divider = 1, Multiplier = 20 to generate PLLACK = 240MHz
  53. * Master Clock (MCK): Source = PLLACK, Prescalar = 1 to generate MCK = 120MHz
  54. * CPU clock: 120MHz
  55. *
  56. * There can be two on-board crystals. However, the 32.768 crystal is not
  57. * populated on the stock SAME70. The fallback is to use th on-chip, slow RC
  58. * oscillator which has a frequency of 22-42 KHz, nominally 32 KHz.
  59. */
  60. #undef BOARD_HAVE_SLOWXTAL /* Slow crystal not populated */
  61. #define BOARD_SLOWCLK_FREQUENCY (32000) /* 32 KHz RC oscillator (nominal) */
  62. #define BOARD_MAINOSC_FREQUENCY (12000000) /* 12 MHz main oscillator */
  63. /* Main oscillator register settings.
  64. *
  65. * The main oscillator could be either the embedded 4/8/12 MHz fast RC oscillators
  66. * or an external 3-20 MHz crystal or ceramic resonator. The external clock source
  67. * is selected by default in sam_clockconfig.c. Here we need to specify the main
  68. * oscillator start-up time.
  69. *
  70. * REVISIT... this is old information:
  71. * The start up time should be should be:
  72. *
  73. * Start Up Time = 8 * MOSCXTST / SLCK = 56 Slow Clock Cycles.
  74. */
  75. #define BOARD_CKGR_MOR_MOSCXTST (62 << PMC_CKGR_MOR_MOSCXTST_SHIFT) /* Start-up Time */
  76. #define BOARD_CKGR_MOR_MOSCXTENBY (PMC_CKGR_MOR_MOSCXTEN) /* Crystal Oscillator Enable */
  77. /* PLLA configuration.
  78. *
  79. * Divider = 1
  80. * Multiplier = 25
  81. *
  82. * Yields:
  83. *
  84. * PLLACK = 25 * 12MHz / 1 = 300MHz
  85. */
  86. #define BOARD_CKGR_PLLAR_STMODE PMC_CKGR_PLLAR_STMODE_FAST
  87. #define BOARD_CKGR_PLLAR_COUNT (63 << PMC_CKGR_PLLAR_COUNT_SHIFT)
  88. #define BOARD_CKGR_PLLAR_MUL PMC_CKGR_PLLAR_MUL(24)
  89. #define BOARD_CKGR_PLLAR_DIV PMC_CKGR_PLLAR_DIV_BYPASS
  90. /* PMC master clock register settings.
  91. *
  92. * BOARD_PMC_MCKR_CSS - The source of main clock input. This may be one of:
  93. *
  94. * PMC_MCKR_CSS_SLOW Slow Clock
  95. * PMC_MCKR_CSS_MAIN Main Clock
  96. * PMC_MCKR_CSS_PLLA PLLA Clock
  97. * PMC_MCKR_CSS_UPLL Divided UPLL Clock
  98. *
  99. * BOARD_PMC_MCKR_PRES - Source clock pre-scaler. May be one of:
  100. *
  101. * PMC_MCKR_PRES_DIV1 Selected clock
  102. * PMC_MCKR_PRES_DIV2 Selected clock divided by 2
  103. * PMC_MCKR_PRES_DIV4 Selected clock divided by 4
  104. * PMC_MCKR_PRES_DIV8 Selected clock divided by 8
  105. * PMC_MCKR_PRES_DIV16 Selected clock divided by 16
  106. * PMC_MCKR_PRES_DIV32 Selected clock divided by 32
  107. * PMC_MCKR_PRES_DIV64 Selected clock divided by 64
  108. * PMC_MCKR_PRES_DIV3 Selected clock divided by 3
  109. *
  110. * The prescaler determines (1) the CPU clock and (2) the input into the
  111. * second divider that then generates the Master Clock (MCK). MCK is the
  112. * source clock of the peripheral clocks.
  113. *
  114. * BOARD_PMC_MCKR_MDIV - MCK divider. May be one of:
  115. *
  116. * PMC_MCKR_MDIV_DIV1 Master Clock = Prescaler Output Clock / 1
  117. * PMC_MCKR_MDIV_DIV2 Master Clock = Prescaler Output Clock / 2
  118. * PMC_MCKR_MDIV_DIV4 Master Clock = Prescaler Output Clock / 4
  119. * PMC_MCKR_MDIV_DIV3 Master Clock = Prescaler Output Clock / 3
  120. */
  121. #define BOARD_PMC_MCKR_CSS PMC_MCKR_CSS_PLLA /* Source = PLLA */
  122. #define BOARD_PMC_MCKR_PRES PMC_MCKR_PRES_DIV1 /* Prescaler = /1 */
  123. #define BOARD_PMC_MCKR_MDIV PMC_MCKR_MDIV_DIV2 /* MCK divider = /2 */
  124. /* USB clocking */
  125. #define BOARD_PMC_MCKR_UPLLDIV2 0 /* UPLL clock not divided by 2 */
  126. /* Resulting frequencies */
  127. #define BOARD_PLLA_FREQUENCY (300000000) /* PLLACK: 25 * 12Mhz / 1 */
  128. #define BOARD_CPU_FREQUENCY (300000000) /* CPU: PLLACK / 1 */
  129. #define BOARD_MCK_FREQUENCY (150000000) /* MCK: PLLACK / 1 / 2 */
  130. #undef BOARD_UPLL_FREQUENCY /* To be provided */
  131. /* HSMCI clocking
  132. *
  133. * Multimedia Card Interface clock (MCCK or MCI_CK) is Master Clock (MCK)
  134. * divided by (2*(CLKDIV) + CLOCKODD + 2).
  135. *
  136. * MCI_SPEED = MCK / (2*CLKDIV + CLOCKODD + 2)
  137. *
  138. * Where CLKDIV has a range of 0-255.
  139. */
  140. /* MCK = 150MHz, CLKDIV = 186, MCI_SPEED = 150MHz / (2*186 + 1 + 2) = 400 KHz */
  141. #define HSMCI_INIT_CLKDIV ((186 << HSMCI_MR_CLKDIV_SHIFT) | HSMCI_MR_CLKODD)
  142. /* MCK = 150MHz, CLKDIV = 3 w/CLOCKODD, MCI_SPEED = 150MHz /(2*3 + 0 + 2) = 18.75 MHz */
  143. #define HSMCI_MMCXFR_CLKDIV (2 << HSMCI_MR_CLKDIV_SHIFT)
  144. /* MCK = 150MHz, CLKDIV = 2, MCI_SPEED = 150MHz /(2*2 + 0 + 2) = 25 MHz */
  145. #define HSMCI_SDXFR_CLKDIV (2 << HSMCI_MR_CLKDIV_SHIFT)
  146. #define HSMCI_SDWIDEXFR_CLKDIV HSMCI_SDXFR_CLKDIV
  147. /* FLASH wait states.
  148. *
  149. * Wait states Max frequency at 105 centigrade (STH conditions)
  150. *
  151. * VDDIO
  152. * 1.62V 2.7V
  153. * --- ------- -------
  154. * 0 26 MHz 30 MHz
  155. * 1 52 MHz 62 MHz
  156. * 2 78 MHz 93 MHz
  157. * 3 104 MHz 124 MHz
  158. * 4 131 MHz 150 MHz
  159. * 5 150 MHz --- MHz
  160. *
  161. * Given: VDDIO=3.3V, VDDCORE=1.2V, MCK=150MHz
  162. */
  163. #define BOARD_FWS 4
  164. /* LED definitions ******************************************************************/
  165. /* LEDs
  166. *
  167. * A single LED is available driven by PC8.
  168. */
  169. /* LED index values for use with board_userled() */
  170. #define BOARD_LED0 0
  171. #define BOARD_NLEDS 1
  172. /* LED bits for use with board_userled_all() */
  173. #define BOARD_LED0_BIT (1 << BOARD_LED0)
  174. /* These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is
  175. * defined. In that case, the usage by the board port is defined in
  176. * include/board.h and src/sam_autoleds.c. The LEDs are used to encode
  177. * OS-related events as follows:
  178. *
  179. * ------------------- ---------------------------- ------
  180. * SYMBOL Meaning LED
  181. * ------------------- ---------------------------- ------ */
  182. #define LED_STARTED 0 /* NuttX has been started OFF */
  183. #define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF */
  184. #define LED_IRQSENABLED 0 /* Interrupts enabled OFF */
  185. #define LED_STACKCREATED 1 /* Idle stack created ON */
  186. #define LED_INIRQ 2 /* In an interrupt N/C */
  187. #define LED_SIGNAL 2 /* In a signal handler N/C */
  188. #define LED_ASSERTION 2 /* An assertion failed N/C */
  189. #define LED_PANIC 3 /* The system has crashed FLASH */
  190. #undef LED_IDLE /* MCU is is sleep mode Not used */
  191. /* Thus is LED is statically on, NuttX has successfully booted and is,
  192. * apparently, running normally. If LED is flashing at approximately
  193. * 2Hz, then a fatal error has been detected and the system has halted.
  194. */
  195. /* Button definitions ***************************************************************/
  196. /* Buttons
  197. *
  198. * SAM E70 Xplained contains two mechanical buttons. One button is the RESET
  199. * button connected to the SAM E70 reset line and the other, PA11, is a generic
  200. * user configurable button. When a button is pressed it will drive the I/O
  201. * line to GND.
  202. *
  203. * NOTE: There are no pull-up resistors connected to the generic user buttons
  204. * so it is necessary to enable the internal pull-up in the SAM E70 to use the
  205. * button.
  206. */
  207. #define BUTTON_SW0 0
  208. #define NUM_BUTTONS 1
  209. #define BUTTON_SW0_BIT (1 << BUTTON_SW0)
  210. /* PIO Disambiguation ***************************************************************/
  211. /* Serial Console
  212. *
  213. * The SAME70-XPLD has no on-board RS-232 drivers so it will be necessary to use
  214. * either the VCOM or an external RS-232 driver. Here are some options.
  215. *
  216. * - Arduino Serial Shield: One option is to use an Arduino-compatible
  217. * serial shield. This will use the RXD and TXD signals available at pins
  218. * 0 an 1, respectively, of the Arduino "Digital Low" connector. On the
  219. * SAME70-XPLD board, this corresponds to UART3:
  220. *
  221. * ------ ------ ------- ------- --------
  222. * Pin on SAME70 Arduino Arduino SAME70
  223. * J503 PIO Name Pin Function
  224. * ------ ------ ------- ------- --------
  225. * 1 PD28 RX0 0 URXD3
  226. * 2 PD30 TX0 1 UTXD3
  227. * ------ ------ ------- ------- --------
  228. *
  229. * There are alternative pin selections only for UART3 TXD:
  230. */
  231. #define GPIO_UART3_TXD GPIO_UART3_TXD_1
  232. /* - Arduino Communications. Additional UART/USART connections are available
  233. * on the Arduino Communications connection J505:
  234. *
  235. * ------ ------ ------- ------- --------
  236. * Pin on SAME70 Arduino Arduino SAME70
  237. * J503 PIO Name Pin Function
  238. * ------ ------ ------- ------- --------
  239. * 3 PD18 RX1 0 URXD4
  240. * 4 PD19 TX1 0 UTXD4
  241. * 5 PD15 RX2 0 RXD2
  242. * 6 PD16 TX2 0 TXD2
  243. * 7 PB0 RX3 0 RXD0
  244. * 8 PB1 TX3 1 TXD0
  245. * ------ ------ ------- ------- --------
  246. *
  247. * There are alternative pin selections only for UART4 TXD:
  248. */
  249. #define GPIO_UART4_TXD GPIO_UART4_TXD_1
  250. /* - SAMV7-XULT EXTn connectors. USART pins are also available the EXTn
  251. * connectors. The following are labelled in the User Guide for USART
  252. * functionality:
  253. *
  254. * ---- -------- ------ --------
  255. * EXT1 EXTI1 SAME70 SAME70
  256. * Pin Name PIO Function
  257. * ---- -------- ------ --------
  258. * 13 USART_RX PB00 RXD0
  259. * 14 USART_TX PB01 TXD0
  260. *
  261. * ---- -------- ------ --------
  262. * EXT2 EXTI2 SAME70 SAME70
  263. * Pin Name PIO Function
  264. * ---- -------- ------ --------
  265. * 13 USART_RX PA21 RXD1
  266. * 14 USART_TX PB04 TXD1
  267. *
  268. * There are no alternative pin selections for USART0 or USART1.
  269. */
  270. /* - VCOM. The Virtual Com Port gateway is available on USART1:
  271. *
  272. * ------ --------
  273. * SAME70 SAME70
  274. * PIO Function
  275. * ------ --------
  276. * PB04 TXD1
  277. * PA21 RXD1
  278. * ------ --------
  279. *
  280. * There are no alternative pin selections for USART1.
  281. */
  282. /* MCAN1
  283. *
  284. * SAM E70 Xplained has two MCAN modules that performs communication according
  285. * to ISO11898-1 (Bosch CAN specification 2.0 part A,B) and Bosch CAN FD
  286. * specification V1.0. MCAN1 is connected to an on-board ATA6561 CAN physical-layer
  287. * transceiver.
  288. *
  289. * ------- -------- -------- -------------
  290. * SAM E70 FUNCTION ATA6561 SHARED
  291. * PIN FUNCTION FUNCTIONALITY
  292. * ------- -------- -------- -------------
  293. * PC14 CANTX1 TXD Shield
  294. * PC12 CANRX1 RXD Shield
  295. * ------- -------- -------- -------------
  296. */
  297. #define GPIO_MCAN1_TX GPIO_MCAN1_TX_2
  298. #define GPIO_MCAN1_RX GPIO_MCAN1_RX_2
  299. /************************************************************************************
  300. * Public Types
  301. ************************************************************************************/
  302. /************************************************************************************
  303. * Public Data
  304. ************************************************************************************/
  305. #ifndef __ASSEMBLY__
  306. #undef EXTERN
  307. #if defined(__cplusplus)
  308. #define EXTERN extern "C"
  309. extern "C"
  310. {
  311. #else
  312. #define EXTERN extern
  313. #endif
  314. /************************************************************************************
  315. * Public Functions
  316. ************************************************************************************/
  317. /************************************************************************************
  318. * Name: sam_lcdclear
  319. *
  320. * Description:
  321. * This is a non-standard LCD interface just for the SAM4e-EK board. Because
  322. * of the various rotations, clearing the display in the normal way by writing a
  323. * sequences of runs that covers the entire display can be very slow. Here the
  324. * display is cleared by simply setting all GRAM memory to the specified color.
  325. *
  326. ************************************************************************************/
  327. void sam_lcdclear(uint16_t color);
  328. #undef EXTERN
  329. #if defined(__cplusplus)
  330. }
  331. #endif
  332. #endif /* __ASSEMBLY__ */
  333. #endif /* __CONFIGS_SAME70_XPLAINED_INCLUDE_BOARD_H */