board.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /****************************************************************************
  2. * configs/lpc4357-link2/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_LPC4357_LINK2_INCLUDE_BOARD_H
  36. #define __CONFIGS_LPC4357_LINK2_INCLUDE_BOARD_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <stdbool.h>
  42. #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ)
  43. # include <nuttx/irq.h>
  44. #endif
  45. /****************************************************************************
  46. * Pre-processor Definitions
  47. ****************************************************************************/
  48. /* Clocking ****************************************************************/
  49. /* NOTE: The following definitions require lpc43_cgu.h. It is not included
  50. * here because the including C file may not have that file in its include
  51. * path.
  52. *
  53. * The Xplorer board has four crystals on board:
  54. *
  55. * Y1 - RTC 32.768 MHz oscillator input,
  56. * Y2 - 24.576 MHz input to the UDA 1380 audio codec,
  57. * Y3 - 12.000 MHz LPC43xx crystal oscillator input
  58. * Y4 - 50 MHz input for Ethernet
  59. */
  60. #define BOARD_XTAL_FREQUENCY (12000000) /* XTAL oscillator frequency (Y3) */
  61. #define BOARD_RTCCLK_FREQUENCY (32768) /* RTC oscillator frequency (Y1) */
  62. #define BOARD_INTRCOSC_FREQUENCY (4000000) /* Internal RC oscillator frequency */
  63. /* Integer and direct modes are supported:
  64. *
  65. * In integer mode (Fclkout < 156000000):
  66. * Fclkin = BOARD_XTAL_FREQUENCY
  67. * Fclkout = Msel * FClkin / Nsel
  68. * Fcco = 2 * Psel * Fclkout
  69. * In direct mode (Fclkout > 156000000):
  70. * Fclkin = BOARD_XTAL_FREQUENCY
  71. * Fclkout = Msel * FClkin / Nsel
  72. * Fcco = Fclkout
  73. */
  74. #ifdef CONFIG_LPC43_72MHz
  75. /* NOTE: At 72MHz, the calibrated value of CONFIG_BOARD_LOOPSPERMSEC was
  76. * determined to be:
  77. *
  78. * CONFIG_BOARD_LOOPSPERMSEC=7191
  79. *
  80. * executing from SRAM.
  81. */
  82. /* Final clocking (Integer mode with no ramp-up)
  83. *
  84. * Fclkout = 6 * 12MHz / 1 = 72MHz
  85. * Fcco = 2 * 2 * 72MHz = 216MHz
  86. */
  87. # define BOARD_PLL_MSEL (6) /* Msel = 6 */
  88. # define BOARD_PLL_NSEL (1) /* Nsel = 1 */
  89. # define BOARD_PLL_PSEL (2) /* Psel = 2 */
  90. # define BOARD_FCLKOUT_FREQUENCY (72000000) /* 6 * 12,000,000 / 1 */
  91. # define BOARD_FCCO_FREQUENCY (244000000) /* 2 * 2 * Fclkout */
  92. #else
  93. /* NOTE: At 72MHz, the calibrated value of CONFIG_BOARD_LOOPSPERMSEC was
  94. * determined to be:
  95. *
  96. * CONFIG_BOARD_LOOPSPERMSEC=18535
  97. *
  98. * executing from SRAM.
  99. */
  100. /* Intermediate ramp-up clocking (Integer mode). If BOARD_PLL_RAMP_MSEL
  101. * is not defined, there will be no ramp-up.
  102. *
  103. * Fclkout = 9 * 12MHz / 1 = 108MHz
  104. * Fcco = 2 * 1 * 108MHz = 216MHz
  105. */
  106. # define BOARD_PLL_RAMP_MSEL (9) /* Msel = 9 */
  107. # define BOARD_PLL_RAMP_NSEL (1) /* Nsel = 1 */
  108. # define BOARD_PLL_RAMP_PSEL (1) /* Psel = 1 */
  109. # define BOARD_RAMP_FCLKOUT (108000000) /* 9 * 12,000,000 / 1 */
  110. # define BOARD_RAMP_FCCO (216000000) /* 2 * 1 * Fclkout */
  111. /* Final clocking (Direct mode).
  112. *
  113. * Fclkout = 17 * 12MHz / 1 = 204MHz
  114. * Fcco = Fclockout = 204MHz
  115. */
  116. # define BOARD_PLL_MSEL (17) /* Msel = 17 */
  117. # define BOARD_PLL_NSEL (1) /* Nsel = 1 */
  118. # define BOARD_FCLKOUT_FREQUENCY (204000000) /* 17 * 12,000,000 / 1 */
  119. # define BOARD_FCCO_FREQUENCY (204000000) /* Fclockout */
  120. #endif
  121. #define LPC43_CCLK BOARD_FCLKOUT_FREQUENCY
  122. #if defined(CONFIG_LPC43_BUS) || defined(CONFIG_LPC43_MCPWM) || defined(CONFIG_LPC43_I2C0) || defined(CONFIG_LPC43_I2S0) || defined(CONFIG_LPC43_I2S1) || defined(CONFIG_LPC43_CAN1)
  123. # define BOARD_ABP1_CLKSRC BASE_APB_CLKSEL_XTAL
  124. # define BOARD_ABP1_FREQUENCY BOARD_XTAL_FREQUENCY
  125. #endif
  126. #if defined(CONFIG_LPC43_BUS) || defined(CONFIG_LPC43_I2C1) || defined(CONFIG_LPC43_DAC) || defined(CONFIG_LPC43_ADC0) || defined(CONFIG_LPC43_ADC1) || defined(CONFIG_LPC43_CAN0)
  127. # define BOARD_ABP3_CLKSRC BASE_APB_CLKSEL_XTAL
  128. # define BOARD_ABP3_FREQUENCY BOARD_XTAL_FREQUENCY
  129. #endif
  130. #define BOARD_IDIVA_DIVIDER (2)
  131. #define BOARD_IDIVA_CLKSRC IDIVA_CLKSEL_PLL1
  132. #define BOARD_IDIVA_FREQUENCY (BOARD_FCLKOUT_FREQUENCY/BOARD_IDIVA_DIVIDER)
  133. /* USB0 ********************************************************************/
  134. /* Settings needed in lpc43_cpu.c */
  135. #define BOARD_USB0_CLKSRC PLL0USB_CLKSEL_XTAL
  136. #define BOARD_USB0_MDIV 0x06167ffa /* Table 149 datsheet, valid for 12Mhz Fclkin */
  137. #define BOARD_USB0_NP_DIV 0x00302062 /* Table 149 datsheet, valid for 12Mhz Fclkin */
  138. /* SPIFI clocking **********************************************************/
  139. /* The SPIFI will receive clocking from a divider per the settings provided
  140. * in this file. The NuttX code will configure PLL1 as the input clock
  141. * for the selected divider
  142. */
  143. #undef BOARD_SPIFI_PLL1 /* No division */
  144. #undef BOARD_SPIFI_DIVA /* Supports division by 1-4 */
  145. #undef BOARD_SPIFI_DIVB /* Supports division by 1-16 */
  146. #undef BOARD_SPIFI_DIVC /* Supports division by 1-16 */
  147. #undef BOARD_SPIFI_DIVD /* Supports division by 1-16 */
  148. #undef BOARD_SPIFI_DIVE /* Supports division by 1-256 */
  149. #if BOARD_FCLKOUT_FREQUENCY < 20000000
  150. # define BOARD_SPIFI_PLL1 1 /* Use PLL1 directly */
  151. #else
  152. # define BOARD_SPIFI_DIVB 1 /* Use IDIVB */
  153. #endif
  154. /* We need to configure the divider so that its output is as close to the
  155. * desired SCLK value. The peak data transfer rate will be about half of
  156. * this frequency in bytes per second.
  157. */
  158. #if BOARD_FCLKOUT_FREQUENCY < 20000000
  159. # define BOARD_SPIFI_FREQUENCY BOARD_FCLKOUT_FREQUENCY /* 72Mhz? */
  160. #else
  161. # define BOARD_SPIFI_DIVIDER (14) /* 204MHz / 14 = 14.57MHz */
  162. # define BOARD_SPIFI_FREQUENCY (102000000) /* 204MHz / 14 = 14.57MHz */
  163. #endif
  164. #if CONFIG_SPIFI_LIBRARY
  165. # define SPIFI_DEVICE_ALL 0 /**< Enables all devices in family */
  166. # define SPIFI_DEVICE_S25FL016K 0 /**< Enables Spansion S25FL016K device */
  167. # define SPIFI_DEVICE_S25FL032P 0 /**< Enables Spansion S25FL032P device */
  168. # define SPIFI_DEVICE_S25FL064P 0 /**< Enables Spansion S25FL064P device */
  169. # define SPIFI_DEVICE_S25FL129P_64K 0 /**< Enables Spansion S25FL129P (64K block) device */
  170. # define SPIFI_DEVICE_S25FL129P_256K 0 /**< Enables Spansion S25FL129P (256K block) device */
  171. # define SPIFI_DEVICE_S25FL164K 0 /**< Enables Spansion S25FL164K device */
  172. # define SPIFI_DEVICE_S25FL256S_64K 0 /**< Enables Spansion S25FL256S (64K block) device */
  173. # define SPIFI_DEVICE_S25FL256S_256K 0 /**< Enables Spansion S25FL256S (256K block) device */
  174. # define SPIFI_DEVICE_S25FL512S 0 /**< Enables Spansion S25FL512S device */
  175. # define SPIFI_DEVICE_MX25L1635E 0 /**< Enables Macronix MX25L1635E device */
  176. # define SPIFI_DEVICE_MX25L3235E 0 /**< Enables Macronix MX25L3235E device */
  177. # define SPIFI_DEVICE_MX25L8035E 0 /**< Enables Macronix MX25L8035E device */
  178. # define SPIFI_DEVICE_MX25L6435E 0 /**< Enables Macronix MX25L6435E device */
  179. # define SPIFI_DEVICE_W25Q32FV 0 /**< Enables Winbond W25Q32FV device */
  180. # define SPIFI_DEVICE_W25Q64FV 0 /**< Enables Winbond W25Q32V device */
  181. # define SPIFI_DEVICE_W25Q80BV 1 /**< Enables Winbond W25Q80BV device */
  182. # define SPIFI_DEVICE_REQUENCY_DIVIDER 2 /* PLL1 clock divider */
  183. #endif
  184. /* UART clocking ***********************************************************/
  185. /* Configure all U[S]ARTs to use the XTAL input frequency */
  186. #define BOARD_USART0_CLKSRC BASE_USART0_CLKSEL_XTAL
  187. #define BOARD_USART0_BASEFREQ BOARD_XTAL_FREQUENCY
  188. #define BOARD_UART1_CLKSRC BASE_UART1_CLKSEL_XTAL
  189. #define BOARD_UART1_BASEFREQ BOARD_XTAL_FREQUENCY
  190. #define BOARD_USART2_CLKSRC BASE_USART2_CLKSEL_XTAL
  191. #define BOARD_USART2_BASEFREQ BOARD_XTAL_FREQUENCY
  192. #define BOARD_USART3_CLKSRC BASE_USART3_CLKSEL_XTAL
  193. #define BOARD_USART3_BASEFREQ BOARD_XTAL_FREQUENCY
  194. /* SSP clocking ***********************************************************
  195. *
  196. * BOARD_SSPX_BASEFREQ may be further divided by 2-254 to get the SSP clock. If we
  197. * want a usable range of 400KHz to 25MHz for the SSP, then:
  198. *
  199. * 1. SSPCLK must be greater than (2*25MHz) = 50MHz, and
  200. * 2. SSPCLK must be less than (254*400Khz) = 101.6MHz.
  201. *
  202. */
  203. #define BOARD_SSP0_CLKSRC BASE_SSP0_CLKSEL_IDIVA
  204. #define BOARD_SSP0_BASEFREQ BOARD_IDIVA_FREQUENCY
  205. #define BOARD_SSP1_CLKSRC BASE_SSP1_CLKSEL_IDIVA
  206. #define BOARD_SSP1_BASEFREQ BOARD_IDIVA_FREQUENCY
  207. /* LED definitions *********************************************************/
  208. /* LED1 K2 GPIO0[8]
  209. *
  210. * LED index values for use with board_userled()
  211. */
  212. #define BOARD_LED 0
  213. #define BOARD_NLEDS 1
  214. /* LED bits for use with board_userled_all() */
  215. #define BOARD_LED_BIT (1 << BOARD_LED)
  216. /* If CONFIG_ARCH_LEDS is defined, the LEDs will be controlled as follows
  217. * for NuttX debug functionality (where NC means "No Change"). If
  218. * CONFIG_ARCH_LEDS is not defined, then the LEDs are completely under
  219. * control of the application. The following interfaces are then available
  220. * for application control of the LEDs:
  221. *
  222. * void board_userled_initialize(void);
  223. * void board_userled(int led, bool ledon);
  224. * void board_userled_all(uint8_t ledset);
  225. */
  226. /* LED */
  227. #define LED_STARTED 0 /* OFF */
  228. #define LED_HEAPALLOCATE 0 /* OFF */
  229. #define LED_IRQSENABLED 0 /* OFF */
  230. #define LED_STACKCREATED 1 /* ON */
  231. #define LED_INIRQ 2 /* NC */
  232. #define LED_SIGNAL 2 /* NC */
  233. #define LED_ASSERTION 2 /* NC */
  234. #define LED_PANIC 3 /* Flashing */
  235. /* UART Pins ****************************************************************/
  236. /*
  237. * The following definitions must be provided so that the LPC43 serial
  238. * driver can set up the U[S]ART for the serial console properly (see the
  239. * file arch/arc/src/lpc43xx/lpc43*_pinconf.h for more info).
  240. */
  241. #define PINCONF_U0_TXD PINCONF_U0_TXD_3
  242. #define PINCONF_U0_RXD PINCONF_U0_RXD_3
  243. #define PINCONF_U0_DIR PINCONF_U0_DIR_3
  244. #define PINCONF_U1_TXD PINCONF_U1_TXD_1
  245. #define PINCONF_U1_RXD PINCONF_U1_RXD_1
  246. #define PINCONF_U2_TXD PINCONF_U2_TXD_2
  247. #define PINCONF_U2_RXD PINCONF_U2_RXD_2
  248. #define PINCONF_U2_DIR PINCONF_U2_DIR_2
  249. #define PINCONF_U3_TXD PINCONF_U3_TXD_2
  250. #define PINCONF_U3_RXD PINCONF_U3_RXD_2
  251. #define PINCONF_U3_DIR PINCONF_U3_DIR_2
  252. /* I2C1 pins, not really accessible on the board */
  253. #define PINCONF_I2C1_SCL PINCONF_I2C1_SCL_1
  254. #define PINCONF_I2C1_SDA PINCONF_I2C1_SDA_1
  255. /* SSP1 pins */
  256. #define PINCONF_SSP1_MISO PINCONF_SSP1_MISO_3
  257. #define PINCONF_SSP1_MOSI PINCONF_SSP1_MOSI_3
  258. #define PINCONF_SSP1_SCK PINCONF_SSP1_SCK_1
  259. #define PINCONF_SSP1_SSEL PINCONF_SSP1_SSEL_1
  260. /****************************************************************************
  261. * Public Types
  262. ****************************************************************************/
  263. #ifndef __ASSEMBLY__
  264. /****************************************************************************
  265. * Public Data
  266. ****************************************************************************/
  267. #undef EXTERN
  268. #if defined(__cplusplus)
  269. #define EXTERN extern "C"
  270. extern "C"
  271. {
  272. #else
  273. #define EXTERN extern
  274. #endif
  275. /****************************************************************************
  276. * Public Function Prototypes
  277. ****************************************************************************/
  278. /****************************************************************************
  279. * Name: lpc43_boardinitialize
  280. *
  281. * Description:
  282. * All LPC43xx architectures must provide the following entry point. This
  283. * entry point is called early in the intitialization -- after all memory
  284. * has been configured and mapped but before any devices have been
  285. * initialized.
  286. *
  287. ****************************************************************************/
  288. void lpc43_boardinitialize(void);
  289. #undef EXTERN
  290. #if defined(__cplusplus)
  291. }
  292. #endif
  293. #endif /* __ASSEMBLY__ */
  294. #endif /* __CONFIGS_LPC4357_LINK2_INCLUDE_BOARD_H */