board.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /************************************************************************************
  2. * configs/nucleo-l496zg/include/board.h
  3. *
  4. * Copyright (C) 2016 Gregory Nutt. All rights reserved.
  5. * Authors: Gregory Nutt <gnutt@nuttx.org>
  6. * Mark Olsson <post@markolsson.se>
  7. * David Sidrane <david_s5@nscdg.com>
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. * 3. Neither the name NuttX nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ************************************************************************************/
  37. #ifndef __CONFIG_NUCLEO_L496ZG_INCLUDE_BOARD_H
  38. #define __CONFIG_NUCLEO_L496ZG_INCLUDE_BOARD_H
  39. /************************************************************************************
  40. * Included Files
  41. ************************************************************************************/
  42. #include <nuttx/config.h>
  43. #ifndef __ASSEMBLY__
  44. # include <stdint.h>
  45. #endif
  46. #ifdef __KERNEL__
  47. #include "stm32l4_rcc.h"
  48. #ifdef CONFIG_STM32L4_SDMMC1
  49. # include "stm32l4_sdmmc.h"
  50. #endif
  51. #endif
  52. /************************************************************************************
  53. * Pre-processor Definitions
  54. ************************************************************************************/
  55. /* Clocking *************************************************************************/
  56. /* The Nucleo-144 board provides the following clock sources:
  57. *
  58. * MCO: 8 MHz from MCO output of ST-LINK is used as input clock
  59. * X2: 32.768 KHz crystal for LSE
  60. * X3: HSE crystal oscillator (not provided)
  61. *
  62. * So we have these clock source available within the STM32
  63. *
  64. * HSI: 16 MHz RC factory-trimmed
  65. * LSI: 32 KHz RC
  66. * HSE: 8 MHz from MCO output of ST-LINK
  67. * LSE: 32.768 kHz
  68. */
  69. #define STM32L4_HSI_FREQUENCY 16000000ul
  70. #define STM32L4_LSI_FREQUENCY 32000
  71. #define STM32L4_HSE_FREQUENCY 8000000ul /* 8 MHz from MCO output */
  72. #define STM32L4_LSE_FREQUENCY 32768
  73. #define HSE_CLOCK_CONFIG
  74. #if defined(HSI_CLOCK_CONFIG)
  75. #define STM32L4_BOARD_USEHSI
  76. /* Prescaler common to all PLL inputs; will be 1 */
  77. #define STM32L4_PLLCFG_PLLM RCC_PLLCFG_PLLM(1)
  78. /* 'main' PLL config; we use this to generate our system clock via the R
  79. * output. We set it up as 16 MHz / 1 * 10 / 2 = 80 MHz
  80. *
  81. * XXX NOTE: currently the main PLL is implicitly turned on and is implicitly
  82. * the system clock; this should be configurable since not all applications may
  83. * want things done this way.
  84. */
  85. #define STM32L4_PLLCFG_PLLN RCC_PLLCFG_PLLN(10)
  86. #define STM32L4_PLLCFG_PLLP 0
  87. #undef STM32L4_PLLCFG_PLLP_ENABLED
  88. #define STM32L4_PLLCFG_PLLQ RCC_PLLCFG_PLLQ_2
  89. #define STM32L4_PLLCFG_PLLQ_ENABLED
  90. #define STM32L4_PLLCFG_PLLR RCC_PLLCFG_PLLR_2
  91. #define STM32L4_PLLCFG_PLLR_ENABLED
  92. /* 'SAIPLL1' is used to generate the 48 MHz clock, since we can't
  93. * do that with the main PLL's N value. We set N = 13, and enable
  94. * the Q output (ultimately for CLK48) with /4. So,
  95. * 16 MHz / 1 * 12 / 4 = 48 MHz
  96. *
  97. * XXX NOTE: currently the SAIPLL /must/ be explicitly selected in the
  98. * menuconfig, or else all this is a moot point, and the various 48 MHz
  99. * peripherals will not work (RNG at present). I would suggest removing
  100. * that option from Kconfig altogether, and simply making it an option
  101. * that is selected via a #define here, like all these other params.
  102. */
  103. #define STM32L4_PLLSAI1CFG_PLLN RCC_PLLSAI1CFG_PLLN(12)
  104. #define STM32L4_PLLSAI1CFG_PLLP 0
  105. #undef STM32L4_PLLSAI1CFG_PLLP_ENABLED
  106. #define STM32L4_PLLSAI1CFG_PLLQ RCC_PLLSAI1CFG_PLLQ_4
  107. #define STM32L4_PLLSAI1CFG_PLLQ_ENABLED
  108. #define STM32L4_PLLSAI1CFG_PLLR 0
  109. #undef STM32L4_PLLSAI1CFG_PLLR_ENABLED
  110. /* 'SAIPLL2' is not used in this application */
  111. #define STM32L4_PLLSAI2CFG_PLLN RCC_PLLSAI2CFG_PLLN(8)
  112. #define STM32L4_PLLSAI2CFG_PLLP 0
  113. #undef STM32L4_PLLSAI2CFG_PLLP_ENABLED
  114. #define STM32L4_PLLSAI2CFG_PLLR 0
  115. #undef STM32L4_PLLSAI2CFG_PLLR_ENABLED
  116. #define STM32L4_SYSCLK_FREQUENCY 80000000ul
  117. /* CLK48 will come from PLLSAI1 (implicitly Q) */
  118. #define STM32L4_USE_CLK48 1
  119. #define STM32L4_CLK48_SEL RCC_CCIPR_CLK48SEL_PLLSAI1
  120. /* Enable the LSE oscillator, used automatically trim the MSI, and for RTC */
  121. #define STM32L4_USE_LSE 1
  122. /* AHB clock (HCLK) is SYSCLK (80MHz) */
  123. #define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */
  124. #define STM32L4_HCLK_FREQUENCY STM32L4_SYSCLK_FREQUENCY
  125. #define STM32L4_BOARD_HCLK STM32L4_HCLK_FREQUENCY /* Same as above, to satisfy compiler */
  126. /* APB1 clock (PCLK1) is HCLK/1 (80MHz) */
  127. #define STM32L4_RCC_CFGR_PPRE1 RCC_CFGR_PPRE1_HCLK /* PCLK1 = HCLK / 1 */
  128. #define STM32L4_PCLK1_FREQUENCY (STM32L4_HCLK_FREQUENCY/1)
  129. /* Timers driven from APB1 will be twice PCLK1 */
  130. /* REVISIT : this can be configured */
  131. #define STM32L4_APB1_TIM2_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  132. #define STM32L4_APB1_TIM3_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  133. #define STM32L4_APB1_TIM4_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  134. #define STM32L4_APB1_TIM5_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  135. #define STM32L4_APB1_TIM6_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  136. #define STM32L4_APB1_TIM7_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  137. /* APB2 clock (PCLK2) is HCLK (80MHz) */
  138. #define STM32L4_RCC_CFGR_PPRE2 RCC_CFGR_PPRE2_HCLK /* PCLK2 = HCLK / 1 */
  139. #define STM32L4_PCLK2_FREQUENCY (STM32L4_HCLK_FREQUENCY/1)
  140. /* Timers driven from APB2 will be twice PCLK2 */
  141. /* REVISIT : this can be configured */
  142. #define STM32L4_APB2_TIM1_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  143. #define STM32L4_APB2_TIM8_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  144. #define STM32L4_APB2_TIM15_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  145. #define STM32L4_APB2_TIM16_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  146. #define STM32L4_APB2_TIM17_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  147. /* Timer Frequencies, if APBx is set to 1, frequency is same to APBx
  148. * otherwise frequency is 2xAPBx.
  149. * Note: TIM1,8,15,16,17 are on APB2, others on APB1
  150. */
  151. /* REVISIT : this can be configured */
  152. #elif defined(HSE_CLOCK_CONFIG)
  153. #define STM32L4_BOARD_USEHSE
  154. /* Prescaler common to all PLL inputs; will be 1 */
  155. #define STM32L4_PLLCFG_PLLM RCC_PLLCFG_PLLM(1)
  156. /* 'main' PLL config; we use this to generate our system clock via the R
  157. * output. We set it up as 8 MHz / 1 * 20 / 2 = 80 MHz
  158. *
  159. * XXX NOTE: currently the main PLL is implicitly turned on and is implicitly
  160. * the system clock; this should be configurable since not all applications may
  161. * want things done this way.
  162. */
  163. #define STM32L4_PLLCFG_PLLN RCC_PLLCFG_PLLN(20)
  164. #define STM32L4_PLLCFG_PLLP 0
  165. #undef STM32L4_PLLCFG_PLLP_ENABLED
  166. #define STM32L4_PLLCFG_PLLQ RCC_PLLCFG_PLLQ_2
  167. #define STM32L4_PLLCFG_PLLQ_ENABLED
  168. #define STM32L4_PLLCFG_PLLR RCC_PLLCFG_PLLR_2
  169. #define STM32L4_PLLCFG_PLLR_ENABLED
  170. /* 'SAIPLL1' is used to generate the 48 MHz clock, since we can't
  171. * do that with the main PLL's N value. We set N = 12, and enable
  172. * the Q output (ultimately for CLK48) with /4. So,
  173. * 8 MHz / 1 * 12 / 2 = 48 MHz
  174. *
  175. * XXX NOTE: currently the SAIPLL /must/ be explicitly selected in the
  176. * menuconfig, or else all this is a moot point, and the various 48 MHz
  177. * peripherals will not work (RNG at present). I would suggest removing
  178. * that option from Kconfig altogether, and simply making it an option
  179. * that is selected via a #define here, like all these other params.
  180. */
  181. #define STM32L4_PLLSAI1CFG_PLLN RCC_PLLSAI1CFG_PLLN(12)
  182. #define STM32L4_PLLSAI1CFG_PLLP 0
  183. #undef STM32L4_PLLSAI1CFG_PLLP_ENABLED
  184. #define STM32L4_PLLSAI1CFG_PLLQ RCC_PLLSAI1CFG_PLLQ_2
  185. #define STM32L4_PLLSAI1CFG_PLLQ_ENABLED
  186. #define STM32L4_PLLSAI1CFG_PLLR 0
  187. #undef STM32L4_PLLSAI1CFG_PLLR_ENABLED
  188. /* 'SAIPLL2' is not used in this application */
  189. #define STM32L4_PLLSAI2CFG_PLLN RCC_PLLSAI2CFG_PLLN(8)
  190. #define STM32L4_PLLSAI2CFG_PLLP 0
  191. #undef STM32L4_PLLSAI2CFG_PLLP_ENABLED
  192. #define STM32L4_PLLSAI2CFG_PLLR 0
  193. #undef STM32L4_PLLSAI2CFG_PLLR_ENABLED
  194. #define STM32L4_SYSCLK_FREQUENCY 80000000ul
  195. /* CLK48 will come from PLLSAI1 (implicitly Q) */
  196. #define STM32L4_USE_CLK48 1
  197. #define STM32L4_CLK48_SEL RCC_CCIPR_CLK48SEL_PLLSAI1
  198. /* Enable the LSE oscillator, used automatically trim the MSI, and for RTC */
  199. #define STM32L4_USE_LSE 1
  200. /* AHB clock (HCLK) is SYSCLK (80MHz) */
  201. #define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */
  202. #define STM32L4_HCLK_FREQUENCY STM32L4_SYSCLK_FREQUENCY
  203. #define STM32L4_BOARD_HCLK STM32L4_HCLK_FREQUENCY /* Same as above, to satisfy compiler */
  204. /* APB1 clock (PCLK1) is HCLK/1 (80MHz) */
  205. #define STM32L4_RCC_CFGR_PPRE1 RCC_CFGR_PPRE1_HCLK /* PCLK1 = HCLK / 1 */
  206. #define STM32L4_PCLK1_FREQUENCY (STM32L4_HCLK_FREQUENCY/1)
  207. /* Timers driven from APB1 will be twice PCLK1 */
  208. /* REVISIT : this can be configured */
  209. #define STM32L4_APB1_TIM2_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  210. #define STM32L4_APB1_TIM3_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  211. #define STM32L4_APB1_TIM4_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  212. #define STM32L4_APB1_TIM5_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  213. #define STM32L4_APB1_TIM6_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  214. #define STM32L4_APB1_TIM7_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  215. /* APB2 clock (PCLK2) is HCLK (80MHz) */
  216. #define STM32L4_RCC_CFGR_PPRE2 RCC_CFGR_PPRE2_HCLK /* PCLK2 = HCLK / 1 */
  217. #define STM32L4_PCLK2_FREQUENCY (STM32L4_HCLK_FREQUENCY/1)
  218. /* Timers driven from APB2 will be twice PCLK2 */
  219. /* REVISIT : this can be configured */
  220. #define STM32L4_APB2_TIM1_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  221. #define STM32L4_APB2_TIM8_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  222. #define STM32L4_APB2_TIM15_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  223. #define STM32L4_APB2_TIM16_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  224. #define STM32L4_APB2_TIM17_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  225. /* Timer Frequencies, if APBx is set to 1, frequency is same to APBx
  226. * otherwise frequency is 2xAPBx.
  227. * Note: TIM1,8,15,16,17 are on APB2, others on APB1
  228. */
  229. /* REVISIT : this can be configured */
  230. #elif defined(MSI_CLOCK_CONFIG)
  231. #define STM32L4_BOARD_USEMSI
  232. #define STM32L4_BOARD_MSIRANGE RCC_CR_MSIRANGE_4M
  233. /* Prescaler common to all PLL inputs; will be 1 */
  234. #define STM32L4_PLLCFG_PLLM RCC_PLLCFG_PLLM(1)
  235. /* 'main' PLL config; we use this to generate our system clock via the R
  236. * output. We set it up as 4 MHz / 1 * 40 / 2 = 80 MHz
  237. *
  238. * XXX NOTE: currently the main PLL is implicitly turned on and is implicitly
  239. * the system clock; this should be configurable since not all applications may
  240. * want things done this way.
  241. */
  242. #define STM32L4_PLLCFG_PLLN RCC_PLLCFG_PLLN(40)
  243. #define STM32L4_PLLCFG_PLLP 0
  244. #undef STM32L4_PLLCFG_PLLP_ENABLED
  245. #define STM32L4_PLLCFG_PLLQ RCC_PLLCFG_PLLQ_2
  246. #define STM32L4_PLLCFG_PLLQ_ENABLED
  247. #define STM32L4_PLLCFG_PLLR RCC_PLLCFG_PLLR_2
  248. #define STM32L4_PLLCFG_PLLR_ENABLED
  249. /* 'SAIPLL1' is used to generate the 48 MHz clock, since we can't
  250. * do that with the main PLL's N value. We set N = 12, and enable
  251. * the Q output (ultimately for CLK48) with /4. So,
  252. * 4 MHz / 1 * 24 / 2 = 48 MHz
  253. *
  254. * XXX NOTE: currently the SAIPLL /must/ be explicitly selected in the
  255. * menuconfig, or else all this is a moot point, and the various 48 MHz
  256. * peripherals will not work (RNG at present). I would suggest removing
  257. * that option from Kconfig altogether, and simply making it an option
  258. * that is selected via a #define here, like all these other params.
  259. */
  260. #define STM32L4_PLLSAI1CFG_PLLN RCC_PLLSAI1CFG_PLLN(24)
  261. #define STM32L4_PLLSAI1CFG_PLLP 0
  262. #undef STM32L4_PLLSAI1CFG_PLLP_ENABLED
  263. #define STM32L4_PLLSAI1CFG_PLLQ RCC_PLLSAI1CFG_PLLQ_2
  264. #define STM32L4_PLLSAI1CFG_PLLQ_ENABLED
  265. #define STM32L4_PLLSAI1CFG_PLLR 0
  266. #undef STM32L4_PLLSAI1CFG_PLLR_ENABLED
  267. /* 'SAIPLL2' is not used in this application */
  268. #define STM32L4_PLLSAI2CFG_PLLN RCC_PLLSAI2CFG_PLLN(8)
  269. #define STM32L4_PLLSAI2CFG_PLLP 0
  270. #undef STM32L4_PLLSAI2CFG_PLLP_ENABLED
  271. #define STM32L4_PLLSAI2CFG_PLLR 0
  272. #undef STM32L4_PLLSAI2CFG_PLLR_ENABLED
  273. #define STM32L4_SYSCLK_FREQUENCY 80000000ul
  274. /* CLK48 will come from PLLSAI1 (implicitly Q) */
  275. #define STM32L4_USE_CLK48 1
  276. #define STM32L4_CLK48_SEL RCC_CCIPR_CLK48SEL_PLLSAI1
  277. /* Enable the LSE oscillator, used automatically trim the MSI, and for RTC */
  278. #define STM32L4_USE_LSE 1
  279. /* AHB clock (HCLK) is SYSCLK (80MHz) */
  280. #define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */
  281. #define STM32L4_HCLK_FREQUENCY STM32L4_SYSCLK_FREQUENCY
  282. #define STM32L4_BOARD_HCLK STM32L4_HCLK_FREQUENCY /* Same as above, to satisfy compiler */
  283. /* APB1 clock (PCLK1) is HCLK/1 (80MHz) */
  284. #define STM32L4_RCC_CFGR_PPRE1 RCC_CFGR_PPRE1_HCLK /* PCLK1 = HCLK / 1 */
  285. #define STM32L4_PCLK1_FREQUENCY (STM32L4_HCLK_FREQUENCY/1)
  286. /* Timers driven from APB1 will be twice PCLK1 */
  287. /* REVISIT : this can be configured */
  288. #define STM32L4_APB1_TIM2_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  289. #define STM32L4_APB1_TIM3_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  290. #define STM32L4_APB1_TIM4_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  291. #define STM32L4_APB1_TIM5_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  292. #define STM32L4_APB1_TIM6_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  293. #define STM32L4_APB1_TIM7_CLKIN (2*STM32L4_PCLK1_FREQUENCY)
  294. /* APB2 clock (PCLK2) is HCLK (80MHz) */
  295. #define STM32L4_RCC_CFGR_PPRE2 RCC_CFGR_PPRE2_HCLK /* PCLK2 = HCLK / 1 */
  296. #define STM32L4_PCLK2_FREQUENCY (STM32L4_HCLK_FREQUENCY/1)
  297. /* Timers driven from APB2 will be twice PCLK2 */
  298. /* REVISIT : this can be configured */
  299. #define STM32L4_APB2_TIM1_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  300. #define STM32L4_APB2_TIM8_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  301. #define STM32L4_APB2_TIM15_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  302. #define STM32L4_APB2_TIM16_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  303. #define STM32L4_APB2_TIM17_CLKIN (2*STM32L4_PCLK2_FREQUENCY)
  304. /* Timer Frequencies, if APBx is set to 1, frequency is same to APBx
  305. * otherwise frequency is 2xAPBx.
  306. * Note: TIM1,8,15,16,17 are on APB2, others on APB1
  307. */
  308. /* REVISIT : this can be configured */
  309. #endif
  310. /* Timer Frequencies, if APBx is set to 1, frequency is same to APBx
  311. * otherwise frequency is 2xAPBx.
  312. * Note: TIM1,8,15,16,17 are on APB2, others on APB1
  313. */
  314. #define BOARD_TIM1_FREQUENCY STM32L4_HCLK_FREQUENCY
  315. #define BOARD_TIM2_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2)
  316. #define BOARD_TIM3_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2)
  317. #define BOARD_TIM4_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2)
  318. #define BOARD_TIM5_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2)
  319. #define BOARD_TIM6_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2)
  320. #define BOARD_TIM7_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2)
  321. #define BOARD_TIM8_FREQUENCY STM32L4_HCLK_FREQUENCY
  322. #define BOARD_TIM15_FREQUENCY STM32L4_HCLK_FREQUENCY
  323. #define BOARD_TIM16_FREQUENCY STM32L4_HCLK_FREQUENCY
  324. #define BOARD_TIM17_FREQUENCY STM32L4_HCLK_FREQUENCY
  325. #define BOARD_LPTIM1_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2)
  326. #define BOARD_LPTIM2_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2)
  327. /* SDMMC dividers. Note that slower clocking is required when DMA is disabled
  328. * in order to avoid RX overrun/TX underrun errors due to delayed responses
  329. * to service FIFOs in interrupt driven mode. These values have not been
  330. * tuned!!!
  331. *
  332. * SDMMCCLK=48MHz, SDMMC_CK=SDMMCCLK/(118+2)=400 KHz
  333. */
  334. #define STM32_SDMMC_INIT_CLKDIV (118 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
  335. /* DMA ON: SDMMCCLK=48MHz, SDMMC_CK=SDMMCCLK/(1+2)=16 MHz
  336. * DMA OFF: SDMMCCLK=48MHz, SDMMC_CK=SDMMCCLK/(2+2)=12 MHz
  337. */
  338. #ifdef CONFIG_SDIO_DMA
  339. # define STM32_SDMMC_MMCXFR_CLKDIV (1 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
  340. #else
  341. # define STM32_SDMMC_MMCXFR_CLKDIV (2 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
  342. #endif
  343. /* DMA ON: SDMMCCLK=48MHz, SDMMC_CK=SDMMCCLK/(1+2)=16 MHz
  344. * DMA OFF: SDMMCCLK=48MHz, SDMMC_CK=SDMMCCLK/(2+2)=12 MHz
  345. */
  346. #ifdef CONFIG_SDIO_DMA
  347. # define STM32_SDMMC_SDXFR_CLKDIV (1 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
  348. #else
  349. # define STM32_SDMMC_SDXFR_CLKDIV (2 << STM32_SDMMC_CLKCR_CLKDIV_SHIFT)
  350. #endif
  351. #if defined(CONFIG_STM32L4_SDMMC2)
  352. # define GPIO_SDMMC2_D0 GPIO_SDMMC2_D0_1
  353. # define GPIO_SDMMC2_D1 GPIO_SDMMC2_D1_1
  354. # define GPIO_SDMMC2_D2 GPIO_SDMMC2_D2_1
  355. # define GPIO_SDMMC2_D3 GPIO_SDMMC2_D3_1
  356. #endif
  357. /* DMA Channel/Stream Selections *****************************************************/
  358. /* Stream selections are arbitrary for now but might become important in the future
  359. * if we set aside more DMA channels/streams.
  360. *
  361. * SDMMC DMA is on DMA2
  362. *
  363. * SDMMC1 DMA
  364. * DMAMAP_SDMMC_1 = Channel 4, Stream 7
  365. * DMAMAP_SDMMC_2 = Channel 5, Stream 7
  366. *
  367. * SDMMC2 DMA
  368. * DMAMAP_SDMMC2_1 = Channel 11, Stream 0
  369. * DMAMAP_SDMMC3_2 = Channel 11, Stream 5
  370. */
  371. #define DMAMAP_SDMMC1 DMACHAN_SDMMC_1
  372. #define DMAMAP_SDMMC2 DMACHAN_SDMMC_2
  373. /* FLASH wait states
  374. *
  375. * --------- ---------- -----------
  376. * VDD MAX SYSCLK WAIT STATES
  377. * --------- ---------- -----------
  378. * 1.7-2.1 V 180 MHz 8
  379. * 2.1-2.4 V 216 MHz 9
  380. * 2.4-2.7 V 216 MHz 8
  381. * 2.7-3.6 V 216 MHz 7
  382. * --------- ---------- -----------
  383. */
  384. #define BOARD_FLASH_WAITSTATES 7
  385. /* LED definitions ******************************************************************/
  386. /* The Nucleo-144 board has numerous LEDs but only three, LD1 a Green LED, LD2 a Blue
  387. * LED and LD3 a Red LED, that can be controlled by software. The following
  388. * definitions assume the default Solder Bridges are installed.
  389. *
  390. * If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in any way.
  391. * The following definitions are used to access individual LEDs.
  392. */
  393. /* LED index values for use with board_userled() */
  394. #define BOARD_LED1 0
  395. #define BOARD_LED2 1
  396. #define BOARD_LED3 2
  397. #define BOARD_NLEDS 3
  398. #define BOARD_LED_GREEN BOARD_LED1
  399. #define BOARD_LED_BLUE BOARD_LED2
  400. #define BOARD_LED_RED BOARD_LED3
  401. /* LED bits for use with board_userled_all() */
  402. #define BOARD_LED1_BIT (1 << BOARD_LED1)
  403. #define BOARD_LED2_BIT (1 << BOARD_LED2)
  404. #define BOARD_LED3_BIT (1 << BOARD_LED3)
  405. /* If CONFIG_ARCH_LEDS is defined, the usage by the board port is defined in
  406. * include/board.h and src/stm32_autoleds.c. The LEDs are used to encode OS-related
  407. * events as follows:
  408. *
  409. *
  410. * SYMBOL Meaning LED state
  411. * Red Green Blue
  412. * ---------------------- -------------------------- ------ ------ ----*/
  413. #define LED_STARTED 0 /* NuttX has been started OFF OFF OFF */
  414. #define LED_HEAPALLOCATE 1 /* Heap has been allocated OFF OFF ON */
  415. #define LED_IRQSENABLED 2 /* Interrupts enabled OFF ON OFF */
  416. #define LED_STACKCREATED 3 /* Idle stack created OFF ON ON */
  417. #define LED_INIRQ 4 /* In an interrupt N/C N/C GLOW */
  418. #define LED_SIGNAL 5 /* In a signal handler N/C GLOW N/C */
  419. #define LED_ASSERTION 6 /* An assertion failed GLOW N/C GLOW */
  420. #define LED_PANIC 7 /* The system has crashed Blink OFF N/C */
  421. #define LED_IDLE 8 /* MCU is is sleep mode ON OFF OFF */
  422. /* Thus if the Green LED is statically on, NuttX has successfully booted and
  423. * is, apparently, running normally. If the Red LED is flashing at
  424. * approximately 2Hz, then a fatal error has been detected and the system
  425. * has halted.
  426. */
  427. /* Button definitions ***************************************************************/
  428. /* The Nucleo-L496ZG supports one button: Pushbutton B1, labeled "User", is
  429. * connected to GPIO PC13. A high value will be sensed when the button is depressed.
  430. */
  431. #define BUTTON_USER 0
  432. #define NUM_BUTTONS 1
  433. #define BUTTON_USER_BIT (1 << BUTTON_USER)
  434. /* Alternate function pin selections ************************************************/
  435. #define GPIO_USART2_TX GPIO_USART2_TX_2
  436. #define GPIO_USART2_RX GPIO_USART2_RX_2
  437. #define GPIO_USART3_TX GPIO_USART3_TX_2
  438. #define GPIO_USART3_RX GPIO_USART3_RX_2
  439. #if defined(CONFIG_NUCLEO_CONSOLE_ARDUINO)
  440. /* USART6:
  441. *
  442. * These configurations assume that you are using a standard Arduio RS-232 shield
  443. * with the serial interface with RX on pin D0 and TX on pin D1:
  444. *
  445. * -------- ---------------
  446. * STM32F7
  447. * ARDUIONO FUNCTION GPIO
  448. * -- ----- --------- -----
  449. * DO RX USART6_RX PG9
  450. * D1 TX USART6_TX PG14
  451. * -- ----- --------- -----
  452. */
  453. # define GPIO_USART6_RX GPIO_USART6_RX_2
  454. # define GPIO_USART6_TX GPIO_USART6_TX_2
  455. #endif
  456. /* USART3:
  457. * Use USART3 and the USB virtual COM port
  458. */
  459. #if defined(CONFIG_NUCLEO_CONSOLE_VIRTUAL)
  460. /* LPUART1 is connector to Virtual COM port PG6 and PG7, but there is no lpserial. */
  461. //#define GPIO_USART2_TX GPIO_LPUART1_TX_3
  462. //#define GPIO_USART2_RX GPIO_LPUART1_RX_3
  463. # error "No Nucleo virtual console before lpserial is unimplemented"
  464. #endif
  465. /* DMA channels *************************************************************/
  466. /* ADC */
  467. #define ADC1_DMA_CHAN DMACHAN_ADC1_1
  468. #define ADC2_DMA_CHAN DMACHAN_ADC2_2
  469. #define ADC3_DMA_CHAN DMACHAN_ADC3_2
  470. /* SPI
  471. *
  472. *
  473. * PA6 SPI1_MISO CN12-13
  474. * PA7 SPI1_MOSI CN12-15
  475. * PA5 SPI1_SCK CN12-11
  476. *
  477. * PB14 SPI2_MISO CN12-28
  478. * PB15 SPI2_MOSI CN12-26
  479. * PB13 SPI2_SCK CN12-30
  480. *
  481. * PB4 SPI3_MISO CN12-27
  482. * PB5 SPI3_MOSI CN12-29
  483. * PB3 SPI3_SCK CN12-31
  484. */
  485. #define GPIO_SPI1_MISO GPIO_SPI1_MISO_1
  486. #define GPIO_SPI1_MOSI GPIO_SPI1_MOSI_1
  487. #define GPIO_SPI1_SCK GPIO_SPI1_SCK_1
  488. #define GPIO_SPI2_MISO GPIO_SPI2_MISO_1
  489. #define GPIO_SPI2_MOSI GPIO_SPI2_MOSI_1
  490. #define GPIO_SPI2_SCK GPIO_SPI2_SCK_3
  491. #define GPIO_SPI3_MISO GPIO_SPI3_MISO_1
  492. #define GPIO_SPI3_MOSI GPIO_SPI3_MOSI_2
  493. #define GPIO_SPI3_SCK GPIO_SPI3_SCK_1
  494. /* I2C
  495. *
  496. *
  497. * PB8 I2C1_SCL CN12-3
  498. * PB9 I2C1_SDA CN12-5
  499. * PB10 I2C2_SCL CN11-51
  500. * PB11 I2C2_SDA CN12-18
  501. *
  502. * PA8 I2C3_SCL CN12-23
  503. * PC9 I2C3_SDA CN12-1
  504. *
  505. */
  506. #define GPIO_I2C1_SCL GPIO_I2C1_SCL_2
  507. #define GPIO_I2C1_SDA GPIO_I2C1_SDA_2
  508. #define GPIO_I2C2_SCL GPIO_I2C2_SCL_1
  509. #define GPIO_I2C2_SDA GPIO_I2C2_SDA_1
  510. #define GPIO_I2C3_SCL GPIO_I2C3_SCL_1
  511. #define GPIO_I2C3_SDA GPIO_I2C3_SDA_1
  512. #define GPIO_I2C4_SCL GPIO_I2C4_SCL_1
  513. #define GPIO_I2C4_SDA GPIO_I2C4_SDA_1
  514. /************************************************************************************
  515. * Public Data
  516. ************************************************************************************/
  517. #ifndef __ASSEMBLY__
  518. #undef EXTERN
  519. #if defined(__cplusplus)
  520. #define EXTERN extern "C"
  521. extern "C"
  522. {
  523. #else
  524. #define EXTERN extern
  525. #endif
  526. /************************************************************************************
  527. * Public Function Prototypes
  528. ************************************************************************************/
  529. /************************************************************************************
  530. * Name: stm32l4_board_initialize
  531. *
  532. * Description:
  533. * All STM32 architectures must provide the following entry point. This entry point
  534. * is called early in the initialization -- after all memory has been configured
  535. * and mapped but before any devices have been initialized.
  536. *
  537. ************************************************************************************/
  538. void stm32l4_board_initialize(void);
  539. #undef EXTERN
  540. #if defined(__cplusplus)
  541. }
  542. #endif
  543. #endif /* __ASSEMBLY__ */
  544. #endif /* __CONFIG_NUCLEO_L496ZG_INCLUDE_BOARD_H */