hal_lld.h 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148
  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. * @file STM32F7xx/hal_lld.h
  15. * @brief STM32F7xx HAL subsystem low level driver header.
  16. * @pre This module requires the following macros to be defined in the
  17. * @p board.h file:
  18. * - STM32_LSECLK.
  19. * - STM32_LSEDRV.
  20. * - STM32_LSE_BYPASS (optionally).
  21. * - STM32_HSECLK.
  22. * - STM32_HSE_BYPASS (optionally).
  23. * - STM32_VDD (as hundredths of Volt).
  24. * .
  25. * One of the following macros must also be defined:
  26. * - STM32F722xx, STM32F723xx very high-performance MCUs.
  27. * - STM32F732xx, STM32F733xx very high-performance MCUs.
  28. * - STM32F745xx, STM32F746xx, STM32F756xx very high-performance MCUs.
  29. * - STM32F765xx, STM32F767xx, STM32F769xx very high-performance MCUs.
  30. * - STM32F777xx, STM32F779xx very high-performance MCUs.
  31. * .
  32. *
  33. * @addtogroup HAL
  34. * @{
  35. */
  36. #ifndef HAL_LLD_H
  37. #define HAL_LLD_H
  38. #include "stm32_registry.h"
  39. /*===========================================================================*/
  40. /* Driver constants. */
  41. /*===========================================================================*/
  42. /**
  43. * @brief Defines the support for realtime counters in the HAL.
  44. */
  45. #define HAL_IMPLEMENTS_COUNTERS TRUE
  46. /**
  47. * @name Platform identification macros
  48. * @{
  49. */
  50. #if defined(STM32F722xx) || defined(__DOXYGEN__)
  51. #define PLATFORM_NAME "STM32F745 Very High Performance with DSP and FPU"
  52. #elif defined(STM32F723xx)
  53. #define PLATFORM_NAME "STM32F745 Very High Performance with DSP and FPU"
  54. #elif defined(STM32F732xx)
  55. #define PLATFORM_NAME "STM32F745 Very High Performance with DSP and FPU"
  56. #elif defined(STM32F733xx)
  57. #define PLATFORM_NAME "STM32F745 Very High Performance with DSP and FPU"
  58. #elif defined(STM32F745xx)
  59. #define PLATFORM_NAME "STM32F745 Very High Performance with DSP and FPU"
  60. #elif defined(STM32F746xx)
  61. #define PLATFORM_NAME "STM32F746 Very High Performance with DSP and FPU"
  62. #elif defined(STM32F756xx)
  63. #define PLATFORM_NAME "STM32F756 Very High Performance with DSP and FPU"
  64. #elif defined(STM32F765xx)
  65. #define PLATFORM_NAME "STM32F767 Very High Performance with DSP and DP FPU"
  66. #elif defined(STM32F767xx)
  67. #define PLATFORM_NAME "STM32F767 Very High Performance with DSP and DP FPU"
  68. #elif defined(STM32F769xx)
  69. #define PLATFORM_NAME "STM32F769 Very High Performance with DSP and DP FPU"
  70. #elif defined(STM32F777xx)
  71. #define PLATFORM_NAME "STM32F767 Very High Performance with DSP and DP FPU"
  72. #elif defined(STM32F779xx)
  73. #define PLATFORM_NAME "STM32F769 Very High Performance with DSP and DP FPU"
  74. #else
  75. #error "STM32F7xx device not specified"
  76. #endif
  77. /** @} */
  78. /**
  79. * @name Sub-family identifier
  80. */
  81. #if !defined(STM32F7XX) || defined(__DOXYGEN__)
  82. #define STM32F7XX
  83. #endif
  84. /** @} */
  85. /**
  86. * @name Absolute Maximum Ratings
  87. * @{
  88. */
  89. /**
  90. * @brief Absolute maximum system clock.
  91. */
  92. #define STM32_SYSCLK_MAX 216000000
  93. /**
  94. * @brief Maximum HSE clock frequency.
  95. */
  96. #define STM32_HSECLK_MAX 26000000
  97. /**
  98. * @brief Maximum HSE clock frequency using an external source.
  99. */
  100. #define STM32_HSECLK_BYP_MAX 50000000
  101. /**
  102. * @brief Minimum HSE clock frequency.
  103. */
  104. #define STM32_HSECLK_MIN 4000000
  105. /**
  106. * @brief Minimum HSE clock frequency.
  107. */
  108. #define STM32_HSECLK_BYP_MIN 1000000
  109. /**
  110. * @brief Maximum LSE clock frequency.
  111. */
  112. #define STM32_LSECLK_MAX 32768
  113. /**
  114. * @brief Maximum LSE clock frequency.
  115. */
  116. #define STM32_LSECLK_BYP_MAX 1000000
  117. /**
  118. * @brief Minimum LSE clock frequency.
  119. */
  120. #define STM32_LSECLK_MIN 32768
  121. /**
  122. * @brief Maximum PLLs input clock frequency.
  123. */
  124. #define STM32_PLLIN_MAX 2100000
  125. /**
  126. * @brief Minimum PLLs input clock frequency.
  127. */
  128. #define STM32_PLLIN_MIN 950000
  129. /**
  130. * @brief Maximum PLLs VCO clock frequency.
  131. */
  132. #define STM32_PLLVCO_MAX 432000000
  133. /**
  134. * @brief Minimum PLLs VCO clock frequency.
  135. */
  136. #define STM32_PLLVCO_MIN 192000000
  137. /**
  138. * @brief Maximum PLL output clock frequency.
  139. */
  140. #define STM32_PLLOUT_MAX 216000000
  141. /**
  142. * @brief Minimum PLL output clock frequency.
  143. */
  144. #define STM32_PLLOUT_MIN 24000000
  145. /**
  146. * @brief Maximum APB1 clock frequency.
  147. */
  148. #define STM32_PCLK1_MAX (STM32_PLLOUT_MAX / 4)
  149. /**
  150. * @brief Maximum APB2 clock frequency.
  151. */
  152. #define STM32_PCLK2_MAX (STM32_PLLOUT_MAX / 2)
  153. /**
  154. * @brief Maximum SPI/I2S clock frequency.
  155. */
  156. #define STM32_SPII2S_MAX 54000000
  157. /** @} */
  158. /**
  159. * @name Internal clock sources
  160. * @{
  161. */
  162. #define STM32_HSICLK 16000000 /**< High speed internal clock. */
  163. #define STM32_LSICLK 32000 /**< Low speed internal clock. */
  164. /** @} */
  165. /**
  166. * @name PWR_CR register bits definitions
  167. * @{
  168. */
  169. #define STM32_VOS_SCALE3 (PWR_CR1_VOS_0)
  170. #define STM32_VOS_SCALE2 (PWR_CR1_VOS_1)
  171. #define STM32_VOS_SCALE1 (PWR_CR1_VOS_1 | PWR_CR1_VOS_0)
  172. #define STM32_PLS_MASK (7 << 5) /**< PLS bits mask. */
  173. #define STM32_PLS_LEV0 (0 << 5) /**< PVD level 0. */
  174. #define STM32_PLS_LEV1 (1 << 5) /**< PVD level 1. */
  175. #define STM32_PLS_LEV2 (2 << 5) /**< PVD level 2. */
  176. #define STM32_PLS_LEV3 (3 << 5) /**< PVD level 3. */
  177. #define STM32_PLS_LEV4 (4 << 5) /**< PVD level 4. */
  178. #define STM32_PLS_LEV5 (5 << 5) /**< PVD level 5. */
  179. #define STM32_PLS_LEV6 (6 << 5) /**< PVD level 6. */
  180. #define STM32_PLS_LEV7 (7 << 5) /**< PVD level 7. */
  181. /** @} */
  182. /**
  183. * @name RCC_PLLCFGR register bits definitions
  184. * @{
  185. */
  186. #define STM32_PLLP_MASK (3 << 16) /**< PLLP mask. */
  187. #define STM32_PLLP_DIV2 (0 << 16) /**< PLL clock divided by 2. */
  188. #define STM32_PLLP_DIV4 (1 << 16) /**< PLL clock divided by 4. */
  189. #define STM32_PLLP_DIV6 (2 << 16) /**< PLL clock divided by 6. */
  190. #define STM32_PLLP_DIV8 (3 << 16) /**< PLL clock divided by 8. */
  191. #define STM32_PLLSRC_HSI (0 << 22) /**< PLL clock source is HSI. */
  192. #define STM32_PLLSRC_HSE (1 << 22) /**< PLL clock source is HSE. */
  193. /** @} */
  194. /**
  195. * @name RCC_CFGR register bits definitions
  196. * @{
  197. */
  198. #define STM32_SW_MASK (3 << 0) /**< SW mask. */
  199. #define STM32_SW_HSI (0 << 0) /**< SYSCLK source is HSI. */
  200. #define STM32_SW_HSE (1 << 0) /**< SYSCLK source is HSE. */
  201. #define STM32_SW_PLL (2 << 0) /**< SYSCLK source is PLL. */
  202. #define STM32_HPRE_MASK (15 << 4) /**< HPRE mask. */
  203. #define STM32_HPRE_DIV1 (0 << 4) /**< SYSCLK divided by 1. */
  204. #define STM32_HPRE_DIV2 (8 << 4) /**< SYSCLK divided by 2. */
  205. #define STM32_HPRE_DIV4 (9 << 4) /**< SYSCLK divided by 4. */
  206. #define STM32_HPRE_DIV8 (10 << 4) /**< SYSCLK divided by 8. */
  207. #define STM32_HPRE_DIV16 (11 << 4) /**< SYSCLK divided by 16. */
  208. #define STM32_HPRE_DIV64 (12 << 4) /**< SYSCLK divided by 64. */
  209. #define STM32_HPRE_DIV128 (13 << 4) /**< SYSCLK divided by 128. */
  210. #define STM32_HPRE_DIV256 (14 << 4) /**< SYSCLK divided by 256. */
  211. #define STM32_HPRE_DIV512 (15 << 4) /**< SYSCLK divided by 512. */
  212. #define STM32_PPRE1_MASK (7 << 10) /**< PPRE1 mask. */
  213. #define STM32_PPRE1_DIV1 (0 << 10) /**< HCLK divided by 1. */
  214. #define STM32_PPRE1_DIV2 (4 << 10) /**< HCLK divided by 2. */
  215. #define STM32_PPRE1_DIV4 (5 << 10) /**< HCLK divided by 4. */
  216. #define STM32_PPRE1_DIV8 (6 << 10) /**< HCLK divided by 8. */
  217. #define STM32_PPRE1_DIV16 (7 << 10) /**< HCLK divided by 16. */
  218. #define STM32_PPRE2_MASK (7 << 13) /**< PPRE2 mask. */
  219. #define STM32_PPRE2_DIV1 (0 << 13) /**< HCLK divided by 1. */
  220. #define STM32_PPRE2_DIV2 (4 << 13) /**< HCLK divided by 2. */
  221. #define STM32_PPRE2_DIV4 (5 << 13) /**< HCLK divided by 4. */
  222. #define STM32_PPRE2_DIV8 (6 << 13) /**< HCLK divided by 8. */
  223. #define STM32_PPRE2_DIV16 (7 << 13) /**< HCLK divided by 16. */
  224. #define STM32_RTCPRE_MASK (31 << 16) /**< RTCPRE mask. */
  225. #define STM32_MCO1SEL_MASK (3 << 21) /**< MCO1 mask. */
  226. #define STM32_MCO1SEL_HSI (0 << 21) /**< HSI clock on MCO1 pin. */
  227. #define STM32_MCO1SEL_LSE (1 << 21) /**< LSE clock on MCO1 pin. */
  228. #define STM32_MCO1SEL_HSE (2 << 21) /**< HSE clock on MCO1 pin. */
  229. #define STM32_MCO1SEL_PLL (3 << 21) /**< PLL clock on MCO1 pin. */
  230. #define STM32_I2SSRC_MASK (1 << 23) /**< I2CSRC mask. */
  231. #define STM32_I2SSRC_PLLI2S (0 << 23) /**< I2SSRC is PLLI2S. */
  232. #define STM32_I2SSRC_CKIN (1 << 23) /**< I2S_CKIN is PLLI2S. */
  233. #define STM32_I2SSRC_OFF (1 << 23) /**< ISS clock not required. */
  234. #define STM32_MCO1PRE_MASK (7 << 24) /**< MCO1PRE mask. */
  235. #define STM32_MCO1PRE_DIV1 (0 << 24) /**< MCO1 divided by 1. */
  236. #define STM32_MCO1PRE_DIV2 (4 << 24) /**< MCO1 divided by 2. */
  237. #define STM32_MCO1PRE_DIV3 (5 << 24) /**< MCO1 divided by 3. */
  238. #define STM32_MCO1PRE_DIV4 (6 << 24) /**< MCO1 divided by 4. */
  239. #define STM32_MCO1PRE_DIV5 (7 << 24) /**< MCO1 divided by 5. */
  240. #define STM32_MCO2PRE_MASK (7 << 27) /**< MCO2PRE mask. */
  241. #define STM32_MCO2PRE_DIV1 (0 << 27) /**< MCO2 divided by 1. */
  242. #define STM32_MCO2PRE_DIV2 (4 << 27) /**< MCO2 divided by 2. */
  243. #define STM32_MCO2PRE_DIV3 (5 << 27) /**< MCO2 divided by 3. */
  244. #define STM32_MCO2PRE_DIV4 (6 << 27) /**< MCO2 divided by 4. */
  245. #define STM32_MCO2PRE_DIV5 (7 << 27) /**< MCO2 divided by 5. */
  246. #define STM32_MCO2SEL_MASK (3 << 30) /**< MCO2 mask. */
  247. #define STM32_MCO2SEL_SYSCLK (0 << 30) /**< SYSCLK clock on MCO2 pin. */
  248. #define STM32_MCO2SEL_PLLI2S (1 << 30) /**< PLLI2S clock on MCO2 pin. */
  249. #define STM32_MCO2SEL_HSE (2 << 30) /**< HSE clock on MCO2 pin. */
  250. #define STM32_MCO2SEL_PLL (3 << 30) /**< PLL clock on MCO2 pin. */
  251. /** @} */
  252. /**
  253. * @name RCC_PLLI2SCFGR register bits definitions
  254. * @{
  255. */
  256. #define STM32_PLLI2SN_MASK (511 << 6) /**< PLLI2SN mask. */
  257. #define STM32_PLLI2SR_MASK (7 << 28) /**< PLLI2SR mask. */
  258. /** @} */
  259. /**
  260. * @name RCC_DCKCFGR1 register bits definitions
  261. * @{
  262. */
  263. #define STM32_PLLSAIDIVR_MASK (3 << 16) /**< PLLSAIDIVR mask. */
  264. #define STM32_PLLSAIDIVR_DIV2 (0 << 16) /**< LCD_CLK is R divided by 2. */
  265. #define STM32_PLLSAIDIVR_DIV4 (1 << 16) /**< LCD_CLK is R divided by 4. */
  266. #define STM32_PLLSAIDIVR_DIV8 (2 << 16) /**< LCD_CLK is R divided by 8. */
  267. #define STM32_PLLSAIDIVR_DIV16 (3 << 16) /**< LCD_CLK is R divided by 16.*/
  268. #define STM32_SAI1SEL_MASK (3 << 20) /**< SAI1SEL mask. */
  269. #define STM32_SAI1SEL_SAIPLL (0 << 20) /**< SAI1 source is SAIPLL. */
  270. #define STM32_SAI1SEL_I2SPLL (1 << 20) /**< SAI1 source is I2SPLL. */
  271. #define STM32_SAI1SEL_CKIN (2 << 20) /**< SAI1 source is I2S_CKIN. */
  272. #define STM32_SAI1SEL_OFF 0xFFFFFFFFU /**< SAI1 clock is not required.*/
  273. #define STM32_SAI2SEL_MASK (3 << 22) /**< SAI2SEL mask. */
  274. #define STM32_SAI2SEL_SAIPLL (0 << 22) /**< SAI2 source is SAIPLL. */
  275. #define STM32_SAI2SEL_I2SPLL (1 << 22) /**< SAI2 source is I2SPLL. */
  276. #define STM32_SAI2SEL_CKIN (2 << 22) /**< SAI2 source is I2S_CKIN. */
  277. #define STM32_SAI2SEL_OFF 0xFFFFFFFFU /**< SAI2 clock is not required.*/
  278. #define STM32_TIMPRE_MASK (1 << 24) /**< TIMPRE mask. */
  279. #define STM32_TIMPRE_PCLK (0 << 24) /**< TIM clocks from PCLKx. */
  280. #define STM32_TIMPRE_HCLK (1 << 24) /**< TIM clocks from HCLK. */
  281. /** @} */
  282. /**
  283. * @name RCC_DCKCFGR2 register bits definitions
  284. * @{
  285. */
  286. #define STM32_USART1SEL_MASK (3 << 0) /**< USART1SEL mask. */
  287. #define STM32_USART1SEL_PCLK2 (0 << 0) /**< USART1 source is PCLK2. */
  288. #define STM32_USART1SEL_SYSCLK (1 << 0) /**< USART1 source is SYSCLK. */
  289. #define STM32_USART1SEL_HSI (2 << 0) /**< USART1 source is HSI. */
  290. #define STM32_USART1SEL_LSE (3 << 0) /**< USART1 source is LSE. */
  291. #define STM32_USART2SEL_MASK (3 << 2) /**< USART2 mask. */
  292. #define STM32_USART2SEL_PCLK1 (0 << 2) /**< USART2 source is PCLK1. */
  293. #define STM32_USART2SEL_SYSCLK (1 << 2) /**< USART2 source is SYSCLK. */
  294. #define STM32_USART2SEL_HSI (2 << 2) /**< USART2 source is HSI. */
  295. #define STM32_USART2SEL_LSE (3 << 2) /**< USART2 source is LSE. */
  296. #define STM32_USART3SEL_MASK (3 << 4) /**< USART3 mask. */
  297. #define STM32_USART3SEL_PCLK1 (0 << 4) /**< USART3 source is PCLK1. */
  298. #define STM32_USART3SEL_SYSCLK (1 << 4) /**< USART3 source is SYSCLK. */
  299. #define STM32_USART3SEL_HSI (2 << 4) /**< USART3 source is HSI. */
  300. #define STM32_USART3SEL_LSE (3 << 4) /**< USART3 source is LSE. */
  301. #define STM32_UART4SEL_MASK (3 << 6) /**< UART4 mask. */
  302. #define STM32_UART4SEL_PCLK1 (0 << 6) /**< UART4 source is PCLK1. */
  303. #define STM32_UART4SEL_SYSCLK (1 << 6) /**< UART4 source is SYSCLK. */
  304. #define STM32_UART4SEL_HSI (2 << 6) /**< UART4 source is HSI. */
  305. #define STM32_UART4SEL_LSE (3 << 6) /**< UART4 source is LSE. */
  306. #define STM32_UART5SEL_MASK (3 << 8) /**< UART5 mask. */
  307. #define STM32_UART5SEL_PCLK1 (0 << 8) /**< UART5 source is PCLK1. */
  308. #define STM32_UART5SEL_SYSCLK (1 << 8) /**< UART5 source is SYSCLK. */
  309. #define STM32_UART5SEL_HSI (2 << 8) /**< UART5 source is HSI. */
  310. #define STM32_UART5SEL_LSE (3 << 8) /**< UART5 source is LSE. */
  311. #define STM32_USART6SEL_MASK (3 << 10) /**< USART6SEL mask. */
  312. #define STM32_USART6SEL_PCLK2 (0 << 10) /**< USART6 source is PCLK2. */
  313. #define STM32_USART6SEL_SYSCLK (1 << 10) /**< USART6 source is SYSCLK. */
  314. #define STM32_USART6SEL_HSI (2 << 10) /**< USART6 source is HSI. */
  315. #define STM32_USART6SEL_LSE (3 << 10) /**< USART6 source is LSE. */
  316. #define STM32_UART7SEL_MASK (3 << 12) /**< UART7 mask. */
  317. #define STM32_UART7SEL_PCLK1 (0 << 12) /**< UART7 source is PCLK1. */
  318. #define STM32_UART7SEL_SYSCLK (1 << 12) /**< UART7 source is SYSCLK. */
  319. #define STM32_UART7SEL_HSI (2 << 12) /**< UART7 source is HSI. */
  320. #define STM32_UART7SEL_LSE (3 << 12) /**< UART7 source is LSE. */
  321. #define STM32_UART8SEL_MASK (3 << 14) /**< UART8 mask. */
  322. #define STM32_UART8SEL_PCLK1 (0 << 14) /**< UART8 source is PCLK1. */
  323. #define STM32_UART8SEL_SYSCLK (1 << 14) /**< UART8 source is SYSCLK. */
  324. #define STM32_UART8SEL_HSI (2 << 14) /**< UART8 source is HSI. */
  325. #define STM32_UART8SEL_LSE (3 << 14) /**< UART8 source is LSE. */
  326. #define STM32_I2C1SEL_MASK (3 << 16) /**< I2C1SEL mask. */
  327. #define STM32_I2C1SEL_PCLK1 (0 << 16) /**< I2C1 source is PCLK1. */
  328. #define STM32_I2C1SEL_SYSCLK (1 << 16) /**< I2C1 source is SYSCLK. */
  329. #define STM32_I2C1SEL_HSI (2 << 16) /**< I2C1 source is HSI. */
  330. #define STM32_I2C1SEL_LSE (3 << 16) /**< I2C1 source is LSE. */
  331. #define STM32_I2C2SEL_MASK (3 << 18) /**< I2C2SEL mask. */
  332. #define STM32_I2C2SEL_PCLK1 (0 << 18) /**< I2C2 source is PCLK1. */
  333. #define STM32_I2C2SEL_SYSCLK (1 << 18) /**< I2C2 source is SYSCLK. */
  334. #define STM32_I2C2SEL_HSI (2 << 18) /**< I2C2 source is HSI. */
  335. #define STM32_I2C2SEL_LSE (3 << 18) /**< I2C2 source is LSE. */
  336. #define STM32_I2C3SEL_MASK (3 << 20) /**< I2C3SEL mask. */
  337. #define STM32_I2C3SEL_PCLK1 (0 << 20) /**< I2C3 source is PCLK1. */
  338. #define STM32_I2C3SEL_SYSCLK (1 << 20) /**< I2C3 source is SYSCLK. */
  339. #define STM32_I2C3SEL_HSI (2 << 20) /**< I2C3 source is HSI. */
  340. #define STM32_I2C3SEL_LSE (3 << 20) /**< I2C3 source is LSE. */
  341. #define STM32_I2C4SEL_MASK (3 << 22) /**< I2C4SEL mask. */
  342. #define STM32_I2C4SEL_PCLK1 (0 << 22) /**< I2C4 source is PCLK1. */
  343. #define STM32_I2C4SEL_SYSCLK (1 << 22) /**< I2C4 source is SYSCLK. */
  344. #define STM32_I2C4SEL_HSI (2 << 22) /**< I2C4 source is HSI. */
  345. #define STM32_I2C4SEL_LSE (3 << 22) /**< I2C4 source is LSE. */
  346. #define STM32_LPTIM1SEL_MASK (3 << 24) /**< LPTIM1SEL mask. */
  347. #define STM32_LPTIM1SEL_PCLK1 (0 << 24) /**< LPTIM1 source is PCLK1. */
  348. #define STM32_LPTIM1SEL_LSI (1 << 24) /**< LPTIM1 source is LSI. */
  349. #define STM32_LPTIM1SEL_HSI (2 << 24) /**< LPTIM1 source is HSI. */
  350. #define STM32_LPTIM1SEL_LSE (3 << 24) /**< LPTIM1 source is LSE. */
  351. #define STM32_CECSEL_MASK (1 << 26) /**< CECSEL mask. */
  352. #define STM32_CECSEL_LSE (0 << 26) /**< CEC source is LSE. */
  353. #define STM32_CECSEL_HSIDIV488 (1 << 26) /**< CEC source is HSI/488. */
  354. #define STM32_CK48MSEL_MASK (1 << 27) /**< CK48MSEL mask. */
  355. #define STM32_CK48MSEL_PLL (0 << 27) /**< PLL48CLK source is PLL. */
  356. #define STM32_CK48MSEL_PLLSAI (1 << 27) /**< PLL48CLK source is PLLSAI. */
  357. #define STM32_SDMMC1SEL_MASK (1 << 28) /**< SDMMC1SEL mask. */
  358. #define STM32_SDMMC1SEL_PLL48CLK (0 << 28) /**< SDMMC1 source is PLL48CLK. */
  359. #define STM32_SDMMC1SEL_SYSCLK (1 << 28) /**< SDMMC1 source is SYSCLK. */
  360. #define STM32_SDMMC2SEL_MASK (1 << 29) /**< SDMMC2SEL mask. */
  361. #define STM32_SDMMC2SEL_PLL48CLK (0 << 29) /**< SDMMC2 source is PLL48CLK. */
  362. #define STM32_SDMMC2SEL_SYSCLK (1 << 29) /**< SDMMC2 source is SYSCLK. */
  363. /** @} */
  364. /**
  365. * @name RCC_BDCR register bits definitions
  366. * @{
  367. */
  368. #define STM32_RTCSEL_MASK (3 << 8) /**< RTC source mask. */
  369. #define STM32_RTCSEL_NOCLOCK (0 << 8) /**< No RTC source. */
  370. #define STM32_RTCSEL_LSE (1 << 8) /**< RTC source is LSE. */
  371. #define STM32_RTCSEL_LSI (2 << 8) /**< RTC source is LSI. */
  372. #define STM32_RTCSEL_HSEDIV (3 << 8) /**< RTC source is HSE divided. */
  373. /** @} */
  374. /*===========================================================================*/
  375. /* Driver pre-compile time settings. */
  376. /*===========================================================================*/
  377. /**
  378. * @name Configuration options
  379. * @{
  380. */
  381. /**
  382. * @brief Disables the PWR/RCC initialization in the HAL.
  383. */
  384. #if !defined(STM32_NO_INIT) || defined(__DOXYGEN__)
  385. #define STM32_NO_INIT FALSE
  386. #endif
  387. /**
  388. * @brief Enables or disables the programmable voltage detector.
  389. */
  390. #if !defined(STM32_PVD_ENABLE) || defined(__DOXYGEN__)
  391. #define STM32_PVD_ENABLE FALSE
  392. #endif
  393. /**
  394. * @brief Sets voltage level for programmable voltage detector.
  395. */
  396. #if !defined(STM32_PLS) || defined(__DOXYGEN__)
  397. #define STM32_PLS STM32_PLS_LEV0
  398. #endif
  399. /**
  400. * @brief Enables the backup RAM regulator.
  401. */
  402. #if !defined(STM32_BKPRAM_ENABLE) || defined(__DOXYGEN__)
  403. #define STM32_BKPRAM_ENABLE FALSE
  404. #endif
  405. /**
  406. * @brief Enables or disables the HSI clock source.
  407. */
  408. #if !defined(STM32_HSI_ENABLED) || defined(__DOXYGEN__)
  409. #define STM32_HSI_ENABLED TRUE
  410. #endif
  411. /**
  412. * @brief Enables or disables the LSI clock source.
  413. */
  414. #if !defined(STM32_LSI_ENABLED) || defined(__DOXYGEN__)
  415. #define STM32_LSI_ENABLED FALSE
  416. #endif
  417. /**
  418. * @brief Enables or disables the HSE clock source.
  419. */
  420. #if !defined(STM32_HSE_ENABLED) || defined(__DOXYGEN__)
  421. #define STM32_HSE_ENABLED TRUE
  422. #endif
  423. /**
  424. * @brief Enables or disables the LSE clock source.
  425. */
  426. #if !defined(STM32_LSE_ENABLED) || defined(__DOXYGEN__)
  427. #define STM32_LSE_ENABLED TRUE
  428. #endif
  429. /**
  430. * @brief USB/SDIO clock setting.
  431. */
  432. #if !defined(STM32_CLOCK48_REQUIRED) || defined(__DOXYGEN__)
  433. #define STM32_CLOCK48_REQUIRED TRUE
  434. #endif
  435. /**
  436. * @brief Main clock source selection.
  437. * @note If the selected clock source is not the PLL then the PLL is not
  438. * initialized and started.
  439. * @note The default value is calculated for a 216MHz system clock from
  440. * an external 25MHz HSE clock.
  441. */
  442. #if !defined(STM32_SW) || defined(__DOXYGEN__)
  443. #define STM32_SW STM32_SW_PLL
  444. #endif
  445. /**
  446. * @brief Clock source for the PLLs.
  447. * @note This setting has only effect if the PLL is selected as the
  448. * system clock source.
  449. * @note The default value is calculated for a 216MHz system clock from
  450. * an external 25MHz HSE clock.
  451. */
  452. #if !defined(STM32_PLLSRC) || defined(__DOXYGEN__)
  453. #define STM32_PLLSRC STM32_PLLSRC_HSE
  454. #endif
  455. /**
  456. * @brief PLLM divider value.
  457. * @note The allowed values are 2..63.
  458. * @note The default value is calculated for a 216MHz system clock from
  459. * an external 25MHz HSE clock.
  460. */
  461. #if !defined(STM32_PLLM_VALUE) || defined(__DOXYGEN__)
  462. #define STM32_PLLM_VALUE 25
  463. #endif
  464. /**
  465. * @brief PLLN multiplier value.
  466. * @note The allowed values are 192..432.
  467. * @note The default value is calculated for a 216MHz system clock from
  468. * an external 25MHz HSE clock.
  469. */
  470. #if !defined(STM32_PLLN_VALUE) || defined(__DOXYGEN__)
  471. #define STM32_PLLN_VALUE 432
  472. #endif
  473. /**
  474. * @brief PLLP divider value.
  475. * @note The allowed values are 2, 4, 6, 8.
  476. * @note The default value is calculated for a 216MHz system clock from
  477. * an external 25MHz HSE clock.
  478. */
  479. #if !defined(STM32_PLLP_VALUE) || defined(__DOXYGEN__)
  480. #define STM32_PLLP_VALUE 2
  481. #endif
  482. /**
  483. * @brief PLLQ divider value.
  484. * @note The allowed values are 2..15.
  485. * @note The default value is calculated for a 216MHz system clock from
  486. * an external 25MHz HSE clock.
  487. */
  488. #if !defined(STM32_PLLQ_VALUE) || defined(__DOXYGEN__)
  489. #define STM32_PLLQ_VALUE 9
  490. #endif
  491. /**
  492. * @brief AHB prescaler value.
  493. */
  494. #if !defined(STM32_HPRE) || defined(__DOXYGEN__)
  495. #define STM32_HPRE STM32_HPRE_DIV1
  496. #endif
  497. /**
  498. * @brief APB1 prescaler value.
  499. */
  500. #if !defined(STM32_PPRE1) || defined(__DOXYGEN__)
  501. #define STM32_PPRE1 STM32_PPRE1_DIV4
  502. #endif
  503. /**
  504. * @brief APB2 prescaler value.
  505. */
  506. #if !defined(STM32_PPRE2) || defined(__DOXYGEN__)
  507. #define STM32_PPRE2 STM32_PPRE2_DIV2
  508. #endif
  509. /**
  510. * @brief RTC clock source.
  511. */
  512. #if !defined(STM32_RTCSEL) || defined(__DOXYGEN__)
  513. #define STM32_RTCSEL STM32_RTCSEL_LSE
  514. #endif
  515. /**
  516. * @brief RTC HSE prescaler value.
  517. * @note The allowed values are 2..31.
  518. */
  519. #if !defined(STM32_RTCPRE_VALUE) || defined(__DOXYGEN__)
  520. #define STM32_RTCPRE_VALUE 25
  521. #endif
  522. /**
  523. * @brief MCO1 clock source value.
  524. * @note The default value outputs HSI clock on MCO1 pin.
  525. */
  526. #if !defined(STM32_MCO1SEL) || defined(__DOXYGEN__)
  527. #define STM32_MCO1SEL STM32_MCO1SEL_HSI
  528. #endif
  529. /**
  530. * @brief MCO1 prescaler value.
  531. * @note The default value outputs HSI clock on MCO1 pin.
  532. */
  533. #if !defined(STM32_MCO1PRE) || defined(__DOXYGEN__)
  534. #define STM32_MCO1PRE STM32_MCO1PRE_DIV1
  535. #endif
  536. /**
  537. * @brief MCO2 clock source value.
  538. * @note The default value outputs SYSCLK / 4 on MCO2 pin.
  539. */
  540. #if !defined(STM32_MCO2SEL) || defined(__DOXYGEN__)
  541. #define STM32_MCO2SEL STM32_MCO2SEL_SYSCLK
  542. #endif
  543. /**
  544. * @brief MCO2 prescaler value.
  545. * @note The default value outputs SYSCLK / 4 on MCO2 pin.
  546. */
  547. #if !defined(STM32_MCO2PRE) || defined(__DOXYGEN__)
  548. #define STM32_MCO2PRE STM32_MCO2PRE_DIV4
  549. #endif
  550. /**
  551. * @brief I2S clock source.
  552. */
  553. #if !defined(STM32_I2SSRC) || defined(__DOXYGEN__)
  554. #define STM32_I2SSRC STM32_I2SSRC_PLLI2S
  555. #endif
  556. /**
  557. * @brief PLLI2SN multiplier value.
  558. * @note The allowed values are 49..432.
  559. */
  560. #if !defined(STM32_PLLI2SN_VALUE) || defined(__DOXYGEN__)
  561. #define STM32_PLLI2SN_VALUE 192
  562. #endif
  563. /**
  564. * @brief PLLI2SP divider value.
  565. * @note The allowed values are 2, 4, 6 and 8.
  566. */
  567. #if !defined(STM32_PLLI2SP_VALUE) || defined(__DOXYGEN__)
  568. #define STM32_PLLI2SP_VALUE 4
  569. #endif
  570. /**
  571. * @brief PLLI2SQ divider value.
  572. * @note The allowed values are 2..15.
  573. */
  574. #if !defined(STM32_PLLI2SQ_VALUE) || defined(__DOXYGEN__)
  575. #define STM32_PLLI2SQ_VALUE 4
  576. #endif
  577. /**
  578. * @brief PLLI2SDIVQ divider value (SAI clock divider).
  579. */
  580. #if !defined(STM32_PLLI2SDIVQ_VALUE) || defined(__DOXYGEN__)
  581. #define STM32_PLLI2SDIVQ_VALUE 2
  582. #endif
  583. /**
  584. * @brief PLLI2SR divider value.
  585. * @note The allowed values are 2..7.
  586. */
  587. #if !defined(STM32_PLLI2SR_VALUE) || defined(__DOXYGEN__)
  588. #define STM32_PLLI2SR_VALUE 4
  589. #endif
  590. /**
  591. * @brief PLLSAIN multiplier value.
  592. * @note The allowed values are 49..432.
  593. */
  594. #if !defined(STM32_PLLSAIN_VALUE) || defined(__DOXYGEN__)
  595. #define STM32_PLLSAIN_VALUE 192
  596. #endif
  597. /**
  598. * @brief PLLSAIP divider value.
  599. * @note The allowed values are 2, 4, 6 and 8.
  600. */
  601. #if !defined(STM32_PLLSAIP_VALUE) || defined(__DOXYGEN__)
  602. #define STM32_PLLSAIP_VALUE 4
  603. #endif
  604. /**
  605. * @brief PLLSAIQ divider value.
  606. * @note The allowed values are 2..15.
  607. */
  608. #if !defined(STM32_PLLSAIQ_VALUE) || defined(__DOXYGEN__)
  609. #define STM32_PLLSAIQ_VALUE 4
  610. #endif
  611. /**
  612. * @brief PLLSAIR divider value.
  613. * @note The allowed values are 2..7.
  614. */
  615. #if !defined(STM32_PLLSAIR_VALUE) || defined(__DOXYGEN__)
  616. #define STM32_PLLSAIR_VALUE 4
  617. #endif
  618. /**
  619. * @brief PLLSAIDIVQ divider value (SAI clock divider).
  620. */
  621. #if !defined(STM32_PLLSAIDIVQ_VALUE) || defined(__DOXYGEN__)
  622. #define STM32_PLLSAIDIVQ_VALUE 2
  623. #endif
  624. /**
  625. * @brief PLLSAIDIVR divider value (LCD clock divider).
  626. */
  627. #if !defined(STM32_PLLSAIDIVR_VALUE) || defined(__DOXYGEN__)
  628. #define STM32_PLLSAIDIVR_VALUE 2
  629. #endif
  630. /**
  631. * @brief SAI1SEL value (SAI1 clock source).
  632. */
  633. #if !defined(STM32_SAI1SEL) || defined(__DOXYGEN__)
  634. #define STM32_SAI1SEL STM32_SAI1SEL_OFF
  635. #endif
  636. /**
  637. * @brief SAI2SEL value (SAI2 clock source).
  638. */
  639. #if !defined(STM32_SAI2SEL) || defined(__DOXYGEN__)
  640. #define STM32_SAI2SEL STM32_SAI2SEL_OFF
  641. #endif
  642. /**
  643. * @brief LCD-TFT clock enable switch.
  644. */
  645. #if !defined(STM32_LCDTFT_REQUIRED) || defined(__DOXYGEN__)
  646. #define STM32_LCDTFT_REQUIRED FALSE
  647. #endif
  648. /**
  649. * @brief USART1 clock source.
  650. */
  651. #if !defined(STM32_USART1SEL) || defined(__DOXYGEN__)
  652. #define STM32_USART1SEL STM32_USART1SEL_PCLK2
  653. #endif
  654. /**
  655. * @brief USART2 clock source.
  656. */
  657. #if !defined(STM32_USART2SEL) || defined(__DOXYGEN__)
  658. #define STM32_USART2SEL STM32_USART2SEL_PCLK1
  659. #endif
  660. /**
  661. * @brief USART3 clock source.
  662. */
  663. #if !defined(STM32_USART3SEL) || defined(__DOXYGEN__)
  664. #define STM32_USART3SEL STM32_USART3SEL_PCLK1
  665. #endif
  666. /**
  667. * @brief UART4 clock source.
  668. */
  669. #if !defined(STM32_UART4SEL) || defined(__DOXYGEN__)
  670. #define STM32_UART4SEL STM32_UART4SEL_PCLK1
  671. #endif
  672. /**
  673. * @brief UART5 clock source.
  674. */
  675. #if !defined(STM32_UART5SEL) || defined(__DOXYGEN__)
  676. #define STM32_UART5SEL STM32_UART5SEL_PCLK1
  677. #endif
  678. /**
  679. * @brief USART6 clock source.
  680. */
  681. #if !defined(STM32_USART6SEL) || defined(__DOXYGEN__)
  682. #define STM32_USART6SEL STM32_USART6SEL_PCLK2
  683. #endif
  684. /**
  685. * @brief UART7 clock source.
  686. */
  687. #if !defined(STM32_UART7SEL) || defined(__DOXYGEN__)
  688. #define STM32_UART7SEL STM32_UART7SEL_PCLK1
  689. #endif
  690. /**
  691. * @brief UART8 clock source.
  692. */
  693. #if !defined(STM32_UART8SEL) || defined(__DOXYGEN__)
  694. #define STM32_UART8SEL STM32_UART8SEL_PCLK1
  695. #endif
  696. /**
  697. * @brief I2C1 clock source.
  698. */
  699. #if !defined(STM32_I2C1SEL) || defined(__DOXYGEN__)
  700. #define STM32_I2C1SEL STM32_I2C1SEL_PCLK1
  701. #endif
  702. /**
  703. * @brief I2C2 clock source.
  704. */
  705. #if !defined(STM32_I2C2SEL) || defined(__DOXYGEN__)
  706. #define STM32_I2C2SEL STM32_I2C2SEL_PCLK1
  707. #endif
  708. /**
  709. * @brief I2C3 clock source.
  710. */
  711. #if !defined(STM32_I2C3SEL) || defined(__DOXYGEN__)
  712. #define STM32_I2C3SEL STM32_I2C3SEL_PCLK1
  713. #endif
  714. /**
  715. * @brief I2C4 clock source.
  716. */
  717. #if !defined(STM32_I2C4SEL) || defined(__DOXYGEN__)
  718. #define STM32_I2C4SEL STM32_I2C4SEL_PCLK1
  719. #endif
  720. /**
  721. * @brief LPTIM1 clock source.
  722. */
  723. #if !defined(STM32_LPTIM1SEL) || defined(__DOXYGEN__)
  724. #define STM32_LPTIM1SEL STM32_LPTIM1SEL_PCLK1
  725. #endif
  726. /**
  727. * @brief CEC clock source.
  728. */
  729. #if !defined(STM32_CECSEL) || defined(__DOXYGEN__)
  730. #define STM32_CECSEL STM32_CECSEL_LSE
  731. #endif
  732. /**
  733. * @brief PLL48CLK clock source.
  734. */
  735. #if !defined(STM32_CK48MSEL) || defined(__DOXYGEN__)
  736. #define STM32_CK48MSEL STM32_CK48MSEL_PLL
  737. #endif
  738. /**
  739. * @brief SDMMC1 clock source.
  740. */
  741. #if !defined(STM32_SDMMC1SEL) || defined(__DOXYGEN__)
  742. #define STM32_SDMMC1SEL STM32_SDMMC1SEL_PLL48CLK
  743. #endif
  744. /**
  745. * @brief SDMMC2 clock source.
  746. */
  747. #if !defined(STM32_SDMMC2SEL) || defined(__DOXYGEN__)
  748. #define STM32_SDMMC2SEL STM32_SDMMC2SEL_PLL48CLK
  749. #endif
  750. /**
  751. * @brief SRAM2 cache-ability.
  752. * @note This setting uses the MPU region 7 if at @p TRUE.
  753. */
  754. #if !defined(STM32_SRAM2_NOCACHE) || defined(__DOXYGEN__)
  755. #define STM32_SRAM2_NOCACHE FALSE
  756. #endif
  757. /** @} */
  758. /*===========================================================================*/
  759. /* Derived constants and error checks. */
  760. /*===========================================================================*/
  761. /*
  762. * Configuration-related checks.
  763. */
  764. #if !defined(STM32F7xx_MCUCONF)
  765. #error "Using a wrong mcuconf.h file, STM32F7xx_MCUCONF not defined"
  766. #endif
  767. #if defined(STM32F722xx) && !defined(STM32F722_MCUCONF)
  768. #error "Using a wrong mcuconf.h file, STM32F722_MCUCONF not defined"
  769. #endif
  770. #if defined(STM32F732xx) && !defined(STM32F732_MCUCONF)
  771. #error "Using a wrong mcuconf.h file, STM32F732_MCUCONF not defined"
  772. #endif
  773. #if defined(STM32F723xx) && !defined(STM32F723_MCUCONF)
  774. #error "Using a wrong mcuconf.h file, STM32F723_MCUCONF not defined"
  775. #endif
  776. #if defined(STM32F733xx) && !defined(STM32F733_MCUCONF)
  777. #error "Using a wrong mcuconf.h file, STM32F733_MCUCONF not defined"
  778. #endif
  779. #if defined(STM32F746xx) && !defined(STM32F746_MCUCONF)
  780. #error "Using a wrong mcuconf.h file, STM32F746_MCUCONF not defined"
  781. #endif
  782. #if defined(STM32F756xx) && !defined(STM32F756_MCUCONF)
  783. #error "Using a wrong mcuconf.h file, STM32F756_MCUCONF not defined"
  784. #endif
  785. #if defined(STM32F765xx) && !defined(STM32F765_MCUCONF)
  786. #error "Using a wrong mcuconf.h file, STM32F765_MCUCONF not defined"
  787. #endif
  788. #if defined(STM32F767xx) && !defined(STM32F767_MCUCONF)
  789. #error "Using a wrong mcuconf.h file, STM32F767_MCUCONF not defined"
  790. #endif
  791. #if defined(STM32F777xx) && !defined(STM32F777_MCUCONF)
  792. #error "Using a wrong mcuconf.h file, STM32F777_MCUCONF not defined"
  793. #endif
  794. #if defined(STM32F769xx) && !defined(STM32F769_MCUCONF)
  795. #error "Using a wrong mcuconf.h file, STM32F769_MCUCONF not defined"
  796. #endif
  797. #if defined(STM32F779xx) && !defined(STM32F779_MCUCONF)
  798. #error "Using a wrong mcuconf.h file, STM32F779_MCUCONF not defined"
  799. #endif
  800. /*
  801. * Board file checks.
  802. */
  803. #if !defined(STM32_LSECLK)
  804. #error "STM32_LSECLK not defined in board.h"
  805. #endif
  806. #if !defined(STM32_LSEDRV)
  807. #error "STM32_LSEDRV not defined in board.h"
  808. #endif
  809. #if !defined(STM32_HSECLK)
  810. #error "STM32_HSECLK not defined in board.h"
  811. #endif
  812. #if !defined(STM32_VDD)
  813. #error "STM32_VDD not defined in board.h"
  814. #endif
  815. /**
  816. * @brief Maximum frequency thresholds and wait states for flash access.
  817. * @note The values are valid for 2.7V to 3.6V supply range.
  818. */
  819. #if ((STM32_VDD >= 270) && (STM32_VDD <= 360)) || defined(__DOXYGEN__)
  820. #define STM32_0WS_THRESHOLD 30000000
  821. #define STM32_1WS_THRESHOLD 60000000
  822. #define STM32_2WS_THRESHOLD 90000000
  823. #define STM32_3WS_THRESHOLD 120000000
  824. #define STM32_4WS_THRESHOLD 150000000
  825. #define STM32_5WS_THRESHOLD 180000000
  826. #define STM32_6WS_THRESHOLD 210000000
  827. #define STM32_7WS_THRESHOLD STM32_SYSCLK_MAX
  828. #define STM32_8WS_THRESHOLD 0
  829. #define STM32_9WS_THRESHOLD 0
  830. #elif (STM32_VDD >= 240) && (STM32_VDD < 270)
  831. #define STM32_0WS_THRESHOLD 24000000
  832. #define STM32_1WS_THRESHOLD 48000000
  833. #define STM32_2WS_THRESHOLD 72000000
  834. #define STM32_3WS_THRESHOLD 96000000
  835. #define STM32_4WS_THRESHOLD 120000000
  836. #define STM32_5WS_THRESHOLD 144000000
  837. #define STM32_6WS_THRESHOLD 168000000
  838. #define STM32_7WS_THRESHOLD 192000000
  839. #define STM32_8WS_THRESHOLD STM32_SYSCLK_MAX
  840. #define STM32_9WS_THRESHOLD 0
  841. #elif (STM32_VDD >= 210) && (STM32_VDD < 240)
  842. #define STM32_0WS_THRESHOLD 22000000
  843. #define STM32_1WS_THRESHOLD 44000000
  844. #define STM32_2WS_THRESHOLD 66000000
  845. #define STM32_3WS_THRESHOLD 88000000
  846. #define STM32_4WS_THRESHOLD 110000000
  847. #define STM32_5WS_THRESHOLD 132000000
  848. #define STM32_6WS_THRESHOLD 154000000
  849. #define STM32_7WS_THRESHOLD 176000000
  850. #define STM32_8WS_THRESHOLD 198000000
  851. #define STM32_9WS_THRESHOLD STM32_SYSCLK_MAX
  852. #elif (STM32_VDD >= 180) && (STM32_VDD < 210)
  853. #define STM32_0WS_THRESHOLD 20000000
  854. #define STM32_1WS_THRESHOLD 40000000
  855. #define STM32_2WS_THRESHOLD 60000000
  856. #define STM32_3WS_THRESHOLD 80000000
  857. #define STM32_4WS_THRESHOLD 100000000
  858. #define STM32_5WS_THRESHOLD 120000000
  859. #define STM32_6WS_THRESHOLD 140000000
  860. #define STM32_7WS_THRESHOLD 160000000
  861. #define STM32_8WS_THRESHOLD 180000000
  862. #define STM32_9WS_THRESHOLD 0
  863. #else
  864. #error "invalid VDD voltage specified"
  865. #endif
  866. /*
  867. * HSI related checks.
  868. */
  869. #if STM32_HSI_ENABLED
  870. #else /* !STM32_HSI_ENABLED */
  871. #if STM32_SW == STM32_SW_HSI
  872. #error "HSI not enabled, required by STM32_SW"
  873. #endif
  874. #if (STM32_SW == STM32_SW_PLL) && (STM32_PLLSRC == STM32_PLLSRC_HSI)
  875. #error "HSI not enabled, required by STM32_SW and STM32_PLLSRC"
  876. #endif
  877. #if (STM32_MCO1SEL == STM32_MCO1SEL_HSI) || \
  878. ((STM32_MCO1SEL == STM32_MCO1SEL_PLL) && \
  879. (STM32_PLLSRC == STM32_PLLSRC_HSI))
  880. #error "HSI not enabled, required by STM32_MCO1SEL"
  881. #endif
  882. #if (STM32_MCO2SEL == STM32_MCO2SEL_PLL) && \
  883. (STM32_PLLSRC == STM32_PLLSRC_HSI)
  884. #error "HSI not enabled, required by STM32_MCO2SEL"
  885. #endif
  886. #if (STM32_I2SSRC == STM32_I2SSRC_PLLI2S) && \
  887. (STM32_PLLSRC == STM32_PLLSRC_HSI)
  888. #error "HSI not enabled, required by STM32_I2SSRC"
  889. #endif
  890. #if ((STM32_SAI1SEL == STM32_SAI1SEL_SAIPLL) || \
  891. (STM32_SAI1SEL == STM32_SAI1SEL_I2SPLL)) && \
  892. (STM32_PLLSRC == STM32_PLLSRC_HSI)
  893. #error "HSI not enabled, required by STM32_SAI1SEL"
  894. #endif
  895. #if ((STM32_SAI2SEL == STM32_SAI2SEL_SAIPLL) || \
  896. (STM32_SAI2SEL == STM32_SAI2SEL_I2SPLL)) && \
  897. (STM32_PLLSRC == STM32_PLLSRC_HSI)
  898. #error "HSI not enabled, required by STM32_SAI2SEL"
  899. #endif
  900. #if STM32_LCDTFT_REQUIRED && \
  901. (STM32_PLLSRC == STM32_PLLSRC_HSI)
  902. #error "HSI not enabled, required by STM32_LCDTFT_REQUIRED"
  903. #endif
  904. #endif /* !STM32_HSI_ENABLED */
  905. /*
  906. * HSE related checks.
  907. */
  908. #if STM32_HSE_ENABLED
  909. #if STM32_HSECLK == 0
  910. #error "HSE frequency not defined"
  911. #else /* STM32_HSECLK != 0 */
  912. #if defined(STM32_HSE_BYPASS)
  913. #if (STM32_HSECLK < STM32_HSECLK_MIN) || (STM32_HSECLK > STM32_HSECLK_BYP_MAX)
  914. #error "STM32_HSECLK outside acceptable range (STM32_HSECLK_MIN...STM32_HSECLK_BYP_MAX)"
  915. #endif
  916. #else /* !defined(STM32_HSE_BYPASS) */
  917. #if (STM32_HSECLK < STM32_HSECLK_MIN) || (STM32_HSECLK > STM32_HSECLK_MAX)
  918. #error "STM32_HSECLK outside acceptable range (STM32_HSECLK_MIN...STM32_HSECLK_MAX)"
  919. #endif
  920. #endif /* !defined(STM32_HSE_BYPASS) */
  921. #endif /* STM32_HSECLK != 0 */
  922. #else /* !STM32_HSE_ENABLED */
  923. #if STM32_SW == STM32_SW_HSE
  924. #error "HSE not enabled, required by STM32_SW"
  925. #endif
  926. #if (STM32_SW == STM32_SW_PLL) && (STM32_PLLSRC == STM32_PLLSRC_HSE)
  927. #error "HSE not enabled, required by STM32_SW and STM32_PLLSRC"
  928. #endif
  929. #if (STM32_MCO1SEL == STM32_MCO1SEL_HSE) || \
  930. ((STM32_MCO1SEL == STM32_MCO1SEL_PLL) && \
  931. (STM32_PLLSRC == STM32_PLLSRC_HSE))
  932. #error "HSE not enabled, required by STM32_MCO1SEL"
  933. #endif
  934. #if (STM32_MCO2SEL == STM32_MCO2SEL_HSE) || \
  935. ((STM32_MCO2SEL == STM32_MCO2SEL_PLL) && \
  936. (STM32_PLLSRC == STM32_PLLSRC_HSE))
  937. #error "HSE not enabled, required by STM32_MCO2SEL"
  938. #endif
  939. #if (STM32_I2SSRC == STM32_I2SSRC_PLLI2S) && \
  940. (STM32_PLLSRC == STM32_PLLSRC_HSE)
  941. #error "HSE not enabled, required by STM32_I2SSRC"
  942. #endif
  943. #if ((STM32_SAI1SEL == STM32_SAI1SEL_SAIPLL) | \
  944. (STM32_SAI1SEL == STM32_SAI1SEL_I2SPLL)) && \
  945. (STM32_PLLSRC == STM32_PLLSRC_HSE)
  946. #error "HSE not enabled, required by STM32_SAI1SEL"
  947. #endif
  948. #if ((STM32_SAI2SEL == STM32_SAI2SEL_SAIPLL) | \
  949. (STM32_SAI2SEL == STM32_SAI2SEL_I2SPLL)) && \
  950. (STM32_PLLSRC == STM32_PLLSRC_HSE)
  951. #error "HSE not enabled, required by STM32_SAI2SEL"
  952. #endif
  953. #if STM32_LCDTFT_REQUIRED && \
  954. (STM32_PLLSRC == STM32_PLLSRC_HSE)
  955. #error "HSE not enabled, required by STM32_LCDTFT_REQUIRED"
  956. #endif
  957. #if STM32_RTCSEL == STM32_RTCSEL_HSEDIV
  958. #error "HSE not enabled, required by STM32_RTCSEL"
  959. #endif
  960. #endif /* !STM32_HSE_ENABLED */
  961. /*
  962. * LSI related checks.
  963. */
  964. #if STM32_LSI_ENABLED
  965. #else /* !STM32_LSI_ENABLED */
  966. #if STM32_RTCSEL == STM32_RTCSEL_LSI
  967. #error "LSI not enabled, required by STM32_RTCSEL"
  968. #endif
  969. #endif /* !STM32_LSI_ENABLED */
  970. /*
  971. * LSE related checks.
  972. */
  973. #if STM32_LSE_ENABLED
  974. #if (STM32_LSECLK == 0)
  975. #error "LSE frequency not defined"
  976. #endif
  977. #if (STM32_LSECLK < STM32_LSECLK_MIN) || (STM32_LSECLK > STM32_LSECLK_MAX)
  978. #error "STM32_LSECLK outside acceptable range (STM32_LSECLK_MIN...STM32_LSECLK_MAX)"
  979. #endif
  980. #if !defined(STM32_LSEDRV)
  981. #error "STM32_LSEDRV not defined"
  982. #endif
  983. #if (STM32_LSEDRV >> 3) > 3
  984. #error "STM32_LSEDRV outside acceptable range ((0<<3)...(3<<3))"
  985. #endif
  986. #else /* !STM32_LSE_ENABLED */
  987. #if STM32_RTCSEL == STM32_RTCSEL_LSE
  988. #error "LSE not enabled, required by STM32_RTCSEL"
  989. #endif
  990. #if STM32_MCO1SEL == STM32_MCO1SEL_LSE
  991. #error "LSE not enabled, required by STM32_MCO1SEL"
  992. #endif
  993. #endif /* !STM32_LSE_ENABLED */
  994. /**
  995. * @brief STM32_PLLM field.
  996. */
  997. #if ((STM32_PLLM_VALUE >= 2) && (STM32_PLLM_VALUE <= 63)) || \
  998. defined(__DOXYGEN__)
  999. #define STM32_PLLM (STM32_PLLM_VALUE << 0)
  1000. #else
  1001. #error "invalid STM32_PLLM_VALUE value specified"
  1002. #endif
  1003. /**
  1004. * @brief PLLs input clock frequency.
  1005. */
  1006. #if (STM32_PLLSRC == STM32_PLLSRC_HSE) || defined(__DOXYGEN__)
  1007. #define STM32_PLLCLKIN (STM32_HSECLK / STM32_PLLM_VALUE)
  1008. #elif STM32_PLLSRC == STM32_PLLSRC_HSI
  1009. #define STM32_PLLCLKIN (STM32_HSICLK / STM32_PLLM_VALUE)
  1010. #else
  1011. #error "invalid STM32_PLLSRC value specified"
  1012. #endif
  1013. /*
  1014. * PLLs input frequency range check.
  1015. */
  1016. #if (STM32_PLLCLKIN < STM32_PLLIN_MIN) || (STM32_PLLCLKIN > STM32_PLLIN_MAX)
  1017. #error "STM32_PLLCLKIN outside acceptable range (STM32_PLLIN_MIN...STM32_PLLIN_MAX)"
  1018. #endif
  1019. /*
  1020. * PLL enable check.
  1021. */
  1022. #if (STM32_CLOCK48_REQUIRED && (STM32_CK48MSEL == STM32_CK48MSEL_PLL)) || \
  1023. (STM32_SW == STM32_SW_PLL) || \
  1024. (STM32_MCO1SEL == STM32_MCO1SEL_PLL) || \
  1025. (STM32_MCO2SEL == STM32_MCO2SEL_PLL) || \
  1026. defined(__DOXYGEN__)
  1027. /**
  1028. * @brief PLL activation flag.
  1029. */
  1030. #define STM32_ACTIVATE_PLL TRUE
  1031. #else
  1032. #define STM32_ACTIVATE_PLL FALSE
  1033. #endif
  1034. /**
  1035. * @brief STM32_PLLN field.
  1036. */
  1037. #if ((STM32_PLLN_VALUE >= 64) && (STM32_PLLN_VALUE <= 432)) || \
  1038. defined(__DOXYGEN__)
  1039. #define STM32_PLLN (STM32_PLLN_VALUE << 6)
  1040. #else
  1041. #error "invalid STM32_PLLN_VALUE value specified"
  1042. #endif
  1043. /**
  1044. * @brief STM32_PLLP field.
  1045. */
  1046. #if (STM32_PLLP_VALUE == 2) || defined(__DOXYGEN__)
  1047. #define STM32_PLLP (0 << 16)
  1048. #elif STM32_PLLP_VALUE == 4
  1049. #define STM32_PLLP (1 << 16)
  1050. #elif STM32_PLLP_VALUE == 6
  1051. #define STM32_PLLP (2 << 16)
  1052. #elif STM32_PLLP_VALUE == 8
  1053. #define STM32_PLLP (3 << 16)
  1054. #else
  1055. #error "invalid STM32_PLLP_VALUE value specified"
  1056. #endif
  1057. /**
  1058. * @brief STM32_PLLQ field.
  1059. */
  1060. #if ((STM32_PLLQ_VALUE >= 2) && (STM32_PLLQ_VALUE <= 15)) || \
  1061. defined(__DOXYGEN__)
  1062. #define STM32_PLLQ (STM32_PLLQ_VALUE << 24)
  1063. #else
  1064. #error "invalid STM32_PLLQ_VALUE value specified"
  1065. #endif
  1066. /**
  1067. * @brief PLL VCO frequency.
  1068. */
  1069. #define STM32_PLLVCO (STM32_PLLCLKIN * STM32_PLLN_VALUE)
  1070. /*
  1071. * PLL VCO frequency range check.
  1072. */
  1073. #if (STM32_PLLVCO < STM32_PLLVCO_MIN) || (STM32_PLLVCO > STM32_PLLVCO_MAX)
  1074. #error "STM32_PLLVCO outside acceptable range (STM32_PLLVCO_MIN...STM32_PLLVCO_MAX)"
  1075. #endif
  1076. /**
  1077. * @brief PLL P output clock frequency.
  1078. */
  1079. #define STM32_PLL_P_CLKOUT (STM32_PLLVCO / STM32_PLLP_VALUE)
  1080. /**
  1081. * @brief PLL Q output clock frequency.
  1082. */
  1083. #define STM32_PLL_Q_CLKOUT (STM32_PLLVCO / STM32_PLLQ_VALUE)
  1084. /*
  1085. * PLL output frequency range check.
  1086. */
  1087. #if (STM32_PLL_P_CLKOUT < STM32_PLLOUT_MIN) || (STM32_PLL_P_CLKOUT > STM32_PLLOUT_MAX)
  1088. #error "STM32_PLL_P_CLKOUT outside acceptable range (STM32_PLLOUT_MIN...STM32_PLLOUT_MAX)"
  1089. #endif
  1090. /**
  1091. * @brief System clock source.
  1092. */
  1093. #if STM32_NO_INIT || defined(__DOXYGEN__)
  1094. #define STM32_SYSCLK STM32_HSICLK
  1095. #elif (STM32_SW == STM32_SW_HSI)
  1096. #define STM32_SYSCLK STM32_HSICLK
  1097. #elif (STM32_SW == STM32_SW_HSE)
  1098. #define STM32_SYSCLK STM32_HSECLK
  1099. #elif (STM32_SW == STM32_SW_PLL)
  1100. #define STM32_SYSCLK STM32_PLL_P_CLKOUT
  1101. #else
  1102. #error "invalid STM32_SW value specified"
  1103. #endif
  1104. /* Check on the system clock.*/
  1105. #if STM32_SYSCLK > STM32_SYSCLK_MAX
  1106. #error "STM32_SYSCLK above maximum rated frequency (STM32_SYSCLK_MAX)"
  1107. #endif
  1108. /* Calculating VOS settings.*/
  1109. #if STM32_SYSCLK <= 144000000
  1110. #define STM32_VOS STM32_VOS_SCALE3
  1111. #define STM32_OVERDRIVE_REQUIRED FALSE
  1112. #elif STM32_SYSCLK <= 168000000
  1113. #define STM32_VOS STM32_VOS_SCALE2
  1114. #define STM32_OVERDRIVE_REQUIRED FALSE
  1115. #elif STM32_SYSCLK <= 180000000
  1116. #define STM32_VOS STM32_VOS_SCALE1
  1117. #define STM32_OVERDRIVE_REQUIRED FALSE
  1118. #else
  1119. #define STM32_VOS STM32_VOS_SCALE1
  1120. #define STM32_OVERDRIVE_REQUIRED TRUE
  1121. #endif
  1122. /**
  1123. * @brief AHB frequency.
  1124. */
  1125. #if (STM32_HPRE == STM32_HPRE_DIV1) || defined(__DOXYGEN__)
  1126. #define STM32_HCLK (STM32_SYSCLK / 1)
  1127. #elif STM32_HPRE == STM32_HPRE_DIV2
  1128. #define STM32_HCLK (STM32_SYSCLK / 2)
  1129. #elif STM32_HPRE == STM32_HPRE_DIV4
  1130. #define STM32_HCLK (STM32_SYSCLK / 4)
  1131. #elif STM32_HPRE == STM32_HPRE_DIV8
  1132. #define STM32_HCLK (STM32_SYSCLK / 8)
  1133. #elif STM32_HPRE == STM32_HPRE_DIV16
  1134. #define STM32_HCLK (STM32_SYSCLK / 16)
  1135. #elif STM32_HPRE == STM32_HPRE_DIV64
  1136. #define STM32_HCLK (STM32_SYSCLK / 64)
  1137. #elif STM32_HPRE == STM32_HPRE_DIV128
  1138. #define STM32_HCLK (STM32_SYSCLK / 128)
  1139. #elif STM32_HPRE == STM32_HPRE_DIV256
  1140. #define STM32_HCLK (STM32_SYSCLK / 256)
  1141. #elif STM32_HPRE == STM32_HPRE_DIV512
  1142. #define STM32_HCLK (STM32_SYSCLK / 512)
  1143. #else
  1144. #error "invalid STM32_HPRE value specified"
  1145. #endif
  1146. /*
  1147. * AHB frequency check.
  1148. */
  1149. #if STM32_HCLK > STM32_SYSCLK_MAX
  1150. #error "STM32_HCLK exceeding maximum frequency (STM32_SYSCLK_MAX)"
  1151. #endif
  1152. /**
  1153. * @brief APB1 frequency.
  1154. */
  1155. #if (STM32_PPRE1 == STM32_PPRE1_DIV1) || defined(__DOXYGEN__)
  1156. #define STM32_PCLK1 (STM32_HCLK / 1)
  1157. #elif STM32_PPRE1 == STM32_PPRE1_DIV2
  1158. #define STM32_PCLK1 (STM32_HCLK / 2)
  1159. #elif STM32_PPRE1 == STM32_PPRE1_DIV4
  1160. #define STM32_PCLK1 (STM32_HCLK / 4)
  1161. #elif STM32_PPRE1 == STM32_PPRE1_DIV8
  1162. #define STM32_PCLK1 (STM32_HCLK / 8)
  1163. #elif STM32_PPRE1 == STM32_PPRE1_DIV16
  1164. #define STM32_PCLK1 (STM32_HCLK / 16)
  1165. #else
  1166. #error "invalid STM32_PPRE1 value specified"
  1167. #endif
  1168. /*
  1169. * APB1 frequency check.
  1170. */
  1171. #if STM32_PCLK1 > STM32_PCLK1_MAX
  1172. #error "STM32_PCLK1 exceeding maximum frequency (STM32_PCLK1_MAX)"
  1173. #endif
  1174. /**
  1175. * @brief APB2 frequency.
  1176. */
  1177. #if (STM32_PPRE2 == STM32_PPRE2_DIV1) || defined(__DOXYGEN__)
  1178. #define STM32_PCLK2 (STM32_HCLK / 1)
  1179. #elif STM32_PPRE2 == STM32_PPRE2_DIV2
  1180. #define STM32_PCLK2 (STM32_HCLK / 2)
  1181. #elif STM32_PPRE2 == STM32_PPRE2_DIV4
  1182. #define STM32_PCLK2 (STM32_HCLK / 4)
  1183. #elif STM32_PPRE2 == STM32_PPRE2_DIV8
  1184. #define STM32_PCLK2 (STM32_HCLK / 8)
  1185. #elif STM32_PPRE2 == STM32_PPRE2_DIV16
  1186. #define STM32_PCLK2 (STM32_HCLK / 16)
  1187. #else
  1188. #error "invalid STM32_PPRE2 value specified"
  1189. #endif
  1190. /*
  1191. * APB2 frequency check.
  1192. */
  1193. #if STM32_PCLK2 > STM32_PCLK2_MAX
  1194. #error "STM32_PCLK2 exceeding maximum frequency (STM32_PCLK2_MAX)"
  1195. #endif
  1196. /*
  1197. * PLLI2S enable check.
  1198. */
  1199. #if (STM32_I2SSRC == STM32_I2SSRC_PLLI2S) || \
  1200. (STM32_SAI1SEL == STM32_SAI1SEL_I2SPLL) || \
  1201. (STM32_SAI2SEL == STM32_SAI2SEL_I2SPLL) || \
  1202. defined(__DOXYGEN__)
  1203. /**
  1204. * @brief PLLI2S activation flag.
  1205. */
  1206. #define STM32_ACTIVATE_PLLI2S TRUE
  1207. #else
  1208. #define STM32_ACTIVATE_PLLI2S FALSE
  1209. #endif
  1210. /**
  1211. * @brief STM32_PLLI2SN field.
  1212. */
  1213. #if ((STM32_PLLI2SN_VALUE >= 49) && (STM32_PLLI2SN_VALUE <= 432)) || \
  1214. defined(__DOXYGEN__)
  1215. #define STM32_PLLI2SN (STM32_PLLI2SN_VALUE << 6)
  1216. #else
  1217. #error "invalid STM32_PLLI2SN_VALUE value specified"
  1218. #endif
  1219. /**
  1220. * @brief STM32_PLLI2SQ field.
  1221. */
  1222. #if ((STM32_PLLI2SQ_VALUE >= 2) && (STM32_PLLI2SQ_VALUE <= 15)) || \
  1223. defined(__DOXYGEN__)
  1224. #define STM32_PLLI2SQ (STM32_PLLI2SQ_VALUE << 24)
  1225. #else
  1226. #error "invalid STM32_PLLI2SQ_VALUE value specified"
  1227. #endif
  1228. /**
  1229. * @brief STM32_PLLI2SR field.
  1230. */
  1231. #if ((STM32_PLLI2SR_VALUE >= 2) && (STM32_PLLI2SR_VALUE <= 7)) || \
  1232. defined(__DOXYGEN__)
  1233. #define STM32_PLLI2SR (STM32_PLLI2SR_VALUE << 28)
  1234. #else
  1235. #error "invalid STM32_PLLI2SR_VALUE value specified"
  1236. #endif
  1237. /**
  1238. * @brief STM32_PLLI2SP field.
  1239. */
  1240. #if (STM32_PLLI2SP_VALUE == 2) || defined(__DOXYGEN__)
  1241. #define STM32_PLLI2SP (0 << 16)
  1242. #elif STM32_PLLI2SP_VALUE == 4
  1243. #define STM32_PLLI2SP (1 << 16)
  1244. #elif STM32_PLLI2SP_VALUE == 6
  1245. #define STM32_PLLI2SP (2 << 16)
  1246. #elif STM32_PLLI2SP_VALUE == 8
  1247. #define STM32_PLLI2SP (3 << 16)
  1248. #else
  1249. #error "invalid STM32_PLLI2SP_VALUE value specified"
  1250. #endif
  1251. /**
  1252. * @brief PLLI2S VCO frequency.
  1253. */
  1254. #define STM32_PLLI2SVCO (STM32_PLLCLKIN * STM32_PLLI2SN_VALUE)
  1255. /*
  1256. * PLLI2S VCO frequency range check.
  1257. */
  1258. #if (STM32_PLLI2SVCO < STM32_PLLVCO_MIN) || \
  1259. (STM32_PLLI2SVCO > STM32_PLLVCO_MAX)
  1260. #error "STM32_PLLI2SVCO outside acceptable range (STM32_PLLVCO_MIN...STM32_PLLVCO_MAX)"
  1261. #endif
  1262. /**
  1263. * @brief PLLI2S P output clock frequency.
  1264. */
  1265. #define STM32_PLLI2S_P_CLKOUT (STM32_PLLI2SVCO / STM32_PLLI2SP_VALUE)
  1266. /**
  1267. * @brief PLLI2S Q output clock frequency.
  1268. */
  1269. #define STM32_PLLI2S_Q_CLKOUT (STM32_PLLI2SVCO / STM32_PLLI2SQ_VALUE)
  1270. /**
  1271. * @brief PLLI2S R output clock frequency.
  1272. */
  1273. #define STM32_PLLI2S_R_CLKOUT (STM32_PLLI2SVCO / STM32_PLLI2SR_VALUE)
  1274. /**
  1275. * @brief STM32_PLLI2SDIVQ field.
  1276. */
  1277. #if (STM32_PLLI2SDIVQ_VALUE < 1) || (STM32_PLLI2SDIVQ_VALUE > 32)
  1278. #error "STM32_PLLI2SDIVQ_VALUE out of acceptable range"
  1279. #endif
  1280. #define STM32_PLLI2SDIVQ ((STM32_PLLI2SDIVQ_VALUE - 1) << 0)
  1281. /**
  1282. * @brief PLLI2S Q output clock frequency after divisor.
  1283. */
  1284. #define STM32_PLLI2SDIVQ_CLKOUT (STM32_PLLI2S_Q_CLKOUT / STM32_PLLI2SDIVQ_VALUE)
  1285. /*
  1286. * PLLSAI enable check.
  1287. */
  1288. #if (STM32_CLOCK48_REQUIRED && (STM32_CK48MSEL == STM32_CK48MSEL_PLLSAI)) | \
  1289. STM32_LCDTFT_REQUIRED || \
  1290. (STM32_SAI1SEL == STM32_SAI1SEL_SAIPLL) || \
  1291. (STM32_SAI2SEL == STM32_SAI2SEL_SAIPLL) || \
  1292. defined(__DOXYGEN__)
  1293. /**
  1294. * @brief PLLSAI activation flag.
  1295. */
  1296. #define STM32_ACTIVATE_PLLSAI TRUE
  1297. #else
  1298. #define STM32_ACTIVATE_PLLSAI FALSE
  1299. #endif
  1300. /**
  1301. * @brief STM32_PLLSAIN field.
  1302. */
  1303. #if ((STM32_PLLSAIN_VALUE >= 49) && (STM32_PLLSAIN_VALUE <= 432)) || \
  1304. defined(__DOXYGEN__)
  1305. #define STM32_PLLSAIN (STM32_PLLSAIN_VALUE << 6)
  1306. #else
  1307. #error "invalid STM32_PLLSAIN_VALUE value specified"
  1308. #endif
  1309. /**
  1310. * @brief STM32_PLLSAIQ field.
  1311. */
  1312. #if ((STM32_PLLSAIQ_VALUE >= 2) && (STM32_PLLSAIQ_VALUE <= 15)) || \
  1313. defined(__DOXYGEN__)
  1314. #define STM32_PLLSAIQ (STM32_PLLSAIQ_VALUE << 24)
  1315. #else
  1316. #error "invalid STM32_PLLSAIR_VALUE value specified"
  1317. #endif
  1318. /**
  1319. * @brief STM32_PLLSAIR field.
  1320. */
  1321. #if ((STM32_PLLSAIR_VALUE >= 2) && (STM32_PLLSAIR_VALUE <= 7)) || \
  1322. defined(__DOXYGEN__)
  1323. #define STM32_PLLSAIR (STM32_PLLSAIR_VALUE << 28)
  1324. #else
  1325. #error "invalid STM32_PLLSAIR_VALUE value specified"
  1326. #endif
  1327. /**
  1328. * @brief STM32_PLLSAIP field.
  1329. */
  1330. #if (STM32_PLLSAIP_VALUE == 2) || defined(__DOXYGEN__)
  1331. #define STM32_PLLSAIP (0 << 16)
  1332. #elif STM32_PLLSAIP_VALUE == 4
  1333. #define STM32_PLLSAIP (1 << 16)
  1334. #elif STM32_PLLSAIP_VALUE == 6
  1335. #define STM32_PLLSAIP (2 << 16)
  1336. #elif STM32_PLLSAIP_VALUE == 8
  1337. #define STM32_PLLSAIP (3 << 16)
  1338. #else
  1339. #error "invalid STM32_PLLSAIP_VALUE value specified"
  1340. #endif
  1341. /**
  1342. * @brief PLLSAI VCO frequency.
  1343. */
  1344. #define STM32_PLLSAIVCO (STM32_PLLCLKIN * STM32_PLLSAIN_VALUE)
  1345. /*
  1346. * PLLSAI VCO frequency range check.
  1347. */
  1348. #if (STM32_PLLSAIVCO < STM32_PLLVCO_MIN) || \
  1349. (STM32_PLLSAIVCO > STM32_PLLVCO_MAX)
  1350. #error "STM32_PLLSAIVCO outside acceptable range (STM32_PLLVCO_MIN...STM32_PLLVCO_MAX)"
  1351. #endif
  1352. /**
  1353. * @brief PLLSAI P output clock frequency.
  1354. */
  1355. #define STM32_PLLSAI_P_CLKOUT (STM32_PLLSAIVCO / STM32_PLLSAIP_VALUE)
  1356. /**
  1357. * @brief PLLSAI Q output clock frequency.
  1358. */
  1359. #define STM32_PLLSAI_Q_CLKOUT (STM32_PLLSAIVCO / STM32_PLLSAIQ_VALUE)
  1360. /**
  1361. * @brief PLLSAI R output clock frequency.
  1362. */
  1363. #define STM32_PLLSAI_R_CLKOUT (STM32_PLLSAIVCO / STM32_PLLSAIR_VALUE)
  1364. /**
  1365. * @brief STM32_PLLSAIDIVQ field.
  1366. */
  1367. #if (STM32_PLLSAIDIVQ_VALUE < 1) || (STM32_PLLSAIDIVQ_VALUE > 32)
  1368. #error "STM32_PLLSAIDIVQ_VALUE out of acceptable range"
  1369. #endif
  1370. #define STM32_PLLSAIDIVQ ((STM32_PLLSAIDIVQ_VALUE - 1) << 8)
  1371. /**
  1372. * @brief PLLSAI Q output clock frequency after divisor.
  1373. */
  1374. #define STM32_PLLSAIDIVQ_CLKOUT (STM32_PLLSAI_Q_CLKOUT / STM32_PLLSAIDIVQ_VALUE)
  1375. /*
  1376. * STM32_PLLSAIDIVR field.
  1377. */
  1378. #if (STM32_PLLSAIDIVR_VALUE == 2) || defined(__DOXYGEN__)
  1379. #define STM32_PLLSAIDIVR (0 << 16)
  1380. #elif STM32_PLLSAIDIVR_VALUE == 4
  1381. #define STM32_PLLSAIDIVR (1 << 16)
  1382. #elif STM32_PLLSAIDIVR_VALUE == 8
  1383. #define STM32_PLLSAIDIVR (2 << 16)
  1384. #elif STM32_PLLSAIDIVR_VALUE == 16
  1385. #define STM32_PLLSAIDIVR (3 << 16)
  1386. #else
  1387. #error "invalid STM32_PLLSAIDIVR_VALUE value specified"
  1388. #endif
  1389. /**
  1390. * @brief PLLSAI R output clock frequency after divisor.
  1391. */
  1392. #define STM32_PLLSAIDIVR_CLKOUT (STM32_PLLSAI_R_CLKOUT / STM32_PLLSAIDIVR_VALUE)
  1393. /**
  1394. * @brief MCO1 divider clock.
  1395. */
  1396. #if (STM32_MCO1SEL == STM32_MCO1SEL_HSI) || defined(__DOXYGEN__)
  1397. #define STM32_MCO1DIVCLK STM32_HSICLK
  1398. #elif STM32_MCO1SEL == STM32_MCO1SEL_LSE
  1399. #define STM32_MCO1DIVCLK STM32_LSECLK
  1400. #elif STM32_MCO1SEL == STM32_MCO1SEL_HSE
  1401. #define STM32_MCO1DIVCLK STM32_HSECLK
  1402. #elif STM32_MCO1SEL == STM32_MCO1SEL_PLL
  1403. #define STM32_MCO1DIVCLK STM32_PLL_P_CLKOUT
  1404. #else
  1405. #error "invalid STM32_MCO1SEL value specified"
  1406. #endif
  1407. /**
  1408. * @brief MCO1 output pin clock.
  1409. */
  1410. #if (STM32_MCO1PRE == STM32_MCO1PRE_DIV1) || defined(__DOXYGEN__)
  1411. #define STM32_MCO1CLK STM32_MCO1DIVCLK
  1412. #elif STM32_MCO1PRE == STM32_MCO1PRE_DIV2
  1413. #define STM32_MCO1CLK (STM32_MCO1DIVCLK / 2)
  1414. #elif STM32_MCO1PRE == STM32_MCO1PRE_DIV3
  1415. #define STM32_MCO1CLK (STM32_MCO1DIVCLK / 3)
  1416. #elif STM32_MCO1PRE == STM32_MCO1PRE_DIV4
  1417. #define STM32_MCO1CLK (STM32_MCO1DIVCLK / 4)
  1418. #elif STM32_MCO1PRE == STM32_MCO1PRE_DIV5
  1419. #define STM32_MCO1CLK (STM32_MCO1DIVCLK / 5)
  1420. #else
  1421. #error "invalid STM32_MCO1PRE value specified"
  1422. #endif
  1423. /**
  1424. * @brief MCO2 divider clock.
  1425. */
  1426. #if (STM32_MCO2SEL == STM32_MCO2SEL_HSE) || defined(__DOXYGEN__)
  1427. #define STM32_MCO2DIVCLK STM32_HSECLK
  1428. #elif STM32_MCO2SEL == STM32_MCO2SEL_PLL
  1429. #define STM32_MCO2DIVCLK STM32_PLL_P_CLKOUT
  1430. #elif STM32_MCO2SEL == STM32_MCO2SEL_SYSCLK
  1431. #define STM32_MCO2DIVCLK STM32_SYSCLK
  1432. #elif STM32_MCO2SEL == STM32_MCO2SEL_PLLI2S
  1433. #define STM32_MCO2DIVCLK STM32_PLLI2S
  1434. #else
  1435. #error "invalid STM32_MCO2SEL value specified"
  1436. #endif
  1437. /**
  1438. * @brief MCO2 output pin clock.
  1439. */
  1440. #if (STM32_MCO2PRE == STM32_MCO2PRE_DIV1) || defined(__DOXYGEN__)
  1441. #define STM32_MCO2CLK STM32_MCO2DIVCLK
  1442. #elif STM32_MCO2PRE == STM32_MCO2PRE_DIV2
  1443. #define STM32_MCO2CLK (STM32_MCO2DIVCLK / 2)
  1444. #elif STM32_MCO2PRE == STM32_MCO2PRE_DIV3
  1445. #define STM32_MCO2CLK (STM32_MCO2DIVCLK / 3)
  1446. #elif STM32_MCO2PRE == STM32_MCO2PRE_DIV4
  1447. #define STM32_MCO2CLK (STM32_MCO2DIVCLK / 4)
  1448. #elif STM32_MCO2PRE == STM32_MCO2PRE_DIV5
  1449. #define STM32_MCO2CLK (STM32_MCO2DIVCLK / 5)
  1450. #else
  1451. #error "invalid STM32_MCO2PRE value specified"
  1452. #endif
  1453. /**
  1454. * @brief RTC HSE divider setting.
  1455. */
  1456. #if ((STM32_RTCPRE_VALUE >= 2) && (STM32_RTCPRE_VALUE <= 31)) || \
  1457. defined(__DOXYGEN__)
  1458. #define STM32_RTCPRE (STM32_RTCPRE_VALUE << 16)
  1459. #else
  1460. #error "invalid STM32_RTCPRE value specified"
  1461. #endif
  1462. /**
  1463. * @brief HSE divider toward RTC clock.
  1464. */
  1465. #if ((STM32_RTCPRE_VALUE >= 2) && (STM32_RTCPRE_VALUE <= 31)) || \
  1466. defined(__DOXYGEN__)
  1467. #define STM32_HSEDIVCLK (STM32_HSECLK / STM32_RTCPRE_VALUE)
  1468. #else
  1469. #error "invalid STM32_RTCPRE value specified"
  1470. #endif
  1471. /**
  1472. * @brief RTC clock.
  1473. */
  1474. #if (STM32_RTCSEL == STM32_RTCSEL_NOCLOCK) || defined(__DOXYGEN__)
  1475. #define STM32_RTCCLK 0
  1476. #elif STM32_RTCSEL == STM32_RTCSEL_LSE
  1477. #define STM32_RTCCLK STM32_LSECLK
  1478. #elif STM32_RTCSEL == STM32_RTCSEL_LSI
  1479. #define STM32_RTCCLK STM32_LSICLK
  1480. #elif STM32_RTCSEL == STM32_RTCSEL_HSEDIV
  1481. #define STM32_RTCCLK STM32_HSEDIVCLK
  1482. #else
  1483. #error "invalid STM32_RTCSEL value specified"
  1484. #endif
  1485. /**
  1486. * @brief USART1 frequency.
  1487. */
  1488. #if (STM32_USART1SEL == STM32_USART1SEL_PCLK2) || defined(__DOXYGEN__)
  1489. #define STM32_USART1CLK STM32_PCLK2
  1490. #elif STM32_USART1SEL == STM32_USART1SEL_SYSCLK
  1491. #define STM32_USART1CLK STM32_SYSCLK
  1492. #elif STM32_USART1SEL == STM32_USART1SEL_HSI
  1493. #define STM32_USART1CLK STM32_HSICLK
  1494. #elif STM32_USART1SEL == STM32_USART1SEL_LSE
  1495. #define STM32_USART1CLK STM32_LSECLK
  1496. #else
  1497. #error "invalid source selected for USART1 clock"
  1498. #endif
  1499. /**
  1500. * @brief USART2 frequency.
  1501. */
  1502. #if (STM32_USART2SEL == STM32_USART2SEL_PCLK1) || defined(__DOXYGEN__)
  1503. #define STM32_USART2CLK STM32_PCLK1
  1504. #elif STM32_USART2SEL == STM32_USART2SEL_SYSCLK
  1505. #define STM32_USART2CLK STM32_SYSCLK
  1506. #elif STM32_USART2SEL == STM32_USART2SEL_HSI
  1507. #define STM32_USART2CLK STM32_HSICLK
  1508. #elif STM32_USART2SEL == STM32_USART2SEL_LSE
  1509. #define STM32_USART2CLK STM32_LSECLK
  1510. #else
  1511. #error "invalid source selected for USART2 clock"
  1512. #endif
  1513. /**
  1514. * @brief USART3 frequency.
  1515. */
  1516. #if (STM32_USART3SEL == STM32_USART3SEL_PCLK1) || defined(__DOXYGEN__)
  1517. #define STM32_USART3CLK STM32_PCLK1
  1518. #elif STM32_USART3SEL == STM32_USART3SEL_SYSCLK
  1519. #define STM32_USART3CLK STM32_SYSCLK
  1520. #elif STM32_USART3SEL == STM32_USART3SEL_HSI
  1521. #define STM32_USART3CLK STM32_HSICLK
  1522. #elif STM32_USART3SEL == STM32_USART3SEL_LSE
  1523. #define STM32_USART3CLK STM32_LSECLK
  1524. #else
  1525. #error "invalid source selected for USART3 clock"
  1526. #endif
  1527. /**
  1528. * @brief UART4 frequency.
  1529. */
  1530. #if (STM32_UART4SEL == STM32_UART4SEL_PCLK1) || defined(__DOXYGEN__)
  1531. #define STM32_UART4CLK STM32_PCLK1
  1532. #elif STM32_UART4SEL == STM32_UART4SEL_SYSCLK
  1533. #define STM32_UART4CLK STM32_SYSCLK
  1534. #elif STM32_UART4SEL == STM32_UART4SEL_HSI
  1535. #define STM32_UART4CLK STM32_HSICLK
  1536. #elif STM32_UART4SEL == STM32_UART4SEL_LSE
  1537. #define STM32_UART4CLK STM32_LSECLK
  1538. #else
  1539. #error "invalid source selected for UART4 clock"
  1540. #endif
  1541. /**
  1542. * @brief UART5 frequency.
  1543. */
  1544. #if (STM32_UART5SEL == STM32_UART5SEL_PCLK1) || defined(__DOXYGEN__)
  1545. #define STM32_UART5CLK STM32_PCLK1
  1546. #elif STM32_UART5SEL == STM32_UART5SEL_SYSCLK
  1547. #define STM32_UART5CLK STM32_SYSCLK
  1548. #elif STM32_UART5SEL == STM32_UART5SEL_HSI
  1549. #define STM32_UART5CLK STM32_HSICLK
  1550. #elif STM32_UART5SEL == STM32_UART5SEL_LSE
  1551. #define STM32_UART5CLK STM32_LSECLK
  1552. #else
  1553. #error "invalid source selected for UART5 clock"
  1554. #endif
  1555. /**
  1556. * @brief USART6 frequency.
  1557. */
  1558. #if (STM32_USART6SEL == STM32_USART6SEL_PCLK2) || defined(__DOXYGEN__)
  1559. #define STM32_USART6CLK STM32_PCLK2
  1560. #elif STM32_USART6SEL == STM32_USART6SEL_SYSCLK
  1561. #define STM32_USART6CLK STM32_SYSCLK
  1562. #elif STM32_USART6SEL == STM32_USART6SEL_HSI
  1563. #define STM32_USART6CLK STM32_HSICLK
  1564. #elif STM32_USART6SEL == STM32_USART6SEL_LSE
  1565. #define STM32_USART6CLK STM32_LSECLK
  1566. #else
  1567. #error "invalid source selected for USART6 clock"
  1568. #endif
  1569. /**
  1570. * @brief UART7 frequency.
  1571. */
  1572. #if (STM32_UART7SEL == STM32_UART7SEL_PCLK1) || defined(__DOXYGEN__)
  1573. #define STM32_UART7CLK STM32_PCLK1
  1574. #elif STM32_UART7SEL == STM32_UART7SEL_SYSCLK
  1575. #define STM32_UART7CLK STM32_SYSCLK
  1576. #elif STM32_UART7SEL == STM32_UART7SEL_HSI
  1577. #define STM32_UART7CLK STM32_HSICLK
  1578. #elif STM32_UART7SEL == STM32_UART7SEL_LSE
  1579. #define STM32_UART7CLK STM32_LSECLK
  1580. #else
  1581. #error "invalid source selected for UART7 clock"
  1582. #endif
  1583. /**
  1584. * @brief UART8 frequency.
  1585. */
  1586. #if (STM32_UART8SEL == STM32_UART8SEL_PCLK1) || defined(__DOXYGEN__)
  1587. #define STM32_UART8CLK STM32_PCLK1
  1588. #elif STM32_UART8SEL == STM32_UART8SEL_SYSCLK
  1589. #define STM32_UART8CLK STM32_SYSCLK
  1590. #elif STM32_UART8SEL == STM32_UART8SEL_HSI
  1591. #define STM32_UART8CLK STM32_HSICLK
  1592. #elif STM32_UART8SEL == STM32_UART8SEL_LSE
  1593. #define STM32_UART8CLK STM32_LSECLK
  1594. #else
  1595. #error "invalid source selected for UART8 clock"
  1596. #endif
  1597. /**
  1598. * @brief I2C1 frequency.
  1599. */
  1600. #if (STM32_I2C1SEL == STM32_I2C1SEL_PCLK1) || defined(__DOXYGEN__)
  1601. #define STM32_I2C1CLK STM32_PCLK1
  1602. #elif STM32_I2C1SEL == STM32_I2C1SEL_SYSCLK
  1603. #define STM32_I2C1CLK STM32_SYSCLK
  1604. #elif STM32_I2C1SEL == STM32_I2C1SEL_HSI
  1605. #define STM32_I2C1CLK STM32_HSICLK
  1606. #else
  1607. #error "invalid source selected for I2C1 clock"
  1608. #endif
  1609. /**
  1610. * @brief I2C2 frequency.
  1611. */
  1612. #if (STM32_I2C2SEL == STM32_I2C2SEL_PCLK1) || defined(__DOXYGEN__)
  1613. #define STM32_I2C2CLK STM32_PCLK1
  1614. #elif STM32_I2C2SEL == STM32_I2C2SEL_SYSCLK
  1615. #define STM32_I2C2CLK STM32_SYSCLK
  1616. #elif STM32_I2C2SEL == STM32_I2C2SEL_HSI
  1617. #define STM32_I2C2CLK STM32_HSICLK
  1618. #else
  1619. #error "invalid source selected for I2C2 clock"
  1620. #endif
  1621. /**
  1622. * @brief I2C3 frequency.
  1623. */
  1624. #if (STM32_I2C3SEL == STM32_I2C3SEL_PCLK1) || defined(__DOXYGEN__)
  1625. #define STM32_I2C3CLK STM32_PCLK1
  1626. #elif STM32_I2C3SEL == STM32_I2C3SEL_SYSCLK
  1627. #define STM32_I2C3CLK STM32_SYSCLK
  1628. #elif STM32_I2C3SEL == STM32_I2C3SEL_HSI
  1629. #define STM32_I2C3CLK STM32_HSICLK
  1630. #else
  1631. #error "invalid source selected for I2C3 clock"
  1632. #endif
  1633. /**
  1634. * @brief I2C4 frequency.
  1635. */
  1636. #if (STM32_I2C4SEL == STM32_I2C4SEL_PCLK1) || defined(__DOXYGEN__)
  1637. #define STM32_I2C4CLK STM32_PCLK1
  1638. #elif STM32_I2C4SEL == STM32_I2C4SEL_SYSCLK
  1639. #define STM32_I2C4CLK STM32_SYSCLK
  1640. #elif STM32_I2C4SEL == STM32_I2C4SEL_HSI
  1641. #define STM32_I2C4CLK STM32_HSICLK
  1642. #else
  1643. #error "invalid source selected for I2C4 clock"
  1644. #endif
  1645. /**
  1646. * @brief LPTIM1 frequency.
  1647. */
  1648. #if (STM32_LPTIM1SEL == STM32_LPTIM1SEL_PCLK1) || defined(__DOXYGEN__)
  1649. #define STM32_LPTIM1CLK STM32_PCLK1
  1650. #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_LSI
  1651. #define STM32_LPTIM1CLK STM32_LSICLK
  1652. #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_HSI
  1653. #define STM32_LPTIM1CLK STM32_HSICLK
  1654. #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_LSE
  1655. #define STM32_LPTIM1CLK STM32_LSECLK
  1656. #else
  1657. #error "invalid source selected for LPTIM1 clock"
  1658. #endif
  1659. /**
  1660. * @brief 48MHz frequency.
  1661. */
  1662. #if STM32_CLOCK48_REQUIRED || defined(__DOXYGEN__)
  1663. #if (STM32_CK48MSEL == STM32_CK48MSEL_PLL) || defined(__DOXYGEN__)
  1664. #define STM32_PLL48CLK (STM32_PLLVCO / STM32_PLLQ_VALUE)
  1665. #elif STM32_CK48MSEL == STM32_CK48MSEL_PLLSAI
  1666. #define STM32_PLL48CLK (STM32_PLLSAIVCO / STM32_PLLSAIP_VALUE)
  1667. #else
  1668. #error "invalid source selected for PLL48CLK clock"
  1669. #endif
  1670. #else /* !STM32_CLOCK48_REQUIRED */
  1671. #define STM32_PLL48CLK 0
  1672. #endif /* !STM32_CLOCK48_REQUIRED */
  1673. /**
  1674. * @brief I2S frequency.
  1675. */
  1676. #if (STM32_I2SSRC == STM32_I2SSRC_OFF) || defined(__DOXYGEN__)
  1677. #define STM32_I2SCLK 0
  1678. #elif STM32_I2SSRC == STM32_I2SSRC_CKIN
  1679. #define STM32_I2SCLK 0 /* Unknown, would require a board value */
  1680. #elif STM32_I2SSRC == STM32_I2SSRC_PLLI2S
  1681. #define STM32_I2SCLK STM32_PLLI2S_R_CLKOUT
  1682. #else
  1683. #error "invalid source selected for I2S clock"
  1684. #endif
  1685. /**
  1686. * @brief SAI1 frequency.
  1687. */
  1688. #if (STM32_SAI1SEL == STM32_SAI1SEL_OFF) || defined(__DOXYGEN__)
  1689. #define STM32_SAI1CLK 0
  1690. #elif STM32_SAI1SEL == STM32_SAI1SEL_SAIPLL
  1691. #define STM32_SAI1CLK STM32_PLLSAIDIVQ_CLKOUT
  1692. #elif STM32_SAI1SEL == STM32_SAI1SEL_I2SPLL
  1693. #define STM32_SAI1CLK STM32_PLLI2SDIVQ_CLKOUT
  1694. #elif STM32_SAI1SEL == STM32_SAI1SEL_CKIN
  1695. #define STM32_SAI1CLK 0 /* Unknown, would require a board value */
  1696. #else
  1697. #error "invalid source selected for SAI1 clock"
  1698. #endif
  1699. /**
  1700. * @brief SAI2 frequency.
  1701. */
  1702. #if (STM32_SAI2SEL == STM32_SAI2SEL_OFF) || defined(__DOXYGEN__)
  1703. #define STM32_SAI2CLK 0
  1704. #elif STM32_SAI2SEL == STM32_SAI2SEL_SAIPLL
  1705. #define STM32_SAI2CLK STM32_PLLSAIDIVQ_CLKOUT
  1706. #elif STM32_SAI2SEL == STM32_SAI2SEL_I2SPLL
  1707. #define STM32_SAI2CLK STM32_PLLI2SDIVQ_CLKOUT
  1708. #elif STM32_SAI2SEL == STM32_SAI2SEL_CKIN
  1709. #define STM32_SAI2CLK 0 /* Unknown, would require a board value */
  1710. #else
  1711. #error "invalid source selected for SAI2 clock"
  1712. #endif
  1713. /**
  1714. * @brief SDMMC1 frequency.
  1715. */
  1716. #if (STM32_SDMMC1SEL == STM32_SDMMC1SEL_PLL48CLK) || defined(__DOXYGEN__)
  1717. #define STM32_SDMMC1CLK STM32_PLL48CLK
  1718. #elif STM32_SDMMC1SEL == STM32_SDMMC1SEL_SYSCLK
  1719. #define STM32_SDMMC1CLK STM32_SYSCLK
  1720. #else
  1721. #error "invalid source selected for SDMMC1 clock"
  1722. #endif
  1723. /**
  1724. * @brief SDMMC2 frequency.
  1725. */
  1726. #if (STM32_SDMMC2SEL == STM32_SDMMC2SEL_PLL48CLK) || defined(__DOXYGEN__)
  1727. #define STM32_SDMMC2CLK STM32_PLL48CLK
  1728. #elif STM32_SDMMC2SEL == STM32_SDMMC2SEL_SYSCLK
  1729. #define STM32_SDMMC2CLK STM32_SYSCLK
  1730. #else
  1731. #error "invalid source selected for SDMMC2 clock"
  1732. #endif
  1733. /**
  1734. * @brief Clock of timers connected to APB1
  1735. */
  1736. #if (STM32_PPRE1 == STM32_PPRE1_DIV1) || defined(__DOXYGEN__)
  1737. #define STM32_TIMCLK1 (STM32_PCLK1 * 1)
  1738. #else
  1739. #define STM32_TIMCLK1 (STM32_PCLK1 * 2)
  1740. #endif
  1741. /**
  1742. * @brief Clock of timers connected to APB2.
  1743. */
  1744. #if (STM32_PPRE2 == STM32_PPRE2_DIV1) || defined(__DOXYGEN__)
  1745. #define STM32_TIMCLK2 (STM32_PCLK2 * 1)
  1746. #else
  1747. #define STM32_TIMCLK2 (STM32_PCLK2 * 2)
  1748. #endif
  1749. /**
  1750. * @brief Flash settings.
  1751. */
  1752. #if (STM32_HCLK <= STM32_0WS_THRESHOLD) || defined(__DOXYGEN__)
  1753. #define STM32_FLASHBITS 0x00000000
  1754. #elif STM32_HCLK <= STM32_1WS_THRESHOLD
  1755. #define STM32_FLASHBITS 0x00000001
  1756. #elif STM32_HCLK <= STM32_2WS_THRESHOLD
  1757. #define STM32_FLASHBITS 0x00000002
  1758. #elif STM32_HCLK <= STM32_3WS_THRESHOLD
  1759. #define STM32_FLASHBITS 0x00000003
  1760. #elif STM32_HCLK <= STM32_4WS_THRESHOLD
  1761. #define STM32_FLASHBITS 0x00000004
  1762. #elif STM32_HCLK <= STM32_5WS_THRESHOLD
  1763. #define STM32_FLASHBITS 0x00000005
  1764. #elif STM32_HCLK <= STM32_6WS_THRESHOLD
  1765. #define STM32_FLASHBITS 0x00000006
  1766. #elif STM32_HCLK <= STM32_7WS_THRESHOLD
  1767. #define STM32_FLASHBITS 0x00000007
  1768. #elif STM32_HCLK <= STM32_8WS_THRESHOLD
  1769. #define STM32_FLASHBITS 0x00000008
  1770. #elif STM32_HCLK <= STM32_9WS_THRESHOLD
  1771. #define STM32_FLASHBITS 0x00000009
  1772. #else
  1773. #error "invalid frequency at specified VDD level"
  1774. #endif
  1775. /*===========================================================================*/
  1776. /* Driver data structures and types. */
  1777. /*===========================================================================*/
  1778. /*===========================================================================*/
  1779. /* Driver macros. */
  1780. /*===========================================================================*/
  1781. /*===========================================================================*/
  1782. /* External declarations. */
  1783. /*===========================================================================*/
  1784. /* Various helpers.*/
  1785. #include "nvic.h"
  1786. #include "cache.h"
  1787. #include "mpu_v7m.h"
  1788. #include "stm32_isr.h"
  1789. #include "stm32_dma.h"
  1790. #include "stm32_exti.h"
  1791. #include "stm32_rcc.h"
  1792. #ifdef __cplusplus
  1793. extern "C" {
  1794. #endif
  1795. void hal_lld_init(void);
  1796. void stm32_clock_init(void);
  1797. #ifdef __cplusplus
  1798. }
  1799. #endif
  1800. #endif /* HAL_LLD_H */
  1801. /** @} */