stm32h7_mcuconf.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /*
  14. this header is modelled on the one for the Nucleo-144 H743 board from ChibiOS
  15. */
  16. #pragma once
  17. #ifndef STM32_LSECLK
  18. #define STM32_LSECLK 32768U
  19. #endif
  20. #ifndef STM32_LSEDRV
  21. #define STM32_LSEDRV (3U << 3U)
  22. #endif
  23. /*
  24. * General settings.
  25. */
  26. #define STM32_NO_INIT FALSE
  27. #define STM32_SYS_CK_ENFORCED_VALUE STM32_HSICLK
  28. /*
  29. * Memory attributes settings.
  30. */
  31. #define STM32_NOCACHE_SRAM1_SRAM2 FALSE
  32. #define STM32_NOCACHE_SRAM3 TRUE
  33. /*
  34. * PWR system settings.
  35. * Reading STM32 Reference Manual is required.
  36. * Register constants are taken from the ST header.
  37. */
  38. #define STM32_VOS STM32_VOS_SCALE1
  39. #define STM32_PWR_CR1 (PWR_CR1_SVOS_1 | PWR_CR1_SVOS_0)
  40. #define STM32_PWR_CR2 (PWR_CR2_BREN)
  41. #define STM32_PWR_CR3 (PWR_CR3_LDOEN | PWR_CR3_USB33DEN)
  42. #define STM32_PWR_CPUCR 0
  43. /*
  44. * Clock tree static settings.
  45. * Reading STM32 Reference Manual is required.
  46. */
  47. #define STM32_HSI_ENABLED FALSE
  48. #define STM32_LSI_ENABLED FALSE
  49. #define STM32_CSI_ENABLED TRUE
  50. #define STM32_HSI48_ENABLED TRUE
  51. #define STM32_HSE_ENABLED TRUE
  52. #define STM32_LSE_ENABLED FALSE
  53. #define STM32_HSIDIV STM32_HSIDIV_DIV1
  54. /*
  55. * PLLs static settings.
  56. * Reading STM32 Reference Manual is required.
  57. */
  58. #define STM32_PLLSRC STM32_PLLSRC_HSE_CK
  59. #define STM32_PLLCFGR_MASK ~0
  60. /*
  61. setup PLLs based on HSE clock
  62. */
  63. #if STM32_HSECLK == 8000000U
  64. // this gives 400MHz system clock
  65. #define STM32_PLL1_DIVM_VALUE 1
  66. #define STM32_PLL2_DIVM_VALUE 1
  67. #define STM32_PLL3_DIVM_VALUE 2
  68. #elif STM32_HSECLK == 16000000U
  69. // this gives 400MHz system clock
  70. #define STM32_PLL1_DIVM_VALUE 2
  71. #define STM32_PLL2_DIVM_VALUE 2
  72. #define STM32_PLL3_DIVM_VALUE 4
  73. #elif STM32_HSECLK == 24000000U
  74. // this gives 400MHz system clock
  75. #define STM32_PLL1_DIVM_VALUE 3
  76. #define STM32_PLL2_DIVM_VALUE 3
  77. #define STM32_PLL3_DIVM_VALUE 6
  78. #else
  79. #error "Unsupported HSE clock"
  80. #endif
  81. #if (STM32_HSECLK == 8000000U) || (STM32_HSECLK == 16000000U) || (STM32_HSECLK == 24000000U)
  82. // common clock tree for multiples of 8MHz crystals
  83. #define STM32_PLL1_DIVN_VALUE 100
  84. #define STM32_PLL1_DIVP_VALUE 2
  85. #define STM32_PLL1_DIVQ_VALUE 8
  86. #define STM32_PLL1_DIVR_VALUE 2
  87. #define STM32_PLL2_DIVN_VALUE 25
  88. #define STM32_PLL2_DIVP_VALUE 2
  89. #define STM32_PLL2_DIVQ_VALUE 2
  90. #define STM32_PLL2_DIVR_VALUE 2
  91. #define STM32_PLL3_DIVN_VALUE 72
  92. #define STM32_PLL3_DIVP_VALUE 3
  93. #define STM32_PLL3_DIVQ_VALUE 6
  94. #define STM32_PLL3_DIVR_VALUE 9
  95. #endif // 8MHz clock multiples
  96. #define STM32_PLL1_ENABLED TRUE
  97. #define STM32_PLL1_P_ENABLED TRUE
  98. #define STM32_PLL1_Q_ENABLED TRUE
  99. #define STM32_PLL1_R_ENABLED TRUE
  100. #define STM32_PLL1_FRACN_VALUE 0
  101. #define STM32_PLL2_ENABLED TRUE
  102. #define STM32_PLL2_P_ENABLED TRUE
  103. #define STM32_PLL2_Q_ENABLED TRUE
  104. #define STM32_PLL2_R_ENABLED TRUE
  105. #define STM32_PLL2_FRACN_VALUE 0
  106. #define STM32_PLL3_ENABLED TRUE
  107. #define STM32_PLL3_P_ENABLED TRUE
  108. #define STM32_PLL3_Q_ENABLED TRUE
  109. #define STM32_PLL3_R_ENABLED TRUE
  110. #define STM32_PLL3_FRACN_VALUE 0
  111. /*
  112. * Core clocks dynamic settings (can be changed at runtime).
  113. * Reading STM32 Reference Manual is required.
  114. */
  115. #define STM32_SW STM32_SW_PLL1_P_CK
  116. #define STM32_RTCSEL STM32_RTCSEL_NOCLK
  117. #define STM32_D1CPRE STM32_D1CPRE_DIV1
  118. #define STM32_D1HPRE STM32_D1HPRE_DIV4
  119. #define STM32_D1PPRE3 STM32_D1PPRE3_DIV1
  120. #define STM32_D2PPRE1 STM32_D2PPRE1_DIV1
  121. #define STM32_D2PPRE2 STM32_D2PPRE2_DIV1
  122. #define STM32_D3PPRE4 STM32_D3PPRE4_DIV1
  123. /*
  124. * Peripherals clocks static settings.
  125. * Reading STM32 Reference Manual is required.
  126. */
  127. #define STM32_MCO1SEL STM32_MCO1SEL_HSE_CK
  128. #define STM32_MCO1PRE_VALUE 4
  129. #define STM32_MCO2SEL STM32_MCO2SEL_SYS_CK
  130. #define STM32_MCO2PRE_VALUE 4
  131. #define STM32_TIMPRE_ENABLE TRUE
  132. #define STM32_HRTIMSEL 0
  133. #define STM32_STOPKERWUCK 0
  134. #define STM32_STOPWUCK 0
  135. #define STM32_RTCPRE_VALUE 8
  136. #define STM32_CKPERSEL STM32_CKPERSEL_HSE_CK
  137. #define STM32_SDMMCSEL STM32_SDMMCSEL_PLL1_Q_CK
  138. #define STM32_QSPISEL STM32_QSPISEL_HCLK
  139. #define STM32_FMCSEL STM32_QSPISEL_HCLK
  140. #define STM32_SWPSEL STM32_SWPSEL_PCLK1
  141. #define STM32_FDCANSEL STM32_FDCANSEL_PLL1_Q_CK
  142. #define STM32_DFSDM1SEL STM32_DFSDM1SEL_PCLK2
  143. #define STM32_SPDIFSEL STM32_SPDIFSEL_PLL1_Q_CK
  144. #define STM32_SPI45SEL STM32_SPI45SEL_PLL2_Q_CK
  145. #define STM32_SPI123SEL STM32_SPI123SEL_PLL1_Q_CK
  146. #define STM32_SAI23SEL STM32_SAI23SEL_PLL1_Q_CK
  147. #define STM32_SAI1SEL STM32_SAI1SEL_PLL1_Q_CK
  148. #define STM32_LPTIM1SEL STM32_LPTIM1SEL_PCLK1
  149. #define STM32_CECSEL STM32_CECSEL_DISABLE
  150. #define STM32_USBSEL STM32_USBSEL_PLL3_Q_CK
  151. #define STM32_I2C123SEL STM32_I2C123SEL_PLL3_R_CK
  152. #define STM32_RNGSEL STM32_RNGSEL_HSI48_CK
  153. #define STM32_USART16SEL STM32_USART16SEL_PCLK2
  154. #define STM32_USART234578SEL STM32_USART234578SEL_PCLK1
  155. #define STM32_SPI6SEL STM32_SPI6SEL_PLL2_Q_CK
  156. #define STM32_SAI4BSEL STM32_SAI4BSEL_PLL1_Q_CK
  157. #define STM32_SAI4ASEL STM32_SAI4ASEL_PLL1_Q_CK
  158. #define STM32_ADCSEL STM32_ADCSEL_PLL3_R_CK
  159. #define STM32_LPTIM345SEL STM32_LPTIM345SEL_PCLK4
  160. #define STM32_LPTIM2SEL STM32_LPTIM2SEL_PCLK4
  161. #define STM32_I2C4SEL STM32_I2C4SEL_PCLK4
  162. #define STM32_LPUART1SEL STM32_LPUART1SEL_PCLK4
  163. #define STM32_SDMMCSEL STM32_SDMMCSEL_PLL1_Q_CK
  164. /*
  165. * IRQ system settings.
  166. */
  167. #define STM32_IRQ_EXTI0_PRIORITY 6
  168. #define STM32_IRQ_EXTI1_PRIORITY 6
  169. #define STM32_IRQ_EXTI2_PRIORITY 6
  170. #define STM32_IRQ_EXTI3_PRIORITY 6
  171. #define STM32_IRQ_EXTI4_PRIORITY 6
  172. #define STM32_IRQ_EXTI5_9_PRIORITY 6
  173. #define STM32_IRQ_EXTI10_15_PRIORITY 6
  174. #define STM32_IRQ_EXTI16_PRIORITY 6
  175. #define STM32_IRQ_EXTI17_PRIORITY 15
  176. #define STM32_IRQ_EXTI18_PRIORITY 6
  177. #define STM32_IRQ_EXTI19_PRIORITY 6
  178. #define STM32_IRQ_EXTI20_PRIORITY 6
  179. #define STM32_IRQ_EXTI21_PRIORITY 15
  180. #define STM32_IRQ_EXTI22_PRIORITY 15
  181. /*
  182. * ADC driver system settings.
  183. */
  184. #define STM32_ADC_DUAL_MODE FALSE
  185. #define STM32_ADC_COMPACT_SAMPLES FALSE
  186. #define STM32_ADC_USE_ADC12 TRUE
  187. #define STM32_ADC_USE_ADC3 FALSE
  188. #define STM32_ADC_ADC12_DMA_PRIORITY 2
  189. #define STM32_ADC_ADC3_DMA_PRIORITY 2
  190. #define STM32_ADC_ADC12_IRQ_PRIORITY 5
  191. #define STM32_ADC_ADC3_IRQ_PRIORITY 5
  192. #define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_ADCCK
  193. #define STM32_ADC_ADC3_CLOCK_MODE ADC_CCR_CKMODE_ADCCK
  194. // we call it ADC1 in hwdef.dat, but driver uses ADC12 for DMA stream
  195. #define STM32_ADC_ADC12_DMA_STREAM STM32_ADC_ADC1_DMA_STREAM
  196. /*
  197. * CAN driver system settings.
  198. */
  199. #define STM32_CAN_USE_CAN1 FALSE
  200. #define STM32_CAN_USE_CAN2 FALSE
  201. #define STM32_CAN_USE_CAN3 FALSE
  202. #define STM32_CAN_CAN1_IRQ_PRIORITY 11
  203. #define STM32_CAN_CAN2_IRQ_PRIORITY 11
  204. #define STM32_CAN_CAN3_IRQ_PRIORITY 11
  205. /*
  206. * DAC driver system settings.
  207. */
  208. #define STM32_DAC_DUAL_MODE FALSE
  209. #define STM32_DAC_USE_DAC1_CH1 FALSE
  210. #define STM32_DAC_USE_DAC1_CH2 FALSE
  211. #define STM32_DAC_DAC1_CH1_IRQ_PRIORITY 10
  212. #define STM32_DAC_DAC1_CH2_IRQ_PRIORITY 10
  213. #define STM32_DAC_DAC1_CH1_DMA_PRIORITY 2
  214. #define STM32_DAC_DAC1_CH2_DMA_PRIORITY 2
  215. /*
  216. * GPT driver system settings.
  217. */
  218. #define STM32_GPT_USE_TIM1 FALSE
  219. #define STM32_GPT_USE_TIM2 FALSE
  220. #define STM32_GPT_USE_TIM3 FALSE
  221. #define STM32_GPT_USE_TIM4 FALSE
  222. #define STM32_GPT_USE_TIM5 FALSE
  223. #define STM32_GPT_USE_TIM6 FALSE
  224. #define STM32_GPT_USE_TIM7 FALSE
  225. #define STM32_GPT_USE_TIM8 FALSE
  226. #define STM32_GPT_USE_TIM9 FALSE
  227. #define STM32_GPT_USE_TIM11 FALSE
  228. #define STM32_GPT_USE_TIM12 FALSE
  229. #define STM32_GPT_USE_TIM14 FALSE
  230. #define STM32_GPT_TIM1_IRQ_PRIORITY 7
  231. #define STM32_GPT_TIM2_IRQ_PRIORITY 7
  232. #define STM32_GPT_TIM3_IRQ_PRIORITY 7
  233. #define STM32_GPT_TIM4_IRQ_PRIORITY 7
  234. #define STM32_GPT_TIM5_IRQ_PRIORITY 7
  235. #define STM32_GPT_TIM6_IRQ_PRIORITY 7
  236. #define STM32_GPT_TIM7_IRQ_PRIORITY 7
  237. #define STM32_GPT_TIM8_IRQ_PRIORITY 7
  238. #define STM32_GPT_TIM9_IRQ_PRIORITY 7
  239. #define STM32_GPT_TIM11_IRQ_PRIORITY 7
  240. #define STM32_GPT_TIM12_IRQ_PRIORITY 7
  241. #define STM32_GPT_TIM14_IRQ_PRIORITY 7
  242. /*
  243. * I2C driver system settings.
  244. */
  245. #define STM32_I2C_BUSY_TIMEOUT 50
  246. #define STM32_I2C_I2C1_IRQ_PRIORITY 5
  247. #define STM32_I2C_I2C2_IRQ_PRIORITY 5
  248. #define STM32_I2C_I2C3_IRQ_PRIORITY 5
  249. #define STM32_I2C_I2C4_IRQ_PRIORITY 5
  250. #define STM32_I2C_I2C1_DMA_PRIORITY 3
  251. #define STM32_I2C_I2C2_DMA_PRIORITY 3
  252. #define STM32_I2C_I2C3_DMA_PRIORITY 3
  253. #define STM32_I2C_I2C4_DMA_PRIORITY 3
  254. #define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
  255. /*
  256. * ICU driver system settings.
  257. */
  258. #define STM32_ICU_USE_TIM1 FALSE
  259. #define STM32_ICU_USE_TIM2 FALSE
  260. #define STM32_ICU_USE_TIM3 FALSE
  261. #define STM32_ICU_USE_TIM4 FALSE
  262. #define STM32_ICU_USE_TIM5 FALSE
  263. #define STM32_ICU_USE_TIM8 FALSE
  264. #define STM32_ICU_USE_TIM9 FALSE
  265. #define STM32_ICU_TIM1_IRQ_PRIORITY 7
  266. #define STM32_ICU_TIM2_IRQ_PRIORITY 7
  267. #define STM32_ICU_TIM3_IRQ_PRIORITY 7
  268. #define STM32_ICU_TIM4_IRQ_PRIORITY 7
  269. #define STM32_ICU_TIM5_IRQ_PRIORITY 7
  270. #define STM32_ICU_TIM8_IRQ_PRIORITY 7
  271. #define STM32_ICU_TIM9_IRQ_PRIORITY 7
  272. /*
  273. * MAC driver system settings.
  274. */
  275. #define STM32_MAC_TRANSMIT_BUFFERS 2
  276. #define STM32_MAC_RECEIVE_BUFFERS 4
  277. #define STM32_MAC_BUFFERS_SIZE 1522
  278. #define STM32_MAC_PHY_TIMEOUT 100
  279. #define STM32_MAC_ETH1_CHANGE_PHY_STATE TRUE
  280. #define STM32_MAC_ETH1_IRQ_PRIORITY 13
  281. #define STM32_MAC_IP_CHECKSUM_OFFLOAD 0
  282. /*
  283. * PWM driver system settings.
  284. */
  285. #define STM32_PWM_TIM1_IRQ_PRIORITY 7
  286. #define STM32_PWM_TIM2_IRQ_PRIORITY 7
  287. #define STM32_PWM_TIM3_IRQ_PRIORITY 7
  288. #define STM32_PWM_TIM4_IRQ_PRIORITY 7
  289. #define STM32_PWM_TIM5_IRQ_PRIORITY 7
  290. #define STM32_PWM_TIM8_IRQ_PRIORITY 7
  291. #define STM32_PWM_TIM9_IRQ_PRIORITY 7
  292. /*
  293. * RTC driver system settings.
  294. */
  295. #define STM32_RTC_PRESA_VALUE 32
  296. #define STM32_RTC_PRESS_VALUE 1024
  297. #define STM32_RTC_CR_INIT 0
  298. #define STM32_RTC_TAMPCR_INIT 0
  299. /*
  300. * SDC driver system settings.
  301. */
  302. #define STM32_SDC_SDMMC_UNALIGNED_SUPPORT TRUE
  303. #define STM32_SDC_SDMMC_WRITE_TIMEOUT 1000
  304. #define STM32_SDC_SDMMC_READ_TIMEOUT 1000
  305. #define STM32_SDC_SDMMC_CLOCK_DELAY 10
  306. #define STM32_SDC_SDMMC1_DMA_PRIORITY 3
  307. #define STM32_SDC_SDMMC1_IRQ_PRIORITY 9
  308. /*
  309. * SERIAL driver system settings.
  310. */
  311. #define STM32_SERIAL_USART1_PRIORITY 12
  312. #define STM32_SERIAL_USART2_PRIORITY 12
  313. #define STM32_SERIAL_USART3_PRIORITY 12
  314. #define STM32_SERIAL_UART4_PRIORITY 12
  315. #define STM32_SERIAL_UART5_PRIORITY 12
  316. #define STM32_SERIAL_USART6_PRIORITY 12
  317. #define STM32_SERIAL_UART7_PRIORITY 12
  318. #define STM32_SERIAL_UART8_PRIORITY 12
  319. #define STM32_UART1CLK STM32_PCLK1
  320. #define STM32_UART2CLK STM32_PCLK1
  321. #define STM32_UART3CLK STM32_PCLK1
  322. #define STM32_UART4CLK STM32_PCLK1
  323. #define STM32_UART5CLK STM32_PCLK1
  324. #define STM32_UART6CLK STM32_PCLK1
  325. #define STM32_UART7CLK STM32_PCLK1
  326. #define STM32_UART8CLK STM32_PCLK1
  327. /*
  328. * SPI driver system settings.
  329. */
  330. #ifndef STM32_SPI_USE_SPI1
  331. #define STM32_SPI_USE_SPI1 FALSE
  332. #endif
  333. #ifndef STM32_SPI_USE_SPI2
  334. #define STM32_SPI_USE_SPI2 FALSE
  335. #endif
  336. #ifndef STM32_SPI_USE_SPI3
  337. #define STM32_SPI_USE_SPI3 FALSE
  338. #endif
  339. #ifndef STM32_SPI_USE_SPI4
  340. #define STM32_SPI_USE_SPI4 FALSE
  341. #endif
  342. #ifndef STM32_SPI_USE_SPI5
  343. #define STM32_SPI_USE_SPI5 FALSE
  344. #endif
  345. #ifndef STM32_SPI_USE_SPI6
  346. #define STM32_SPI_USE_SPI6 FALSE
  347. #endif
  348. #define STM32_SPI_SPI1_DMA_PRIORITY 1
  349. #define STM32_SPI_SPI2_DMA_PRIORITY 1
  350. #define STM32_SPI_SPI3_DMA_PRIORITY 1
  351. #define STM32_SPI_SPI4_DMA_PRIORITY 1
  352. #define STM32_SPI_SPI5_DMA_PRIORITY 1
  353. #define STM32_SPI_SPI6_DMA_PRIORITY 1
  354. #define STM32_SPI_SPI1_IRQ_PRIORITY 10
  355. #define STM32_SPI_SPI2_IRQ_PRIORITY 10
  356. #define STM32_SPI_SPI3_IRQ_PRIORITY 10
  357. #define STM32_SPI_SPI4_IRQ_PRIORITY 10
  358. #define STM32_SPI_SPI5_IRQ_PRIORITY 10
  359. #define STM32_SPI_SPI6_IRQ_PRIORITY 10
  360. #define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
  361. /*
  362. * ST driver system settings.
  363. */
  364. #define STM32_ST_IRQ_PRIORITY 8
  365. #ifndef STM32_ST_USE_TIMER
  366. #define STM32_ST_USE_TIMER 5
  367. #endif
  368. /*
  369. * UART driver system settings.
  370. */
  371. #define STM32_UART_USART1_IRQ_PRIORITY 12
  372. #define STM32_UART_USART2_IRQ_PRIORITY 12
  373. #define STM32_UART_USART3_IRQ_PRIORITY 12
  374. #define STM32_UART_UART4_IRQ_PRIORITY 12
  375. #define STM32_UART_UART5_IRQ_PRIORITY 12
  376. #define STM32_UART_USART6_IRQ_PRIORITY 12
  377. #define STM32_UART_USART1_DMA_PRIORITY 0
  378. #define STM32_UART_USART2_DMA_PRIORITY 0
  379. #define STM32_UART_USART3_DMA_PRIORITY 0
  380. #define STM32_UART_UART4_DMA_PRIORITY 0
  381. #define STM32_UART_UART5_DMA_PRIORITY 0
  382. #define STM32_UART_USART6_DMA_PRIORITY 0
  383. #define STM32_UART_UART7_DMA_PRIORITY 0
  384. #define STM32_UART_UART8_DMA_PRIORITY 0
  385. #define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
  386. /*
  387. * USB driver system settings.
  388. */
  389. #define STM32_USB_USE_OTG1 TRUE
  390. #define STM32_USB_USE_OTG2 TRUE
  391. #define STM32_USB_OTG1_IRQ_PRIORITY 14
  392. #define STM32_USB_OTG2_IRQ_PRIORITY 14
  393. #define STM32_USB_OTG1_RX_FIFO_SIZE 512
  394. #define STM32_USB_OTG2_RX_FIFO_SIZE 1024
  395. #define STM32_USB_HOST_WAKEUP_DURATION 2
  396. /*
  397. * WDG driver system settings.
  398. */
  399. #define STM32_WDG_USE_IWDG FALSE
  400. #define STM32_EXTI_ENHANCED
  401. // limit ISR count per byte
  402. #define STM32_I2C_ISR_LIMIT 6