hal_lld.h 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930
  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 STM32H7xx/hal_lld.h
  15. * @brief STM32H7xx 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. * - STM32H743xx, STM32H753xx very high-performance MCUs.
  27. * .
  28. *
  29. * @addtogroup HAL
  30. * @{
  31. */
  32. #ifndef HAL_LLD_H
  33. #define HAL_LLD_H
  34. #include "stm32_registry.h"
  35. /*===========================================================================*/
  36. /* Driver constants. */
  37. /*===========================================================================*/
  38. /**
  39. * @name Platform identification macros
  40. * @{
  41. */
  42. #if defined(STM32H743xx) || defined(__DOXYGEN__)
  43. #define PLATFORM_NAME "STM32H743 Very High Performance with DSP and FPU"
  44. #elif defined(STM32H753xx)
  45. #define PLATFORM_NAME "STM32H753 Very High Performance with DSP and FPU"
  46. #else
  47. #error "STM32H7xx device not specified"
  48. #endif
  49. /** @} */
  50. /**
  51. * @name Sub-family identifier
  52. */
  53. #if !defined(STM32H7XX) || defined(__DOXYGEN__)
  54. #define STM32H7XX
  55. #endif
  56. /** @} */
  57. /**
  58. * @name Absolute Maximum Ratings
  59. * @{
  60. */
  61. /**
  62. * @brief Absolute maximum system clock.
  63. */
  64. #define STM32_SYSCLK_MAX 400000000
  65. /**
  66. * @brief Absolute maximum HCLK clock.
  67. */
  68. #define STM32_HCLK_MAX 200000000
  69. /**
  70. * @brief Maximum HSE clock frequency.
  71. */
  72. #define STM32_HSECLK_MAX 48000000
  73. /**
  74. * @brief Maximum HSE clock frequency using an external source.
  75. */
  76. #define STM32_HSECLK_BYP_MAX 50000000
  77. /**
  78. * @brief Minimum HSE clock frequency.
  79. */
  80. #define STM32_HSECLK_MIN 4000000
  81. /**
  82. * @brief Minimum HSE clock frequency.
  83. */
  84. #define STM32_HSECLK_BYP_MIN 4000000
  85. /**
  86. * @brief Maximum LSE clock frequency.
  87. */
  88. #define STM32_LSE_CK_MAX 32768
  89. /**
  90. * @brief Maximum LSE clock frequency.
  91. */
  92. #define STM32_LSE_CK_BYP_MAX 1000000
  93. /**
  94. * @brief Minimum LSE clock frequency.
  95. */
  96. #define STM32_LSE_CK_MIN 32768
  97. /**
  98. * @brief Minimum PLLs input clock frequency..
  99. */
  100. #define STM32_PLLIN_MIN 1000000
  101. /**
  102. * @brief PLLs input threshold frequency 1.
  103. */
  104. #define STM32_PLLIN_THRESHOLD1 2000000
  105. /**
  106. * @brief PLLs input threshold frequency 2.
  107. */
  108. #define STM32_PLLIN_THRESHOLD2 4000000
  109. /**
  110. * @brief PLLs input threshold frequency 3.
  111. */
  112. #define STM32_PLLIN_THRESHOLD3 8000000
  113. /**
  114. * @brief Maximum PLLs input clock frequency.
  115. */
  116. #define STM32_PLLIN_MAX 16000000
  117. /**
  118. * @brief Minimum PLLs VCO clock frequency.
  119. */
  120. #define STM32_PLLVCO_MIN 150000000
  121. /**
  122. * @brief Threshold PLLs clock frequency.
  123. */
  124. #define STM32_PLLVCO_THRESHOLD 420000000
  125. /**
  126. * @brief Maximum PLLs VCOH clock frequency.
  127. */
  128. #define STM32_PLLVCO_MAX 836000000
  129. /**
  130. * @brief Maximum APB1 clock frequency.
  131. */
  132. #define STM32_PCLK1_MAX (STM32_HCLK_MAX / 2)
  133. /**
  134. * @brief Maximum APB2 clock frequency.
  135. */
  136. #define STM32_PCLK2_MAX (STM32_HCLK_MAX / 2)
  137. /**
  138. * @brief Maximum APB3 clock frequency.
  139. */
  140. #define STM32_PCLK3_MAX (STM32_HCLK_MAX / 2)
  141. /**
  142. * @brief Maximum APB4 clock frequency.
  143. */
  144. #define STM32_PCLK4_MAX (STM32_HCLK_MAX / 2)
  145. /**
  146. * @brief Maximum SPI1, SPI2 and SPI3 clock frequency.
  147. */
  148. #define STM32_SPI123_MAX 133000000
  149. /**
  150. * @brief Maximum SPI4, SPI5 and SPI6 clock frequency.
  151. */
  152. #define STM32_SPI456_MAX 100000000
  153. /**
  154. * @brief Maximum ADC clock frequency.
  155. */
  156. #define STM32_ADCCLK_MAX 36000000
  157. /** @} */
  158. /**
  159. * @name Internal clock sources frequencies
  160. * @{
  161. */
  162. #define STM32_HSI_OSC 64000000
  163. #define STM32_HSI48_OSC 48000000
  164. #define STM32_CSI_OSC 4000000
  165. #define STM32_LSI_OSC 32000
  166. /** @} */
  167. /**
  168. * @name Register helpers not found in ST headers
  169. * @{
  170. */
  171. #define RCC_CR_HSIDIV_VALUE(n) ((n) << 3U)
  172. #define RCC_CFGR_SW_VALUE(n) ((n) << 0U)
  173. #define RCC_CFGR_RTCPRE_VALUE(n) ((n) << 8U)
  174. #define RCC_CFGR_MCO1PRE_VALUE(n) ((n) << 18U)
  175. #define RCC_CFGR_MCO1_VALUE(n) ((n) << 22U)
  176. #define RCC_CFGR_MCO2PRE_VALUE(n) ((n) << 25U)
  177. #define RCC_CFGR_MCO2_VALUE(n) ((n) << 29U)
  178. #define RCC_D1CFGR_D1HPRE_VALUE(n) ((n) << RCC_D1CFGR_HPRE_Pos)
  179. #define RCC_D1CFGR_D1CPRE_VALUE(n) ((n) << RCC_D1CFGR_D1CPRE_Pos)
  180. #define RCC_D1CFGR_D1PPRE3_VALUE(n) ((n) << RCC_D1CFGR_D1PPRE_Pos)
  181. #define RCC_D2CFGR_D2PPRE1_VALUE(n) ((n) << RCC_D2CFGR_D2PPRE1_Pos)
  182. #define RCC_D2CFGR_D2PPRE2_VALUE(n) ((n) << RCC_D2CFGR_D2PPRE2_Pos)
  183. #define RCC_D3CFGR_D3PPRE4_VALUE(n) ((n) << RCC_D3CFGR_D3PPRE_Pos)
  184. #define RCC_PLLCKSELR_PLLSRC_VALUE(n) ((n) << RCC_PLLCKSELR_PLLSRC_Pos)
  185. #define RCC_PLLCKSELR_DIVM1_VALUE(n) ((n) << RCC_PLLCKSELR_DIVM1_Pos)
  186. #define RCC_PLLCKSELR_DIVM2_VALUE(n) ((n) << RCC_PLLCKSELR_DIVM2_Pos)
  187. #define RCC_PLLCKSELR_DIVM3_VALUE(n) ((n) << RCC_PLLCKSELR_DIVM3_Pos)
  188. #define RCC_PLL1DIVR_DIVN1_VALUE(n) ((n) << RCC_PLL1DIVR_N1)
  189. #define RCC_PLL1DIVR_DIVP1_VALUE(n) ((n) << RCC_PLL1DIVR_P1)
  190. #define RCC_PLL1DIVR_DIVQ1_VALUE(n) ((n) << RCC_PLL1DIVR_Q1)
  191. #define RCC_PLL1DIVR_DIVR1_VALUE(n) ((n) << RCC_PLL1DIVR_R1)
  192. #define RCC_PLL1FRACR_FRACN1_VALUE(n) ((n) << RCC_PLL1FRACR_FRACN1_Pos)
  193. #define RCC_PLL2DIVR_DIVN2_VALUE(n) ((n) << RCC_PLL2DIVR_N2)
  194. #define RCC_PLL2DIVR_DIVP2_VALUE(n) ((n) << RCC_PLL2DIVR_P2)
  195. #define RCC_PLL2DIVR_DIVQ2_VALUE(n) ((n) << RCC_PLL2DIVR_Q2)
  196. #define RCC_PLL2DIVR_DIVR2_VALUE(n) ((n) << RCC_PLL2DIVR_R2)
  197. #define RCC_PLL2FRACR_FRACN2_VALUE(n) ((n) << RCC_PLL2FRACR_FRACN2_Pos)
  198. #define RCC_PLL3DIVR_DIVN3_VALUE(n) ((n) << RCC_PLL3DIVR_N3)
  199. #define RCC_PLL3DIVR_DIVP3_VALUE(n) ((n) << RCC_PLL3DIVR_P3)
  200. #define RCC_PLL3DIVR_DIVQ3_VALUE(n) ((n) << RCC_PLL3DIVR_Q3)
  201. #define RCC_PLL3DIVR_DIVR3_VALUE(n) ((n) << RCC_PLL3DIVR_R3)
  202. #define RCC_PLL3FRACR_FRACN3_VALUE(n) ((n) << RCC_PLL3FRACR_FRACN3_Pos)
  203. #define RCC_D1CCIPR_CKPERSEL_VALUE(n) ((n) << RCC_D1CCIPR_CKPERSEL_Pos)
  204. #define RCC_D1CCIPR_SDMMCSEL_VALUE(n) ((n) << RCC_D1CCIPR_SDMMCSEL_Pos)
  205. #define RCC_D1CCIPR_QSPISEL_VALUE(n) ((n) << RCC_D1CCIPR_QSPISEL_Pos)
  206. #define RCC_D1CCIPR_FMCSEL_VALUE(n) ((n) << RCC_D1CCIPR_FMCSEL_Pos)
  207. #define RCC_D2CCIP1R_SWPSEL_VALUE(n) ((n) << RCC_D2CCIP1R_SWPSEL_Pos)
  208. #define RCC_D2CCIP1R_FDCANSEL_VALUE(n) ((n) << RCC_D2CCIP1R_FDCANSEL_Pos)
  209. #define RCC_D2CCIP1R_DFSDM1SEL_VALUE(n) ((n) << RCC_D2CCIP1R_DFSDM1SEL_Pos)
  210. #define RCC_D2CCIP1R_SPDIFSEL_VALUE(n) ((n) << RCC_D2CCIP1R_SPDIFSEL_Pos)
  211. #define RCC_D2CCIP1R_SPI45SEL_VALUE(n) ((n) << RCC_D2CCIP1R_SPI45SEL_Pos)
  212. #define RCC_D2CCIP1R_SPI123SEL_VALUE(n) ((n) << RCC_D2CCIP1R_SPI123SEL_Pos)
  213. #define RCC_D2CCIP1R_SAI23SEL_VALUE(n) ((n) << RCC_D2CCIP1R_SAI23SEL_Pos)
  214. #define RCC_D2CCIP1R_SAI1SEL_VALUE(n) ((n) << RCC_D2CCIP1R_SAI1SEL_Pos)
  215. #define RCC_D2CCIP2R_LPTIM1SEL_VALUE(n) ((n) << RCC_D2CCIP2R_LPTIM1SEL_Pos)
  216. #define RCC_D2CCIP2R_CECSEL_VALUE(n) ((n) << RCC_D2CCIP2R_CECSEL_Pos)
  217. #define RCC_D2CCIP2R_USBSEL_VALUE(n) ((n) << RCC_D2CCIP2R_USBSEL_Pos)
  218. #define RCC_D2CCIP2R_I2C123SEL_VALUE(n) ((n) << RCC_D2CCIP2R_I2C123SEL_Pos)
  219. #define RCC_D2CCIP2R_RNGSEL_VALUE(n) ((n) << RCC_D2CCIP2R_RNGSEL_Pos)
  220. #define RCC_D2CCIP2R_USART16SEL_VALUE(n) ((n) << RCC_D2CCIP2R_USART16SEL_Pos)
  221. #define RCC_D2CCIP2R_USART234578SEL_VALUE(n) ((n) << RCC_D2CCIP2R_USART28SEL_Pos)
  222. #define RCC_D3CCIPR_SPI6SEL_VALUE(n) ((n) << RCC_D3CCIPR_SPI6SEL_Pos)
  223. #define RCC_D3CCIPR_SAI4BSEL_VALUE(n) ((n) << RCC_D3CCIPR_SAI4BSEL_Pos)
  224. #define RCC_D3CCIPR_SAI4ASEL_VALUE(n) ((n) << RCC_D3CCIPR_SAI4ASEL_Pos)
  225. #define RCC_D3CCIPR_ADCSEL_VALUE(n) ((n) << RCC_D3CCIPR_ADCSEL_Pos)
  226. #define RCC_D3CCIPR_LPTIM345SEL_VALUE(n) ((n) << RCC_D3CCIPR_LPTIM345SEL_Pos)
  227. #define RCC_D3CCIPR_LPTIM2SEL_VALUE(n) ((n) << RCC_D3CCIPR_LPTIM2SEL_Pos)
  228. #define RCC_D3CCIPR_I2C4SEL_VALUE(n) ((n) << RCC_D3CCIPR_I2C4SEL_Pos)
  229. #define RCC_D3CCIPR_LPUART1SEL_VALUE(n) ((n) << RCC_D3CCIPR_LPUART1SEL_Pos)
  230. #define RCC_BDCR_RTCSEL_VALUE(n) ((n) << RCC_BDCR_RTCSEL_Pos)
  231. /** @} */
  232. /**
  233. * @name Configuration switches to be used in @p mcuconf.h
  234. * @{
  235. */
  236. #define STM32_VOS_SCALE3 (PWR_D3CR_VOS_0)
  237. #define STM32_VOS_SCALE2 (PWR_D3CR_VOS_1)
  238. #define STM32_VOS_SCALE1 (PWR_D3CR_VOS_1 | PWR_D3CR_VOS_0)
  239. #define STM32_SW_HSI_CK RCC_CFGR_SW_VALUE(0U)
  240. #define STM32_SW_CSI_CK RCC_CFGR_SW_VALUE(1U)
  241. #define STM32_SW_HSE_CK RCC_CFGR_SW_VALUE(2U)
  242. #define STM32_SW_PLL1_P_CK RCC_CFGR_SW_VALUE(3U)
  243. #define STM32_D1CPRE_DIV1 RCC_D1CFGR_D1CPRE_VALUE(0U)
  244. #define STM32_D1CPRE_DIV2 RCC_D1CFGR_D1CPRE_VALUE(8U)
  245. #define STM32_D1CPRE_DIV4 RCC_D1CFGR_D1CPRE_VALUE(9U)
  246. #define STM32_D1CPRE_DIV8 RCC_D1CFGR_D1CPRE_VALUE(10U)
  247. #define STM32_D1CPRE_DIV16 RCC_D1CFGR_D1CPRE_VALUE(11U)
  248. #define STM32_D1CPRE_DIV64 RCC_D1CFGR_D1CPRE_VALUE(12U)
  249. #define STM32_D1CPRE_DIV128 RCC_D1CFGR_D1CPRE_VALUE(13U)
  250. #define STM32_D1CPRE_DIV256 RCC_D1CFGR_D1CPRE_VALUE(14U)
  251. #define STM32_D1CPRE_DIV512 RCC_D1CFGR_D1CPRE_VALUE(15U)
  252. #define STM32_D1HPRE_DIV1 RCC_D1CFGR_D1HPRE_VALUE(0U)
  253. #define STM32_D1HPRE_DIV2 RCC_D1CFGR_D1HPRE_VALUE(8U)
  254. #define STM32_D1HPRE_DIV4 RCC_D1CFGR_D1HPRE_VALUE(9U)
  255. #define STM32_D1HPRE_DIV8 RCC_D1CFGR_D1HPRE_VALUE(10U)
  256. #define STM32_D1HPRE_DIV16 RCC_D1CFGR_D1HPRE_VALUE(11U)
  257. #define STM32_D1HPRE_DIV64 RCC_D1CFGR_D1HPRE_VALUE(12U)
  258. #define STM32_D1HPRE_DIV128 RCC_D1CFGR_D1HPRE_VALUE(13U)
  259. #define STM32_D1HPRE_DIV256 RCC_D1CFGR_D1HPRE_VALUE(14U)
  260. #define STM32_D1HPRE_DIV512 RCC_D1CFGR_D1HPRE_VALUE(15U)
  261. #define STM32_D1PPRE3_DIV1 RCC_D1CFGR_D1PPRE3_VALUE(0U)
  262. #define STM32_D1PPRE3_DIV2 RCC_D1CFGR_D1PPRE3_VALUE(4U)
  263. #define STM32_D1PPRE3_DIV4 RCC_D1CFGR_D1PPRE3_VALUE(5U)
  264. #define STM32_D1PPRE3_DIV8 RCC_D1CFGR_D1PPRE3_VALUE(6U)
  265. #define STM32_D1PPRE3_DIV16 RCC_D1CFGR_D1PPRE3_VALUE(7U)
  266. #define STM32_D2PPRE1_DIV1 RCC_D2CFGR_D2PPRE1_VALUE(0U)
  267. #define STM32_D2PPRE1_DIV2 RCC_D2CFGR_D2PPRE1_VALUE(4U)
  268. #define STM32_D2PPRE1_DIV4 RCC_D2CFGR_D2PPRE1_VALUE(5U)
  269. #define STM32_D2PPRE1_DIV8 RCC_D2CFGR_D2PPRE1_VALUE(6U)
  270. #define STM32_D2PPRE1_DIV16 RCC_D2CFGR_D2PPRE1_VALUE(7U)
  271. #define STM32_D2PPRE2_DIV1 RCC_D2CFGR_D2PPRE2_VALUE(0U)
  272. #define STM32_D2PPRE2_DIV2 RCC_D2CFGR_D2PPRE2_VALUE(4U)
  273. #define STM32_D2PPRE2_DIV4 RCC_D2CFGR_D2PPRE2_VALUE(5U)
  274. #define STM32_D2PPRE2_DIV8 RCC_D2CFGR_D2PPRE2_VALUE(6U)
  275. #define STM32_D2PPRE2_DIV16 RCC_D2CFGR_D2PPRE2_VALUE(7U)
  276. #define STM32_D3PPRE4_DIV1 RCC_D3CFGR_D3PPRE4_VALUE(0U)
  277. #define STM32_D3PPRE4_DIV2 RCC_D3CFGR_D3PPRE4_VALUE(4U)
  278. #define STM32_D3PPRE4_DIV4 RCC_D3CFGR_D3PPRE4_VALUE(5U)
  279. #define STM32_D3PPRE4_DIV8 RCC_D3CFGR_D3PPRE4_VALUE(6U)
  280. #define STM32_D3PPRE4_DIV16 RCC_D3CFGR_D3PPRE4_VALUE(7U)
  281. #define STM32_HSIDIV_DIV1 RCC_CR_HSIDIV_VALUE(0U)
  282. #define STM32_HSIDIV_DIV2 RCC_CR_HSIDIV_VALUE(1U)
  283. #define STM32_HSIDIV_DIV4 RCC_CR_HSIDIV_VALUE(2U)
  284. #define STM32_HSIDIV_DIV8 RCC_CR_HSIDIV_VALUE(3U)
  285. #define STM32_MCO1SEL_HSI_CK RCC_CFGR_MCO1_VALUE(0U)
  286. #define STM32_MCO1SEL_LSE_CK RCC_CFGR_MCO1_VALUE(1U)
  287. #define STM32_MCO1SEL_HSE_CK RCC_CFGR_MCO1_VALUE(2U)
  288. #define STM32_MCO1SEL_PLL1_Q_CK RCC_CFGR_MCO1_VALUE(3U)
  289. #define STM32_MCO1SEL_HSI48_CK RCC_CFGR_MCO1_VALUE(4U)
  290. #define STM32_MCO2SEL_SYS_CK RCC_CFGR_MCO2_VALUE(0U)
  291. #define STM32_MCO2SEL_PLL2_P_CK RCC_CFGR_MCO2_VALUE(1U)
  292. #define STM32_MCO2SEL_HSE_CK RCC_CFGR_MCO2_VALUE(2U)
  293. #define STM32_MCO2SEL_PLL1_P_CK RCC_CFGR_MCO2_VALUE(3U)
  294. #define STM32_MCO2SEL_CSI_CK RCC_CFGR_MCO2_VALUE(4U)
  295. #define STM32_MCO2SEL_LSI_CK RCC_CFGR_MCO2_VALUE(5U)
  296. #define STM32_RTCSEL_MASK RCC_BDCR_RTCSEL_Msk
  297. #define STM32_RTCSEL_NOCLK RCC_BDCR_RTCSEL_VALUE(0U)
  298. #define STM32_RTCSEL_LSE_CK RCC_BDCR_RTCSEL_VALUE(1U)
  299. #define STM32_RTCSEL_LSI_CK RCC_BDCR_RTCSEL_VALUE(2U)
  300. #define STM32_RTCSEL_HSE_1M_CK RCC_BDCR_RTCSEL_VALUE(3U)
  301. #define STM32_HRTIMSEL_C_CLK RCC_CFGR_HRTIMSEL
  302. #define STM32_STOPKERWUCK_ENABLED RCC_CFGR_STOPKERWUCK
  303. #define STM32_STOPWUCK_ENABLED RCC_CFGR_STOPKERWUCK
  304. #define STM32_PLLSRC_HSI_CK RCC_PLLCKSELR_PLLSRC_VALUE(0U)
  305. #define STM32_PLLSRC_CSI_CK RCC_PLLCKSELR_PLLSRC_VALUE(1U)
  306. #define STM32_PLLSRC_HSE_CK RCC_PLLCKSELR_PLLSRC_VALUE(2U)
  307. #define STM32_PLLSRC_DISABLE RCC_PLLCKSELR_PLLSRC_VALUE(23U)
  308. #define STM32_CKPERSEL_HSI_CK RCC_D1CCIPR_CKPERSEL_VALUE(0U)
  309. #define STM32_CKPERSEL_CSI_CK RCC_D1CCIPR_CKPERSEL_VALUE(1U)
  310. #define STM32_CKPERSEL_HSE_CK RCC_D1CCIPR_CKPERSEL_VALUE(2U)
  311. #define STM32_SDMMCSEL_PLL1_Q_CK RCC_D1CCIPR_SDMMCSEL_VALUE(0U)
  312. #define STM32_SDMMCSEL_PLL2_R_CK RCC_D1CCIPR_SDMMCSEL_VALUE(1U)
  313. #define STM32_QSPISEL_HCLK RCC_D1CCIPR_QSPISEL_VALUE(0U)
  314. #define STM32_QSPISEL_PLL1_Q_CK RCC_D1CCIPR_QSPISEL_VALUE(1U)
  315. #define STM32_QSPISEL_PLL2_R_CK RCC_D1CCIPR_QSPISEL_VALUE(2U)
  316. #define STM32_QSPISEL_PER_CK RCC_D1CCIPR_QSPISEL_VALUE(3U)
  317. #define STM32_FMCSEL_HCLK RCC_D1CCIPR_FMCSEL_VALUE(0U)
  318. #define STM32_FMCSEL_PLL1_Q_CK RCC_D1CCIPR_FMCSEL_VALUE(1U)
  319. #define STM32_FMCSEL_PLL2_R_CK RCC_D1CCIPR_FMCSEL_VALUE(2U)
  320. #define STM32_FMCSEL_PER_CK RCC_D1CCIPR_FMCSEL_VALUE(3U)
  321. #define STM32_SWPSEL_PCLK1 RCC_D2CCIP1R_SWPSEL_VALUE(0U)
  322. #define STM32_SWPSEL_HSI_KER_CK RCC_D2CCIP1R_SWPSEL_VALUE(1U)
  323. #define STM32_FDCANSEL_HSE_CK RCC_D2CCIP1R_FDCANSEL_VALUE(0U)
  324. #define STM32_FDCANSEL_PLL1_Q_CK RCC_D2CCIP1R_FDCANSEL_VALUE(1U)
  325. #define STM32_FDCANSEL_PLL2_Q_CK RCC_D2CCIP1R_FDCANSEL_VALUE(2U)
  326. #define STM32_DFSDM1SEL_PCLK2 RCC_D2CCIP1R_DFSDM1SEL_VALUE(0U)
  327. #define STM32_DFSDM1SEL_SYS_CK RCC_D2CCIP1R_DFSDM1SEL_VALUE(1U)
  328. #define STM32_SPDIFSEL_PLL1_Q_CK RCC_D2CCIP1R_SPDIFSEL_VALUE(0U)
  329. #define STM32_SPDIFSEL_PLL2_R_CK RCC_D2CCIP1R_SPDIFSEL_VALUE(1U)
  330. #define STM32_SPDIFSEL_PLL3_R_CK RCC_D2CCIP1R_SPDIFSEL_VALUE(2U)
  331. #define STM32_SPDIFSEL_HSI_KET_CLK RCC_D2CCIP1R_SPDIFSEL_VALUE(3U)
  332. #define STM32_SPI45SEL_PCLK2 RCC_D2CCIP1R_SPI45SEL_VALUE(0U)
  333. #define STM32_SPI45SEL_PLL2_Q_CK RCC_D2CCIP1R_SPI45SEL_VALUE(1U)
  334. #define STM32_SPI45SEL_PLL3_Q_CK RCC_D2CCIP1R_SPI45SEL_VALUE(2U)
  335. #define STM32_SPI45SEL_HSI_KER_CK RCC_D2CCIP1R_SPI45SEL_VALUE(3U)
  336. #define STM32_SPI45SEL_CSI_KER_CK RCC_D2CCIP1R_SPI45SEL_VALUE(4U)
  337. #define STM32_SPI45SEL_HSE_CK RCC_D2CCIP1R_SPI45SEL_VALUE(5U)
  338. #define STM32_SPI123SEL_PLL1_Q_CK RCC_D2CCIP1R_SPI123SEL_VALUE(0U)
  339. #define STM32_SPI123SEL_PLL2_P_CK RCC_D2CCIP1R_SPI123SEL_VALUE(1U)
  340. #define STM32_SPI123SEL_PLL3_P_CK RCC_D2CCIP1R_SPI123SEL_VALUE(2U)
  341. #define STM32_SPI123SEL_I2S_CKIN RCC_D2CCIP1R_SPI123SEL_VALUE(3U)
  342. #define STM32_SPI123SEL_PER_CK RCC_D2CCIP1R_SPI123SEL_VALUE(4U)
  343. #define STM32_SAI23SEL_PLL1_Q_CK RCC_D2CCIP1R_SAI23SEL_VALUE(0U)
  344. #define STM32_SAI23SEL_PLL2_P_CK RCC_D2CCIP1R_SAI23SEL_VALUE(1U)
  345. #define STM32_SAI23SEL_PLL3_P_CK RCC_D2CCIP1R_SAI23SEL_VALUE(2U)
  346. #define STM32_SAI23SEL_I2S_CKIN RCC_D2CCIP1R_SAI23SEL_VALUE(3U)
  347. #define STM32_SAI23SEL_PER_CK RCC_D2CCIP1R_SAI23SEL_VALUE(4U)
  348. #define STM32_SAI1SEL_PLL1_Q_CK RCC_D2CCIP1R_SAI1SEL_VALUE(0U)
  349. #define STM32_SAI1SEL_PLL2_P_CK RCC_D2CCIP1R_SAI1SEL_VALUE(1U)
  350. #define STM32_SAI1SEL_PLL3_P_CK RCC_D2CCIP1R_SAI1SEL_VALUE(2U)
  351. #define STM32_SAI1SEL_I2S_CKIN RCC_D2CCIP1R_SAI1SEL_VALUE(3U)
  352. #define STM32_SAI1SEL_PER_CK RCC_D2CCIP1R_SAI1SEL_VALUE(4U)
  353. #define STM32_LPTIM1SEL_PCLK1 RCC_D2CCIP2R_LPTIM1SEL_VALUE(0U)
  354. #define STM32_LPTIM1SEL_PLL2_P_CK RCC_D2CCIP2R_LPTIM1SEL_VALUE(1U)
  355. #define STM32_LPTIM1SEL_PLL3_R_CK RCC_D2CCIP2R_LPTIM1SEL_VALUE(2U)
  356. #define STM32_LPTIM1SEL_LSE_CK RCC_D2CCIP2R_LPTIM1SEL_VALUE(3U)
  357. #define STM32_LPTIM1SEL_LSI_CK RCC_D2CCIP2R_LPTIM1SEL_VALUE(4U)
  358. #define STM32_LPTIM1SEL_PER_CK RCC_D2CCIP2R_LPTIM1SEL_VALUE(5U)
  359. #define STM32_CECSEL_LSE_CK RCC_D2CCIP2R_CECSEL_VALUE(0U)
  360. #define STM32_CECSEL_LSI_CK RCC_D2CCIP2R_CECSEL_VALUE(1U)
  361. #define STM32_CECSEL_CSI_KER_CK RCC_D2CCIP2R_CECSEL_VALUE(2U)
  362. #define STM32_CECSEL_DISABLE RCC_D2CCIP2R_CECSEL_VALUE(3U)
  363. #define STM32_USBSEL_DISABLE RCC_D2CCIP2R_USBSEL_VALUE(0U)
  364. #define STM32_USBSEL_PLL1_Q_CK RCC_D2CCIP2R_USBSEL_VALUE(1U)
  365. #define STM32_USBSEL_PLL3_Q_CK RCC_D2CCIP2R_USBSEL_VALUE(2U)
  366. #define STM32_USBSEL_HSI48_CK RCC_D2CCIP2R_USBSEL_VALUE(3U)
  367. #define STM32_I2C123SEL_PCLK1 RCC_D2CCIP2R_I2C123SEL_VALUE(0U)
  368. #define STM32_I2C123SEL_PLL3_R_CK RCC_D2CCIP2R_I2C123SEL_VALUE(1U)
  369. #define STM32_I2C123SEL_HSI_KER_CK RCC_D2CCIP2R_I2C123SEL_VALUE(2U)
  370. #define STM32_I2C123SEL_CSI_KER_CK RCC_D2CCIP2R_I2C123SEL_VALUE(3U)
  371. #define STM32_RNGSEL_HSI48_CK RCC_D2CCIP2R_RNGSEL_VALUE(0U)
  372. #define STM32_RNGSEL_PLL1_Q_CK RCC_D2CCIP2R_RNGSEL_VALUE(1U)
  373. #define STM32_RNGSEL_LSE_CK RCC_D2CCIP2R_RNGSEL_VALUE(2U)
  374. #define STM32_RNGSEL_LSI_CK RCC_D2CCIP2R_RNGSEL_VALUE(3U)
  375. #define STM32_USART16SEL_PCLK2 RCC_D2CCIP2R_USART16SEL_VALUE(0U)
  376. #define STM32_USART16SEL_PLL2_Q_CK RCC_D2CCIP2R_USART16SEL_VALUE(1U)
  377. #define STM32_USART16SEL_PLL3_Q_CK RCC_D2CCIP2R_USART16SEL_VALUE(2U)
  378. #define STM32_USART16SEL_HSI_KER_CK RCC_D2CCIP2R_USART16SEL_VALUE(3U)
  379. #define STM32_USART16SEL_CSI_KER_CK RCC_D2CCIP2R_USART16SEL_VALUE(4U)
  380. #define STM32_USART16SEL_LSE_CK RCC_D2CCIP2R_USART16SEL_VALUE(5U)
  381. #define STM32_USART234578SEL_PCLK1 RCC_D2CCIP2R_USART234578SEL_VALUE(0U)
  382. #define STM32_USART234578SEL_PLL2_Q_CK RCC_D2CCIP2R_USART234578SEL_VALUE(1U)
  383. #define STM32_USART234578SEL_PLL3_Q_CK RCC_D2CCIP2R_USART234578SEL_VALUE(2U)
  384. #define STM32_USART234578SEL_HSI_KER_CK RCC_D2CCIP2R_USART234578SEL_VALUE(3U)
  385. #define STM32_USART234578SEL_CSI_KER_CK RCC_D2CCIP2R_USART234578SEL_VALUE(4U)
  386. #define STM32_USART234578SEL_LSE_CK RCC_D2CCIP2R_USART234578SEL_VALUE(5U)
  387. #define STM32_SPI6SEL_PCLK4 RCC_D3CCIPR_SPI6SEL_VALUE(0U)
  388. #define STM32_SPI6SEL_PLL2_Q_CK RCC_D3CCIPR_SPI6SEL_VALUE(1U)
  389. #define STM32_SPI6SEL_PLL3_Q_CK RCC_D3CCIPR_SPI6SEL_VALUE(2U)
  390. #define STM32_SPI6SEL_HSI_KER_CK RCC_D3CCIPR_SPI6SEL_VALUE(3U)
  391. #define STM32_SPI6SEL_CSI_KER_CK RCC_D3CCIPR_SPI6SEL_VALUE(4U)
  392. #define STM32_SPI6SEL_HSE_CK RCC_D3CCIPR_SPI6SEL_VALUE(5U)
  393. #define STM32_SAI4BSEL_PLL1_Q_CK RCC_D3CCIPR_SAI4BSEL_VALUE(0U)
  394. #define STM32_SAI4BSEL_PLL2_P_CK RCC_D3CCIPR_SAI4BSEL_VALUE(1U)
  395. #define STM32_SAI4BSEL_PLL3_P_CK RCC_D3CCIPR_SAI4BSEL_VALUE(2U)
  396. #define STM32_SAI4BSEL_I2S_CKIN RCC_D3CCIPR_SAI4BSEL_VALUE(3U)
  397. #define STM32_SAI4BSEL_PER_CK RCC_D3CCIPR_SAI4BSEL_VALUE(4U)
  398. #define STM32_SAI4ASEL_PLL1_Q_CK RCC_D3CCIPR_SAI4ASEL_VALUE(0U)
  399. #define STM32_SAI4ASEL_PLL2_P_CK RCC_D3CCIPR_SAI4ASEL_VALUE(1U)
  400. #define STM32_SAI4ASEL_PLL3_P_CK RCC_D3CCIPR_SAI4ASEL_VALUE(2U)
  401. #define STM32_SAI4ASEL_I2S_CKIN RCC_D3CCIPR_SAI4ASEL_VALUE(3U)
  402. #define STM32_SAI4ASEL_PER_CK RCC_D3CCIPR_SAI4ASEL_VALUE(4U)
  403. #define STM32_ADCSEL_PLL2_P_CK RCC_D3CCIPR_ADCSEL_VALUE(0U)
  404. #define STM32_ADCSEL_PLL3_R_CK RCC_D3CCIPR_ADCSEL_VALUE(1U)
  405. #define STM32_ADCSEL_PER_CK RCC_D3CCIPR_ADCSEL_VALUE(2U)
  406. #define STM32_ADCSEL_DISABLE RCC_D3CCIPR_ADCSEL_VALUE(0U)
  407. #define STM32_LPTIM345SEL_PCLK4 RCC_D3CCIPR_LPTIM345SEL_VALUE(0U)
  408. #define STM32_LPTIM345SEL_PLL2_P_CK RCC_D3CCIPR_LPTIM345SEL_VALUE(1U)
  409. #define STM32_LPTIM345SEL_PLL3_P_CK RCC_D3CCIPR_LPTIM345SEL_VALUE(2U)
  410. #define STM32_LPTIM345SEL_LSE_CK RCC_D3CCIPR_LPTIM345SEL_VALUE(3U)
  411. #define STM32_LPTIM345SEL_LSI_CK RCC_D3CCIPR_LPTIM345SEL_VALUE(4U)
  412. #define STM32_LPTIM345SEL_PER_CK RCC_D3CCIPR_LPTIM345SEL_VALUE(5U)
  413. #define STM32_LPTIM2SEL_PCLK4 RCC_D3CCIPR_LPTIM2SEL_VALUE(0U)
  414. #define STM32_LPTIM2SEL_PLL2_P_CK RCC_D3CCIPR_LPTIM2SEL_VALUE(1U)
  415. #define STM32_LPTIM2SEL_PLL3_P_CK RCC_D3CCIPR_LPTIM2SEL_VALUE(2U)
  416. #define STM32_LPTIM2SEL_LSE_CK RCC_D3CCIPR_LPTIM2SEL_VALUE(3U)
  417. #define STM32_LPTIM2SEL_LSI_CK RCC_D3CCIPR_LPTIM2SEL_VALUE(4U)
  418. #define STM32_LPTIM2SEL_PER_CK RCC_D3CCIPR_LPTIM2SEL_VALUE(5U)
  419. #define STM32_I2C4SEL_PCLK4 RCC_D3CCIPR_I2C4SEL_VALUE(0U)
  420. #define STM32_I2C4SEL_PLL3_R_CK RCC_D3CCIPR_I2C4SEL_VALUE(1U)
  421. #define STM32_I2C4SEL_HSI_KER_CK RCC_D3CCIPR_I2C4SEL_VALUE(2U)
  422. #define STM32_I2C4SEL_CSI_KER_CK RCC_D3CCIPR_I2C4SEL_VALUE(3U)
  423. #define STM32_LPUART1SEL_PCLK4 RCC_D3CCIPR_LPUART1SEL_VALUE(0U)
  424. #define STM32_LPUART1SEL_PLL2_Q_CK RCC_D3CCIPR_LPUART1SEL_VALUE(1U)
  425. #define STM32_LPUART1SEL_PLL3_Q_CK RCC_D3CCIPR_LPUART1SEL_VALUE(2U)
  426. #define STM32_LPUART1SEL_HSI_KER_CK RCC_D3CCIPR_LPUART1SEL_VALUE(3U)
  427. #define STM32_LPUART1SEL_CSI_KER_CK RCC_D3CCIPR_LPUART1SEL_VALUE(4U)
  428. #define STM32_LPUART1SEL_LSE_CK RCC_D3CCIPR_LPUART1SEL_VALUE(5U)
  429. /** @} */
  430. /*===========================================================================*/
  431. /* Driver pre-compile time settings. */
  432. /*===========================================================================*/
  433. /**
  434. * @name Configuration options
  435. * @{
  436. */
  437. /**
  438. * @brief Disables the PWR/RCC initialization in the HAL.
  439. */
  440. #if !defined(STM32_NO_INIT) || defined(__DOXYGEN__)
  441. #define STM32_NO_INIT FALSE
  442. #endif
  443. /**
  444. * @brief SYS_CK value assumed if @p STM32_NO_INIT is enabled.
  445. */
  446. #if !defined(STM32_SYS_CK_ENFORCED_VALUE) || defined(__DOXYGEN__)
  447. #define STM32_SYS_CK_ENFORCED_VALUE STM32_HSICLK
  448. #endif
  449. /**
  450. * @brief Add no-cache attribute to SRAM1 and SRAM2.
  451. * @note MPU region 7 is used if enabled.
  452. */
  453. #if !defined(STM32_NOCACHE_SRAM1_SRAM2) || defined(__DOXYGEN__)
  454. #define STM32_NOCACHE_SRAM1_SRAM2 FALSE
  455. #endif
  456. /**
  457. * @brief Add no-cache attribute to SRAM3.
  458. * @note MPU region 7 is used if enabled.
  459. */
  460. #if !defined(STM32_NOCACHE_SRAM3) || defined(__DOXYGEN__)
  461. #define STM32_NOCACHE_SRAM3 TRUE
  462. #endif
  463. /**
  464. * @brief PWR CR1 initializer.
  465. */
  466. #if !defined(STM32_PWR_CR1) || defined(__DOXYGEN__)
  467. #define STM32_PWR_CR1 (PWR_CR1_SVOS_1 | \
  468. PWR_CR1_SVOS_0)
  469. #endif
  470. /**
  471. * @brief PWR CR2 initializer.
  472. */
  473. #if !defined(STM32_PWR_CR2) || defined(__DOXYGEN__)
  474. #define STM32_PWR_CR2 (PWR_CR2_BREN)
  475. #endif
  476. /**
  477. * @brief PWR CR3 initializer.
  478. */
  479. #if !defined(STM32_PWR_CR3) || defined(__DOXYGEN__)
  480. #define STM32_PWR_CR3 (PWR_CR3_LDOEN | \
  481. PWR_CR3_USBREGEN | \
  482. PWR_CR3_USB33DEN)
  483. #endif
  484. /**
  485. * @brief PWR CPUCR initializer.
  486. */
  487. #if !defined(STM32_PWR_CPUCR) || defined(__DOXYGEN__)
  488. #define STM32_PWR_CPUCR 0
  489. #endif
  490. /**
  491. * @brief VOS setting.
  492. */
  493. #if !defined(STM32_VOS) || defined(__DOXYGEN__)
  494. #define STM32_VOS STM32_VOS_SCALE1
  495. #endif
  496. /**
  497. * @brief Enables or disables the HSI clock source.
  498. */
  499. #if !defined(STM32_HSI_ENABLED) || defined(__DOXYGEN__)
  500. #define STM32_HSI_ENABLED TRUE
  501. #endif
  502. /**
  503. * @brief Enables or disables the LSI clock source.
  504. */
  505. #if !defined(STM32_LSI_ENABLED) || defined(__DOXYGEN__)
  506. #define STM32_LSI_ENABLED FALSE
  507. #endif
  508. /**
  509. * @brief Enables or disables the LSI clock source.
  510. */
  511. #if !defined(STM32_CSI_ENABLED) || defined(__DOXYGEN__)
  512. #define STM32_CSI_ENABLED FALSE
  513. #endif
  514. /**
  515. * @brief Enables or disables the HSI48 clock source.
  516. */
  517. #if !defined(STM32_HSI48_ENABLED) || defined(__DOXYGEN__)
  518. #define STM32_HSI48_ENABLED TRUE
  519. #endif
  520. /**
  521. * @brief Enables or disables the HSE clock source.
  522. */
  523. #if !defined(STM32_HSE_ENABLED) || defined(__DOXYGEN__)
  524. #define STM32_HSE_ENABLED TRUE
  525. #endif
  526. /**
  527. * @brief Enables or disables the LSE clock source.
  528. */
  529. #if !defined(STM32_LSE_ENABLED) || defined(__DOXYGEN__)
  530. #define STM32_LSE_ENABLED TRUE
  531. #endif
  532. /**
  533. * @brief HSI divider.
  534. */
  535. #if !defined(STM32_HSIDIV) || defined(__DOXYGEN__)
  536. #define STM32_HSIDIV STM32_HSIDIV_DIV1
  537. #endif
  538. /**
  539. * @brief Clock source for all PLLs.
  540. */
  541. #if !defined(STM32_PLLSRC) || defined(__DOXYGEN__)
  542. #define STM32_PLLSRC STM32_PLLSRC_HSE_CK
  543. #endif
  544. /**
  545. * @brief Masking of PLLCFGR register.
  546. * @note By default all options in PLLCFGR are enabled, this option
  547. * allows to mask specific bits for power saving reasons.
  548. * Use with caution.
  549. */
  550. #if !defined(STM32_PLLCFGR_MASK) || defined(__DOXYGEN__)
  551. #define STM32_PLLCFGR_MASK ~0
  552. #endif
  553. /**
  554. * @brief Enables or disables the PLL1.
  555. */
  556. #if !defined(STM32_PLL1_ENABLED) || defined(__DOXYGEN__)
  557. #define STM32_PLL1_ENABLED TRUE
  558. #endif
  559. /**
  560. * @brief Enables or disables the PLL1 P output.
  561. */
  562. #if !defined(STM32_PLL1_P_ENABLED) || defined(__DOXYGEN__)
  563. #define STM32_PLL1_P_ENABLED TRUE
  564. #endif
  565. /**
  566. * @brief Enables or disables the PLL1 Q output.
  567. */
  568. #if !defined(STM32_PLL1_Q_ENABLED) || defined(__DOXYGEN__)
  569. #define STM32_PLL1_Q_ENABLED TRUE
  570. #endif
  571. /**
  572. * @brief Enables or disables the PLL1 R output.
  573. */
  574. #if !defined(STM32_PLL1_R_ENABLED) || defined(__DOXYGEN__)
  575. #define STM32_PLL1_R_ENABLED TRUE
  576. #endif
  577. /**
  578. * @brief PLL1 DIVM divider.
  579. * @note The allowed values are 1..63.
  580. */
  581. #if !defined(STM32_PLL1_DIVM_VALUE) || defined(__DOXYGEN__)
  582. #define STM32_PLL1_DIVM_VALUE 4
  583. #endif
  584. /**
  585. * @brief PLL1 DIVN multiplier.
  586. * @note The allowed values are 4..512.
  587. */
  588. #if !defined(STM32_PLL1_DIVN_VALUE) || defined(__DOXYGEN__)
  589. #define STM32_PLL1_DIVN_VALUE 400
  590. #endif
  591. /**
  592. * @brief PLL1 FRACN multiplier, zero if no fractional part.
  593. * @note The allowed values are 0..8191.
  594. */
  595. #if !defined(STM32_PLL1_FRACN_VALUE) || defined(__DOXYGEN__)
  596. #define STM32_PLL1_FRACN_VALUE 0
  597. #endif
  598. /**
  599. * @brief PLL1 DIVP divider.
  600. * @note The allowed values are 2..128, odd values not allowed.
  601. */
  602. #if !defined(STM32_PLL1_DIVP_VALUE) || defined(__DOXYGEN__)
  603. #define STM32_PLL1_DIVP_VALUE 2
  604. #endif
  605. /**
  606. * @brief PLL1 DIVQ divider.
  607. * @note The allowed values are 1..128.
  608. */
  609. #if !defined(STM32_PLL1_DIVQ_VALUE) || defined(__DOXYGEN__)
  610. #define STM32_PLL1_DIVQ_VALUE 8
  611. #endif
  612. /**
  613. * @brief PLL1 DIVR divider.
  614. * @note The allowed values are 1..128.
  615. */
  616. #if !defined(STM32_PLL1_DIVR_VALUE) || defined(__DOXYGEN__)
  617. #define STM32_PLL1_DIVR_VALUE 8
  618. #endif
  619. /**
  620. * @brief Enables or disables the PLL2.
  621. */
  622. #if !defined(STM32_PLL2_ENABLED) || defined(__DOXYGEN__)
  623. #define STM32_PLL2_ENABLED TRUE
  624. #endif
  625. /**
  626. * @brief Enables or disables the PLL2 P output.
  627. */
  628. #if !defined(STM32_PLL2_P_ENABLED) || defined(__DOXYGEN__)
  629. #define STM32_PLL1_2_ENABLED TRUE
  630. #endif
  631. /**
  632. * @brief Enables or disables the PLL2 Q output.
  633. */
  634. #if !defined(STM32_PLL2_Q_ENABLED) || defined(__DOXYGEN__)
  635. #define STM32_PLL2_Q_ENABLED TRUE
  636. #endif
  637. /**
  638. * @brief Enables or disables the PLL2 R output.
  639. */
  640. #if !defined(STM32_PLL2_R_ENABLED) || defined(__DOXYGEN__)
  641. #define STM32_PLL2_R_ENABLED TRUE
  642. #endif
  643. /**
  644. * @brief PLL2 DIVM divider.
  645. * @note The allowed values are 1..63.
  646. */
  647. #if !defined(STM32_PLL2_DIVM_VALUE) || defined(__DOXYGEN__)
  648. #define STM32_PLL2_DIVM_VALUE 4
  649. #endif
  650. /**
  651. * @brief PLL2 DIVN multiplier.
  652. * @note The allowed values are 4..512.
  653. */
  654. #if !defined(STM32_PLL2_DIVN_VALUE) || defined(__DOXYGEN__)
  655. #define STM32_PLL2_DIVN_VALUE 400
  656. #endif
  657. /**
  658. * @brief PLL2 FRACN multiplier, zero if no fractional part.
  659. * @note The allowed values are 0..8191.
  660. */
  661. #if !defined(STM32_PLL2_FRACN_VALUE) || defined(__DOXYGEN__)
  662. #define STM32_PLL2_FRACN_VALUE 0
  663. #endif
  664. /**
  665. * @brief PLL2 DIVP divider.
  666. * @note The allowed values are 2..128, odd values not allowed.
  667. */
  668. #if !defined(STM32_PLL2_DIVP_VALUE) || defined(__DOXYGEN__)
  669. #define STM32_PLL2_DIVP_VALUE 40
  670. #endif
  671. /**
  672. * @brief PLL2 DIVQ divider.
  673. * @note The allowed values are 1..128.
  674. */
  675. #if !defined(STM32_PLL2_DIVQ_VALUE) || defined(__DOXYGEN__)
  676. #define STM32_PLL2_DIVQ_VALUE 8
  677. #endif
  678. /**
  679. * @brief PLL2 DIVR divider.
  680. * @note The allowed values are 1..128.
  681. */
  682. #if !defined(STM32_PLL2_DIVR_VALUE) || defined(__DOXYGEN__)
  683. #define STM32_PLL2_DIVR_VALUE 8
  684. #endif
  685. /**
  686. * @brief Enables or disables the PLL3.
  687. */
  688. #if !defined(STM32_PLL3_ENABLED) || defined(__DOXYGEN__)
  689. #define STM32_PLL3_ENABLED TRUE
  690. #endif
  691. /**
  692. * @brief Enables or disables the PLL3 P output.
  693. */
  694. #if !defined(STM32_PLL3_P_ENABLED) || defined(__DOXYGEN__)
  695. #define STM32_PLL3_P_ENABLED TRUE
  696. #endif
  697. /**
  698. * @brief Enables or disables the PLL3 Q output.
  699. */
  700. #if !defined(STM32_PLL3_Q_ENABLED) || defined(__DOXYGEN__)
  701. #define STM32_PLL3_Q_ENABLED TRUE
  702. #endif
  703. /**
  704. * @brief Enables or disables the PLL3 R output.
  705. */
  706. #if !defined(STM32_PLL3_R_ENABLED) || defined(__DOXYGEN__)
  707. #define STM32_PLL3_R_ENABLED TRUE
  708. #endif
  709. /**
  710. * @brief PLL3 DIVM divider.
  711. * @note The allowed values are 1..63.
  712. */
  713. #if !defined(STM32_PLL3_DIVM_VALUE) || defined(__DOXYGEN__)
  714. #define STM32_PLL3_DIVM_VALUE 4
  715. #endif
  716. /**
  717. * @brief PLL3 DIVN multiplier.
  718. * @note The allowed values are 4..512.
  719. */
  720. #if !defined(STM32_PLL3_DIVN_VALUE) || defined(__DOXYGEN__)
  721. #define STM32_PLL3_DIVN_VALUE 400
  722. #endif
  723. /**
  724. * @brief PLL3 FRACN multiplier, zero if no fractional part.
  725. * @note The allowed values are 0..8191.
  726. */
  727. #if !defined(STM32_PLL3_FRACN_VALUE) || defined(__DOXYGEN__)
  728. #define STM32_PLL3_FRACN_VALUE 0
  729. #endif
  730. /**
  731. * @brief PLL3 DIVP divider.
  732. * @note The allowed values are 2..128, odd values not allowed.
  733. */
  734. #if !defined(STM32_PLL3_DIVP_VALUE) || defined(__DOXYGEN__)
  735. #define STM32_PLL3_DIVP_VALUE 8
  736. #endif
  737. /**
  738. * @brief PLL3 DIVQ divider.
  739. * @note The allowed values are 1..128.
  740. */
  741. #if !defined(STM32_PLL3_DIVQ_VALUE) || defined(__DOXYGEN__)
  742. #define STM32_PLL3_DIVQ_VALUE 8
  743. #endif
  744. /**
  745. * @brief PLL3 DIVR divider.
  746. * @note The allowed values are 1..128.
  747. */
  748. #if !defined(STM32_PLL3_DIVR_VALUE) || defined(__DOXYGEN__)
  749. #define STM32_PLL3_DIVR_VALUE 8
  750. #endif
  751. /**
  752. * @brief Peripherals clock selector.
  753. */
  754. #if !defined(STM32_CKPERSEL) || defined(__DOXYGEN__)
  755. #define STM32_CKPERSEL STM32_CKPERSEL_HSE_CK
  756. #endif
  757. /**
  758. * @brief MCO1 clock selector.
  759. */
  760. #if !defined(STM32_MCO1SEL) || defined(__DOXYGEN__)
  761. #define STM32_MCO1SEL STM32_MCO1SEL_HSI_CK
  762. #endif
  763. /**
  764. * @brief MCO1 clock prescaler.
  765. */
  766. #if !defined(STM32_MCO1PRE_VALUE) || defined(__DOXYGEN__)
  767. #define STM32_MCO1PRE_VALUE 4
  768. #endif
  769. /**
  770. * @brief MCO2 clock selector.
  771. */
  772. #if !defined(STM32_MCO2SEL) || defined(__DOXYGEN__)
  773. #define STM32_MCO2SEL STM32_MCO2SEL_SYS_CK
  774. #endif
  775. /**
  776. * @brief MCO2 clock prescaler.
  777. */
  778. #if !defined(STM32_MCO2PRE_VALUE) || defined(__DOXYGEN__)
  779. #define STM32_MCO2PRE_VALUE 4
  780. #endif
  781. /**
  782. * @brief TIM clock prescaler selection.
  783. */
  784. #if !defined(STM32_TIMPRE_ENABLE) || defined(__DOXYGEN__)
  785. #define STM32_TIMPRE_ENABLE FALSE
  786. #endif
  787. /**
  788. * @brief HRTIM clock prescaler selection.
  789. */
  790. #if !defined(STM32_HRTIMSEL) || defined(__DOXYGEN__)
  791. #define STM32_HRTIMSEL 0
  792. #endif
  793. /**
  794. * @brief Kernel clock selection after a wake up from system Stop.
  795. */
  796. #if !defined(STM32_STOPKERWUCK) || defined(__DOXYGEN__)
  797. #define STM32_STOPKERWUCK 0
  798. #endif
  799. /**
  800. * @brief System clock selection after a wake up from system Stop.
  801. */
  802. #if !defined(STM32_STOPWUCK) || defined(__DOXYGEN__)
  803. #define STM32_STOPWUCK 0
  804. #endif
  805. /**
  806. * @brief RTC HSE prescaler value.
  807. * @note The allowed values are 2..63.
  808. */
  809. #if !defined(STM32_RTCPRE_VALUE) || defined(__DOXYGEN__)
  810. #define STM32_RTCPRE_VALUE 8
  811. #endif
  812. /**
  813. * @brief Main clock source selection.
  814. * @note This setting can be modified at runtime.
  815. */
  816. #if !defined(STM32_SW) || defined(__DOXYGEN__)
  817. #define STM32_SW STM32_SW_PLL1_P_CK1_P_CK
  818. #endif
  819. /**
  820. * @brief RTC clock selector.
  821. * @note This setting can be modified at runtime.
  822. */
  823. #if !defined(STM32_RTCSEL) || defined(__DOXYGEN__)
  824. #define STM32_RTCSEL STM32_RTCSEL_LSE_CK
  825. #endif
  826. /**
  827. * @brief Clock domain 1 core bus prescaler.
  828. * @note This setting can be modified at runtime.
  829. */
  830. #if !defined(STM32_D1CPRE) || defined(__DOXYGEN__)
  831. #define STM32_D1CPRE STM32_D1CPRE_DIV1
  832. #endif
  833. /**
  834. * @brief Clock domain 1 HPRE prescaler.
  835. * @note This setting can be modified at runtime.
  836. */
  837. #if !defined(STM32_D1HPRE) || defined(__DOXYGEN__)
  838. #define STM32_D1HPRE STM32_D1HPRE_DIV4
  839. #endif
  840. /**
  841. * @brief Clock domain 1 peripherals bus prescaler.
  842. * @note This setting can be modified at runtime.
  843. */
  844. #if !defined(STM32_D1PPRE3) || defined(__DOXYGEN__)
  845. #define STM32_D1PPRE3 STM32_D1PPRE3_DIV1
  846. #endif
  847. /**
  848. * @brief Clock domain 2 peripherals bus 1 prescaler.
  849. * @note This setting can be modified at runtime.
  850. */
  851. #if !defined(STM32_D2PPRE1) || defined(__DOXYGEN__)
  852. #define STM32_D2PPRE1 STM32_D2PPRE1_DIV1
  853. #endif
  854. /**
  855. * @brief Clock domain 2 peripherals bus 2 prescaler.
  856. * @note This setting can be modified at runtime.
  857. */
  858. #if !defined(STM32_D2PPRE2) || defined(__DOXYGEN__)
  859. #define STM32_D2PPRE2 STM32_D2PPRE2_DIV1
  860. #endif
  861. /**
  862. * @brief Clock domain 3 peripherals bus prescaler.
  863. * @note This setting can be modified at runtime.
  864. */
  865. #if !defined(STM32_D3PPRE4) || defined(__DOXYGEN__)
  866. #define STM32_D3PPRE4 STM32_D3PPRE4_DIV1
  867. #endif
  868. /**
  869. * @brief QSPI clock source.
  870. */
  871. #if !defined(STM32_QSPISEL) || defined(__DOXYGEN__)
  872. #define STM32_QSPISEL STM32_QSPISEL_HCLK
  873. #endif
  874. /**
  875. * @brief FMC clock source.
  876. */
  877. #if !defined(STM32_FMCSEL) || defined(__DOXYGEN__)
  878. #define STM32_FMCSEL STM32_QSPISEL_HCLK
  879. #endif
  880. /**
  881. * @brief SWP clock source.
  882. */
  883. #if !defined(STM32_SWPSEL) || defined(__DOXYGEN__)
  884. #define STM32_SWPSEL STM32_SWPSEL_PCLK1
  885. #endif
  886. /**
  887. * @brief FDCAN clock source.
  888. */
  889. #if !defined(STM32_FDCANSEL) || defined(__DOXYGEN__)
  890. #define STM32_FDCANSEL STM32_FDCANSEL_HSE_CK
  891. #endif
  892. /**
  893. * @brief DFSDM1 clock source.
  894. */
  895. #if !defined(STM32_DFSDM1SEL) || defined(__DOXYGEN__)
  896. #define STM32_DFSDM1SEL STM32_DFSDM1SEL_PCLK2
  897. #endif
  898. /**
  899. * @brief SPDIF clock source.
  900. */
  901. #if !defined(STM32_SPDIFSEL) || defined(__DOXYGEN__)
  902. #define STM32_SPDIFSEL STM32_SPDIFSEL_PLL1_Q_CK
  903. #endif
  904. /**
  905. * @brief SPI45 clock source.
  906. */
  907. #if !defined(STM32_SPI45SEL) || defined(__DOXYGEN__)
  908. #define STM32_SPI45SEL STM32_SPI45SEL_PCLK2
  909. #endif
  910. /**
  911. * @brief SPI123 clock source.
  912. */
  913. #if !defined(STM32_SPI123SEL) || defined(__DOXYGEN__)
  914. #define STM32_SPI123SEL STM32_SPI123SEL_PLL1_Q_CK
  915. #endif
  916. /**
  917. * @brief SAI23 clock source.
  918. */
  919. #if !defined(STM32_SAI23SEL) || defined(__DOXYGEN__)
  920. #define STM32_SAI23SEL STM32_SAI23SEL_PLL1_Q_CK
  921. #endif
  922. /**
  923. * @brief SAI1 clock source.
  924. */
  925. #if !defined(STM32_SAI1SEL) || defined(__DOXYGEN__)
  926. #define STM32_SAI1SEL STM32_SAI1SEL_PLL1_Q_CK
  927. #endif
  928. /**
  929. * @brief LPTIM1 clock source.
  930. */
  931. #if !defined(STM32_LPTIM1SEL) || defined(__DOXYGEN__)
  932. #define STM32_LPTIM1SEL STM32_LPTIM1SEL_PCLK1
  933. #endif
  934. /**
  935. * @brief CEC clock source.
  936. */
  937. #if !defined(STM32_CECSEL) || defined(__DOXYGEN__)
  938. #define STM32_CECSEL STM32_CECSEL_LSE_CK
  939. #endif
  940. /**
  941. * @brief USB clock source.
  942. */
  943. #if !defined(STM32_USBSEL) || defined(__DOXYGEN__)
  944. #define STM32_USBSEL STM32_USBSEL_PLL3_Q_CK
  945. #endif
  946. /**
  947. * @brief I2C123 clock source.
  948. */
  949. #if !defined(STM32_I2C123SEL) || defined(__DOXYGEN__)
  950. #define STM32_I2C123SEL STM32_I2C123SEL_PCLK1
  951. #endif
  952. /**
  953. * @brief RNG clock source.
  954. */
  955. #if !defined(STM32_RNGSEL) || defined(__DOXYGEN__)
  956. #define STM32_RNGSEL STM32_RNGSEL_HSI48_CK
  957. #endif
  958. /**
  959. * @brief USART16 clock source.
  960. */
  961. #if !defined(STM32_USART16SEL) || defined(__DOXYGEN__)
  962. #define STM32_USART16SEL STM32_USART16SEL_PCLK2
  963. #endif
  964. /**
  965. * @brief USART234578 clock source.
  966. */
  967. #if !defined(STM32_USART234578SEL) || defined(__DOXYGEN__)
  968. #define STM32_USART234578SEL STM32_USART234578SEL_PCLK1
  969. #endif
  970. /**
  971. * @brief SPI6SEL clock source.
  972. */
  973. #if !defined(STM32_SPI6SEL) || defined(__DOXYGEN__)
  974. #define STM32_SPI6SEL STM32_SPI6SEL_PCLK4
  975. #endif
  976. /**
  977. * @brief SAI4BSEL clock source.
  978. */
  979. #if !defined(STM32_SAI4BSEL) || defined(__DOXYGEN__)
  980. #define STM32_SAI4BSEL STM32_SAI4BSEL_PLL1_Q_CK
  981. #endif
  982. /**
  983. * @brief SAI4ASEL clock source.
  984. */
  985. #if !defined(STM32_SAI4ASEL) || defined(__DOXYGEN__)
  986. #define STM32_SAI4ASEL STM32_SAI4ASEL_PLL1_Q_CK
  987. #endif
  988. /**
  989. * @brief ADCSEL clock source.
  990. */
  991. #if !defined(STM32_ADCSEL) || defined(__DOXYGEN__)
  992. #define STM32_ADCSEL STM32_ADCSEL_PLL2_P_CK
  993. #endif
  994. /**
  995. * @brief LPTIM345SEL clock source.
  996. */
  997. #if !defined(STM32_LPTIM345SEL) || defined(__DOXYGEN__)
  998. #define STM32_LPTIM345SEL STM32_LPTIM345SEL_PCLK4
  999. #endif
  1000. /**
  1001. * @brief LPTIM2SEL clock source.
  1002. */
  1003. #if !defined(STM32_LPTIM2SEL) || defined(__DOXYGEN__)
  1004. #define STM32_LPTIM2SEL STM32_LPTIM2SEL_PCLK4
  1005. #endif
  1006. /**
  1007. * @brief I2C4SEL clock source.
  1008. */
  1009. #if !defined(STM32_I2C4SEL) || defined(__DOXYGEN__)
  1010. #define STM32_I2C4SEL STM32_I2C4SEL_PCLK4
  1011. #endif
  1012. /**
  1013. * @brief LPUART1SEL clock source.
  1014. */
  1015. #if !defined(STM32_LPUART1SEL) || defined(__DOXYGEN__)
  1016. #define STM32_LPUART1SEL STM32_LPUART1SEL_PCLK4
  1017. #endif
  1018. /** @} */
  1019. /*===========================================================================*/
  1020. /* Derived constants and error checks. */
  1021. /*===========================================================================*/
  1022. /*
  1023. * Configuration-related checks.
  1024. */
  1025. #if !defined(STM32H7xx_MCUCONF)
  1026. #error "Using a wrong mcuconf.h file, STM32H7xx_MCUCONF not defined"
  1027. #endif
  1028. #if defined(STM32H743xx) && \
  1029. !defined(STM32H743_MCUCONF)
  1030. #error "Using a wrong mcuconf.h file, STM32H743_MCUCONF not defined"
  1031. #endif
  1032. #if defined(STM32H753xx) && \
  1033. !defined(STM32H753_MCUCONF)
  1034. #error "Using a wrong mcuconf.h file, STM32H753_MCUCONF not defined"
  1035. #endif
  1036. /*
  1037. * Board file checks.
  1038. */
  1039. #if !defined(STM32_LSECLK)
  1040. #error "STM32_LSECLK not defined in board.h"
  1041. #endif
  1042. #if !defined(STM32_LSEDRV)
  1043. #error "STM32_LSEDRV not defined in board.h"
  1044. #endif
  1045. #if !defined(STM32_HSECLK)
  1046. #error "STM32_HSECLK not defined in board.h"
  1047. #endif
  1048. /**
  1049. * @name Constants depending on VOS setting
  1050. * @{
  1051. */
  1052. #if (STM32_VOS == STM32_VOS_SCALE1) || defined(__DOXYGEN__)
  1053. #define STM32_0WS_THRESHOLD 70000000U
  1054. #define STM32_1WS_THRESHOLD 140000000U
  1055. #define STM32_2WS_THRESHOLD 210000000U
  1056. #define STM32_3WS_THRESHOLD 0U
  1057. #define STM32_4WS_THRESHOLD 0U
  1058. #define STM32_PLLOUT_MAX 400000000U
  1059. #define STM32_PLLOUT_MIN 1500000U
  1060. #elif STM32_VOS == STM32_VOS_SCALE2
  1061. #define STM32_0WS_THRESHOLD 55000000U
  1062. #define STM32_1WS_THRESHOLD 110000000U
  1063. #define STM32_2WS_THRESHOLD 165000000U
  1064. #define STM32_3WS_THRESHOLD 220000000U
  1065. #define STM32_4WS_THRESHOLD 0U
  1066. #define STM32_PLLOUT_MAX 300000000U
  1067. #define STM32_PLLOUT_MIN 1500000U
  1068. #elif STM32_VOS == STM32_VOS_SCALE3
  1069. #define STM32_0WS_THRESHOLD 45000000U
  1070. #define STM32_1WS_THRESHOLD 90000000U
  1071. #define STM32_2WS_THRESHOLD 135000000U
  1072. #define STM32_3WS_THRESHOLD 180000000U
  1073. #define STM32_4WS_THRESHOLD 225000000U
  1074. #define STM32_PLLOUT_MAX 200000000U
  1075. #define STM32_PLLOUT_MIN 1500000U
  1076. #else
  1077. #error "invalid STM32_VOS setting specified"
  1078. #endif
  1079. /** @} */
  1080. /*
  1081. * HSI related checks.
  1082. */
  1083. #if STM32_HSI_ENABLED
  1084. #define STM32_HSICLK STM32_HSI_OSC
  1085. #else /* !STM32_HSI_ENABLED */
  1086. #define STM32_HSICLK 0U
  1087. #if STM32_SW == STM32_SW_HSI_CK
  1088. #error "HSI not enabled, required by STM32_SW"
  1089. #endif
  1090. #if (STM32_PLLSRC == STM32_PLLSRC_HSI_CK) && \
  1091. (STM32_PLL1_ENABLED || STM32_PLL2_ENABLED || STM32_PLL3_ENABLED)
  1092. #error "HSI not enabled, required by STM32_PLLSRC and STM32_PLLx_ENABLED"
  1093. #endif
  1094. #if STM32_CKPERSEL == STM32_CKPERSEL_HSI_CK
  1095. #error "HSI not enabled, required by STM32_CKPERSEL"
  1096. #endif
  1097. #if STM32_MCO1SEL == STM32_MCO1SEL_HSI_CK
  1098. #error "HSI not enabled, required by STM32_MCO1SEL"
  1099. #endif
  1100. #endif /* !STM32_HSI_ENABLED */
  1101. /*
  1102. * HSI48 related checks.
  1103. */
  1104. #if STM32_HSI48_ENABLED
  1105. #define STM32_HSI48_CK STM32_HSI48_OSC
  1106. #else /* !STM32_HSI48_ENABLED */
  1107. #define STM32_HSI48_CK 0U
  1108. #if STM32_MCO1SEL == STM32_MCO1SEL_HSI48_CK
  1109. #error "HSI48 not enabled, required by STM32_MCO1SEL"
  1110. #endif
  1111. #endif /* !STM32_HSI48_ENABLED */
  1112. /*
  1113. * CSI related checks.
  1114. */
  1115. #if STM32_CSI_ENABLED
  1116. #define STM32_CSI_CK STM32_CSI_OSC
  1117. #else /* !STM32_CSI_ENABLED */
  1118. #define STM32_CSI_CK 0U
  1119. #if STM32_SW == STM32_SW_CSI_CK
  1120. #error "CSI not enabled, required by STM32_SW"
  1121. #endif
  1122. #if (STM32_PLLSRC == STM32_PLLSRC_CSI_CK) && \
  1123. (STM32_PLL1_ENABLED || STM32_PLL2_ENABLED || STM32_PLL3_ENABLED)
  1124. #error "CSI not enabled, required by STM32_PLLSRC and STM32_PLLx_ENABLED"
  1125. #endif
  1126. #if STM32_CKPERSEL == STM32_CKPERSEL_CSI_CK
  1127. #error "CSI not enabled, required by STM32_CKPERSEL"
  1128. #endif
  1129. #if STM32_MCO2SEL == STM32_MCO2SEL_CSI_CK
  1130. #error "CSI not enabled, required by STM32_MCO2SEL"
  1131. #endif
  1132. #endif /* !STM32_CSI_ENABLED */
  1133. /*
  1134. * HSE related checks.
  1135. */
  1136. #if STM32_HSE_ENABLED
  1137. #if !defined(STM32_HSECLK)
  1138. #error "HSE frequency not defined"
  1139. #endif
  1140. #define STM32_HSE_CK STM32_HSECLK
  1141. #if STM32_HSECLK == 0
  1142. #error "HSE oscllator not available"
  1143. #else /* STM32_HSECLK != 0 */
  1144. #if defined(STM32_HSE_BYPASS)
  1145. #if (STM32_HSECLK < STM32_HSECLK_BYP_MIN) || (STM32_HSECLK > STM32_HSECLK_BYP_MAX)
  1146. #error "STM32_HSECLK outside acceptable range (STM32_HSECLK_BYP_MIN..STM32_HSECLK_BYP_MAX)"
  1147. #endif
  1148. #else /* !defined(STM32_HSE_BYPASS) */
  1149. #if (STM32_HSECLK < STM32_HSECLK_MIN) || (STM32_HSECLK > STM32_HSECLK_MAX)
  1150. #error "STM32_HSECLK outside acceptable range (STM32_HSECLK_MIN..STM32_HSECLK_MAX)"
  1151. #endif
  1152. #endif /* !defined(STM32_HSE_BYPASS) */
  1153. #endif /* STM32_HSECLK != 0 */
  1154. #else /* !STM32_HSE_ENABLED */
  1155. #if STM32_SW == STM32_SW_HSE_CK
  1156. #error "HSE not enabled, required by STM32_SW"
  1157. #endif
  1158. #if (STM32_PLLSRC == STM32_PLLSRC_HSE_CK) && \
  1159. (STM32_PLL1_ENABLED || STM32_PLL2_ENABLED || STM32_PLL3_ENABLED)
  1160. #error "HSE not enabled, required by STM32_PLLSRC and STM32_PLLx_ENABLED"
  1161. #endif
  1162. #if STM32_MCO1SEL == STM32_MCO1SEL_HSE_CK
  1163. #error "HSE not enabled, required by STM32_MCO1SEL"
  1164. #endif
  1165. #if STM32_MCO2SEL == STM32_MCO2SEL_HSE_CK
  1166. #error "HSE not enabled, required by STM32_MCO2SEL"
  1167. #endif
  1168. #if STM32_RTCSEL == STM32_RTCSEL_HSE_1M_CK
  1169. #error "HSE not enabled, required by STM32_RTCSEL"
  1170. #endif
  1171. #endif /* !STM32_HSE_ENABLED */
  1172. /*
  1173. * LSI related checks.
  1174. */
  1175. #if STM32_LSI_ENABLED
  1176. #define STM32_LSI_CK STM32_LSI_OSC
  1177. #else /* !STM32_LSI_ENABLED */
  1178. #define STM32_LSI_CK 0U
  1179. #if STM32_RTCSEL == STM32_RTCSEL_LSI_CK
  1180. #error "LSI not enabled, required by STM32_RTCSEL"
  1181. #endif
  1182. #if STM32_MCO2SEL == STM32_MCO2SEL_LSI_CK
  1183. #error "HSE not enabled, required by STM32_MCO2SEL"
  1184. #endif
  1185. #endif /* !STM32_LSI_ENABLED */
  1186. /*
  1187. * LSE related checks.
  1188. */
  1189. #if STM32_LSE_ENABLED
  1190. #if !defined(STM32_LSECLK)
  1191. #error "LSE frequency not defined"
  1192. #endif
  1193. #define STM32_LSE_CK STM32_LSECLK
  1194. #if (STM32_LSE_CK == 0)
  1195. #error "LSE oscillator not available"
  1196. #endif
  1197. #if defined(STM32_LSE_BYPASS)
  1198. #if (STM32_LSE_CK < STM32_LSE_CK_MIN) || (STM32_LSE_CK > STM32_LSE_CK_BYP_MAX)
  1199. #error "STM32_LSE_CK outside acceptable range (STM32_LSE_CK_MIN..STM32_LSE_CK_BYP_MAX)"
  1200. #endif
  1201. #else
  1202. #if (STM32_LSE_CK < STM32_LSE_CK_MIN) || (STM32_LSE_CK > STM32_LSE_CK_MAX)
  1203. #error "STM32_LSE_CK outside acceptable range (STM32_LSE_CK_MIN..STM32_LSE_CK_MAX)"
  1204. #endif
  1205. #endif
  1206. #if !defined(STM32_LSEDRV)
  1207. #error "STM32_LSEDRV not defined"
  1208. #endif
  1209. #if (STM32_LSEDRV >> 3) > 3
  1210. #error "STM32_LSEDRV outside acceptable range ((0<<3)..(3<<3))"
  1211. #endif
  1212. #else /* !STM32_LSE_ENABLED */
  1213. #if STM32_RTCSEL == STM32_RTCSEL_LSE_CK
  1214. #error "LSE not enabled, required by STM32_RTCSEL"
  1215. #endif
  1216. #if STM32_MCO1SEL == STM32_MCO1SEL_LSE_CK
  1217. #error "LSE not enabled, required by STM32_MCO1SEL"
  1218. #endif
  1219. #endif /* !STM32_LSE_ENABLED */
  1220. /**
  1221. * @brief HSI divided clock.
  1222. */
  1223. #if (STM32_HSIDIV == STM32_HSIDIV_DIV1) || defined(__DOXYGEN__)
  1224. #define STM32_HSI_CK (STM32_HSICLK / 1U)
  1225. #elif STM32_HSIDIV == STM32_HSIDIV_DIV2
  1226. #define STM32_HSI_CK (STM32_HSICLK / 2U)
  1227. #elif STM32_HSIDIV == STM32_HSIDIV_DIV4
  1228. #define STM32_HSI_CK (STM32_HSICLK / 4U)
  1229. #elif STM32_HSIDIV == STM32_HSIDIV_DIV8
  1230. #define STM32_HSI_CK (STM32_HSICLK / 8U)
  1231. #else
  1232. #error "invalid STM32_HSIDIV value specified"
  1233. #endif
  1234. /**
  1235. * @brief HSE divided clock for RTC.
  1236. */
  1237. #if ((STM32_RTCPRE_VALUE >= 2) && (STM32_RTCPRE_VALUE <= 63)) || \
  1238. defined(__DOXYGEN__)
  1239. #define STM32_HSE_1M_CK (STM32_HSE_CK / STM32_RTCPRE_VALUE)
  1240. #else
  1241. #error "invalid STM32_RTCPRE_VALUE value specified"
  1242. #endif
  1243. /**
  1244. * @brief PLLs input clock frequency.
  1245. */
  1246. #if (STM32_PLLSRC == STM32_PLLSRC_HSE_CK) || defined(__DOXYGEN__)
  1247. #define STM32_PLLCLKIN STM32_HSE_CK
  1248. #elif STM32_PLLSRC == STM32_PLLSRC_HSI_CK
  1249. #define STM32_PLLCLKIN STM32_HSI_CK
  1250. #elif STM32_PLLSRC == STM32_PLLSRC_CSI_CK
  1251. #define STM32_PLLCLKIN STM32_CSI_CK
  1252. #else
  1253. #error "invalid STM32_PLLSRC value specified"
  1254. #endif
  1255. /**
  1256. * @brief PLL1 DIVM field.
  1257. */
  1258. #if ((STM32_PLL1_DIVM_VALUE >= 1) && (STM32_PLL1_DIVM_VALUE <= 63)) || \
  1259. defined(__DOXYGEN__)
  1260. #define STM32_PLL1_DIVM (STM32_PLL1_DIVM_VALUE << 4)
  1261. #define STM32_PLL1_REF_CK (STM32_PLLCLKIN / STM32_PLL1_DIVM_VALUE)
  1262. #else
  1263. #error "invalid STM32_PLL1_DIVM_VALUE value specified"
  1264. #endif
  1265. /*
  1266. * PLL1 input frequency range check.
  1267. */
  1268. #if (STM32_PLL1_REF_CK < STM32_PLLIN_MIN) || (STM32_PLL1_REF_CK > STM32_PLLIN_MAX)
  1269. #error "STM32_PLL1_REF_CK outside acceptable range (STM32_PLLIN_MIN..STM32_PLLIN_MAX)"
  1270. #endif
  1271. /**
  1272. * @brief PLL1 input range selector.
  1273. */
  1274. #if (STM32_PLL1_REF_CK < STM32_PLLIN_THRESHOLD1) || defined(__DOXYGEN__)
  1275. #define STM32_PLLCFGR_PLL1RGE RCC_PLLCFGR_PLL1RGE_0
  1276. #elif STM32_PLL1_REF_CK < STM32_PLLIN_THRESHOLD2
  1277. #define STM32_PLLCFGR_PLL1RGE RCC_PLLCFGR_PLL1RGE_1
  1278. #elif STM32_PLL1_REF_CK < STM32_PLLIN_THRESHOLD3
  1279. #define STM32_PLLCFGR_PLL1RGE RCC_PLLCFGR_PLL1RGE_2
  1280. #else
  1281. #define STM32_PLLCFGR_PLL1RGE RCC_PLLCFGR_PLL1RGE_3
  1282. #endif
  1283. /**
  1284. * @brief PLL2 DIVM field.
  1285. */
  1286. #if ((STM32_PLL2_DIVM_VALUE >= 1) && (STM32_PLL2_DIVM_VALUE <= 63)) || \
  1287. defined(__DOXYGEN__)
  1288. #define STM32_PLL2_DIVM (STM32_PLL2_DIVM_VALUE << 12)
  1289. #define STM32_PLL2_REF_CK (STM32_PLLCLKIN / STM32_PLL2_DIVM_VALUE)
  1290. #else
  1291. #error "invalid STM32_PLL2_DIVM_VALUE value specified"
  1292. #endif
  1293. /*
  1294. * PLL2 input frequency range check.
  1295. */
  1296. #if (STM32_PLL2_REF_CK < STM32_PLLIN_MIN) || (STM32_PLL2_REF_CK > STM32_PLLIN_MAX)
  1297. #error "STM32_PLL2_REF_CK outside acceptable range (STM32_PLLIN_MIN..STM32_PLLIN_MAX)"
  1298. #endif
  1299. /**
  1300. * @brief PLL2 input range selector.
  1301. */
  1302. #if (STM32_PLL2_REF_CK < STM32_PLLIN_THRESHOLD1) || defined(__DOXYGEN__)
  1303. #define STM32_PLLCFGR_PLL2RGE RCC_PLLCFGR_PLL2RGE_0
  1304. #elif STM32_PLL2_REF_CK < STM32_PLLIN_THRESHOLD2
  1305. #define STM32_PLLCFGR_PLL2RGE RCC_PLLCFGR_PLL2RGE_1
  1306. #elif STM32_PLL2_REF_CK < STM32_PLLIN_THRESHOLD3
  1307. #define STM32_PLLCFGR_PLL2RGE RCC_PLLCFGR_PLL2RGE_2
  1308. #else
  1309. #define STM32_PLLCFGR_PLL2RGE RCC_PLLCFGR_PLL2RGE_3
  1310. #endif
  1311. /**
  1312. * @brief PLL3 DIVM field.
  1313. */
  1314. #if ((STM32_PLL3_DIVM_VALUE >= 1) && (STM32_PLL3_DIVM_VALUE <= 63)) || \
  1315. defined(__DOXYGEN__)
  1316. #define STM32_PLL3_DIVM (STM32_PLL3_DIVM_VALUE << 20)
  1317. #define STM32_PLL3_REF_CK (STM32_PLLCLKIN / STM32_PLL3_DIVM_VALUE)
  1318. #else
  1319. #error "invalid STM32_PLL3_DIVM_VALUE value specified"
  1320. #endif
  1321. /*
  1322. * PLL3 input frequency range check.
  1323. */
  1324. #if (STM32_PLL3_REF_CK < STM32_PLLIN_MIN) || (STM32_PLL3_REF_CK > STM32_PLLIN_MAX)
  1325. #error "STM32_PLL3_REF_CK outside acceptable range (STM32_PLLIN_MIN..STM32_PLLIN_MAX)"
  1326. #endif
  1327. /**
  1328. * @brief PLL3 input range selector.
  1329. */
  1330. #if (STM32_PLL3_REF_CK < STM32_PLLIN_THRESHOLD1) || defined(__DOXYGEN__)
  1331. #define STM32_PLLCFGR_PLL3RGE RCC_PLLCFGR_PLL3RGE_0
  1332. #elif STM32_PLL3_REF_CK < STM32_PLLIN_THRESHOLD2
  1333. #define STM32_PLLCFGR_PLL3RGE RCC_PLLCFGR_PLL3RGE_1
  1334. #elif STM32_PLL3_REF_CK < STM32_PLLIN_THRESHOLD3
  1335. #define STM32_PLLCFGR_PLL3RGE RCC_PLLCFGR_PLL3RGE_2
  1336. #else
  1337. #define STM32_PLLCFGR_PLL3RGE RCC_PLLCFGR_PLL3RGE_3
  1338. #endif
  1339. /**
  1340. * @brief PLL1 DIVN field.
  1341. */
  1342. #if ((STM32_PLL1_DIVN_VALUE >= 4) && (STM32_PLL1_DIVN_VALUE <= 512)) || \
  1343. defined(__DOXYGEN__)
  1344. #define STM32_PLL1_DIVN ((STM32_PLL1_DIVN_VALUE - 1U) << 0U)
  1345. #else
  1346. #error "invalid STM32_PLL1_DIVN_VALUE value specified"
  1347. #endif
  1348. /**
  1349. * @brief PLL2 DIVN field.
  1350. */
  1351. #if ((STM32_PLL2_DIVN_VALUE >= 4) && (STM32_PLL2_DIVN_VALUE <= 512)) || \
  1352. defined(__DOXYGEN__)
  1353. #define STM32_PLL2_DIVN ((STM32_PLL2_DIVN_VALUE - 1U) << 0U)
  1354. #else
  1355. #error "invalid STM32_PLL2_DIVN_VALUE value specified"
  1356. #endif
  1357. /**
  1358. * @brief PLL3 DIVN field.
  1359. */
  1360. #if ((STM32_PLL3_DIVN_VALUE >= 4) && (STM32_PLL3_DIVN_VALUE <= 512)) || \
  1361. defined(__DOXYGEN__)
  1362. #define STM32_PLL3_DIVN ((STM32_PLL3_DIVN_VALUE - 1U) << 0U)
  1363. #else
  1364. #error "invalid STM32_PLL3_DIVN_VALUE value specified"
  1365. #endif
  1366. /**
  1367. * @brief PLL1 FRACN field.
  1368. */
  1369. #if ((STM32_PLL1_FRACN_VALUE >= 0) && (STM32_PLL1_FRACN_VALUE <= 8191)) || \
  1370. defined(__DOXYGEN__)
  1371. #define STM32_PLL1_FRACN (STM32_PLL1_FRACN_VALUE << 3U)
  1372. #else
  1373. #error "invalid STM32_PLL1_FRACN_VALUE value specified"
  1374. #endif
  1375. /**
  1376. * @brief PLL2 FRACN field.
  1377. */
  1378. #if ((STM32_PLL2_FRACN_VALUE >= 0) && (STM32_PLL2_FRACN_VALUE <= 8191)) || \
  1379. defined(__DOXYGEN__)
  1380. #define STM32_PLL2_FRACN (STM32_PLL2_FRACN_VALUE << 3U)
  1381. #else
  1382. #error "invalid STM32_PLL2_FRACN_VALUE value specified"
  1383. #endif
  1384. /**
  1385. * @brief PLL3 FRACN field.
  1386. */
  1387. #if ((STM32_PLL3_FRACN_VALUE >= 0) && (STM32_PLL3_FRACN_VALUE <= 8191)) || \
  1388. defined(__DOXYGEN__)
  1389. #define STM32_PLL3_FRACN (STM32_PLL3_FRACN_VALUE << 3U)
  1390. #else
  1391. #error "invalid STM32_PLL3_FRACN_VALUE value specified"
  1392. #endif
  1393. /**
  1394. * @brief PLL1 DIVP field.
  1395. */
  1396. #if ((STM32_PLL1_DIVP_VALUE >= 2) && (STM32_PLL1_DIVP_VALUE <= 128) && \
  1397. ((STM32_PLL1_DIVP_VALUE & 1U) == 0U)) || \
  1398. defined(__DOXYGEN__)
  1399. #define STM32_PLL1_DIVP ((STM32_PLL1_DIVP_VALUE - 1U) << 9U)
  1400. #else
  1401. #error "invalid STM32_PLL1_DIVP_VALUE value specified"
  1402. #endif
  1403. /**
  1404. * @brief PLL2 DIVP field.
  1405. */
  1406. #if ((STM32_PLL2_DIVP_VALUE >= 1) && (STM32_PLL2_DIVP_VALUE <= 128)) || \
  1407. defined(__DOXYGEN__)
  1408. #define STM32_PLL2_DIVP ((STM32_PLL2_DIVP_VALUE - 1U) << 9U)
  1409. #else
  1410. #error "invalid STM32_PLL2_DIVP_VALUE value specified"
  1411. #endif
  1412. /**
  1413. * @brief PLL3 DIVP field.
  1414. */
  1415. #if ((STM32_PLL3_DIVP_VALUE >= 1) && (STM32_PLL3_DIVP_VALUE <= 128)) || \
  1416. defined(__DOXYGEN__)
  1417. #define STM32_PLL3_DIVP ((STM32_PLL3_DIVP_VALUE - 1U) << 9U)
  1418. #else
  1419. #error "invalid STM32_PLL3_DIVP_VALUE value specified"
  1420. #endif
  1421. /**
  1422. * @brief PLL1 DIVQ field.
  1423. */
  1424. #if ((STM32_PLL1_DIVQ_VALUE >= 1) && (STM32_PLL1_DIVQ_VALUE <= 128)) || \
  1425. defined(__DOXYGEN__)
  1426. #define STM32_PLL1_DIVQ ((STM32_PLL1_DIVQ_VALUE - 1U) << 16U)
  1427. #else
  1428. #error "invalid STM32_PLL1_DIVQ_VALUE value specified"
  1429. #endif
  1430. /**
  1431. * @brief PLL2 DIVQ field.
  1432. */
  1433. #if ((STM32_PLL2_DIVQ_VALUE >= 1) && (STM32_PLL2_DIVQ_VALUE <= 128)) || \
  1434. defined(__DOXYGEN__)
  1435. #define STM32_PLL2_DIVQ ((STM32_PLL2_DIVQ_VALUE - 1U) << 16U)
  1436. #else
  1437. #error "invalid STM32_PLL2_DIVQ_VALUE value specified"
  1438. #endif
  1439. /**
  1440. * @brief PLL3 DIVQ field.
  1441. */
  1442. #if ((STM32_PLL3_DIVQ_VALUE >= 1) && (STM32_PLL3_DIVQ_VALUE <= 128)) || \
  1443. defined(__DOXYGEN__)
  1444. #define STM32_PLL3_DIVQ ((STM32_PLL3_DIVQ_VALUE - 1U) << 16U)
  1445. #else
  1446. #error "invalid STM32_PLL3_DIVQ_VALUE value specified"
  1447. #endif
  1448. /**
  1449. * @brief PLL1 DIVR field.
  1450. */
  1451. #if ((STM32_PLL1_DIVR_VALUE >= 1) && (STM32_PLL1_DIVR_VALUE <= 128)) || \
  1452. defined(__DOXYGEN__)
  1453. #define STM32_PLL1_DIVR ((STM32_PLL1_DIVR_VALUE - 1U) << 24U)
  1454. #else
  1455. #error "invalid STM32_PLL1_DIVR_VALUE value specified"
  1456. #endif
  1457. /**
  1458. * @brief PLL2 DIVR field.
  1459. */
  1460. #if ((STM32_PLL2_DIVR_VALUE >= 1) && (STM32_PLL2_DIVR_VALUE <= 128)) || \
  1461. defined(__DOXYGEN__)
  1462. #define STM32_PLL2_DIVR ((STM32_PLL2_DIVR_VALUE - 1U) << 24U)
  1463. #else
  1464. #error "invalid STM32_PLL2_DIVR_VALUE value specified"
  1465. #endif
  1466. /**
  1467. * @brief PLL3 DIVR field.
  1468. */
  1469. #if ((STM32_PLL3_DIVR_VALUE >= 1) && (STM32_PLL3_DIVR_VALUE <= 128)) || \
  1470. defined(__DOXYGEN__)
  1471. #define STM32_PLL3_DIVR ((STM32_PLL3_DIVR_VALUE - 1U) << 24U)
  1472. #else
  1473. #error "invalid STM32_PLL3_DIVR_VALUE value specified"
  1474. #endif
  1475. /**
  1476. * @brief PLL1 VCO frequency.
  1477. */
  1478. #define STM32_PLL1_VCO_CK (STM32_PLL1_REF_CK * STM32_PLL1_DIVN_VALUE)
  1479. /*
  1480. * PLL1 VCO frequency range check.
  1481. */
  1482. #if (STM32_PLL1_VCO_CK < STM32_PLLVCO_MIN) || (STM32_PLL1_VCO_CK > STM32_PLLVCO_MAX)
  1483. #error "STM32_PLL1_VCO_CK outside acceptable range (STM32_PLLVCO_MIN..STM32_PLLVCO_MAX)"
  1484. #endif
  1485. /*
  1486. * PLL1 VCO mode.
  1487. */
  1488. #if (STM32_PLL1_VCO_CK > STM32_PLLVCO_THRESHOLD) || defined(__DOXYGEN__)
  1489. #define STM32_PLLCFGR_PLL1VCOSEL 0U
  1490. #else
  1491. #define STM32_PLLCFGR_PLL1VCOSEL RCC_PLLCFGR_PLL1VCOSEL
  1492. #endif
  1493. /**
  1494. * @brief PLL2 VCO frequency.
  1495. */
  1496. #define STM32_PLL2_VCO_CK (STM32_PLL2_REF_CK * STM32_PLL2_DIVN_VALUE)
  1497. /*
  1498. * PLL2 VCO frequency range check.
  1499. */
  1500. #if (STM32_PLL2_VCO_CK < STM32_PLLVCO_MIN) || (STM32_PLL2_VCO_CK > STM32_PLLVCO_MAX)
  1501. #error "STM32_PLL2_VCO_CK outside acceptable range (STM32_PLLVCO_MIN..STM32_PLLVCO_MAX)"
  1502. #endif
  1503. /*
  1504. * PLL2 VCO mode.
  1505. */
  1506. #if (STM32_PLL2_VCO_CK > STM32_PLLVCO_THRESHOLD) || defined(__DOXYGEN__)
  1507. #define STM32_PLLCFGR_PLL2VCOSEL 0U
  1508. #else
  1509. #define STM32_PLLCFGR_PLL2VCOSEL RCC_PLLCFGR_PLL2VCOSEL
  1510. #endif
  1511. /**
  1512. * @brief PLL3 VCO frequency.
  1513. */
  1514. #define STM32_PLL3_VCO_CK (STM32_PLL3_REF_CK * STM32_PLL3_DIVN_VALUE)
  1515. /*
  1516. * PLL3 VCO frequency range check.
  1517. */
  1518. #if (STM32_PLL3_VCO_CK < STM32_PLLVCO_MIN) || (STM32_PLL3_VCO_CK > STM32_PLLVCO_MAX)
  1519. #error "STM32_PLL3_VCO_CK outside acceptable range (STM32_PLLVCO_MIN..STM32_PLLVCO_MAX)"
  1520. #endif
  1521. /*
  1522. * PLL3 VCO mode.
  1523. */
  1524. #if (STM32_PLL3_VCO_CK > STM32_PLLVCO_THRESHOLD) || defined(__DOXYGEN__)
  1525. #define STM32_PLLCFGR_PLL3VCOSEL 0U
  1526. #else
  1527. #define STM32_PLLCFGR_PLL3VCOSEL RCC_PLLCFGR_PLL3VCOSEL
  1528. #endif
  1529. #if ((STM32_PLL1_ENABLED == TRUE) && (STM32_PLL1_P_ENABLED == TRUE)) || \
  1530. defined(__DOXYGEN__)
  1531. /**
  1532. * @brief PLL1 P output clock frequency.
  1533. */
  1534. #define STM32_PLL1_P_CK (STM32_PLL1_VCO_CK / STM32_PLL1_DIVP_VALUE)
  1535. /*
  1536. * PLL1 P output frequency range check.
  1537. */
  1538. #if (STM32_PLL1_P_CK < STM32_PLLOUT_MIN) || (STM32_PLL1_P_CK > STM32_PLLOUT_MAX)
  1539. #error "STM32_PLL1_P_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1540. #endif
  1541. #else
  1542. #define STM32_PLL1_P_CK 0U
  1543. #endif
  1544. #if ((STM32_PLL2_ENABLED == TRUE) && (STM32_PLL2_P_ENABLED == TRUE)) || \
  1545. defined(__DOXYGEN__)
  1546. /**
  1547. * @brief PLL2 P output clock frequency.
  1548. */
  1549. #define STM32_PLL2_P_CK (STM32_PLL2_VCO_CK / STM32_PLL2_DIVP_VALUE)
  1550. /*
  1551. * PLL2 P output frequency range check.
  1552. */
  1553. #if (STM32_PLL2_P_CK < STM32_PLLOUT_MIN) || (STM32_PLL2_P_CK > STM32_PLLOUT_MAX)
  1554. #error "STM32_PLL2_P_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1555. #endif
  1556. #else
  1557. #define STM32_PLL2_P_CK 0U
  1558. #endif
  1559. #if ((STM32_PLL3_ENABLED == TRUE) && (STM32_PLL3_P_ENABLED == TRUE)) || \
  1560. defined(__DOXYGEN__)
  1561. /**
  1562. * @brief PLL3 P output clock frequency.
  1563. */
  1564. #define STM32_PLL3_P_CK (STM32_PLL3_VCO_CK / STM32_PLL3_DIVP_VALUE)
  1565. /*
  1566. * PLL3 P output frequency range check.
  1567. */
  1568. #if (STM32_PLL3_P_CK < STM32_PLLOUT_MIN) || (STM32_PLL3_P_CK > STM32_PLLOUT_MAX)
  1569. #error "STM32_PLL3_P_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1570. #endif
  1571. #else
  1572. #define STM32_PLL3_P_CK 0U
  1573. #endif
  1574. #if ((STM32_PLL1_ENABLED == TRUE) && (STM32_PLL1_Q_ENABLED == TRUE)) || \
  1575. defined(__DOXYGEN__)
  1576. /**
  1577. * @brief PLL1 Q output clock frequency.
  1578. */
  1579. #define STM32_PLL1_Q_CK (STM32_PLL1_VCO_CK / STM32_PLL1_DIVQ_VALUE)
  1580. /*
  1581. * PLL1 Q output frequency range check.
  1582. */
  1583. #if (STM32_PLL1_Q_CK < STM32_PLLOUT_MIN) || (STM32_PLL1_Q_CK > STM32_PLLOUT_MAX)
  1584. #error "STM32_PLL1_Q_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1585. #endif
  1586. #else
  1587. #define STM32_PLL1_Q_CK 0U
  1588. #endif
  1589. #if ((STM32_PLL2_ENABLED == TRUE) && (STM32_PLL2_Q_ENABLED == TRUE)) || \
  1590. defined(__DOXYGEN__)
  1591. /**
  1592. * @brief PLL2 Q output clock frequency.
  1593. */
  1594. #define STM32_PLL2_Q_CK (STM32_PLL2_VCO_CK / STM32_PLL2_DIVQ_VALUE)
  1595. /*
  1596. * PLL2 Q output frequency range check.
  1597. */
  1598. #if (STM32_PLL2_Q_CK < STM32_PLLOUT_MIN) || (STM32_PLL2_Q_CK > STM32_PLLOUT_MAX)
  1599. #error "STM32_PLL2_Q_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1600. #endif
  1601. #else
  1602. #define STM32_PLL2_Q_CK 0U
  1603. #endif
  1604. #if ((STM32_PLL3_ENABLED == TRUE) && (STM32_PLL3_Q_ENABLED == TRUE)) || \
  1605. defined(__DOXYGEN__)
  1606. /**
  1607. * @brief PLL3 Q output clock frequency.
  1608. */
  1609. #define STM32_PLL3_Q_CK (STM32_PLL3_VCO_CK / STM32_PLL3_DIVQ_VALUE)
  1610. /*
  1611. * PLL3 Q output frequency range check.
  1612. */
  1613. #if (STM32_PLL3_Q_CK < STM32_PLLOUT_MIN) || (STM32_PLL3_Q_CK > STM32_PLLOUT_MAX)
  1614. #error "STM32_PLL3_Q_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1615. #endif
  1616. #else
  1617. #define STM32_PLL3_Q_CK 0U
  1618. #endif
  1619. #if ((STM32_PLL1_ENABLED == TRUE) && (STM32_PLL1_R_ENABLED == TRUE)) || \
  1620. defined(__DOXYGEN__)
  1621. /**
  1622. * @brief PLL1 R output clock frequency.
  1623. */
  1624. #define STM32_PLL1_R_CK (STM32_PLL1_VCO_CK / STM32_PLL1_DIVR_VALUE)
  1625. /*
  1626. * PLL1 R output frequency range check.
  1627. */
  1628. #if (STM32_PLL1_R_CK < STM32_PLLOUT_MIN) || (STM32_PLL1_R_CK > STM32_PLLOUT_MAX)
  1629. #error "STM32_PLL1_R_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1630. #endif
  1631. #else
  1632. #define STM32_PLL1_R_CK 0U
  1633. #endif
  1634. #if ((STM32_PLL2_ENABLED == TRUE) && (STM32_PLL2_R_ENABLED == TRUE)) || \
  1635. defined(__DOXYGEN__)
  1636. /**
  1637. * @brief PLL2 R output clock frequency.
  1638. */
  1639. #define STM32_PLL2_R_CK (STM32_PLL2_VCO_CK / STM32_PLL2_DIVR_VALUE)
  1640. /*
  1641. * PLL2 R output frequency range check.
  1642. */
  1643. #if (STM32_PLL2_R_CK < STM32_PLLOUT_MIN) || (STM32_PLL2_R_CK > STM32_PLLOUT_MAX)
  1644. #error "STM32_PLL2_R_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1645. #endif
  1646. #else
  1647. #define STM32_PLL2_R_CK 0U
  1648. #endif
  1649. #if ((STM32_PLL3_ENABLED == TRUE) && (STM32_PLL3_R_ENABLED == TRUE)) || \
  1650. defined(__DOXYGEN__)
  1651. /**
  1652. * @brief PLL3 R output clock frequency.
  1653. */
  1654. #define STM32_PLL3_R_CK (STM32_PLL3_VCO_CK / STM32_PLL3_DIVR_VALUE)
  1655. /*
  1656. * PLL3 R output frequency range check.
  1657. */
  1658. #if (STM32_PLL3_R_CK < STM32_PLLOUT_MIN) || (STM32_PLL3_R_CK > STM32_PLLOUT_MAX)
  1659. #error "STM32_PLL3_R_CLKOUT outside acceptable range (STM32_PLLOUT_MIN..STM32_PLLOUT_MAX)"
  1660. #endif
  1661. #else
  1662. #define STM32_PLL3_R_CK 0U
  1663. #endif
  1664. /**
  1665. * @brief System clock source.
  1666. */
  1667. #if STM32_NO_INIT || defined(__DOXYGEN__)
  1668. #define STM32_SYS_CK STM32_SYS_CK_ENFORCED_VALUE
  1669. #elif (STM32_SW == STM32_SW_HSI_CK)
  1670. #define STM32_SYS_CK STM32_HSI_CK
  1671. #elif (STM32_SW == STM32_SW_CSI_CK)
  1672. #define STM32_SYS_CK STM32_CSI_CK
  1673. #elif (STM32_SW == STM32_SW_HSE_CK)
  1674. #define STM32_SYS_CK STM32_HSE_CK
  1675. #elif (STM32_SW == STM32_SW_PLL1_P_CK)
  1676. #define STM32_SYS_CK STM32_PLL1_P_CK
  1677. #else
  1678. #error "invalid STM32_SW value specified"
  1679. #endif
  1680. /*
  1681. * Check on the system clock.
  1682. */
  1683. #if STM32_SW > STM32_SYSCLK_MAX
  1684. #error "STM32_SYS_CK above maximum rated frequency (STM32_SYSCLK_MAX)"
  1685. #endif
  1686. /**
  1687. * @brief Peripherals clock source.
  1688. */
  1689. #if (STM32_CKPERSEL == STM32_CKPERSEL_HSI_CK) || defined(__DOXYGEN__)
  1690. #define STM32_PER_CK STM32_HSI_CK
  1691. #elif (STM32_CKPERSEL == STM32_CKPERSEL_CSI_CK)
  1692. #define STM32_PER_CK STM32_CSI_CK
  1693. #elif (STM32_CKPERSEL == STM32_CKPERSEL_HSE_CK)
  1694. #define STM32_PER_CK STM32_HSE_CK
  1695. #else
  1696. #error "invalid STM32_CKPERSEL value specified"
  1697. #endif
  1698. /*
  1699. * Check on the peripherals clock.
  1700. */
  1701. #if STM32_PER_CK > STM32_HCLK_MAX
  1702. #error "STM32_PER_CK above maximum rated frequency (STM32_HCLK_MAX)"
  1703. #endif
  1704. /**
  1705. * @brief MCO1 divider clock.
  1706. */
  1707. #if (STM32_MCO1SEL == STM32_MCO1SEL_HSI_CK) || defined(__DOXYGEN__)
  1708. #define STM32_MCO1DIVCLK STM32_HSI_CK
  1709. #elif STM32_MCO1SEL == STM32_MCO1SEL_LSE_CK
  1710. #define STM32_MCO1DIVCLK STM32_LSE_CK
  1711. #elif STM32_MCO1SEL == STM32_MCO1SEL_HSE_CK
  1712. #define STM32_MCO1DIVCLK STM32_HSE_CK
  1713. #elif STM32_MCO1SEL == STM32_MCO1SEL_PLL1_Q_CK
  1714. #define STM32_MCO1DIVCLK STM32_PLL1_P_CK
  1715. #elif STM32_MCO1SEL == STM32_MCO1SEL_HSI48_CK
  1716. #define STM32_MCO1DIVCLK STM32_HSI48_CK
  1717. #else
  1718. #error "invalid STM32_MCO1SEL value specified"
  1719. #endif
  1720. /**
  1721. * @brief MCO1 output pin clock.
  1722. */
  1723. #if (STM32_MCO1PRE_VALUE < 1) || (STM32_MCO1PRE_VALUE > 15)
  1724. #error "STM32_MCO1PRE_VALUE outside acceptable range (1..15)"
  1725. #endif
  1726. /**
  1727. * @brief MCO2 divider clock.
  1728. */
  1729. #if (STM32_MCO2SEL == STM32_MCO2SEL_SYS_CK) || defined(__DOXYGEN__)
  1730. #define STM32_MCO2DIVCLK STM32_SYS_CK
  1731. #elif STM32_MCO2SEL == STM32_MCO2SEL_PLL1_P_CK
  1732. #define STM32_MCO2DIVCLK STM32_PLL2_P_CK
  1733. #elif STM32_MCO2SEL == STM32_MCO2SEL_HSE_CK
  1734. #define STM32_MCO2DIVCLK STM32_HSE_CK
  1735. #elif STM32_MCO2SEL == STM32_MCO2SEL_PLL2_P_CK
  1736. #define STM32_MCO2DIVCLK STM32_PLL2_P_CK
  1737. #elif STM32_MCO2SEL == STM32_MCO2SEL_CSI_CK
  1738. #define STM32_MCO2DIVCLK STM32_CSI_CK
  1739. #elif STM32_MCO2SEL == STM32_MCO2SEL_LSI_CK
  1740. #define STM32_MCO2DIVCLK STM32_LSI_CK
  1741. #else
  1742. #error "invalid STM32_MCO2SEL value specified"
  1743. #endif
  1744. /**
  1745. * @brief MCO2 output pin clock.
  1746. */
  1747. #if (STM32_MCO2PRE_VALUE < 1) || (STM32_MCO2PRE_VALUE > 15)
  1748. #error "STM32_MCO2PRE_VALUE outside acceptable range (1..15)"
  1749. #endif
  1750. /**
  1751. * @brief RTC clock.
  1752. */
  1753. #if (STM32_RTCSEL == STM32_RTCSEL_NOCLK) || defined(__DOXYGEN__)
  1754. #define STM32_RTC_CK 0
  1755. #elif STM32_RTCSEL == STM32_RTCSEL_LSE_CK
  1756. #define STM32_RTC_CK STM32_LSE_CK
  1757. #elif STM32_RTCSEL == STM32_RTCSEL_LSI_CK
  1758. #define STM32_RTC_CK STM32_LSI_CK
  1759. #elif STM32_RTCSEL == STM32_RTCSEL_HSE_1M_CK
  1760. #define STM32_RTC_CK STM32_HSE_1M_CK
  1761. #else
  1762. #error "invalid STM32_RTCSEL value specified"
  1763. #endif
  1764. /*
  1765. * Check on the RTC clock.
  1766. */
  1767. #if STM32_RTC_CK > 1000000
  1768. #error "STM32_RTC_CK above maximum rated frequency (1000000)"
  1769. #endif
  1770. /**
  1771. * @brief D1CPRE clock.
  1772. */
  1773. #if (STM32_D1CPRE == STM32_D1CPRE_DIV1) || defined(__DOXYGEN__)
  1774. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 1U)
  1775. #elif STM32_D1CPRE == STM32_D1CPRE_DIV2
  1776. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 2U)
  1777. #elif STM32_D1CPRE == STM32_D1CPRE_DIV4
  1778. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 4U)
  1779. #elif STM32_D1CPRE == STM32_D1CPRE_DIV8
  1780. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 8U)
  1781. #elif STM32_D1CPRE == STM32_D1CPRE_DIV16
  1782. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 16U)
  1783. #elif STM32_D1CPRE == STM32_D1CPRE_DIV64
  1784. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 64U)
  1785. #elif STM32_D1CPRE == STM32_D1CPRE_DIV128
  1786. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 128U)
  1787. #elif STM32_D1CPRE == STM32_D1CPRE_DIV256
  1788. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 256U)
  1789. #elif STM32_D1CPRE == STM32_D1CPRE_DIV512
  1790. #define STM32_SYS_D1CPRE_CK (STM32_SYS_CK / 512U)
  1791. #else
  1792. #error "invalid STM32_D1CPRE value specified"
  1793. #endif
  1794. /**
  1795. * @brief Core clock.
  1796. */
  1797. #define STM32_CORE_CK STM32_SYS_D1CPRE_CK
  1798. /**
  1799. * @brief HCLK clock.
  1800. */
  1801. #if (STM32_D1HPRE == STM32_D1HPRE_DIV1) || defined(__DOXYGEN__)
  1802. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 1U)
  1803. #elif STM32_D1HPRE == STM32_D1HPRE_DIV2
  1804. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 2U)
  1805. #elif STM32_D1HPRE == STM32_D1HPRE_DIV4
  1806. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 4U)
  1807. #elif STM32_D1HPRE == STM32_D1HPRE_DIV8
  1808. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 8U)
  1809. #elif STM32_D1HPRE == STM32_D1HPRE_DIV16
  1810. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 16U)
  1811. #elif STM32_D1HPRE == STM32_D1HPRE_DIV64
  1812. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 64U)
  1813. #elif STM32_D1HPRE == STM32_D1HPRE_DIV128
  1814. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 128U)
  1815. #elif STM32_D1HPRE == STM32_D1HPRE_DIV256
  1816. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 256U)
  1817. #elif STM32_D1HPRE == STM32_D1HPRE_DIV512
  1818. #define STM32_HCLK (STM32_SYS_D1CPRE_CK / 512U)
  1819. #else
  1820. #error "invalid STM32_D1HPRE value specified"
  1821. #endif
  1822. /*
  1823. * AHB frequency check.
  1824. */
  1825. #if STM32_HCLK > STM32_HCLK_MAX
  1826. #error "STM32_HCLK exceeding maximum frequency (STM32_HCLK_MAX)"
  1827. #endif
  1828. /**
  1829. * @brief D1 PCLK3 clock.
  1830. */
  1831. #if (STM32_D1PPRE3 == STM32_D1PPRE3_DIV1) || defined(__DOXYGEN__)
  1832. #define STM32_PCLK3 (STM32_HCLK / 1U)
  1833. #elif STM32_D1PPRE3 == STM32_D1PPRE3_DIV2
  1834. #define STM32_PCLK3 (STM32_HCLK / 2U)
  1835. #elif STM32_D1PPRE3 == STM32_D1PPRE3_DIV4
  1836. #define STM32_PCLK3 (STM32_HCLK / 4U)
  1837. #elif STM32_D1PPRE3 == STM32_D1PPRE3_DIV8
  1838. #define STM32_PCLK3 (STM32_HCLK / 8U)
  1839. #elif STM32_D1PPRE3 == STM32_D1PPRE3_DIV16
  1840. #define STM32_PCLK3 (STM32_HCLK / 16U)
  1841. #else
  1842. #error "invalid STM32_D1PPRE3 value specified"
  1843. #endif
  1844. /*
  1845. * D1 PCLK3 frequency check.
  1846. */
  1847. #if STM32_PCLK3 > STM32_PCLK3_MAX
  1848. #error "STM32_PCLK3 exceeding maximum frequency (STM32_PCLK3_MAX)"
  1849. #endif
  1850. /**
  1851. * @brief D2 PCLK1 clock.
  1852. */
  1853. #if (STM32_D2PPRE1 == STM32_D2PPRE1_DIV1) || defined(__DOXYGEN__)
  1854. #define STM32_PCLK1 (STM32_HCLK / 1U)
  1855. #elif STM32_D2PPRE1 == STM32_D2PPRE1_DIV2
  1856. #define STM32_PCLK1 (STM32_HCLK / 2U)
  1857. #elif STM32_D2PPRE1 == STM32_D2PPRE1_DIV4
  1858. #define STM32_PCLK1 (STM32_HCLK / 4U)
  1859. #elif STM32_D2PPRE1 == STM32_D2PPRE1_DIV8
  1860. #define STM32_PCLK1 (STM32_HCLK / 8U)
  1861. #elif STM32_D2PPRE1 == STM32_D2PPRE1_DIV16
  1862. #define STM32_PCLK1 (STM32_HCLK / 16U)
  1863. #else
  1864. #error "invalid STM32_D2PPRE1 value specified"
  1865. #endif
  1866. /*
  1867. * D2 PCLK1 frequency check.
  1868. */
  1869. #if STM32_PCLK1 > STM32_PCLK1_MAX
  1870. #error "STM32_PCLK1 exceeding maximum frequency (STM32_PCLK1_MAX)"
  1871. #endif
  1872. /**
  1873. * @brief D2 PCLK2 clock.
  1874. */
  1875. #if (STM32_D2PPRE2 == STM32_D2PPRE2_DIV1) || defined(__DOXYGEN__)
  1876. #define STM32_PCLK2 (STM32_HCLK / 1U)
  1877. #elif STM32_D2PPRE2 == STM32_D2PPRE2_DIV2
  1878. #define STM32_PCLK2 (STM32_HCLK / 2U)
  1879. #elif STM32_D2PPRE2 == STM32_D2PPRE2_DIV4
  1880. #define STM32_PCLK2 (STM32_HCLK / 4U)
  1881. #elif STM32_D2PPRE2 == STM32_D2PPRE2_DIV8
  1882. #define STM32_PCLK2 (STM32_HCLK / 8U)
  1883. #elif STM32_D2PPRE2 == STM32_D2PPRE2_DIV16
  1884. #define STM32_PCLK2 (STM32_HCLK / 16U)
  1885. #else
  1886. #error "invalid STM32_D2PPRE2 value specified"
  1887. #endif
  1888. /*
  1889. * D2 PCLK2 frequency check.
  1890. */
  1891. #if STM32_PCLK2 > STM32_PCLK2_MAX
  1892. #error "STM32_PCLK2 exceeding maximum frequency (STM32_PCLK2_MAX)"
  1893. #endif
  1894. /**
  1895. * @brief D3 PCLK4 clock.
  1896. */
  1897. #if (STM32_D3PPRE4 == STM32_D3PPRE4_DIV1) || defined(__DOXYGEN__)
  1898. #define STM32_PCLK4 (STM32_HCLK / 1U)
  1899. #elif STM32_D3PPRE4 == STM32_D3PPRE4_DIV2
  1900. #define STM32_PCLK4 (STM32_HCLK / 2U)
  1901. #elif STM32_D3PPRE4 == STM32_D3PPRE4_DIV4
  1902. #define STM32_PCLK4 (STM32_HCLK / 4U)
  1903. #elif STM32_D3PPRE4 == STM32_D3PPRE4_DIV8
  1904. #define STM32_PCLK4 (STM32_HCLK / 8U)
  1905. #elif STM32_D3PPRE4 == STM32_D3PPRE4_DIV16
  1906. #define STM32_PCLK4 (STM32_HCLK / 16U)
  1907. #else
  1908. #error "invalid STM32_D3PPRE4 value specified"
  1909. #endif
  1910. /*
  1911. * D3 PCLK4 frequency check.
  1912. */
  1913. #if STM32_PCLK4 > STM32_PCLK4_MAX
  1914. #error "STM32_PCLK4 exceeding maximum frequency (STM32_PCLK4_MAX)"
  1915. #endif
  1916. /**
  1917. * @brief Flash settings.
  1918. */
  1919. #if (STM32_HCLK <= STM32_0WS_THRESHOLD) || defined(__DOXYGEN__)
  1920. #define STM32_FLASHBITS 0x00000000
  1921. #elif STM32_HCLK <= STM32_1WS_THRESHOLD
  1922. #define STM32_FLASHBITS 0x00000001
  1923. #elif STM32_HCLK <= STM32_2WS_THRESHOLD
  1924. #define STM32_FLASHBITS 0x00000002
  1925. #elif STM32_HCLK <= STM32_3WS_THRESHOLD
  1926. #define STM32_FLASHBITS 0x00000003
  1927. #elif STM32_HCLK <= STM32_4WS_THRESHOLD
  1928. #define STM32_FLASHBITS 0x00000004
  1929. #else
  1930. #define STM32_FLASHBITS 0x00000007
  1931. #endif
  1932. #if (STM32_D2PPRE1 == STM32_D2PPRE1_DIV1) || defined(__DOXYGEN__)
  1933. /**
  1934. * @brief Clock of timers connected to APB1
  1935. */
  1936. #define STM32_TIMCLK1 (STM32_PCLK1 * 1)
  1937. #else
  1938. #if (STM32_TIMPRE_ENABLE == FALSE) || (STM32_D2PPRE1 == STM32_D2PPRE1_DIV2)
  1939. #define STM32_TIMCLK1 (STM32_PCLK1 * 2)
  1940. #else
  1941. #define STM32_TIMCLK1 (STM32_PCLK1 * 4)
  1942. #endif
  1943. #endif
  1944. #if (STM32_D2PPRE2 == STM32_D2PPRE2_DIV1) || defined(__DOXYGEN__)
  1945. /**
  1946. * @brief Clock of timers connected to APB2.
  1947. */
  1948. #define STM32_TIMCLK2 (STM32_PCLK2 * 1)
  1949. #else
  1950. #if (STM32_TIMPRE_ENABLE == FALSE) || (STM32_D2PPRE2 == STM32_D2PPRE2_DIV2)
  1951. #define STM32_TIMCLK2 (STM32_PCLK2 * 2)
  1952. #else
  1953. #define STM32_TIMCLK2 (STM32_PCLK2 * 4)
  1954. #endif
  1955. #endif
  1956. #if (STM32_LPTIM1SEL == STM32_LPTIM1SEL_PCLK1) || defined(__DOXYGEN__)
  1957. /**
  1958. * @brief LPTIM1 clock.
  1959. */
  1960. #define STM32_LPTIM1CLK STM32_PCLK1
  1961. #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_PLL2_P_CK
  1962. #define STM32_LPTIM1CLK STM32_PLL2_P_CK
  1963. #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_PLL3_R_CK
  1964. #define STM32_LPTIM1CLK STM32_PLL3_R_CK
  1965. #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_LSE_CK
  1966. #define STM32_LPTIM1CLK STM32_LSE_CK
  1967. #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_LSI_CK
  1968. #define STM32_LPTIM1CLK STM32_LSI_CK
  1969. #elif STM32_LPTIM1SEL == STM32_LPTIM1SEL_PER_CK
  1970. #define STM32_LPTIM1CLK STM32_PER_CK
  1971. #else
  1972. #error "invalid source selected for STM32_LPTIM1SEL clock"
  1973. #endif
  1974. #if (STM32_LPTIM2SEL == STM32_LPTIM2SEL_PCLK4) || defined(__DOXYGEN__)
  1975. /**
  1976. * @brief LPTIM2 clock.
  1977. */
  1978. #define STM32_LPTIM2CLK STM32_PCLK4
  1979. #elif STM32_LPTIM2SEL == STM32_LPTIM2SEL_PLL2_P_CK
  1980. #define STM32_LPTIM2CLK STM32_PLL2_P_CK
  1981. #elif STM32_LPTIM2SEL == STM32_LPTIM2SEL_PLL3_P_CK
  1982. #define STM32_LPTIM2CLK STM32_PLL3_P_CK
  1983. #elif STM32_LPTIM2SEL == STM32_LPTIM2SEL_LSE_CK
  1984. #define STM32_LPTIM2CLK STM32_LSE_CK
  1985. #elif STM32_LPTIM2SEL == STM32_LPTIM2SEL_LSI_CK
  1986. #define STM32_LPTIM2CLK STM32_LSI_CK
  1987. #elif STM32_LPTIM2SEL == STM32_LPTIM2SEL_PER_CK
  1988. #define STM32_LPTIM2CLK STM32_PER_CK
  1989. #else
  1990. #error "invalid source selected for STM32_LPTIM2SEL clock"
  1991. #endif
  1992. #if (STM32_LPTIM345SEL == STM32_LPTIM345SEL_PCLK4) || defined(__DOXYGEN__)
  1993. /**
  1994. * @brief LPTIM3 clock.
  1995. */
  1996. #define STM32_LPTIM3CLK STM32_PCLK4
  1997. /**
  1998. * @brief LPTIM4 clock.
  1999. */
  2000. #define STM32_LPTIM4CLK STM32_PCLK4
  2001. /**
  2002. * @brief LPTIM5 clock.
  2003. */
  2004. #define STM32_LPTIM5CLK STM32_PCLK4
  2005. #elif STM32_LPTIM345SEL == STM32_LPTIM345SEL_PLL2_P_CK
  2006. #define STM32_LPTIM3CLK STM32_PLL2_P_CK
  2007. #define STM32_LPTIM4CLK STM32_PLL2_P_CK
  2008. #define STM32_LPTIM5CLK STM32_PLL2_P_CK
  2009. #elif STM32_LPTIM345SEL == STM32_LPTIM345SEL_PLL3_P_CK
  2010. #define STM32_LPTIM3CLK STM32_PLL3_P_CK
  2011. #define STM32_LPTIM4CLK STM32_PLL3_P_CK
  2012. #define STM32_LPTIM5CLK STM32_PLL3_P_CK
  2013. #elif STM32_LPTIM345SEL == STM32_LPTIM345SEL_LSE_CK
  2014. #define STM32_LPTIM3CLK STM32_LSE_CK
  2015. #define STM32_LPTIM4CLK STM32_LSE_CK
  2016. #define STM32_LPTIM5CLK STM32_LSE_CK
  2017. #elif STM32_LPTIM345SEL == STM32_LPTIM345SEL_LSI_CK
  2018. #define STM32_LPTIM3CLK STM32_LSI_CK
  2019. #define STM32_LPTIM4CLK STM32_LSI_CK
  2020. #define STM32_LPTIM5CLK STM32_LSI_CK
  2021. #elif STM32_LPTIM345SEL == STM32_LPTIM345SEL_PER_CK
  2022. #define STM32_LPTIM3CLK STM32_PER_CK
  2023. #define STM32_LPTIM4CLK STM32_PER_CK
  2024. #define STM32_LPTIM5CLK STM32_PER_CK
  2025. #else
  2026. #error "invalid source selected for STM32_LPTIM345SEL clock"
  2027. #endif
  2028. #if (STM32_USART16SEL == STM32_USART16SEL_PCLK2) || defined(__DOXYGEN__)
  2029. /**
  2030. * @brief USART1 clock.
  2031. */
  2032. #define STM32_USART1CLK STM32_PCLK2
  2033. /**
  2034. * @brief USART6 clock.
  2035. */
  2036. #define STM32_USART6CLK STM32_PCLK2
  2037. #elif STM32_USART16SEL == STM32_USART16SEL_PLL2_Q_CK
  2038. #define STM32_USART1CLK STM32_PLL2_Q_CK
  2039. #define STM32_USART6CLK STM32_PLL2_Q_CK
  2040. #elif STM32_USART16SEL == STM32_USART16SEL_PLL3_Q_CK
  2041. #define STM32_USART1CLK STM32_PLL3_Q_CK
  2042. #define STM32_USART6CLK STM32_PLL3_Q_CK
  2043. #elif STM32_USART16SEL == STM32_USART16SEL_HSI_KER_CK
  2044. #define STM32_USART1CLK STM32_HSI_CK
  2045. #define STM32_USART6CLK STM32_HSI_CK
  2046. #elif STM32_USART16SEL == STM32_USART16SEL_CSI_KER_CK
  2047. #define STM32_USART1CLK STM32_CSI_CK
  2048. #define STM32_USART6CLK STM32_CSI_CK
  2049. #elif STM32_USART16SEL == STM32_USART16SEL_LSE_CK
  2050. #define STM32_USART1CLK STM32_LSE_CK
  2051. #define STM32_USART6CLK STM32_LSE_CK
  2052. #else
  2053. #error "invalid source selected for STM32_USART16SEL clock"
  2054. #endif
  2055. #if (STM32_USART234578SEL == STM32_USART234578SEL_PCLK1) || defined(__DOXYGEN__)
  2056. /**
  2057. * @brief USART2 clock.
  2058. */
  2059. #define STM32_USART2CLK STM32_PCLK1
  2060. /**
  2061. * @brief USART3 clock.
  2062. */
  2063. #define STM32_USART3CLK STM32_PCLK1
  2064. /**
  2065. * @brief USART4 clock.
  2066. */
  2067. #define STM32_USART4CLK STM32_PCLK1
  2068. /**
  2069. * @brief USART5 clock.
  2070. */
  2071. #define STM32_USART5CLK STM32_PCLK1
  2072. /**
  2073. * @brief USART7 clock.
  2074. */
  2075. #define STM32_USART7CLK STM32_PCLK1
  2076. /**
  2077. * @brief USART8 clock.
  2078. */
  2079. #define STM32_USART8CLK STM32_PCLK2
  2080. #elif STM32_USART234578SEL == STM32_USART234578SEL_PLL2_Q_CK
  2081. #define STM32_USART2CLK STM32_PLL2_Q_CK
  2082. #define STM32_USART3CLK STM32_PLL2_Q_CK
  2083. #define STM32_USART4CLK STM32_PLL2_Q_CK
  2084. #define STM32_USART5CLK STM32_PLL2_Q_CK
  2085. #define STM32_USART7CLK STM32_PLL2_Q_CK
  2086. #define STM32_USART8CLK STM32_PLL2_Q_CK
  2087. #elif STM32_USART234578SEL == STM32_USART234578SEL_PLL3_Q_CK
  2088. #define STM32_USART2CLK STM32_PLL3_Q_CK
  2089. #define STM32_USART3CLK STM32_PLL3_Q_CK
  2090. #define STM32_USART4CLK STM32_PLL3_Q_CK
  2091. #define STM32_USART5CLK STM32_PLL3_Q_CK
  2092. #define STM32_USART7CLK STM32_PLL3_Q_CK
  2093. #define STM32_USART8CLK STM32_PLL3_Q_CK
  2094. #elif STM32_USART234578SEL == STM32_USART234578SEL_HSI_KER_CK
  2095. #define STM32_USART2CLK STM32_HSI_CK
  2096. #define STM32_USART3CLK STM32_HSI_CK
  2097. #define STM32_USART4CLK STM32_HSI_CK
  2098. #define STM32_USART5CLK STM32_HSI_CK
  2099. #define STM32_USART7CLK STM32_HSI_CK
  2100. #define STM32_USART8CLK STM32_HSI_CK
  2101. #elif STM32_USART234578SEL == STM32_USART234578SEL_CSI_KER_CK
  2102. #define STM32_USART2CLK STM32_CSI_CK
  2103. #define STM32_USART3CLK STM32_CSI_CK
  2104. #define STM32_USART4CLK STM32_CSI_CK
  2105. #define STM32_USART5CLK STM32_CSI_CK
  2106. #define STM32_USART7CLK STM32_CSI_CK
  2107. #define STM32_USART8CLK STM32_CSI_CK
  2108. #elif STM32_USART234578SEL == STM32_USART234578SEL_LSE_CK
  2109. #define STM32_USART2CLK STM32_LSE_CK
  2110. #define STM32_USART3CLK STM32_LSE_CK
  2111. #define STM32_USART4CLK STM32_LSE_CK
  2112. #define STM32_USART6CLK STM32_LSE_CK
  2113. #define STM32_USART7CLK STM32_LSE_CK
  2114. #define STM32_USART8CLK STM32_LSE_CK
  2115. #else
  2116. #error "invalid source selected for STM32_USART234578SEL clock"
  2117. #endif
  2118. #if (STM32_LPUART1SEL == STM32_LPUART1SEL_PCLK4) || defined(__DOXYGEN__)
  2119. /**
  2120. * @brief LPUART1 clock.
  2121. */
  2122. #define STM32_LPUART1CLK STM32_PCLK1
  2123. #elif STM32_LPUART1SEL == STM32_LPUART1SEL_PLL2_Q_CK
  2124. #define STM32_LPUART1CLK STM32_PLL2_Q_CK
  2125. #elif STM32_LPUART1SEL == STM32_LPUART1SEL_PLL3_Q_CK
  2126. #define STM32_LPUART1CLK STM32_PLL3_Q_CK
  2127. #elif STM32_LPUART1SEL == STM32_LPUART1SEL_HSI_KER_CK
  2128. #define STM32_LPUART1CLK STM32_HSI_CK
  2129. #elif STM32_LPUART1SEL == STM32_LPUART1SEL_CSI_KER_CK
  2130. #define STM32_LPUART1CLK STM32_CSI_CK
  2131. #elif STM32_LPUART1SEL == STM32_LPUART1SEL_LSE_CK
  2132. #define STM32_LPUART1CLK STM32_LSE_CK
  2133. #else
  2134. #error "invalid source selected for STM32_LPUART1SEL clock"
  2135. #endif
  2136. #if (STM32_SPI123SEL == STM32_SPI123SEL_PLL1_Q_CK) || defined(__DOXYGEN__)
  2137. /**
  2138. * @brief SPI1 clock.
  2139. */
  2140. #define STM32_SPI1CLK STM32_PLL1_Q_CK
  2141. /**
  2142. * @brief SPI2 clock.
  2143. */
  2144. #define STM32_SPI2CLK STM32_PLL1_Q_CK
  2145. /**
  2146. * @brief SPI3 clock.
  2147. */
  2148. #define STM32_SPI3CLK STM32_PLL1_Q_CK
  2149. #elif STM32_SPI123SEL == STM32_SPI123SEL_PLL2_P_CK
  2150. #define STM32_SPI1CLK STM32_PLL2_P_CK
  2151. #define STM32_SPI2CLK STM32_PLL2_P_CK
  2152. #define STM32_SPI3CLK STM32_PLL2_P_CK
  2153. #elif STM32_SPI123SEL == STM32_SPI123SEL_PLL3_P_CK
  2154. #define STM32_SPI1CLK STM32_PLL3_P_CK
  2155. #define STM32_SPI2CLK STM32_PLL3_P_CK
  2156. #define STM32_SPI3CLK STM32_PLL3_P_CK
  2157. #elif STM32_SPI123SEL == STM32_SPI123SEL_I2S_CKIN
  2158. #define STM32_SPI1CLK 0 /* Unknown, would require a board value */
  2159. #define STM32_SPI2CLK 0 /* Unknown, would require a board value */
  2160. #define STM32_SPI3CLK 0 /* Unknown, would require a board value */
  2161. #elif STM32_SPI123SEL == STM32_SPI123SEL_PER_CK
  2162. #define STM32_SPI1CLK STM32_PER_CK
  2163. #define STM32_SPI2CLK STM32_PER_CK
  2164. #define STM32_SPI3CLK STM32_PER_CK
  2165. #else
  2166. #error "invalid source selected for STM32_SPI123SEL clock"
  2167. #endif
  2168. #if (STM32_SPI45SEL == STM32_SPI45SEL_PCLK2) || defined(__DOXYGEN__)
  2169. /**
  2170. * @brief SPI4 clock.
  2171. */
  2172. #define STM32_SPI4CLK STM32_PCLK2
  2173. /**
  2174. * @brief SPI5 clock.
  2175. */
  2176. #define STM32_SPI5CLK STM32_PCLK2
  2177. #elif STM32_SPI45SEL == STM32_SPI45SEL_PLL2_Q_CK
  2178. #define STM32_SPI4CLK STM32_PLL2_Q_CK
  2179. #define STM32_SPI5CLK STM32_PLL2_Q_CK
  2180. #elif STM32_SPI45SEL == STM32_SPI45SEL_PLL3_Q_CK
  2181. #define STM32_SPI4CLK STM32_PLL3_Q_CK
  2182. #define STM32_SPI5CLK STM32_PLL3_Q_CK
  2183. #elif STM32_SPI45SEL == STM32_SPI45SEL_HSI_KER_CK
  2184. #define STM32_SPI4CLK STM32_HSI_CK
  2185. #define STM32_SPI5CLK STM32_HSI_CK
  2186. #elif STM32_SPI45SEL == STM32_SPI45SEL_CSI_KER_CK
  2187. #define STM32_SPI4CLK STM32_CSI_CK
  2188. #define STM32_SPI5CLK STM32_CSI_CK
  2189. #elif STM32_SPI45SEL == STM32_SPI45SEL_HSE_CK
  2190. #define STM32_SPI4CLK STM32_HSE_CK
  2191. #define STM32_SPI5CLK STM32_HSE_CK
  2192. #else
  2193. #error "invalid source selected for STM32_SPI45SEL clock"
  2194. #endif
  2195. #if (STM32_SPI6SEL == STM32_SPI6SEL_PCLK4) || defined(__DOXYGEN__)
  2196. /**
  2197. * @brief SPI6 clock.
  2198. */
  2199. #define STM32_SPI6CLK STM32_PCLK4
  2200. #elif STM32_SPI6SEL == STM32_SPI6SEL_PLL2_Q_CK
  2201. #define STM32_SPI6CLK STM32_PLL2_Q_CK
  2202. #elif STM32_SPI6SEL == STM32_SPI6SEL_PLL3_Q_CK
  2203. #define STM32_SPI6CLK STM32_PLL3_Q_CK
  2204. #elif STM32_SPI6SEL == STM32_SPI6SEL_HSI_KER_CK
  2205. #define STM32_SPI6CLK STM32_HSI_CK
  2206. #elif STM32_SPI6SEL == STM32_SPI6SEL_CSI_KER_CK
  2207. #define STM32_SPI6CLK STM32_CSI_CK
  2208. #elif STM32_SPI6SEL == STM32_SPI6SEL_HSE_CK
  2209. #define STM32_SPI6CLK STM32_HSE_CK
  2210. #else
  2211. #error "invalid source selected for STM32_SPI6SEL clock"
  2212. #endif
  2213. #if (STM32_I2C123SEL == STM32_I2C123SEL_PCLK1) || defined(__DOXYGEN__)
  2214. /**
  2215. * @brief I2C1 clock.
  2216. */
  2217. #define STM32_I2C1CLK STM32_PCLK1
  2218. /**
  2219. * @brief I2C2 clock.
  2220. */
  2221. #define STM32_I2C2CLK STM32_PCLK1
  2222. /**
  2223. * @brief I2C2 clock.
  2224. */
  2225. #define STM32_I2C2CLK STM32_PCLK1
  2226. #elif STM32_I2C123SEL == STM32_I2C123SEL_PLL3_R_CK
  2227. #define STM32_I2C1CLK STM32_PLL3_R_CK
  2228. #define STM32_I2C2CLK STM32_PLL3_R_CK
  2229. #define STM32_I2C2CLK STM32_PLL3_R_CK
  2230. #elif STM32_I2C123SEL == STM32_I2C123SEL_HSI_KER_CK
  2231. #define STM32_I2C1CLK STM32_HSI_CK
  2232. #define STM32_I2C2CLK STM32_HSI_CK
  2233. #define STM32_I2C2CLK STM32_HSI_CK
  2234. #elif STM32_I2C123SEL == STM32_I2C123SEL_CSI_KER_CK
  2235. #define STM32_I2C1CLK STM32_CSI_CK
  2236. #define STM32_I2C2CLK STM32_CSI_CK
  2237. #define STM32_I2C2CLK STM32_CSI_CK
  2238. #else
  2239. #error "invalid source selected for STM32_I2C123SEL clock"
  2240. #endif
  2241. #if (STM32_I2C4SEL == STM32_I2C4SEL_PCLK4) || defined(__DOXYGEN__)
  2242. /**
  2243. * @brief I2C1 clock.
  2244. */
  2245. #define STM32_I2C4CLK STM32_PCLK4
  2246. #elif STM32_I2C4SEL == STM32_I2C4SEL_PLL3_R_CK
  2247. #define STM32_I2C4CLK STM32_PLL3_R_CK
  2248. #elif STM32_I2C4SEL == STM32_I2C4SEL_HSI_KER_CK
  2249. #define STM32_I2C4CLK STM32_HSI_CK
  2250. #elif STM32_I2C4SEL == STM32_I2C4SEL_CSI_KER_CK
  2251. #define STM32_I2C4CLK STM32_CSI_CK
  2252. #else
  2253. #error "invalid source selected for STM32_I2C4SEL clock"
  2254. #endif
  2255. #if (STM32_SAI1SEL == STM32_SAI1SEL_PLL1_Q_CK) || defined(__DOXYGEN__)
  2256. /**
  2257. * @brief SAI1 clock.
  2258. */
  2259. #define STM32_SAI1CLK STM32_PLL1_Q_CK
  2260. #elif STM32_SAI1SEL == STM32_SAI1SEL_PLL2_P_CK
  2261. #define STM32_SAI1CLK STM32_PLL2_P_CK
  2262. #elif STM32_SAI1SEL == STM32_SAI1SEL_PLL3_P_CK
  2263. #define STM32_SAI1CLK STM32_PLL3_P_CK
  2264. #elif STM32_SAI1SEL == STM32_SAI1SEL_I2S_CKIN
  2265. #define STM32_SAI1CLK 0 /* Unknown, would require a board value */
  2266. #elif STM32_SAI1SEL == STM32_SAI1SEL_PER_CK
  2267. #define STM32_SAI1CLK STM32_PER_CK
  2268. #else
  2269. #error "invalid source selected for STM32_SAI1SEL clock"
  2270. #endif
  2271. #if (STM32_SAI23SEL == STM32_SAI23SEL_PLL1_Q_CK) || defined(__DOXYGEN__)
  2272. /**
  2273. * @brief SAI2 clock.
  2274. */
  2275. #define STM32_SAI2CLK STM32_PLL1_Q_CK
  2276. /**
  2277. * @brief SAI3 clock.
  2278. */
  2279. #define STM32_SAI3CLK STM32_PLL1_Q_CK
  2280. #elif STM32_SAI23SEL == STM32_SAI23SEL_PLL2_P_CK
  2281. #define STM32_SAI2CLK STM32_PLL2_P_CK
  2282. #define STM32_SAI3CLK STM32_PLL2_P_CK
  2283. #elif STM32_SAI23SEL == STM32_SAI23SEL_PLL3_P_CK
  2284. #define STM32_SAI2CLK STM32_PLL3_P_CK
  2285. #define STM32_SAI3CLK STM32_PLL3_P_CK
  2286. #elif STM32_SAI23SEL == STM32_SAI23SEL_I2S_CKIN
  2287. #define STM32_SAI2CLK 0 /* Unknown, would require a board value */
  2288. #define STM32_SAI3CLK 0 /* Unknown, would require a board value */
  2289. #elif STM32_SAI23SEL == STM32_SAI23SEL_PER_CK
  2290. #define STM32_SAI2CLK STM32_PER_CK
  2291. #define STM32_SAI3CLK STM32_PER_CK
  2292. #else
  2293. #error "invalid source selected for STM32_SAI23SEL clock"
  2294. #endif
  2295. #if (STM32_SAI4ASEL == STM32_SAI4ASEL_PLL1_Q_CK) || defined(__DOXYGEN__)
  2296. /**
  2297. * @brief SAI4A clock.
  2298. */
  2299. #define STM32_SAI4ACLK STM32_PLL1_Q_CK
  2300. #elif STM32_SAI4ASEL == STM32_SAI4ASEL_PLL2_P_CK
  2301. #define STM32_SAI4ACLK STM32_PLL2_P_CK
  2302. #elif STM32_SAI4ASEL == STM32_SAI4ASEL_PLL3_P_CK
  2303. #define STM32_SAI4ACLK STM32_PLL3_P_CK
  2304. #elif STM32_SAI4ASEL == STM32_SAI4ASEL_I2S_CKIN
  2305. #define STM32_SAI4ACLK 0 /* Unknown, would require a board value */
  2306. #elif STM32_SAI4ASEL == STM32_SAI4ASEL_PER_CK
  2307. #define STM32_SAI4ACLK STM32_PER_CK
  2308. #else
  2309. #error "invalid source selected for STM32_SAI4ASEL clock"
  2310. #endif
  2311. #if (STM32_SAI4BSEL == STM32_SAI4BSEL_PLL1_Q_CK) || defined(__DOXYGEN__)
  2312. /**
  2313. * @brief SAI4B clock.
  2314. */
  2315. #define STM32_SAI4BCLK STM32_PLL1_Q_CK
  2316. #elif STM32_SAI4BSEL == STM32_SAI4BSEL_PLL2_P_CK
  2317. #define STM32_SAI4BCLK STM32_PLL2_P_CK
  2318. #elif STM32_SAI4BSEL == STM32_SAI4BSEL_PLL3_P_CK
  2319. #define STM32_SAI4BCLK STM32_PLL3_P_CK
  2320. #elif STM32_SAI4BSEL == STM32_SAI4BSEL_I2S_CKIN
  2321. #define STM32_SAI4BCLK 0 /* Unknown, would require a board value */
  2322. #elif STM32_SAI4BSEL == STM32_SAI4BSEL_PER_CK
  2323. #define STM32_SAI4BCLK STM32_PER_CK
  2324. #else
  2325. #error "invalid source selected for STM32_SAI4BSEL clock"
  2326. #endif
  2327. #if (STM32_USBSEL == STM32_USBSEL_DISABLE) || defined(__DOXYGEN__)
  2328. /**
  2329. * @brief USB clock.
  2330. */
  2331. #define STM32_USBCLK 0
  2332. #elif STM32_USBSEL == STM32_USBSEL_PLL1_Q_CK
  2333. #define STM32_USBCLK STM32_PLL1_Q_CK
  2334. #elif STM32_USBSEL == STM32_USBSEL_PLL3_Q_CK
  2335. #define STM32_USBCLK STM32_PLL3_Q_CK
  2336. #elif STM32_USBSEL == STM32_USBSEL_HSI48_CK
  2337. #define STM32_USBCLK STM32_HSI48_CK
  2338. #else
  2339. #error "invalid source selected for STM32_USBSEL clock"
  2340. #endif
  2341. #if (STM32_SDMMCSEL == STM32_SDMMCSEL_PLL1_Q_CK) || defined(__DOXYGEN__)
  2342. /**
  2343. * @brief SDMMC frequency.
  2344. */
  2345. #define STM32_SDMMCCLK STM32_PLL1_Q_CK
  2346. #elif STM32_SDMMCSEL == STM32_SDMMCSEL_PLL2_R_CK
  2347. #define STM32_SDMMCCLK STM32_PLL2_R_CK
  2348. #else
  2349. #error "invalid source selected for STM32_SDMMCSEL clock"
  2350. #endif
  2351. #if (STM32_QSPISEL == STM32_QSPISEL_HCLK) || defined(__DOXYGEN__)
  2352. /**
  2353. * @brief QSPI frequency.
  2354. */
  2355. #define STM32_QSPICLK STM32_HCLK
  2356. #elif STM32_QSPISEL == STM32_QSPISEL_PLL1_Q_CK
  2357. #define STM32_QSPICLK STM32_PLL1_Q_CK
  2358. #elif STM32_QSPISEL == STM32_QSPISEL_PLL2_R_CK
  2359. #define STM32_QSPICLK STM32_PLL2_R_CK
  2360. #elif STM32_QSPISEL == STM32_QSPISEL_PER_CK
  2361. #define STM32_QSPICLK STM32_PER_CK
  2362. #else
  2363. #error "invalid source selected for STM32_QSPISEL clock"
  2364. #endif
  2365. #if (STM32_FMCSEL == STM32_FMCSEL_HCLK) || defined(__DOXYGEN__)
  2366. /**
  2367. * @brief FMC frequency.
  2368. */
  2369. #define STM32_FMCCLK STM32_HCLK
  2370. #elif STM32_FMCSEL == STM32_FMCSEL_PLL1_Q_CK
  2371. #define STM32_FMCCLK STM32_PLL1_Q_CK
  2372. #elif STM32_FMCSEL == STM32_FMCSEL_PLL2_R_CK
  2373. #define STM32_FMCCLK STM32_PLL2_R_CK
  2374. #elif STM32_FMCSEL == STM32_FMCSEL_PER_CK
  2375. #define STM32_FMCCLK STM32_PER_CK
  2376. #else
  2377. #error "invalid source selected for STM32_FMCSEL clock"
  2378. #endif
  2379. #if (STM32_SWPSEL == STM32_SWPSEL_PCLK1) || defined(__DOXYGEN__)
  2380. /**
  2381. * @brief SDMMC frequency.
  2382. */
  2383. #define STM32_SWPCLK STM32_PCLK1
  2384. #elif STM32_SWPSEL == STM32_SWPSEL_HSI_KER_CK
  2385. #define STM32_SWPCLK STM32_HSI_CK
  2386. #else
  2387. #error "invalid source selected for STM32_SWPSEL clock"
  2388. #endif
  2389. #if (STM32_FDCANSEL == STM32_FDCANSEL_HSE_CK) || defined(__DOXYGEN__)
  2390. /**
  2391. * @brief FDCAN frequency.
  2392. */
  2393. #define STM32_FDCANCLK STM32_HSE_CK
  2394. #elif STM32_FDCANSEL == STM32_FDCANSEL_PLL1_Q_CK
  2395. #define STM32_FDCANCLK STM32_PLL1_Q_CK
  2396. #elif STM32_FDCANSEL == STM32_FDCANSEL_PLL2_Q_CK
  2397. #define STM32_FDCANCLK STM32_PLL2_Q_CK
  2398. #else
  2399. #error "invalid source selected for STM32_FDCANSEL clock"
  2400. #endif
  2401. #if (STM32_DFSDM1SEL == STM32_DFSDM1SEL_PCLK2) || defined(__DOXYGEN__)
  2402. /**
  2403. * @brief SDMMC frequency.
  2404. */
  2405. #define STM32_DFSDM1CLK STM32_PCLK2
  2406. #elif STM32_DFSDM1SEL == STM32_DFSDM1SEL_SYS_CK
  2407. #define STM32_DFSDM1CLK STM32_SYS_CK
  2408. #else
  2409. #error "invalid source selected for STM32_DFSDM1SEL clock"
  2410. #endif
  2411. #if (STM32_SPDIFSEL == STM32_SPDIFSEL_PLL1_Q_CK) || defined(__DOXYGEN__)
  2412. /**
  2413. * @brief SPDIF frequency.
  2414. */
  2415. #define STM32_SPDIFCLK STM32_PLL1_Q_CK
  2416. #elif STM32_SPDIFSEL == STM32_SPDIFSEL_PLL2_R_CK
  2417. #define STM32_SPDIFCLK STM32_PLL2_R_CK
  2418. #elif STM32_SPDIFSEL == STM32_SPDIFSEL_PLL3_R_CK
  2419. #define STM32_SPDIFCLK STM32_PLL3_R_CK
  2420. #elif STM32_SPDIFSEL == STM32_SPDIFSEL_HSI_KET_CLK
  2421. #define STM32_SPDIFCLK STM32_HSI_CK
  2422. #else
  2423. #error "invalid source selected for STM32_SPDIFSEL clock"
  2424. #endif
  2425. #if (STM32_CECSEL == STM32_CECSEL_LSE_CK) || defined(__DOXYGEN__)
  2426. /**
  2427. * @brief CEC frequency.
  2428. */
  2429. #define STM32_CECCLK STM32_LSE_CK
  2430. #elif STM32_CECSEL == STM32_CECSEL_LSI_CK
  2431. #define STM32_CECCLK STM32_LSI_CK
  2432. #elif STM32_CECSEL == STM32_CECSEL_CSI_KER_CK
  2433. #define STM32_CECCLK STM32_CSI_CK
  2434. #elif STM32_CECSEL == STM32_CECSEL_DISABLE
  2435. #define STM32_CECCLK 0
  2436. #else
  2437. #error "invalid source selected for STM32_CECSEL clock"
  2438. #endif
  2439. #if (STM32_RNGSEL == STM32_RNGSEL_HSI48_CK) || defined(__DOXYGEN__)
  2440. /**
  2441. * @brief RNG frequency.
  2442. */
  2443. #define STM32_RNGCLK STM32_HSI48_CK
  2444. #elif STM32_RNGSEL == STM32_RNGSEL_PLL1_Q_CK
  2445. #define STM32_RNGCLK STM32_PLL1_Q_CK
  2446. #elif STM32_RNGSEL == STM32_RNGSEL_LSE_CK
  2447. #define STM32_RNGCLK STM32_LSE_CK
  2448. #elif STM32_RNGSEL == STM32_RNGSEL_LSI_CK
  2449. #define STM32_RNGCLK STM32_LSI_CK
  2450. #else
  2451. #error "invalid source selected for STM32_RNGSEL clock"
  2452. #endif
  2453. #if (STM32_ADCSEL == STM32_ADCSEL_PLL2_P_CK) || defined(__DOXYGEN__)
  2454. /**
  2455. * @brief ADC frequency.
  2456. */
  2457. #define STM32_ADCCLK STM32_PLL2_P_CK
  2458. #elif STM32_ADCSEL == STM32_ADCSEL_PLL3_R_CK
  2459. #define STM32_ADCCLK STM32_PLL3_R_CK
  2460. #elif STM32_ADCSEL == STM32_ADCSEL_PER_CK
  2461. #define STM32_ADCCLK STM32_PER_CK
  2462. #elif STM32_ADCSEL == STM32_ADCSEL_DISABLE
  2463. #define STM32_ADCCLK 0
  2464. #else
  2465. #error "invalid source selected for STM32_ADCSEL clock"
  2466. #endif
  2467. /**
  2468. * @brief SDMMC frequency (applies to both SDMMC1 and SDMMC2)
  2469. */
  2470. #if (STM32_SDMMCSEL == STM32_SDMMCSEL_PLL1_Q_CK) || defined(__DOXYGEN__)
  2471. #define STM32_SDMMCCLK STM32_PLL1_Q_CK
  2472. #elif STM32_SDMMCSEL == STM32_SDMMCSEL_PLL2_R_CK
  2473. #define STM32_SDMMCCLK STM32_PLL2_R_CK
  2474. #else
  2475. #error "invalid source selected for SDMMC clock"
  2476. #endif
  2477. /*===========================================================================*/
  2478. /* Driver data structures and types. */
  2479. /*===========================================================================*/
  2480. /*===========================================================================*/
  2481. /* Driver macros. */
  2482. /*===========================================================================*/
  2483. /*===========================================================================*/
  2484. /* External declarations. */
  2485. /*===========================================================================*/
  2486. /* Various helpers.*/
  2487. #include "nvic.h"
  2488. #include "cache.h"
  2489. #include "mpu_v7m.h"
  2490. #include "stm32_isr.h"
  2491. #include "stm32_dma.h"
  2492. #include "stm32_bdma.h"
  2493. #include "stm32_rcc.h"
  2494. #ifdef __cplusplus
  2495. extern "C" {
  2496. #endif
  2497. void hal_lld_init(void);
  2498. void stm32_clock_init(void);
  2499. #ifdef __cplusplus
  2500. }
  2501. #endif
  2502. #endif /* HAL_LLD_H */
  2503. /** @} */