stm32f4xx_rcc.c 130 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_rcc.c
  4. * @author MCD Application Team
  5. * @version V1.8.1
  6. * @date 27-January-2022
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the Reset and clock control (RCC) peripheral:
  9. * + Internal/external clocks, PLL, CSS and MCO configuration
  10. * + System, AHB and APB busses clocks configuration
  11. * + Peripheral clocks configuration
  12. * + Interrupts and flags management
  13. *
  14. @verbatim
  15. ===============================================================================
  16. ##### RCC specific features #####
  17. ===============================================================================
  18. [..]
  19. After reset the device is running from Internal High Speed oscillator
  20. (HSI 16MHz) with Flash 0 wait state, Flash prefetch buffer, D-Cache
  21. and I-Cache are disabled, and all peripherals are off except internal
  22. SRAM, Flash and JTAG.
  23. (+) There is no prescaler on High speed (AHB) and Low speed (APB) busses;
  24. all peripherals mapped on these busses are running at HSI speed.
  25. (+) The clock for all peripherals is switched off, except the SRAM and FLASH.
  26. (+) All GPIOs are in input floating state, except the JTAG pins which
  27. are assigned to be used for debug purpose.
  28. [..]
  29. Once the device started from reset, the user application has to:
  30. (+) Configure the clock source to be used to drive the System clock
  31. (if the application needs higher frequency/performance)
  32. (+) Configure the System clock frequency and Flash settings
  33. (+) Configure the AHB and APB busses prescalers
  34. (+) Enable the clock for the peripheral(s) to be used
  35. (+) Configure the clock source(s) for peripherals which clocks are not
  36. derived from the System clock (I2S, RTC, ADC, USB OTG FS/SDIO/RNG)
  37. @endverbatim
  38. ******************************************************************************
  39. * @attention
  40. *
  41. * Copyright (c) 2016 STMicroelectronics.
  42. * All rights reserved.
  43. *
  44. * This software is licensed under terms that can be found in the LICENSE file
  45. * in the root directory of this software component.
  46. * If no LICENSE file comes with this software, it is provided AS-IS.
  47. *
  48. ******************************************************************************
  49. */
  50. /* Includes ------------------------------------------------------------------*/
  51. #include "stm32f4xx_rcc.h"
  52. /** @addtogroup STM32F4xx_StdPeriph_Driver
  53. * @{
  54. */
  55. /** @defgroup RCC
  56. * @brief RCC driver modules
  57. * @{
  58. */
  59. /* Private typedef -----------------------------------------------------------*/
  60. /* Private define ------------------------------------------------------------*/
  61. /* ------------ RCC registers bit address in the alias region ----------- */
  62. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  63. /* --- CR Register ---*/
  64. /* Alias word address of HSION bit */
  65. #define CR_OFFSET (RCC_OFFSET + 0x00)
  66. #define HSION_BitNumber 0x00
  67. #define CR_HSION_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (HSION_BitNumber * 4))
  68. /* Alias word address of CSSON bit */
  69. #define CSSON_BitNumber 0x13
  70. #define CR_CSSON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))
  71. /* Alias word address of PLLON bit */
  72. #define PLLON_BitNumber 0x18
  73. #define CR_PLLON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))
  74. /* Alias word address of PLLI2SON bit */
  75. #define PLLI2SON_BitNumber 0x1A
  76. #define CR_PLLI2SON_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLI2SON_BitNumber * 4))
  77. /* Alias word address of PLLSAION bit */
  78. #define PLLSAION_BitNumber 0x1C
  79. #define CR_PLLSAION_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLSAION_BitNumber * 4))
  80. /* --- CFGR Register ---*/
  81. /* Alias word address of I2SSRC bit */
  82. #define CFGR_OFFSET (RCC_OFFSET + 0x08)
  83. #define I2SSRC_BitNumber 0x17
  84. #define CFGR_I2SSRC_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (I2SSRC_BitNumber * 4))
  85. /* --- BDCR Register ---*/
  86. /* Alias word address of RTCEN bit */
  87. #define BDCR_OFFSET (RCC_OFFSET + 0x70)
  88. #define RTCEN_BitNumber 0x0F
  89. #define BDCR_RTCEN_BB (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (RTCEN_BitNumber * 4))
  90. /* Alias word address of BDRST bit */
  91. #define BDRST_BitNumber 0x10
  92. #define BDCR_BDRST_BB (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (BDRST_BitNumber * 4))
  93. /* --- CSR Register ---*/
  94. /* Alias word address of LSION bit */
  95. #define CSR_OFFSET (RCC_OFFSET + 0x74)
  96. #define LSION_BitNumber 0x00
  97. #define CSR_LSION_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))
  98. /* --- DCKCFGR Register ---*/
  99. /* Alias word address of TIMPRE bit */
  100. #define DCKCFGR_OFFSET (RCC_OFFSET + 0x8C)
  101. #define TIMPRE_BitNumber 0x18
  102. #define DCKCFGR_TIMPRE_BB (PERIPH_BB_BASE + (DCKCFGR_OFFSET * 32) + (TIMPRE_BitNumber * 4))
  103. /* --- CFGR Register ---*/
  104. #define RCC_CFGR_OFFSET (RCC_OFFSET + 0x08)
  105. #if defined(STM32F410xx)
  106. /* Alias word address of MCO1EN bit */
  107. #define RCC_MCO1EN_BIT_NUMBER 0x8
  108. #define RCC_CFGR_MCO1EN_BB (PERIPH_BB_BASE + (RCC_CFGR_OFFSET * 32) + (RCC_MCO1EN_BIT_NUMBER * 4))
  109. /* Alias word address of MCO2EN bit */
  110. #define RCC_MCO2EN_BIT_NUMBER 0x9
  111. #define RCC_CFGR_MCO2EN_BB (PERIPH_BB_BASE + (RCC_CFGR_OFFSET * 32) + (RCC_MCO2EN_BIT_NUMBER * 4))
  112. #endif /* STM32F410xx */
  113. /* ---------------------- RCC registers bit mask ------------------------ */
  114. /* CFGR register bit mask */
  115. #define CFGR_MCO2_RESET_MASK ((uint32_t)0x07FFFFFF)
  116. #define CFGR_MCO1_RESET_MASK ((uint32_t)0xF89FFFFF)
  117. /* RCC Flag Mask */
  118. #define FLAG_MASK ((uint8_t)0x1F)
  119. /* CR register byte 3 (Bits[23:16]) base address */
  120. #define CR_BYTE3_ADDRESS ((uint32_t)0x40023802)
  121. /* CIR register byte 2 (Bits[15:8]) base address */
  122. #define CIR_BYTE2_ADDRESS ((uint32_t)(RCC_BASE + 0x0C + 0x01))
  123. /* CIR register byte 3 (Bits[23:16]) base address */
  124. #define CIR_BYTE3_ADDRESS ((uint32_t)(RCC_BASE + 0x0C + 0x02))
  125. /* BDCR register base address */
  126. #define BDCR_ADDRESS (PERIPH_BASE + BDCR_OFFSET)
  127. /* Private macro -------------------------------------------------------------*/
  128. /* Private variables ---------------------------------------------------------*/
  129. static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
  130. /* Private function prototypes -----------------------------------------------*/
  131. /* Private functions ---------------------------------------------------------*/
  132. /** @defgroup RCC_Private_Functions
  133. * @{
  134. */
  135. /** @defgroup RCC_Group1 Internal and external clocks, PLL, CSS and MCO configuration functions
  136. * @brief Internal and external clocks, PLL, CSS and MCO configuration functions
  137. *
  138. @verbatim
  139. ===================================================================================
  140. ##### Internal and external clocks, PLL, CSS and MCO configuration functions #####
  141. ===================================================================================
  142. [..]
  143. This section provide functions allowing to configure the internal/external clocks,
  144. PLLs, CSS and MCO pins.
  145. (#) HSI (high-speed internal), 16 MHz factory-trimmed RC used directly or through
  146. the PLL as System clock source.
  147. (#) LSI (low-speed internal), 32 KHz low consumption RC used as IWDG and/or RTC
  148. clock source.
  149. (#) HSE (high-speed external), 4 to 26 MHz crystal oscillator used directly or
  150. through the PLL as System clock source. Can be used also as RTC clock source.
  151. (#) LSE (low-speed external), 32 KHz oscillator used as RTC clock source.
  152. (#) PLL (clocked by HSI or HSE), featuring two different output clocks:
  153. (++) The first output is used to generate the high speed system clock (up to 168 MHz)
  154. (++) The second output is used to generate the clock for the USB OTG FS (48 MHz),
  155. the random analog generator (<=48 MHz) and the SDIO (<= 48 MHz).
  156. (#) PLLI2S (clocked by HSI or HSE), used to generate an accurate clock to achieve
  157. high-quality audio performance on the I2S interface or SAI interface in case
  158. of STM32F429x/439x devices.
  159. (#) PLLSAI clocked by (HSI or HSE), used to generate an accurate clock to SAI
  160. interface and LCD TFT controller available only for STM32F42xxx/43xxx/446xx/469xx/479xx devices.
  161. (#) CSS (Clock security system), once enable and if a HSE clock failure occurs
  162. (HSE used directly or through PLL as System clock source), the System clock
  163. is automatically switched to HSI and an interrupt is generated if enabled.
  164. The interrupt is linked to the Cortex-M4 NMI (Non-Maskable Interrupt)
  165. exception vector.
  166. (#) MCO1 (microcontroller clock output), used to output HSI, LSE, HSE or PLL
  167. clock (through a configurable prescaler) on PA8 pin.
  168. (#) MCO2 (microcontroller clock output), used to output HSE, PLL, SYSCLK or PLLI2S
  169. clock (through a configurable prescaler) on PC9 pin.
  170. @endverbatim
  171. * @{
  172. */
  173. /**
  174. * @brief Resets the RCC clock configuration to the default reset state.
  175. * @note The default reset state of the clock configuration is given below:
  176. * - HSI ON and used as system clock source
  177. * - HSE, PLL and PLLI2S OFF
  178. * - AHB, APB1 and APB2 prescaler set to 1.
  179. * - CSS, MCO1 and MCO2 OFF
  180. * - All interrupts disabled
  181. * @note This function doesn't modify the configuration of the
  182. * - Peripheral clocks
  183. * - LSI, LSE and RTC clocks
  184. * @param None
  185. * @retval None
  186. */
  187. void RCC_DeInit(void)
  188. {
  189. /* Set HSION bit */
  190. RCC->CR |= (uint32_t)0x00000001;
  191. /* Reset CFGR register */
  192. RCC->CFGR = 0x00000000;
  193. /* Reset HSEON, CSSON, PLLON, PLLI2S and PLLSAI(STM32F42xxx/43xxx/446xx/469xx/479xx devices) bits */
  194. RCC->CR &= (uint32_t)0xEAF6FFFF;
  195. /* Reset PLLCFGR register */
  196. RCC->PLLCFGR = 0x24003010;
  197. #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F413_423xx) || defined(STM32F469_479xx)
  198. /* Reset PLLI2SCFGR register */
  199. RCC->PLLI2SCFGR = 0x20003000;
  200. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F411xE || STM32F446xx || STM32F413_423xx || STM32F469_479xx */
  201. #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx) || defined(STM32F469_479xx)
  202. /* Reset PLLSAICFGR register, only available for STM32F42xxx/43xxx/446xx/469xx/479xx devices */
  203. RCC->PLLSAICFGR = 0x24003000;
  204. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F446xx || STM32F469_479xx */
  205. /* Reset HSEBYP bit */
  206. RCC->CR &= (uint32_t)0xFFFBFFFF;
  207. /* Disable all interrupts */
  208. RCC->CIR = 0x00000000;
  209. /* Disable Timers clock prescalers selection, only available for STM32F42/43xxx and STM32F413_423xx devices */
  210. RCC->DCKCFGR = 0x00000000;
  211. #if defined(STM32F410xx) || defined(STM32F413_423xx)
  212. /* Disable LPTIM and FMPI2C clock prescalers selection, only available for STM32F410xx and STM32F413_423xx devices */
  213. RCC->DCKCFGR2 = 0x00000000;
  214. #endif /* STM32F410xx || STM32F413_423xx */
  215. }
  216. /**
  217. * @brief Configures the External High Speed oscillator (HSE).
  218. * @note After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application
  219. * software should wait on HSERDY flag to be set indicating that HSE clock
  220. * is stable and can be used to clock the PLL and/or system clock.
  221. * @note HSE state can not be changed if it is used directly or through the
  222. * PLL as system clock. In this case, you have to select another source
  223. * of the system clock then change the HSE state (ex. disable it).
  224. * @note The HSE is stopped by hardware when entering STOP and STANDBY modes.
  225. * @note This function reset the CSSON bit, so if the Clock security system(CSS)
  226. * was previously enabled you have to enable it again after calling this
  227. * function.
  228. * @param RCC_HSE: specifies the new state of the HSE.
  229. * This parameter can be one of the following values:
  230. * @arg RCC_HSE_OFF: turn OFF the HSE oscillator, HSERDY flag goes low after
  231. * 6 HSE oscillator clock cycles.
  232. * @arg RCC_HSE_ON: turn ON the HSE oscillator
  233. * @arg RCC_HSE_Bypass: HSE oscillator bypassed with external clock
  234. * @retval None
  235. */
  236. void RCC_HSEConfig(uint8_t RCC_HSE)
  237. {
  238. /* Check the parameters */
  239. assert_param(IS_RCC_HSE(RCC_HSE));
  240. /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/
  241. *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE_OFF;
  242. /* Set the new HSE configuration -------------------------------------------*/
  243. *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE;
  244. }
  245. /**
  246. * @brief Waits for HSE start-up.
  247. * @note This functions waits on HSERDY flag to be set and return SUCCESS if
  248. * this flag is set, otherwise returns ERROR if the timeout is reached
  249. * and this flag is not set. The timeout value is defined by the constant
  250. * HSE_STARTUP_TIMEOUT in stm32f4xx.h file. You can tailor it depending
  251. * on the HSE crystal used in your application.
  252. * @param None
  253. * @retval An ErrorStatus enumeration value:
  254. * - SUCCESS: HSE oscillator is stable and ready to use
  255. * - ERROR: HSE oscillator not yet ready
  256. */
  257. ErrorStatus RCC_WaitForHSEStartUp(void)
  258. {
  259. __IO uint32_t startupcounter = 0;
  260. ErrorStatus status = ERROR;
  261. FlagStatus hsestatus = RESET;
  262. /* Wait till HSE is ready and if Time out is reached exit */
  263. do
  264. {
  265. hsestatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY);
  266. startupcounter++;
  267. } while((startupcounter != HSE_STARTUP_TIMEOUT) && (hsestatus == RESET));
  268. if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET)
  269. {
  270. status = SUCCESS;
  271. }
  272. else
  273. {
  274. status = ERROR;
  275. }
  276. return (status);
  277. }
  278. /**
  279. * @brief Adjusts the Internal High Speed oscillator (HSI) calibration value.
  280. * @note The calibration is used to compensate for the variations in voltage
  281. * and temperature that influence the frequency of the internal HSI RC.
  282. * @param HSICalibrationValue: specifies the calibration trimming value.
  283. * This parameter must be a number between 0 and 0x1F.
  284. * @retval None
  285. */
  286. void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue)
  287. {
  288. uint32_t tmpreg = 0;
  289. /* Check the parameters */
  290. assert_param(IS_RCC_CALIBRATION_VALUE(HSICalibrationValue));
  291. tmpreg = RCC->CR;
  292. /* Clear HSITRIM[4:0] bits */
  293. tmpreg &= ~RCC_CR_HSITRIM;
  294. /* Set the HSITRIM[4:0] bits according to HSICalibrationValue value */
  295. tmpreg |= (uint32_t)HSICalibrationValue << 3;
  296. /* Store the new value */
  297. RCC->CR = tmpreg;
  298. }
  299. /**
  300. * @brief Enables or disables the Internal High Speed oscillator (HSI).
  301. * @note The HSI is stopped by hardware when entering STOP and STANDBY modes.
  302. * It is used (enabled by hardware) as system clock source after startup
  303. * from Reset, wakeup from STOP and STANDBY mode, or in case of failure
  304. * of the HSE used directly or indirectly as system clock (if the Clock
  305. * Security System CSS is enabled).
  306. * @note HSI can not be stopped if it is used as system clock source. In this case,
  307. * you have to select another source of the system clock then stop the HSI.
  308. * @note After enabling the HSI, the application software should wait on HSIRDY
  309. * flag to be set indicating that HSI clock is stable and can be used as
  310. * system clock source.
  311. * @param NewState: new state of the HSI.
  312. * This parameter can be: ENABLE or DISABLE.
  313. * @note When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator
  314. * clock cycles.
  315. * @retval None
  316. */
  317. void RCC_HSICmd(FunctionalState NewState)
  318. {
  319. /* Check the parameters */
  320. assert_param(IS_FUNCTIONAL_STATE(NewState));
  321. *(__IO uint32_t *) CR_HSION_BB = (uint32_t)NewState;
  322. }
  323. /**
  324. * @brief Configures the External Low Speed oscillator (LSE).
  325. * @note As the LSE is in the Backup domain and write access is denied to
  326. * this domain after reset, you have to enable write access using
  327. * PWR_BackupAccessCmd(ENABLE) function before to configure the LSE
  328. * (to be done once after reset).
  329. * @note After enabling the LSE (RCC_LSE_ON or RCC_LSE_Bypass), the application
  330. * software should wait on LSERDY flag to be set indicating that LSE clock
  331. * is stable and can be used to clock the RTC.
  332. * @param RCC_LSE: specifies the new state of the LSE.
  333. * This parameter can be one of the following values:
  334. * @arg RCC_LSE_OFF: turn OFF the LSE oscillator, LSERDY flag goes low after
  335. * 6 LSE oscillator clock cycles.
  336. * @arg RCC_LSE_ON: turn ON the LSE oscillator
  337. * @arg RCC_LSE_Bypass: LSE oscillator bypassed with external clock
  338. * @retval None
  339. */
  340. void RCC_LSEConfig(uint8_t RCC_LSE)
  341. {
  342. /* Check the parameters */
  343. assert_param(IS_RCC_LSE(RCC_LSE));
  344. /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
  345. /* Reset LSEON bit */
  346. *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;
  347. /* Reset LSEBYP bit */
  348. *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;
  349. /* Configure LSE (RCC_LSE_OFF is already covered by the code section above) */
  350. switch (RCC_LSE)
  351. {
  352. case RCC_LSE_ON:
  353. /* Set LSEON bit */
  354. *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_ON;
  355. break;
  356. case RCC_LSE_Bypass:
  357. /* Set LSEBYP and LSEON bits */
  358. *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_Bypass | RCC_LSE_ON;
  359. break;
  360. default:
  361. break;
  362. }
  363. }
  364. /**
  365. * @brief Enables or disables the Internal Low Speed oscillator (LSI).
  366. * @note After enabling the LSI, the application software should wait on
  367. * LSIRDY flag to be set indicating that LSI clock is stable and can
  368. * be used to clock the IWDG and/or the RTC.
  369. * @note LSI can not be disabled if the IWDG is running.
  370. * @param NewState: new state of the LSI.
  371. * This parameter can be: ENABLE or DISABLE.
  372. * @note When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator
  373. * clock cycles.
  374. * @retval None
  375. */
  376. void RCC_LSICmd(FunctionalState NewState)
  377. {
  378. /* Check the parameters */
  379. assert_param(IS_FUNCTIONAL_STATE(NewState));
  380. *(__IO uint32_t *) CSR_LSION_BB = (uint32_t)NewState;
  381. }
  382. #if defined(STM32F410xx) || defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx) || defined(STM32F469_479xx)
  383. /**
  384. * @brief Configures the main PLL clock source, multiplication and division factors.
  385. * @note This function must be used only when the main PLL is disabled.
  386. *
  387. * @param RCC_PLLSource: specifies the PLL entry clock source.
  388. * This parameter can be one of the following values:
  389. * @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock entry
  390. * @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock entry
  391. * @note This clock source (RCC_PLLSource) is common for the main PLL and PLLI2S.
  392. *
  393. * @param PLLM: specifies the division factor for PLL VCO input clock
  394. * This parameter must be a number between 0 and 63.
  395. * @note You have to set the PLLM parameter correctly to ensure that the VCO input
  396. * frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
  397. * of 2 MHz to limit PLL jitter.
  398. *
  399. * @param PLLN: specifies the multiplication factor for PLL VCO output clock
  400. * This parameter must be a number between 50 and 432.
  401. * @note You have to set the PLLN parameter correctly to ensure that the VCO
  402. * output frequency is between 100 and 432 MHz.
  403. *
  404. * @param PLLP: specifies the division factor for main system clock (SYSCLK)
  405. * This parameter must be a number in the range {2, 4, 6, or 8}.
  406. * @note You have to set the PLLP parameter correctly to not exceed 168 MHz on
  407. * the System clock frequency.
  408. *
  409. * @param PLLQ: specifies the division factor for OTG FS, SDIO and RNG clocks
  410. * This parameter must be a number between 4 and 15.
  411. *
  412. * @param PLLR: specifies the division factor for I2S, SAI, SYSTEM, SPDIF in STM32F446xx devices
  413. * This parameter must be a number between 2 and 7.
  414. *
  415. * @note If the USB OTG FS is used in your application, you have to set the
  416. * PLLQ parameter correctly to have 48 MHz clock for the USB. However,
  417. * the SDIO and RNG need a frequency lower than or equal to 48 MHz to work
  418. * correctly.
  419. *
  420. * @retval None
  421. */
  422. void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ, uint32_t PLLR)
  423. {
  424. /* Check the parameters */
  425. assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));
  426. assert_param(IS_RCC_PLLM_VALUE(PLLM));
  427. assert_param(IS_RCC_PLLN_VALUE(PLLN));
  428. assert_param(IS_RCC_PLLP_VALUE(PLLP));
  429. assert_param(IS_RCC_PLLQ_VALUE(PLLQ));
  430. assert_param(IS_RCC_PLLR_VALUE(PLLR));
  431. RCC->PLLCFGR = PLLM | (PLLN << 6) | (((PLLP >> 1) -1) << 16) | (RCC_PLLSource) |
  432. (PLLQ << 24) | (PLLR << 28);
  433. }
  434. #endif /* STM32F410xx || STM32F412xG || STM32F413_423xx || STM32F446xx || STM32F469_479xx */
  435. #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F411xE)
  436. /**
  437. * @brief Configures the main PLL clock source, multiplication and division factors.
  438. * @note This function must be used only when the main PLL is disabled.
  439. *
  440. * @param RCC_PLLSource: specifies the PLL entry clock source.
  441. * This parameter can be one of the following values:
  442. * @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock entry
  443. * @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock entry
  444. * @note This clock source (RCC_PLLSource) is common for the main PLL and PLLI2S.
  445. *
  446. * @param PLLM: specifies the division factor for PLL VCO input clock
  447. * This parameter must be a number between 0 and 63.
  448. * @note You have to set the PLLM parameter correctly to ensure that the VCO input
  449. * frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
  450. * of 2 MHz to limit PLL jitter.
  451. *
  452. * @param PLLN: specifies the multiplication factor for PLL VCO output clock
  453. * This parameter must be a number between 50 and 432.
  454. * @note You have to set the PLLN parameter correctly to ensure that the VCO
  455. * output frequency is between 100 and 432 MHz.
  456. *
  457. * @param PLLP: specifies the division factor for main system clock (SYSCLK)
  458. * This parameter must be a number in the range {2, 4, 6, or 8}.
  459. * @note You have to set the PLLP parameter correctly to not exceed 168 MHz on
  460. * the System clock frequency.
  461. *
  462. * @param PLLQ: specifies the division factor for OTG FS, SDIO and RNG clocks
  463. * This parameter must be a number between 4 and 15.
  464. * @note If the USB OTG FS is used in your application, you have to set the
  465. * PLLQ parameter correctly to have 48 MHz clock for the USB. However,
  466. * the SDIO and RNG need a frequency lower than or equal to 48 MHz to work
  467. * correctly.
  468. *
  469. * @retval None
  470. */
  471. void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ)
  472. {
  473. /* Check the parameters */
  474. assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));
  475. assert_param(IS_RCC_PLLM_VALUE(PLLM));
  476. assert_param(IS_RCC_PLLN_VALUE(PLLN));
  477. assert_param(IS_RCC_PLLP_VALUE(PLLP));
  478. assert_param(IS_RCC_PLLQ_VALUE(PLLQ));
  479. RCC->PLLCFGR = PLLM | (PLLN << 6) | (((PLLP >> 1) -1) << 16) | (RCC_PLLSource) |
  480. (PLLQ << 24);
  481. }
  482. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F411xE */
  483. /**
  484. * @brief Enables or disables the main PLL.
  485. * @note After enabling the main PLL, the application software should wait on
  486. * PLLRDY flag to be set indicating that PLL clock is stable and can
  487. * be used as system clock source.
  488. * @note The main PLL can not be disabled if it is used as system clock source
  489. * @note The main PLL is disabled by hardware when entering STOP and STANDBY modes.
  490. * @param NewState: new state of the main PLL. This parameter can be: ENABLE or DISABLE.
  491. * @retval None
  492. */
  493. void RCC_PLLCmd(FunctionalState NewState)
  494. {
  495. /* Check the parameters */
  496. assert_param(IS_FUNCTIONAL_STATE(NewState));
  497. *(__IO uint32_t *) CR_PLLON_BB = (uint32_t)NewState;
  498. }
  499. #if defined(STM32F40_41xxx) || defined(STM32F401xx)
  500. /**
  501. * @brief Configures the PLLI2S clock multiplication and division factors.
  502. *
  503. * @note This function can be used only for STM32F405xx/407xx, STM32F415xx/417xx
  504. * or STM32F401xx devices.
  505. *
  506. * @note This function must be used only when the PLLI2S is disabled.
  507. * @note PLLI2S clock source is common with the main PLL (configured in
  508. * RCC_PLLConfig function )
  509. *
  510. * @param PLLI2SN: specifies the multiplication factor for PLLI2S VCO output clock
  511. * This parameter must be a number between 50 and 432.
  512. * @note You have to set the PLLI2SN parameter correctly to ensure that the VCO
  513. * output frequency is between 100 and 432 MHz.
  514. *
  515. * @param PLLI2SR: specifies the division factor for I2S clock
  516. * This parameter must be a number between 2 and 7.
  517. * @note You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
  518. * on the I2S clock frequency.
  519. *
  520. * @retval None
  521. */
  522. void RCC_PLLI2SConfig(uint32_t PLLI2SN, uint32_t PLLI2SR)
  523. {
  524. /* Check the parameters */
  525. assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SN));
  526. assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SR));
  527. RCC->PLLI2SCFGR = (PLLI2SN << 6) | (PLLI2SR << 28);
  528. }
  529. #endif /* STM32F40_41xxx || STM32F401xx */
  530. #if defined(STM32F411xE)
  531. /**
  532. * @brief Configures the PLLI2S clock multiplication and division factors.
  533. *
  534. * @note This function can be used only for STM32F411xE devices.
  535. *
  536. * @note This function must be used only when the PLLI2S is disabled.
  537. * @note PLLI2S clock source is common with the main PLL (configured in
  538. * RCC_PLLConfig function )
  539. *
  540. * @param PLLI2SM: specifies the division factor for PLLI2S VCO input clock
  541. * This parameter must be a number between Min_Data = 2 and Max_Data = 63.
  542. * @note You have to set the PLLI2SM parameter correctly to ensure that the VCO input
  543. * frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
  544. * of 2 MHz to limit PLLI2S jitter.
  545. *
  546. * @param PLLI2SN: specifies the multiplication factor for PLLI2S VCO output clock
  547. * This parameter must be a number between 50 and 432.
  548. * @note You have to set the PLLI2SN parameter correctly to ensure that the VCO
  549. * output frequency is between 100 and 432 MHz.
  550. *
  551. * @param PLLI2SR: specifies the division factor for I2S clock
  552. * This parameter must be a number between 2 and 7.
  553. * @note You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
  554. * on the I2S clock frequency.
  555. *
  556. * @retval None
  557. */
  558. void RCC_PLLI2SConfig(uint32_t PLLI2SN, uint32_t PLLI2SR, uint32_t PLLI2SM)
  559. {
  560. /* Check the parameters */
  561. assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SN));
  562. assert_param(IS_RCC_PLLI2SM_VALUE(PLLI2SM));
  563. assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SR));
  564. RCC->PLLI2SCFGR = (PLLI2SN << 6) | (PLLI2SR << 28) | PLLI2SM;
  565. }
  566. #endif /* STM32F411xE */
  567. #if defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F469_479xx)
  568. /**
  569. * @brief Configures the PLLI2S clock multiplication and division factors.
  570. *
  571. * @note This function can be used only for STM32F42xxx/43xxx devices
  572. *
  573. * @note This function must be used only when the PLLI2S is disabled.
  574. * @note PLLI2S clock source is common with the main PLL (configured in
  575. * RCC_PLLConfig function )
  576. *
  577. * @param PLLI2SN: specifies the multiplication factor for PLLI2S VCO output clock
  578. * This parameter must be a number between 50 and 432.
  579. * @note You have to set the PLLI2SN parameter correctly to ensure that the VCO
  580. * output frequency is between 100 and 432 MHz.
  581. *
  582. * @param PLLI2SQ: specifies the division factor for SAI1 clock
  583. * This parameter must be a number between 2 and 15.
  584. *
  585. * @param PLLI2SR: specifies the division factor for I2S clock
  586. * This parameter must be a number between 2 and 7.
  587. * @note You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
  588. * on the I2S clock frequency.
  589. *
  590. * @retval None
  591. */
  592. void RCC_PLLI2SConfig(uint32_t PLLI2SN, uint32_t PLLI2SQ, uint32_t PLLI2SR)
  593. {
  594. /* Check the parameters */
  595. assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SN));
  596. assert_param(IS_RCC_PLLI2SQ_VALUE(PLLI2SQ));
  597. assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SR));
  598. RCC->PLLI2SCFGR = (PLLI2SN << 6) | (PLLI2SQ << 24) | (PLLI2SR << 28);
  599. }
  600. #endif /* STM32F427_437xx || STM32F429_439xx || STM32F469_479xx */
  601. #if defined(STM32F412xG ) || defined(STM32F413_423xx) || defined(STM32F446xx)
  602. /**
  603. * @brief Configures the PLLI2S clock multiplication and division factors.
  604. *
  605. * @note This function can be used only for STM32F446xx devices
  606. *
  607. * @note This function must be used only when the PLLI2S is disabled.
  608. * @note PLLI2S clock source is common with the main PLL (configured in
  609. * RCC_PLLConfig function )
  610. *
  611. * @param PLLI2SM: specifies the division factor for PLLI2S VCO input clock
  612. * This parameter must be a number between Min_Data = 2 and Max_Data = 63.
  613. * @note You have to set the PLLI2SM parameter correctly to ensure that the VCO input
  614. * frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
  615. * of 2 MHz to limit PLLI2S jitter.
  616. *
  617. * @param PLLI2SN: specifies the multiplication factor for PLLI2S VCO output clock
  618. * This parameter must be a number between 50 and 432.
  619. * @note You have to set the PLLI2SN parameter correctly to ensure that the VCO
  620. * output frequency is between 100 and 432 MHz.
  621. *
  622. * @param PLLI2SP: specifies the division factor for PLL 48Mhz clock output
  623. * This parameter must be a number in the range {2, 4, 6, or 8}.
  624. *
  625. * @param PLLI2SQ: specifies the division factor for SAI1 clock
  626. * This parameter must be a number between 2 and 15.
  627. *
  628. * @param PLLI2SR: specifies the division factor for I2S clock
  629. * This parameter must be a number between 2 and 7.
  630. * @note You have to set the PLLI2SR parameter correctly to not exceed 192 MHz
  631. * on the I2S clock frequency.
  632. * @note the PLLI2SR parameter is only available with STM32F42xxx/43xxx devices.
  633. *
  634. * @retval None
  635. */
  636. void RCC_PLLI2SConfig(uint32_t PLLI2SM, uint32_t PLLI2SN, uint32_t PLLI2SP, uint32_t PLLI2SQ, uint32_t PLLI2SR)
  637. {
  638. /* Check the parameters */
  639. assert_param(IS_RCC_PLLI2SM_VALUE(PLLI2SM));
  640. assert_param(IS_RCC_PLLI2SN_VALUE(PLLI2SN));
  641. assert_param(IS_RCC_PLLI2SP_VALUE(PLLI2SP));
  642. assert_param(IS_RCC_PLLI2SQ_VALUE(PLLI2SQ));
  643. assert_param(IS_RCC_PLLI2SR_VALUE(PLLI2SR));
  644. RCC->PLLI2SCFGR = PLLI2SM | (PLLI2SN << 6) | (((PLLI2SP >> 1) -1) << 16) | (PLLI2SQ << 24) | (PLLI2SR << 28);
  645. }
  646. #endif /* STM32F412xG || STM32F413_423xx || STM32F446xx */
  647. /**
  648. * @brief Enables or disables the PLLI2S.
  649. * @note The PLLI2S is disabled by hardware when entering STOP and STANDBY modes.
  650. * @param NewState: new state of the PLLI2S. This parameter can be: ENABLE or DISABLE.
  651. * @retval None
  652. */
  653. void RCC_PLLI2SCmd(FunctionalState NewState)
  654. {
  655. /* Check the parameters */
  656. assert_param(IS_FUNCTIONAL_STATE(NewState));
  657. *(__IO uint32_t *) CR_PLLI2SON_BB = (uint32_t)NewState;
  658. }
  659. #if defined(STM32F469_479xx)
  660. /**
  661. * @brief Configures the PLLSAI clock multiplication and division factors.
  662. *
  663. * @note This function can be used only for STM32F469_479xx devices
  664. *
  665. * @note This function must be used only when the PLLSAI is disabled.
  666. * @note PLLSAI clock source is common with the main PLL (configured in
  667. * RCC_PLLConfig function )
  668. *
  669. * @param PLLSAIN: specifies the multiplication factor for PLLSAI VCO output clock
  670. * This parameter must be a number between 50 and 432.
  671. * @note You have to set the PLLSAIN parameter correctly to ensure that the VCO
  672. * output frequency is between 100 and 432 MHz.
  673. *
  674. * @param PLLSAIP: specifies the division factor for PLL 48Mhz clock output
  675. * This parameter must be a number in the range {2, 4, 6, or 8}..
  676. *
  677. * @param PLLSAIQ: specifies the division factor for SAI1 clock
  678. * This parameter must be a number between 2 and 15.
  679. *
  680. * @param PLLSAIR: specifies the division factor for LTDC clock
  681. * This parameter must be a number between 2 and 7.
  682. *
  683. * @retval None
  684. */
  685. void RCC_PLLSAIConfig(uint32_t PLLSAIN, uint32_t PLLSAIP, uint32_t PLLSAIQ, uint32_t PLLSAIR)
  686. {
  687. /* Check the parameters */
  688. assert_param(IS_RCC_PLLSAIN_VALUE(PLLSAIN));
  689. assert_param(IS_RCC_PLLSAIP_VALUE(PLLSAIP));
  690. assert_param(IS_RCC_PLLSAIQ_VALUE(PLLSAIQ));
  691. assert_param(IS_RCC_PLLSAIR_VALUE(PLLSAIR));
  692. RCC->PLLSAICFGR = (PLLSAIN << 6) | (((PLLSAIP >> 1) -1) << 16) | (PLLSAIQ << 24) | (PLLSAIR << 28);
  693. }
  694. #endif /* STM32F469_479xx */
  695. #if defined(STM32F446xx)
  696. /**
  697. * @brief Configures the PLLSAI clock multiplication and division factors.
  698. *
  699. * @note This function can be used only for STM32F446xx devices
  700. *
  701. * @note This function must be used only when the PLLSAI is disabled.
  702. * @note PLLSAI clock source is common with the main PLL (configured in
  703. * RCC_PLLConfig function )
  704. *
  705. * @param PLLSAIM: specifies the division factor for PLLSAI VCO input clock
  706. * This parameter must be a number between Min_Data = 2 and Max_Data = 63.
  707. * @note You have to set the PLLSAIM parameter correctly to ensure that the VCO input
  708. * frequency ranges from 1 to 2 MHz. It is recommended to select a frequency
  709. * of 2 MHz to limit PLLSAI jitter.
  710. *
  711. * @param PLLSAIN: specifies the multiplication factor for PLLSAI VCO output clock
  712. * This parameter must be a number between 50 and 432.
  713. * @note You have to set the PLLSAIN parameter correctly to ensure that the VCO
  714. * output frequency is between 100 and 432 MHz.
  715. *
  716. * @param PLLSAIP: specifies the division factor for PLL 48Mhz clock output
  717. * This parameter must be a number in the range {2, 4, 6, or 8}.
  718. *
  719. * @param PLLSAIQ: specifies the division factor for SAI1 clock
  720. * This parameter must be a number between 2 and 15.
  721. *
  722. * @retval None
  723. */
  724. void RCC_PLLSAIConfig(uint32_t PLLSAIM, uint32_t PLLSAIN, uint32_t PLLSAIP, uint32_t PLLSAIQ)
  725. {
  726. /* Check the parameters */
  727. assert_param(IS_RCC_PLLSAIM_VALUE(PLLSAIM));
  728. assert_param(IS_RCC_PLLSAIN_VALUE(PLLSAIN));
  729. assert_param(IS_RCC_PLLSAIP_VALUE(PLLSAIP));
  730. assert_param(IS_RCC_PLLSAIQ_VALUE(PLLSAIQ));
  731. RCC->PLLSAICFGR = PLLSAIM | (PLLSAIN << 6) | (((PLLSAIP >> 1) -1) << 16) | (PLLSAIQ << 24);
  732. }
  733. #endif /* STM32F446xx */
  734. #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F411xE)
  735. /**
  736. * @brief Configures the PLLSAI clock multiplication and division factors.
  737. *
  738. * @note This function can be used only for STM32F42xxx/43xxx devices
  739. *
  740. * @note This function must be used only when the PLLSAI is disabled.
  741. * @note PLLSAI clock source is common with the main PLL (configured in
  742. * RCC_PLLConfig function )
  743. *
  744. * @param PLLSAIN: specifies the multiplication factor for PLLSAI VCO output clock
  745. * This parameter must be a number between 50 and 432.
  746. * @note You have to set the PLLSAIN parameter correctly to ensure that the VCO
  747. * output frequency is between 100 and 432 MHz.
  748. *
  749. * @param PLLSAIQ: specifies the division factor for SAI1 clock
  750. * This parameter must be a number between 2 and 15.
  751. *
  752. * @param PLLSAIR: specifies the division factor for LTDC clock
  753. * This parameter must be a number between 2 and 7.
  754. *
  755. * @retval None
  756. */
  757. void RCC_PLLSAIConfig(uint32_t PLLSAIN, uint32_t PLLSAIQ, uint32_t PLLSAIR)
  758. {
  759. /* Check the parameters */
  760. assert_param(IS_RCC_PLLSAIN_VALUE(PLLSAIN));
  761. assert_param(IS_RCC_PLLSAIR_VALUE(PLLSAIR));
  762. assert_param(IS_RCC_PLLSAIQ_VALUE(PLLSAIQ));
  763. RCC->PLLSAICFGR = (PLLSAIN << 6) | (PLLSAIQ << 24) | (PLLSAIR << 28);
  764. }
  765. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F411xE */
  766. /**
  767. * @brief Enables or disables the PLLSAI.
  768. *
  769. * @note This function can be used only for STM32F42xxx/43xxx/446xx/469xx/479xx devices
  770. *
  771. * @note The PLLSAI is disabled by hardware when entering STOP and STANDBY modes.
  772. * @param NewState: new state of the PLLSAI. This parameter can be: ENABLE or DISABLE.
  773. * @retval None
  774. */
  775. void RCC_PLLSAICmd(FunctionalState NewState)
  776. {
  777. /* Check the parameters */
  778. assert_param(IS_FUNCTIONAL_STATE(NewState));
  779. *(__IO uint32_t *) CR_PLLSAION_BB = (uint32_t)NewState;
  780. }
  781. /**
  782. * @brief Enables or disables the Clock Security System.
  783. * @note If a failure is detected on the HSE oscillator clock, this oscillator
  784. * is automatically disabled and an interrupt is generated to inform the
  785. * software about the failure (Clock Security System Interrupt, CSSI),
  786. * allowing the MCU to perform rescue operations. The CSSI is linked to
  787. * the Cortex-M4 NMI (Non-Maskable Interrupt) exception vector.
  788. * @param NewState: new state of the Clock Security System.
  789. * This parameter can be: ENABLE or DISABLE.
  790. * @retval None
  791. */
  792. void RCC_ClockSecuritySystemCmd(FunctionalState NewState)
  793. {
  794. /* Check the parameters */
  795. assert_param(IS_FUNCTIONAL_STATE(NewState));
  796. *(__IO uint32_t *) CR_CSSON_BB = (uint32_t)NewState;
  797. }
  798. /**
  799. * @brief Selects the clock source to output on MCO1 pin(PA8).
  800. * @note PA8 should be configured in alternate function mode.
  801. * @param RCC_MCO1Source: specifies the clock source to output.
  802. * This parameter can be one of the following values:
  803. * @arg RCC_MCO1Source_HSI: HSI clock selected as MCO1 source
  804. * @arg RCC_MCO1Source_LSE: LSE clock selected as MCO1 source
  805. * @arg RCC_MCO1Source_HSE: HSE clock selected as MCO1 source
  806. * @arg RCC_MCO1Source_PLLCLK: main PLL clock selected as MCO1 source
  807. * @param RCC_MCO1Div: specifies the MCO1 prescaler.
  808. * This parameter can be one of the following values:
  809. * @arg RCC_MCO1Div_1: no division applied to MCO1 clock
  810. * @arg RCC_MCO1Div_2: division by 2 applied to MCO1 clock
  811. * @arg RCC_MCO1Div_3: division by 3 applied to MCO1 clock
  812. * @arg RCC_MCO1Div_4: division by 4 applied to MCO1 clock
  813. * @arg RCC_MCO1Div_5: division by 5 applied to MCO1 clock
  814. * @retval None
  815. */
  816. void RCC_MCO1Config(uint32_t RCC_MCO1Source, uint32_t RCC_MCO1Div)
  817. {
  818. uint32_t tmpreg = 0;
  819. /* Check the parameters */
  820. assert_param(IS_RCC_MCO1SOURCE(RCC_MCO1Source));
  821. assert_param(IS_RCC_MCO1DIV(RCC_MCO1Div));
  822. tmpreg = RCC->CFGR;
  823. /* Clear MCO1[1:0] and MCO1PRE[2:0] bits */
  824. tmpreg &= CFGR_MCO1_RESET_MASK;
  825. /* Select MCO1 clock source and prescaler */
  826. tmpreg |= RCC_MCO1Source | RCC_MCO1Div;
  827. /* Store the new value */
  828. RCC->CFGR = tmpreg;
  829. #if defined(STM32F410xx)
  830. RCC_MCO1Cmd(ENABLE);
  831. #endif /* STM32F410xx */
  832. }
  833. /**
  834. * @brief Selects the clock source to output on MCO2 pin(PC9).
  835. * @note PC9 should be configured in alternate function mode.
  836. * @param RCC_MCO2Source: specifies the clock source to output.
  837. * This parameter can be one of the following values:
  838. * @arg RCC_MCO2Source_SYSCLK: System clock (SYSCLK) selected as MCO2 source
  839. * @arg RCC_MCO2SOURCE_PLLI2SCLK: PLLI2S clock selected as MCO2 source, available for all STM32F4 devices except STM32F410xx
  840. * @arg RCC_MCO2SOURCE_I2SCLK: I2SCLK clock selected as MCO2 source, available only for STM32F410xx devices
  841. * @arg RCC_MCO2Source_HSE: HSE clock selected as MCO2 source
  842. * @arg RCC_MCO2Source_PLLCLK: main PLL clock selected as MCO2 source
  843. * @param RCC_MCO2Div: specifies the MCO2 prescaler.
  844. * This parameter can be one of the following values:
  845. * @arg RCC_MCO2Div_1: no division applied to MCO2 clock
  846. * @arg RCC_MCO2Div_2: division by 2 applied to MCO2 clock
  847. * @arg RCC_MCO2Div_3: division by 3 applied to MCO2 clock
  848. * @arg RCC_MCO2Div_4: division by 4 applied to MCO2 clock
  849. * @arg RCC_MCO2Div_5: division by 5 applied to MCO2 clock
  850. * @note For STM32F410xx devices to output I2SCLK clock on MCO2 you should have
  851. * at last one of the SPI clocks enabled (SPI1, SPI2 or SPI5).
  852. * @retval None
  853. */
  854. void RCC_MCO2Config(uint32_t RCC_MCO2Source, uint32_t RCC_MCO2Div)
  855. {
  856. uint32_t tmpreg = 0;
  857. /* Check the parameters */
  858. assert_param(IS_RCC_MCO2SOURCE(RCC_MCO2Source));
  859. assert_param(IS_RCC_MCO2DIV(RCC_MCO2Div));
  860. tmpreg = RCC->CFGR;
  861. /* Clear MCO2 and MCO2PRE[2:0] bits */
  862. tmpreg &= CFGR_MCO2_RESET_MASK;
  863. /* Select MCO2 clock source and prescaler */
  864. tmpreg |= RCC_MCO2Source | RCC_MCO2Div;
  865. /* Store the new value */
  866. RCC->CFGR = tmpreg;
  867. #if defined(STM32F410xx)
  868. RCC_MCO2Cmd(ENABLE);
  869. #endif /* STM32F410xx */
  870. }
  871. /**
  872. * @}
  873. */
  874. /** @defgroup RCC_Group2 System AHB and APB busses clocks configuration functions
  875. * @brief System, AHB and APB busses clocks configuration functions
  876. *
  877. @verbatim
  878. ===============================================================================
  879. ##### System, AHB and APB busses clocks configuration functions #####
  880. ===============================================================================
  881. [..]
  882. This section provide functions allowing to configure the System, AHB, APB1 and
  883. APB2 busses clocks.
  884. (#) Several clock sources can be used to drive the System clock (SYSCLK): HSI,
  885. HSE and PLL.
  886. The AHB clock (HCLK) is derived from System clock through configurable
  887. prescaler and used to clock the CPU, memory and peripherals mapped
  888. on AHB bus (DMA, GPIO...). APB1 (PCLK1) and APB2 (PCLK2) clocks are derived
  889. from AHB clock through configurable prescalers and used to clock
  890. the peripherals mapped on these busses. You can use
  891. "RCC_GetClocksFreq()" function to retrieve the frequencies of these clocks.
  892. -@- All the peripheral clocks are derived from the System clock (SYSCLK) except:
  893. (+@) I2S: the I2S clock can be derived either from a specific PLL (PLLI2S) or
  894. from an external clock mapped on the I2S_CKIN pin.
  895. You have to use RCC_I2SCLKConfig() function to configure this clock.
  896. (+@) RTC: the RTC clock can be derived either from the LSI, LSE or HSE clock
  897. divided by 2 to 31. You have to use RCC_RTCCLKConfig() and RCC_RTCCLKCmd()
  898. functions to configure this clock.
  899. (+@) USB OTG FS, SDIO and RTC: USB OTG FS require a frequency equal to 48 MHz
  900. to work correctly, while the SDIO require a frequency equal or lower than
  901. to 48. This clock is derived of the main PLL through PLLQ divider.
  902. (+@) IWDG clock which is always the LSI clock.
  903. (#) For STM32F405xx/407xx and STM32F415xx/417xx devices, the maximum frequency
  904. of the SYSCLK and HCLK is 168 MHz, PCLK2 84 MHz and PCLK1 42 MHz. Depending
  905. on the device voltage range, the maximum frequency should be adapted accordingly:
  906. +-------------------------------------------------------------------------------------+
  907. | Latency | HCLK clock frequency (MHz) |
  908. | |---------------------------------------------------------------------|
  909. | | voltage range | voltage range | voltage range | voltage range |
  910. | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
  911. |---------------|----------------|----------------|-----------------|-----------------|
  912. |0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 22 |0 < HCLK <= 20 |
  913. |---------------|----------------|----------------|-----------------|-----------------|
  914. |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44 |20 < HCLK <= 40 |
  915. |---------------|----------------|----------------|-----------------|-----------------|
  916. |2WS(3CPU cycle)|60 < HCLK <= 90 |48 < HCLK <= 72 |44 < HCLK <= 66 |40 < HCLK <= 60 |
  917. |---------------|----------------|----------------|-----------------|-----------------|
  918. |3WS(4CPU cycle)|90 < HCLK <= 120|72 < HCLK <= 96 |66 < HCLK <= 88 |60 < HCLK <= 80 |
  919. |---------------|----------------|----------------|-----------------|-----------------|
  920. |4WS(5CPU cycle)|120< HCLK <= 150|96 < HCLK <= 120|88 < HCLK <= 110 |80 < HCLK <= 100 |
  921. |---------------|----------------|----------------|-----------------|-----------------|
  922. |5WS(6CPU cycle)|150< HCLK <= 168|120< HCLK <= 144|110 < HCLK <= 132|100 < HCLK <= 120|
  923. |---------------|----------------|----------------|-----------------|-----------------|
  924. |6WS(7CPU cycle)| NA |144< HCLK <= 168|132 < HCLK <= 154|120 < HCLK <= 140|
  925. |---------------|----------------|----------------|-----------------|-----------------|
  926. |7WS(8CPU cycle)| NA | NA |154 < HCLK <= 168|140 < HCLK <= 160|
  927. +---------------|----------------|----------------|-----------------|-----------------+
  928. (#) For STM32F42xxx/43xxx/469xx/479xx devices, the maximum frequency of the SYSCLK and HCLK is 180 MHz,
  929. PCLK2 90 MHz and PCLK1 45 MHz. Depending on the device voltage range, the maximum
  930. frequency should be adapted accordingly:
  931. +-------------------------------------------------------------------------------------+
  932. | Latency | HCLK clock frequency (MHz) |
  933. | |---------------------------------------------------------------------|
  934. | | voltage range | voltage range | voltage range | voltage range |
  935. | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
  936. |---------------|----------------|----------------|-----------------|-----------------|
  937. |0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 22 |0 < HCLK <= 20 |
  938. |---------------|----------------|----------------|-----------------|-----------------|
  939. |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44 |20 < HCLK <= 40 |
  940. |---------------|----------------|----------------|-----------------|-----------------|
  941. |2WS(3CPU cycle)|60 < HCLK <= 90 |48 < HCLK <= 72 |44 < HCLK <= 66 |40 < HCLK <= 60 |
  942. |---------------|----------------|----------------|-----------------|-----------------|
  943. |3WS(4CPU cycle)|90 < HCLK <= 120|72 < HCLK <= 96 |66 < HCLK <= 88 |60 < HCLK <= 80 |
  944. |---------------|----------------|----------------|-----------------|-----------------|
  945. |4WS(5CPU cycle)|120< HCLK <= 150|96 < HCLK <= 120|88 < HCLK <= 110 |80 < HCLK <= 100 |
  946. |---------------|----------------|----------------|-----------------|-----------------|
  947. |5WS(6CPU cycle)|120< HCLK <= 180|120< HCLK <= 144|110 < HCLK <= 132|100 < HCLK <= 120|
  948. |---------------|----------------|----------------|-----------------|-----------------|
  949. |6WS(7CPU cycle)| NA |144< HCLK <= 168|132 < HCLK <= 154|120 < HCLK <= 140|
  950. |---------------|----------------|----------------|-----------------|-----------------|
  951. |7WS(8CPU cycle)| NA |168< HCLK <= 180|154 < HCLK <= 176|140 < HCLK <= 160|
  952. |---------------|----------------|----------------|-----------------|-----------------|
  953. |8WS(9CPU cycle)| NA | NA |176 < HCLK <= 180|160 < HCLK <= 168|
  954. +-------------------------------------------------------------------------------------+
  955. (#) For STM32F401xx devices, the maximum frequency of the SYSCLK and HCLK is 84 MHz,
  956. PCLK2 84 MHz and PCLK1 42 MHz. Depending on the device voltage range, the maximum
  957. frequency should be adapted accordingly:
  958. +-------------------------------------------------------------------------------------+
  959. | Latency | HCLK clock frequency (MHz) |
  960. | |---------------------------------------------------------------------|
  961. | | voltage range | voltage range | voltage range | voltage range |
  962. | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
  963. |---------------|----------------|----------------|-----------------|-----------------|
  964. |0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 22 |0 < HCLK <= 20 |
  965. |---------------|----------------|----------------|-----------------|-----------------|
  966. |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44 |20 < HCLK <= 40 |
  967. |---------------|----------------|----------------|-----------------|-----------------|
  968. |2WS(3CPU cycle)|60 < HCLK <= 84 |48 < HCLK <= 72 |44 < HCLK <= 66 |40 < HCLK <= 60 |
  969. |---------------|----------------|----------------|-----------------|-----------------|
  970. |3WS(4CPU cycle)| NA |72 < HCLK <= 84 |66 < HCLK <= 84 |60 < HCLK <= 80 |
  971. |---------------|----------------|----------------|-----------------|-----------------|
  972. |4WS(5CPU cycle)| NA | NA | NA |80 < HCLK <= 84 |
  973. +-------------------------------------------------------------------------------------+
  974. (#) For STM32F410xx/STM32F411xE devices, the maximum frequency of the SYSCLK and HCLK is 100 MHz,
  975. PCLK2 100 MHz and PCLK1 50 MHz. Depending on the device voltage range, the maximum
  976. frequency should be adapted accordingly:
  977. +-------------------------------------------------------------------------------------+
  978. | Latency | HCLK clock frequency (MHz) |
  979. | |---------------------------------------------------------------------|
  980. | | voltage range | voltage range | voltage range | voltage range |
  981. | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
  982. |---------------|----------------|----------------|-----------------|-----------------|
  983. |0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 18 |0 < HCLK <= 16 |
  984. |---------------|----------------|----------------|-----------------|-----------------|
  985. |1WS(2CPU cycle)|30 < HCLK <= 64 |24 < HCLK <= 48 |18 < HCLK <= 36 |16 < HCLK <= 32 |
  986. |---------------|----------------|----------------|-----------------|-----------------|
  987. |2WS(3CPU cycle)|64 < HCLK <= 90 |48 < HCLK <= 72 |36 < HCLK <= 54 |32 < HCLK <= 48 |
  988. |---------------|----------------|----------------|-----------------|-----------------|
  989. |3WS(4CPU cycle)|90 < HCLK <= 100|72 < HCLK <= 96 |54 < HCLK <= 72 |48 < HCLK <= 64 |
  990. |---------------|----------------|----------------|-----------------|-----------------|
  991. |4WS(5CPU cycle)| NA |96 < HCLK <= 100|72 < HCLK <= 90 |64 < HCLK <= 80 |
  992. |---------------|----------------|----------------|-----------------|-----------------|
  993. |5WS(6CPU cycle)| NA | NA |90 < HCLK <= 100 |80 < HCLK <= 96 |
  994. |---------------|----------------|----------------|-----------------|-----------------|
  995. |6WS(7CPU cycle)| NA | NA | NA |96 < HCLK <= 100 |
  996. +-------------------------------------------------------------------------------------+
  997. -@- On STM32F405xx/407xx and STM32F415xx/417xx devices:
  998. (++) when VOS = '0', the maximum value of fHCLK = 144MHz.
  999. (++) when VOS = '1', the maximum value of fHCLK = 168MHz.
  1000. [..]
  1001. On STM32F42xxx/43xxx/469xx/479xx devices:
  1002. (++) when VOS[1:0] = '0x01', the maximum value of fHCLK is 120MHz.
  1003. (++) when VOS[1:0] = '0x10', the maximum value of fHCLK is 144MHz.
  1004. (++) when VOS[1:0] = '0x11', the maximum value of f is 168MHz
  1005. [..]
  1006. On STM32F401x devices:
  1007. (++) when VOS[1:0] = '0x01', the maximum value of fHCLK is 64MHz.
  1008. (++) when VOS[1:0] = '0x10', the maximum value of fHCLK is 84MHz.
  1009. On STM32F410xx/STM32F411xE devices:
  1010. (++) when VOS[1:0] = '0x01' the maximum value of fHCLK is 64MHz.
  1011. (++) when VOS[1:0] = '0x10' the maximum value of fHCLK is 84MHz.
  1012. (++) when VOS[1:0] = '0x11' the maximum value of fHCLK is 100MHz.
  1013. You can use PWR_MainRegulatorModeConfig() function to control VOS bits.
  1014. @endverbatim
  1015. * @{
  1016. */
  1017. /**
  1018. * @brief Configures the system clock (SYSCLK).
  1019. * @note The HSI is used (enabled by hardware) as system clock source after
  1020. * startup from Reset, wake-up from STOP and STANDBY mode, or in case
  1021. * of failure of the HSE used directly or indirectly as system clock
  1022. * (if the Clock Security System CSS is enabled).
  1023. * @note A switch from one clock source to another occurs only if the target
  1024. * clock source is ready (clock stable after startup delay or PLL locked).
  1025. * If a clock source which is not yet ready is selected, the switch will
  1026. * occur when the clock source will be ready.
  1027. * You can use RCC_GetSYSCLKSource() function to know which clock is
  1028. * currently used as system clock source.
  1029. * @param RCC_SYSCLKSource: specifies the clock source used as system clock.
  1030. * This parameter can be one of the following values:
  1031. * @arg RCC_SYSCLKSource_HSI: HSI selected as system clock source
  1032. * @arg RCC_SYSCLKSource_HSE: HSE selected as system clock source
  1033. * @arg RCC_SYSCLKSource_PLLCLK: PLL selected as system clock source (RCC_SYSCLKSource_PLLPCLK for STM32F446xx devices)
  1034. * @arg RCC_SYSCLKSource_PLLRCLK: PLL R selected as system clock source only for STM32F412xG, STM32F413_423xx and STM32F446xx devices
  1035. * @retval None
  1036. */
  1037. void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource)
  1038. {
  1039. uint32_t tmpreg = 0;
  1040. /* Check the parameters */
  1041. assert_param(IS_RCC_SYSCLK_SOURCE(RCC_SYSCLKSource));
  1042. tmpreg = RCC->CFGR;
  1043. /* Clear SW[1:0] bits */
  1044. tmpreg &= ~RCC_CFGR_SW;
  1045. /* Set SW[1:0] bits according to RCC_SYSCLKSource value */
  1046. tmpreg |= RCC_SYSCLKSource;
  1047. /* Store the new value */
  1048. RCC->CFGR = tmpreg;
  1049. }
  1050. /**
  1051. * @brief Returns the clock source used as system clock.
  1052. * @param None
  1053. * @retval The clock source used as system clock. The returned value can be one
  1054. * of the following:
  1055. * - 0x00: HSI used as system clock
  1056. * - 0x04: HSE used as system clock
  1057. * - 0x08: PLL used as system clock (PLL P for STM32F446xx devices)
  1058. * - 0x0C: PLL R used as system clock (only for STM32F412xG, STM32F413_423xx and STM32F446xx devices)
  1059. */
  1060. uint8_t RCC_GetSYSCLKSource(void)
  1061. {
  1062. return ((uint8_t)(RCC->CFGR & RCC_CFGR_SWS));
  1063. }
  1064. /**
  1065. * @brief Configures the AHB clock (HCLK).
  1066. * @note Depending on the device voltage range, the software has to set correctly
  1067. * these bits to ensure that HCLK not exceed the maximum allowed frequency
  1068. * (for more details refer to section above
  1069. * "CPU, AHB and APB busses clocks configuration functions")
  1070. * @param RCC_SYSCLK: defines the AHB clock divider. This clock is derived from
  1071. * the system clock (SYSCLK).
  1072. * This parameter can be one of the following values:
  1073. * @arg RCC_SYSCLK_Div1: AHB clock = SYSCLK
  1074. * @arg RCC_SYSCLK_Div2: AHB clock = SYSCLK/2
  1075. * @arg RCC_SYSCLK_Div4: AHB clock = SYSCLK/4
  1076. * @arg RCC_SYSCLK_Div8: AHB clock = SYSCLK/8
  1077. * @arg RCC_SYSCLK_Div16: AHB clock = SYSCLK/16
  1078. * @arg RCC_SYSCLK_Div64: AHB clock = SYSCLK/64
  1079. * @arg RCC_SYSCLK_Div128: AHB clock = SYSCLK/128
  1080. * @arg RCC_SYSCLK_Div256: AHB clock = SYSCLK/256
  1081. * @arg RCC_SYSCLK_Div512: AHB clock = SYSCLK/512
  1082. * @retval None
  1083. */
  1084. void RCC_HCLKConfig(uint32_t RCC_SYSCLK)
  1085. {
  1086. uint32_t tmpreg = 0;
  1087. /* Check the parameters */
  1088. assert_param(IS_RCC_HCLK(RCC_SYSCLK));
  1089. tmpreg = RCC->CFGR;
  1090. /* Clear HPRE[3:0] bits */
  1091. tmpreg &= ~RCC_CFGR_HPRE;
  1092. /* Set HPRE[3:0] bits according to RCC_SYSCLK value */
  1093. tmpreg |= RCC_SYSCLK;
  1094. /* Store the new value */
  1095. RCC->CFGR = tmpreg;
  1096. }
  1097. /**
  1098. * @brief Configures the Low Speed APB clock (PCLK1).
  1099. * @param RCC_HCLK: defines the APB1 clock divider. This clock is derived from
  1100. * the AHB clock (HCLK).
  1101. * This parameter can be one of the following values:
  1102. * @arg RCC_HCLK_Div1: APB1 clock = HCLK
  1103. * @arg RCC_HCLK_Div2: APB1 clock = HCLK/2
  1104. * @arg RCC_HCLK_Div4: APB1 clock = HCLK/4
  1105. * @arg RCC_HCLK_Div8: APB1 clock = HCLK/8
  1106. * @arg RCC_HCLK_Div16: APB1 clock = HCLK/16
  1107. * @retval None
  1108. */
  1109. void RCC_PCLK1Config(uint32_t RCC_HCLK)
  1110. {
  1111. uint32_t tmpreg = 0;
  1112. /* Check the parameters */
  1113. assert_param(IS_RCC_PCLK(RCC_HCLK));
  1114. tmpreg = RCC->CFGR;
  1115. /* Clear PPRE1[2:0] bits */
  1116. tmpreg &= ~RCC_CFGR_PPRE1;
  1117. /* Set PPRE1[2:0] bits according to RCC_HCLK value */
  1118. tmpreg |= RCC_HCLK;
  1119. /* Store the new value */
  1120. RCC->CFGR = tmpreg;
  1121. }
  1122. /**
  1123. * @brief Configures the High Speed APB clock (PCLK2).
  1124. * @param RCC_HCLK: defines the APB2 clock divider. This clock is derived from
  1125. * the AHB clock (HCLK).
  1126. * This parameter can be one of the following values:
  1127. * @arg RCC_HCLK_Div1: APB2 clock = HCLK
  1128. * @arg RCC_HCLK_Div2: APB2 clock = HCLK/2
  1129. * @arg RCC_HCLK_Div4: APB2 clock = HCLK/4
  1130. * @arg RCC_HCLK_Div8: APB2 clock = HCLK/8
  1131. * @arg RCC_HCLK_Div16: APB2 clock = HCLK/16
  1132. * @retval None
  1133. */
  1134. void RCC_PCLK2Config(uint32_t RCC_HCLK)
  1135. {
  1136. uint32_t tmpreg = 0;
  1137. /* Check the parameters */
  1138. assert_param(IS_RCC_PCLK(RCC_HCLK));
  1139. tmpreg = RCC->CFGR;
  1140. /* Clear PPRE2[2:0] bits */
  1141. tmpreg &= ~RCC_CFGR_PPRE2;
  1142. /* Set PPRE2[2:0] bits according to RCC_HCLK value */
  1143. tmpreg |= RCC_HCLK << 3;
  1144. /* Store the new value */
  1145. RCC->CFGR = tmpreg;
  1146. }
  1147. /**
  1148. * @brief Returns the frequencies of different on chip clocks; SYSCLK, HCLK,
  1149. * PCLK1 and PCLK2.
  1150. *
  1151. * @note The system frequency computed by this function is not the real
  1152. * frequency in the chip. It is calculated based on the predefined
  1153. * constant and the selected clock source:
  1154. * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
  1155. * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(**)
  1156. * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE(**)
  1157. * or HSI_VALUE(*) multiplied/divided by the PLL factors.
  1158. * @note (*) HSI_VALUE is a constant defined in stm32f4xx.h file (default value
  1159. * 16 MHz) but the real value may vary depending on the variations
  1160. * in voltage and temperature.
  1161. * @note (**) HSE_VALUE is a constant defined in stm32f4xx.h file (default value
  1162. * 25 MHz), user has to ensure that HSE_VALUE is same as the real
  1163. * frequency of the crystal used. Otherwise, this function may
  1164. * have wrong result.
  1165. *
  1166. * @note The result of this function could be not correct when using fractional
  1167. * value for HSE crystal.
  1168. *
  1169. * @param RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which will hold
  1170. * the clocks frequencies.
  1171. *
  1172. * @note This function can be used by the user application to compute the
  1173. * baudrate for the communication peripherals or configure other parameters.
  1174. * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function
  1175. * must be called to update the structure's field. Otherwise, any
  1176. * configuration based on this function will be incorrect.
  1177. *
  1178. * @retval None
  1179. */
  1180. void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)
  1181. {
  1182. uint32_t tmp = 0, presc = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
  1183. #if defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx)
  1184. uint32_t pllr = 2;
  1185. #endif /* STM32F412xG || STM32F413_423xx || STM32F446xx */
  1186. /* Get SYSCLK source -------------------------------------------------------*/
  1187. tmp = RCC->CFGR & RCC_CFGR_SWS;
  1188. switch (tmp)
  1189. {
  1190. case 0x00: /* HSI used as system clock source */
  1191. RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;
  1192. break;
  1193. case 0x04: /* HSE used as system clock source */
  1194. RCC_Clocks->SYSCLK_Frequency = HSE_VALUE;
  1195. break;
  1196. case 0x08: /* PLL P used as system clock source */
  1197. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
  1198. SYSCLK = PLL_VCO / PLLP
  1199. */
  1200. pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
  1201. pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
  1202. if (pllsource != 0)
  1203. {
  1204. /* HSE used as PLL clock source */
  1205. pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
  1206. }
  1207. else
  1208. {
  1209. /* HSI used as PLL clock source */
  1210. pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
  1211. }
  1212. pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
  1213. RCC_Clocks->SYSCLK_Frequency = pllvco/pllp;
  1214. break;
  1215. #if defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx)
  1216. case 0x0C: /* PLL R used as system clock source */
  1217. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
  1218. SYSCLK = PLL_VCO / PLLR
  1219. */
  1220. pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
  1221. pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
  1222. if (pllsource != 0)
  1223. {
  1224. /* HSE used as PLL clock source */
  1225. pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
  1226. }
  1227. else
  1228. {
  1229. /* HSI used as PLL clock source */
  1230. pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
  1231. }
  1232. pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >>28) + 1 ) *2;
  1233. RCC_Clocks->SYSCLK_Frequency = pllvco/pllr;
  1234. break;
  1235. #endif /* STM32F412xG || STM32F413_423xx || STM32F446xx */
  1236. default:
  1237. RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;
  1238. break;
  1239. }
  1240. /* Compute HCLK, PCLK1 and PCLK2 clocks frequencies ------------------------*/
  1241. /* Get HCLK prescaler */
  1242. tmp = RCC->CFGR & RCC_CFGR_HPRE;
  1243. tmp = tmp >> 4;
  1244. presc = APBAHBPrescTable[tmp];
  1245. /* HCLK clock frequency */
  1246. RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> presc;
  1247. /* Get PCLK1 prescaler */
  1248. tmp = RCC->CFGR & RCC_CFGR_PPRE1;
  1249. tmp = tmp >> 10;
  1250. presc = APBAHBPrescTable[tmp];
  1251. /* PCLK1 clock frequency */
  1252. RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> presc;
  1253. /* Get PCLK2 prescaler */
  1254. tmp = RCC->CFGR & RCC_CFGR_PPRE2;
  1255. tmp = tmp >> 13;
  1256. presc = APBAHBPrescTable[tmp];
  1257. /* PCLK2 clock frequency */
  1258. RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> presc;
  1259. }
  1260. /**
  1261. * @}
  1262. */
  1263. /** @defgroup RCC_Group3 Peripheral clocks configuration functions
  1264. * @brief Peripheral clocks configuration functions
  1265. *
  1266. @verbatim
  1267. ===============================================================================
  1268. ##### Peripheral clocks configuration functions #####
  1269. ===============================================================================
  1270. [..] This section provide functions allowing to configure the Peripheral clocks.
  1271. (#) The RTC clock which is derived from the LSI, LSE or HSE clock divided
  1272. by 2 to 31.
  1273. (#) After restart from Reset or wakeup from STANDBY, all peripherals are off
  1274. except internal SRAM, Flash and JTAG. Before to start using a peripheral
  1275. you have to enable its interface clock. You can do this using
  1276. RCC_AHBPeriphClockCmd(), RCC_APB2PeriphClockCmd() and RCC_APB1PeriphClockCmd() functions.
  1277. (#) To reset the peripherals configuration (to the default state after device reset)
  1278. you can use RCC_AHBPeriphResetCmd(), RCC_APB2PeriphResetCmd() and
  1279. RCC_APB1PeriphResetCmd() functions.
  1280. (#) To further reduce power consumption in SLEEP mode the peripheral clocks
  1281. can be disabled prior to executing the WFI or WFE instructions.
  1282. You can do this using RCC_AHBPeriphClockLPModeCmd(),
  1283. RCC_APB2PeriphClockLPModeCmd() and RCC_APB1PeriphClockLPModeCmd() functions.
  1284. @endverbatim
  1285. * @{
  1286. */
  1287. /**
  1288. * @brief Configures the RTC clock (RTCCLK).
  1289. * @note As the RTC clock configuration bits are in the Backup domain and write
  1290. * access is denied to this domain after reset, you have to enable write
  1291. * access using PWR_BackupAccessCmd(ENABLE) function before to configure
  1292. * the RTC clock source (to be done once after reset).
  1293. * @note Once the RTC clock is configured it can't be changed unless the
  1294. * Backup domain is reset using RCC_BackupResetCmd() function, or by
  1295. * a Power On Reset (POR).
  1296. *
  1297. * @param RCC_RTCCLKSource: specifies the RTC clock source.
  1298. * This parameter can be one of the following values:
  1299. * @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock
  1300. * @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock
  1301. * @arg RCC_RTCCLKSource_HSE_Divx: HSE clock divided by x selected
  1302. * as RTC clock, where x:[2,31]
  1303. *
  1304. * @note If the LSE or LSI is used as RTC clock source, the RTC continues to
  1305. * work in STOP and STANDBY modes, and can be used as wakeup source.
  1306. * However, when the HSE clock is used as RTC clock source, the RTC
  1307. * cannot be used in STOP and STANDBY modes.
  1308. * @note The maximum input clock frequency for RTC is 1MHz (when using HSE as
  1309. * RTC clock source).
  1310. *
  1311. * @retval None
  1312. */
  1313. void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)
  1314. {
  1315. uint32_t tmpreg = 0;
  1316. /* Check the parameters */
  1317. assert_param(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));
  1318. if ((RCC_RTCCLKSource & 0x00000300) == 0x00000300)
  1319. { /* If HSE is selected as RTC clock source, configure HSE division factor for RTC clock */
  1320. tmpreg = RCC->CFGR;
  1321. /* Clear RTCPRE[4:0] bits */
  1322. tmpreg &= ~RCC_CFGR_RTCPRE;
  1323. /* Configure HSE division factor for RTC clock */
  1324. tmpreg |= (RCC_RTCCLKSource & 0xFFFFCFF);
  1325. /* Store the new value */
  1326. RCC->CFGR = tmpreg;
  1327. }
  1328. /* Select the RTC clock source */
  1329. RCC->BDCR |= (RCC_RTCCLKSource & 0x00000FFF);
  1330. }
  1331. /**
  1332. * @brief Enables or disables the RTC clock.
  1333. * @note This function must be used only after the RTC clock source was selected
  1334. * using the RCC_RTCCLKConfig function.
  1335. * @param NewState: new state of the RTC clock. This parameter can be: ENABLE or DISABLE.
  1336. * @retval None
  1337. */
  1338. void RCC_RTCCLKCmd(FunctionalState NewState)
  1339. {
  1340. /* Check the parameters */
  1341. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1342. *(__IO uint32_t *) BDCR_RTCEN_BB = (uint32_t)NewState;
  1343. }
  1344. /**
  1345. * @brief Forces or releases the Backup domain reset.
  1346. * @note This function resets the RTC peripheral (including the backup registers)
  1347. * and the RTC clock source selection in RCC_CSR register.
  1348. * @note The BKPSRAM is not affected by this reset.
  1349. * @param NewState: new state of the Backup domain reset.
  1350. * This parameter can be: ENABLE or DISABLE.
  1351. * @retval None
  1352. */
  1353. void RCC_BackupResetCmd(FunctionalState NewState)
  1354. {
  1355. /* Check the parameters */
  1356. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1357. *(__IO uint32_t *) BDCR_BDRST_BB = (uint32_t)NewState;
  1358. }
  1359. #if defined (STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx)
  1360. /**
  1361. * @brief Configures the I2S clock source (I2SCLK).
  1362. * @note This function must be called before enabling the I2S APB clock.
  1363. *
  1364. * @param RCC_I2SAPBx: specifies the APBx I2S clock source.
  1365. * This parameter can be one of the following values:
  1366. * @arg RCC_I2SBus_APB1: I2S peripheral instance is on APB1 Bus
  1367. * @arg RCC_I2SBus_APB2: I2S peripheral instance is on APB2 Bus
  1368. *
  1369. * @param RCC_I2SCLKSource: specifies the I2S clock source.
  1370. * This parameter can be one of the following values:
  1371. * @arg RCC_I2SCLKSource_PLLI2S: PLLI2S clock used as I2S clock source
  1372. * @arg RCC_I2SCLKSource_Ext: External clock mapped on the I2S_CKIN pin
  1373. * used as I2S clock source
  1374. * @arg RCC_I2SCLKSource_PLL: PLL clock used as I2S clock source
  1375. * @arg RCC_I2SCLKSource_HSI_HSE: HSI or HSE depends on PLLSRC used as I2S clock source
  1376. * @retval None
  1377. */
  1378. void RCC_I2SCLKConfig(uint32_t RCC_I2SAPBx, uint32_t RCC_I2SCLKSource)
  1379. {
  1380. /* Check the parameters */
  1381. assert_param(IS_RCC_I2SCLK_SOURCE(RCC_I2SCLKSource));
  1382. assert_param(IS_RCC_I2S_APBx(RCC_I2SAPBx));
  1383. if(RCC_I2SAPBx == RCC_I2SBus_APB1)
  1384. {
  1385. /* Clear APB1 I2Sx clock source selection bits */
  1386. RCC->DCKCFGR &= ~RCC_DCKCFGR_I2S1SRC;
  1387. /* Set new APB1 I2Sx clock source*/
  1388. RCC->DCKCFGR |= RCC_I2SCLKSource;
  1389. }
  1390. else
  1391. {
  1392. /* Clear APB2 I2Sx clock source selection bits */
  1393. RCC->DCKCFGR &= ~RCC_DCKCFGR_I2S2SRC;
  1394. /* Set new APB2 I2Sx clock source */
  1395. RCC->DCKCFGR |= (RCC_I2SCLKSource << 2);
  1396. }
  1397. }
  1398. #if defined(STM32F446xx)
  1399. /**
  1400. * @brief Configures the SAIx clock source (SAIxCLK).
  1401. * @note This function must be called before enabling the SAIx APB clock.
  1402. *
  1403. * @param RCC_SAIInstance: specifies the SAIx clock source.
  1404. * This parameter can be one of the following values:
  1405. * @arg RCC_SAIInstance_SAI1: SAI1 clock source selection
  1406. * @arg RCC_SAIInstance_SAI2: SAI2 clock source selections
  1407. *
  1408. * @param RCC_SAICLKSource: specifies the SAI clock source.
  1409. * This parameter can be one of the following values:
  1410. * @arg RCC_SAICLKSource_PLLSAI: PLLSAI clock used as SAI clock source
  1411. * @arg RCC_SAICLKSource_PLLI2S: PLLI2S clock used as SAI clock source
  1412. * @arg RCC_SAICLKSource_PLL: PLL clock used as SAI clock source
  1413. * @arg RCC_SAICLKSource_HSI_HSE: HSI or HSE depends on PLLSRC used as SAI clock source
  1414. * @retval None
  1415. */
  1416. void RCC_SAICLKConfig(uint32_t RCC_SAIInstance, uint32_t RCC_SAICLKSource)
  1417. {
  1418. /* Check the parameters */
  1419. assert_param(IS_RCC_SAICLK_SOURCE(RCC_SAICLKSource));
  1420. assert_param(IS_RCC_SAI_INSTANCE(RCC_SAIInstance));
  1421. if(RCC_SAIInstance == RCC_SAIInstance_SAI1)
  1422. {
  1423. /* Clear SAI1 clock source selection bits */
  1424. RCC->DCKCFGR &= ~RCC_DCKCFGR_SAI1SRC;
  1425. /* Set new SAI1 clock source */
  1426. RCC->DCKCFGR |= RCC_SAICLKSource;
  1427. }
  1428. else
  1429. {
  1430. /* Clear SAI2 clock source selection bits */
  1431. RCC->DCKCFGR &= ~RCC_DCKCFGR_SAI2SRC;
  1432. /* Set new SAI2 clock source */
  1433. RCC->DCKCFGR |= (RCC_SAICLKSource << 2);
  1434. }
  1435. }
  1436. #endif /* STM32F446xx */
  1437. #if defined(STM32F413_423xx)
  1438. /**
  1439. * @brief Configures SAI1BlockA clock source selection.
  1440. * @note This function must be called before enabling PLLSAI, PLLI2S and
  1441. * the SAI clock.
  1442. * @param RCC_SAIBlockACLKSource: specifies the SAI Block A clock source.
  1443. * This parameter can be one of the following values:
  1444. * @arg RCC_SAIACLKSource_PLLI2SR: PLLI2SR clock used as SAI clock source
  1445. * @arg RCC_SAIACLKSource_PLLI2S: PLLI2S clock used as SAI clock source
  1446. * @arg RCC_SAIACLKSource_PLL: PLL clock used as SAI clock source
  1447. * @arg RCC_SAIACLKSource_HSI_HSE: HSI or HSE depends on PLLSRC used as SAI clock source
  1448. * @retval None
  1449. */
  1450. void RCC_SAIBlockACLKConfig(uint32_t RCC_SAIBlockACLKSource)
  1451. {
  1452. uint32_t tmpreg = 0;
  1453. /* Check the parameters */
  1454. assert_param(IS_RCC_SAIACLK_SOURCE(RCC_SAIBlockACLKSource));
  1455. tmpreg = RCC->DCKCFGR;
  1456. /* Clear RCC_DCKCFGR_SAI1ASRC[1:0] bits */
  1457. tmpreg &= ~RCC_DCKCFGR_SAI1ASRC;
  1458. /* Set SAI Block A source selection value */
  1459. tmpreg |= RCC_SAIBlockACLKSource;
  1460. /* Store the new value */
  1461. RCC->DCKCFGR = tmpreg;
  1462. }
  1463. /**
  1464. * @brief Configures SAI1BlockB clock source selection.
  1465. * @note This function must be called before enabling PLLSAI, PLLI2S and
  1466. * the SAI clock.
  1467. * @param RCC_SAIBlockBCLKSource: specifies the SAI Block B clock source.
  1468. * This parameter can be one of the following values:
  1469. * @arg RCC_SAIBCLKSource_PLLI2SR: PLLI2SR clock used as SAI clock source
  1470. * @arg RCC_SAIBCLKSource_PLLI2S: PLLI2S clock used as SAI clock source
  1471. * @arg RCC_SAIBCLKSource_PLL: PLL clock used as SAI clock source
  1472. * @arg RCC_SAIBCLKSource_HSI_HSE: HSI or HSE depends on PLLSRC used as SAI clock source
  1473. * @retval None
  1474. */
  1475. void RCC_SAIBlockBCLKConfig(uint32_t RCC_SAIBlockBCLKSource)
  1476. {
  1477. uint32_t tmpreg = 0;
  1478. /* Check the parameters */
  1479. assert_param(IS_RCC_SAIBCLK_SOURCE(RCC_SAIBlockBCLKSource));
  1480. tmpreg = RCC->DCKCFGR;
  1481. /* Clear RCC_DCKCFGR_SAI1ASRC[1:0] bits */
  1482. tmpreg &= ~RCC_DCKCFGR_SAI1BSRC;
  1483. /* Set SAI Block B source selection value */
  1484. tmpreg |= RCC_SAIBlockBCLKSource;
  1485. /* Store the new value */
  1486. RCC->DCKCFGR = tmpreg;
  1487. }
  1488. #endif /* STM32F413_423xx */
  1489. #endif /* STM32F412xG || STM32F413_423xx || STM32F446xx */
  1490. #if defined(STM32F410xx)
  1491. /**
  1492. * @brief Configures the I2S clock source (I2SCLK).
  1493. * @note This function must be called before enabling the I2S clock.
  1494. *
  1495. * @param RCC_I2SCLKSource: specifies the I2S clock source.
  1496. * This parameter can be one of the following values:
  1497. * @arg RCC_I2SAPBCLKSOURCE_PLLR: PLL VCO output clock divided by PLLR.
  1498. * @arg RCC_I2SAPBCLKSOURCE_EXT: External clock mapped on the I2S_CKIN pin.
  1499. * @arg RCC_I2SAPBCLKSOURCE_PLLSRC: HSI/HSE depends on PLLSRC.
  1500. * @retval None
  1501. */
  1502. void RCC_I2SCLKConfig(uint32_t RCC_I2SCLKSource)
  1503. {
  1504. /* Check the parameters */
  1505. assert_param(IS_RCC_I2SCLK_SOURCE(RCC_I2SCLKSource));
  1506. /* Clear I2Sx clock source selection bits */
  1507. RCC->DCKCFGR &= ~RCC_DCKCFGR_I2SSRC;
  1508. /* Set new I2Sx clock source*/
  1509. RCC->DCKCFGR |= RCC_I2SCLKSource;
  1510. }
  1511. #endif /* STM32F410xx */
  1512. #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F411xE) || defined(STM32F469_479xx)
  1513. /**
  1514. * @brief Configures the I2S clock source (I2SCLK).
  1515. * @note This function must be called before enabling the I2S APB clock.
  1516. * @param RCC_I2SCLKSource: specifies the I2S clock source.
  1517. * This parameter can be one of the following values:
  1518. * @arg RCC_I2S2CLKSource_PLLI2S: PLLI2S clock used as I2S clock source
  1519. * @arg RCC_I2S2CLKSource_Ext: External clock mapped on the I2S_CKIN pin
  1520. * used as I2S clock source
  1521. * @retval None
  1522. */
  1523. void RCC_I2SCLKConfig(uint32_t RCC_I2SCLKSource)
  1524. {
  1525. /* Check the parameters */
  1526. assert_param(IS_RCC_I2SCLK_SOURCE(RCC_I2SCLKSource));
  1527. *(__IO uint32_t *) CFGR_I2SSRC_BB = RCC_I2SCLKSource;
  1528. }
  1529. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F411xE || STM32F469_479xx */
  1530. #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F469_479xx)
  1531. /**
  1532. * @brief Configures SAI1BlockA clock source selection.
  1533. *
  1534. * @note This function can be used only for STM32F42xxx/43xxx/469xx/479xx devices.
  1535. *
  1536. * @note This function must be called before enabling PLLSAI, PLLI2S and
  1537. * the SAI clock.
  1538. * @param RCC_SAIBlockACLKSource: specifies the SAI Block A clock source.
  1539. * This parameter can be one of the following values:
  1540. * @arg RCC_SAIACLKSource_PLLI2S: PLLI2S_Q clock divided by PLLI2SDIVQ used
  1541. * as SAI1 Block A clock
  1542. * @arg RCC_SAIACLKSource_PLLSAI: PLLISAI_Q clock divided by PLLSAIDIVQ used
  1543. * as SAI1 Block A clock
  1544. * @arg RCC_SAIACLKSource_Ext: External clock mapped on the I2S_CKIN pin
  1545. * used as SAI1 Block A clock
  1546. * @retval None
  1547. */
  1548. void RCC_SAIBlockACLKConfig(uint32_t RCC_SAIBlockACLKSource)
  1549. {
  1550. uint32_t tmpreg = 0;
  1551. /* Check the parameters */
  1552. assert_param(IS_RCC_SAIACLK_SOURCE(RCC_SAIBlockACLKSource));
  1553. tmpreg = RCC->DCKCFGR;
  1554. /* Clear RCC_DCKCFGR_SAI1ASRC[1:0] bits */
  1555. tmpreg &= ~RCC_DCKCFGR_SAI1ASRC;
  1556. /* Set SAI Block A source selection value */
  1557. tmpreg |= RCC_SAIBlockACLKSource;
  1558. /* Store the new value */
  1559. RCC->DCKCFGR = tmpreg;
  1560. }
  1561. /**
  1562. * @brief Configures SAI1BlockB clock source selection.
  1563. *
  1564. * @note This function can be used only for STM32F42xxx/43xxx/469xx/479xx devices.
  1565. *
  1566. * @note This function must be called before enabling PLLSAI, PLLI2S and
  1567. * the SAI clock.
  1568. * @param RCC_SAIBlockBCLKSource: specifies the SAI Block B clock source.
  1569. * This parameter can be one of the following values:
  1570. * @arg RCC_SAIBCLKSource_PLLI2S: PLLI2S_Q clock divided by PLLI2SDIVQ used
  1571. * as SAI1 Block B clock
  1572. * @arg RCC_SAIBCLKSource_PLLSAI: PLLISAI_Q clock divided by PLLSAIDIVQ used
  1573. * as SAI1 Block B clock
  1574. * @arg RCC_SAIBCLKSource_Ext: External clock mapped on the I2S_CKIN pin
  1575. * used as SAI1 Block B clock
  1576. * @retval None
  1577. */
  1578. void RCC_SAIBlockBCLKConfig(uint32_t RCC_SAIBlockBCLKSource)
  1579. {
  1580. uint32_t tmpreg = 0;
  1581. /* Check the parameters */
  1582. assert_param(IS_RCC_SAIBCLK_SOURCE(RCC_SAIBlockBCLKSource));
  1583. tmpreg = RCC->DCKCFGR;
  1584. /* Clear RCC_DCKCFGR_SAI1BSRC[1:0] bits */
  1585. tmpreg &= ~RCC_DCKCFGR_SAI1BSRC;
  1586. /* Set SAI Block B source selection value */
  1587. tmpreg |= RCC_SAIBlockBCLKSource;
  1588. /* Store the new value */
  1589. RCC->DCKCFGR = tmpreg;
  1590. }
  1591. #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F469_479xx */
  1592. /**
  1593. * @brief Configures the SAI clock Divider coming from PLLI2S.
  1594. *
  1595. * @note This function can be used only for STM32F42xxx/43xxx/446xx/469xx/479xx devices.
  1596. *
  1597. * @note This function must be called before enabling the PLLI2S.
  1598. *
  1599. * @param RCC_PLLI2SDivQ: specifies the PLLI2S division factor for SAI1 clock .
  1600. * This parameter must be a number between 1 and 32.
  1601. * SAI1 clock frequency = f(PLLI2S_Q) / RCC_PLLI2SDivQ
  1602. *
  1603. * @retval None
  1604. */
  1605. void RCC_SAIPLLI2SClkDivConfig(uint32_t RCC_PLLI2SDivQ)
  1606. {
  1607. uint32_t tmpreg = 0;
  1608. /* Check the parameters */
  1609. assert_param(IS_RCC_PLLI2S_DIVQ_VALUE(RCC_PLLI2SDivQ));
  1610. tmpreg = RCC->DCKCFGR;
  1611. /* Clear PLLI2SDIVQ[4:0] bits */
  1612. tmpreg &= ~(RCC_DCKCFGR_PLLI2SDIVQ);
  1613. /* Set PLLI2SDIVQ values */
  1614. tmpreg |= (RCC_PLLI2SDivQ - 1);
  1615. /* Store the new value */
  1616. RCC->DCKCFGR = tmpreg;
  1617. }
  1618. /**
  1619. * @brief Configures the SAI clock Divider coming from PLLSAI.
  1620. *
  1621. * @note This function can be used only for STM32F42xxx/43xxx/446xx/469xx/479xx devices.
  1622. *
  1623. * @note This function must be called before enabling the PLLSAI.
  1624. *
  1625. * @param RCC_PLLSAIDivQ: specifies the PLLSAI division factor for SAI1 clock .
  1626. * This parameter must be a number between 1 and 32.
  1627. * SAI1 clock frequency = f(PLLSAI_Q) / RCC_PLLSAIDivQ
  1628. *
  1629. * @retval None
  1630. */
  1631. void RCC_SAIPLLSAIClkDivConfig(uint32_t RCC_PLLSAIDivQ)
  1632. {
  1633. uint32_t tmpreg = 0;
  1634. /* Check the parameters */
  1635. assert_param(IS_RCC_PLLSAI_DIVQ_VALUE(RCC_PLLSAIDivQ));
  1636. tmpreg = RCC->DCKCFGR;
  1637. /* Clear PLLI2SDIVQ[4:0] and PLLSAIDIVQ[4:0] bits */
  1638. tmpreg &= ~(RCC_DCKCFGR_PLLSAIDIVQ);
  1639. /* Set PLLSAIDIVQ values */
  1640. tmpreg |= ((RCC_PLLSAIDivQ - 1) << 8);
  1641. /* Store the new value */
  1642. RCC->DCKCFGR = tmpreg;
  1643. }
  1644. #if defined(STM32F413_423xx)
  1645. /**
  1646. * @brief Configures the SAI clock Divider coming from PLLI2S.
  1647. *
  1648. * @note This function can be used only for STM32F413_423xx
  1649. *
  1650. * @param RCC_PLLI2SDivR: specifies the PLLI2S division factor for SAI1 clock.
  1651. * This parameter must be a number between 1 and 32.
  1652. * SAI1 clock frequency = f(PLLI2SR) / RCC_PLLI2SDivR
  1653. * @retval None
  1654. */
  1655. void RCC_SAIPLLI2SRClkDivConfig(uint32_t RCC_PLLI2SDivR)
  1656. {
  1657. uint32_t tmpreg = 0;
  1658. /* Check the parameters */
  1659. assert_param(IS_RCC_PLLI2S_DIVR_VALUE(RCC_PLLI2SDivR));
  1660. tmpreg = RCC->DCKCFGR;
  1661. /* Clear PLLI2SDIVR[4:0] bits */
  1662. tmpreg &= ~(RCC_DCKCFGR_PLLI2SDIVR);
  1663. /* Set PLLI2SDIVR values */
  1664. tmpreg |= (RCC_PLLI2SDivR-1);
  1665. /* Store the new value */
  1666. RCC->DCKCFGR = tmpreg;
  1667. }
  1668. /**
  1669. * @brief Configures the SAI clock Divider coming from PLL.
  1670. *
  1671. * @note This function can be used only for STM32F413_423xx
  1672. *
  1673. * @note This function must be called before enabling the PLLSAI.
  1674. *
  1675. * @param RCC_PLLDivR: specifies the PLL division factor for SAI1 clock.
  1676. * This parameter must be a number between 1 and 32.
  1677. * SAI1 clock frequency = f(PLLR) / RCC_PLLDivR
  1678. *
  1679. * @retval None
  1680. */
  1681. void RCC_SAIPLLRClkDivConfig(uint32_t RCC_PLLDivR)
  1682. {
  1683. uint32_t tmpreg = 0;
  1684. /* Check the parameters */
  1685. assert_param(IS_RCC_PLL_DIVR_VALUE(RCC_PLLDivR));
  1686. tmpreg = RCC->DCKCFGR;
  1687. /* Clear PLLDIVR[12:8] */
  1688. tmpreg &= ~(RCC_DCKCFGR_PLLDIVR);
  1689. /* Set PLLDivR values */
  1690. tmpreg |= ((RCC_PLLDivR - 1 ) << 8);
  1691. /* Store the new value */
  1692. RCC->DCKCFGR = tmpreg;
  1693. }
  1694. #endif /* STM32F413_423xx */
  1695. /**
  1696. * @brief Configures the LTDC clock Divider coming from PLLSAI.
  1697. *
  1698. * @note The LTDC peripheral is only available with STM32F42xxx/43xxx/446xx/469xx/479xx Devices.
  1699. *
  1700. * @note This function must be called before enabling the PLLSAI.
  1701. *
  1702. * @param RCC_PLLSAIDivR: specifies the PLLSAI division factor for LTDC clock .
  1703. * LTDC clock frequency = f(PLLSAI_R) / RCC_PLLSAIDivR
  1704. * This parameter can be one of the following values:
  1705. * @arg RCC_PLLSAIDivR_Div2: LTDC clock = f(PLLSAI_R)/2
  1706. * @arg RCC_PLLSAIDivR_Div4: LTDC clock = f(PLLSAI_R)/4
  1707. * @arg RCC_PLLSAIDivR_Div8: LTDC clock = f(PLLSAI_R)/8
  1708. * @arg RCC_PLLSAIDivR_Div16: LTDC clock = f(PLLSAI_R)/16
  1709. *
  1710. * @retval None
  1711. */
  1712. void RCC_LTDCCLKDivConfig(uint32_t RCC_PLLSAIDivR)
  1713. {
  1714. uint32_t tmpreg = 0;
  1715. /* Check the parameters */
  1716. assert_param(IS_RCC_PLLSAI_DIVR_VALUE(RCC_PLLSAIDivR));
  1717. tmpreg = RCC->DCKCFGR;
  1718. /* Clear PLLSAIDIVR[2:0] bits */
  1719. tmpreg &= ~RCC_DCKCFGR_PLLSAIDIVR;
  1720. /* Set PLLSAIDIVR values */
  1721. tmpreg |= RCC_PLLSAIDivR;
  1722. /* Store the new value */
  1723. RCC->DCKCFGR = tmpreg;
  1724. }
  1725. #if defined(STM32F412xG) || defined(STM32F413_423xx)
  1726. /**
  1727. * @brief Configures the DFSDM clock source (DFSDMCLK).
  1728. * @note This function must be called before enabling the DFSDM APB clock.
  1729. * @param RCC_DFSDMCLKSource: specifies the DFSDM clock source.
  1730. * This parameter can be one of the following values:
  1731. * @arg RCC_DFSDMCLKSource_APB: APB clock used as DFSDM clock source.
  1732. * @arg RCC_DFSDMCLKSource_SYS: System clock used as DFSDM clock source.
  1733. *
  1734. * @retval None
  1735. */
  1736. void RCC_DFSDM1CLKConfig(uint32_t RCC_DFSDMCLKSource)
  1737. {
  1738. uint32_t tmpreg = 0;
  1739. /* Check the parameters */
  1740. assert_param(IS_RCC_DFSDM1CLK_SOURCE(RCC_DFSDMCLKSource));
  1741. tmpreg = RCC->DCKCFGR;
  1742. /* Clear CKDFSDM-SEL bit */
  1743. tmpreg &= ~RCC_DCKCFGR_CKDFSDM1SEL;
  1744. /* Set CKDFSDM-SEL bit according to RCC_DFSDMCLKSource value */
  1745. tmpreg |= (RCC_DFSDMCLKSource << 31) ;
  1746. /* Store the new value */
  1747. RCC->DCKCFGR = tmpreg;
  1748. }
  1749. /**
  1750. * @brief Configures the DFSDM Audio clock source (DFSDMACLK).
  1751. * @note This function must be called before enabling the DFSDM APB clock.
  1752. * @param RCC_DFSDM1ACLKSource: specifies the DFSDM clock source.
  1753. * This parameter can be one of the following values:
  1754. * @arg RCC_DFSDM1AUDIOCLKSOURCE_I2SAPB1: APB clock used as DFSDM clock source.
  1755. * @arg RCC_DFSDM1AUDIOCLKSOURCE_I2SAPB2: System clock used as DFSDM clock source.
  1756. *
  1757. * @retval None
  1758. */
  1759. void RCC_DFSDM1ACLKConfig(uint32_t RCC_DFSDM1ACLKSource)
  1760. {
  1761. uint32_t tmpreg = 0;
  1762. /* Check the parameters */
  1763. assert_param(IS_RCC_DFSDMACLK_SOURCE(RCC_DFSDM1ACLKSource));
  1764. tmpreg = RCC->DCKCFGR;
  1765. /* Clear CKDFSDMA SEL bit */
  1766. tmpreg &= ~RCC_DCKCFGR_CKDFSDM1ASEL;
  1767. /* Set CKDFSDM-SEL bt according to RCC_DFSDMCLKSource value */
  1768. tmpreg |= RCC_DFSDM1ACLKSource;
  1769. /* Store the new value */
  1770. RCC->DCKCFGR = tmpreg;
  1771. }
  1772. #if defined(STM32F413_423xx)
  1773. /**
  1774. * @brief Configures the DFSDM Audio clock source (DFSDMACLK).
  1775. * @note This function must be called before enabling the DFSDM APB clock.
  1776. * @param RCC_DFSDM2ACLKSource: specifies the DFSDM clock source.
  1777. * This parameter can be one of the following values:
  1778. * @arg RCC_DFSDM2AUDIOCLKSOURCE_I2SAPB1: APB clock used as DFSDM clock source.
  1779. * @arg RCC_DFSDM2AUDIOCLKSOURCE_I2SAPB2: System clock used as DFSDM clock source.
  1780. *
  1781. * @retval None
  1782. */
  1783. void RCC_DFSDM2ACLKConfig(uint32_t RCC_DFSDMACLKSource)
  1784. {
  1785. uint32_t tmpreg = 0;
  1786. /* Check the parameters */
  1787. assert_param(IS_RCC_DFSDMCLK_SOURCE(RCC_DFSDMACLKSource));
  1788. tmpreg = RCC->DCKCFGR;
  1789. /* Clear CKDFSDMA SEL bit */
  1790. tmpreg &= ~RCC_DCKCFGR_CKDFSDM1ASEL;
  1791. /* Set CKDFSDM-SEL bt according to RCC_DFSDMCLKSource value */
  1792. tmpreg |= RCC_DFSDMACLKSource;
  1793. /* Store the new value */
  1794. RCC->DCKCFGR = tmpreg;
  1795. }
  1796. #endif /* STM32F413_423xx */
  1797. #endif /* STM32F412xG || STM32F413_423xx */
  1798. /**
  1799. * @brief Configures the Timers clocks prescalers selection.
  1800. *
  1801. * @note This function can be used only for STM32F42xxx/43xxx and STM32F401xx/411xE devices.
  1802. *
  1803. * @param RCC_TIMCLKPrescaler : specifies the Timers clocks prescalers selection
  1804. * This parameter can be one of the following values:
  1805. * @arg RCC_TIMPrescDesactivated: The Timers kernels clocks prescaler is
  1806. * equal to HPRE if PPREx is corresponding to division by 1 or 2,
  1807. * else it is equal to [(HPRE * PPREx) / 2] if PPREx is corresponding to
  1808. * division by 4 or more.
  1809. *
  1810. * @arg RCC_TIMPrescActivated: The Timers kernels clocks prescaler is
  1811. * equal to HPRE if PPREx is corresponding to division by 1, 2 or 4,
  1812. * else it is equal to [(HPRE * PPREx) / 4] if PPREx is corresponding
  1813. * to division by 8 or more.
  1814. * @retval None
  1815. */
  1816. void RCC_TIMCLKPresConfig(uint32_t RCC_TIMCLKPrescaler)
  1817. {
  1818. /* Check the parameters */
  1819. assert_param(IS_RCC_TIMCLK_PRESCALER(RCC_TIMCLKPrescaler));
  1820. *(__IO uint32_t *) DCKCFGR_TIMPRE_BB = RCC_TIMCLKPrescaler;
  1821. }
  1822. /**
  1823. * @brief Enables or disables the AHB1 peripheral clock.
  1824. * @note After reset, the peripheral clock (used for registers read/write access)
  1825. * is disabled and the application software has to enable this clock before
  1826. * using it.
  1827. * @param RCC_AHBPeriph: specifies the AHB1 peripheral to gates its clock.
  1828. * This parameter can be any combination of the following values:
  1829. * @arg RCC_AHB1Periph_GPIOA: GPIOA clock
  1830. * @arg RCC_AHB1Periph_GPIOB: GPIOB clock
  1831. * @arg RCC_AHB1Periph_GPIOC: GPIOC clock
  1832. * @arg RCC_AHB1Periph_GPIOD: GPIOD clock
  1833. * @arg RCC_AHB1Periph_GPIOE: GPIOE clock
  1834. * @arg RCC_AHB1Periph_GPIOF: GPIOF clock
  1835. * @arg RCC_AHB1Periph_GPIOG: GPIOG clock
  1836. * @arg RCC_AHB1Periph_GPIOG: GPIOG clock
  1837. * @arg RCC_AHB1Periph_GPIOI: GPIOI clock
  1838. * @arg RCC_AHB1Periph_GPIOJ: GPIOJ clock (STM32F42xxx/43xxx devices)
  1839. * @arg RCC_AHB1Periph_GPIOK: GPIOK clock (STM32F42xxx/43xxx devices)
  1840. * @arg RCC_AHB1Periph_CRC: CRC clock
  1841. * @arg RCC_AHB1Periph_BKPSRAM: BKPSRAM interface clock
  1842. * @arg RCC_AHB1Periph_CCMDATARAMEN CCM data RAM interface clock
  1843. * @arg RCC_AHB1Periph_DMA1: DMA1 clock
  1844. * @arg RCC_AHB1Periph_DMA2: DMA2 clock
  1845. * @arg RCC_AHB1Periph_DMA2D: DMA2D clock (STM32F429xx/439xx devices)
  1846. * @arg RCC_AHB1Periph_ETH_MAC: Ethernet MAC clock
  1847. * @arg RCC_AHB1Periph_ETH_MAC_Tx: Ethernet Transmission clock
  1848. * @arg RCC_AHB1Periph_ETH_MAC_Rx: Ethernet Reception clock
  1849. * @arg RCC_AHB1Periph_ETH_MAC_PTP: Ethernet PTP clock
  1850. * @arg RCC_AHB1Periph_OTG_HS: USB OTG HS clock
  1851. * @arg RCC_AHB1Periph_OTG_HS_ULPI: USB OTG HS ULPI clock
  1852. * @param NewState: new state of the specified peripheral clock.
  1853. * This parameter can be: ENABLE or DISABLE.
  1854. * @retval None
  1855. */
  1856. void RCC_AHB1PeriphClockCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState)
  1857. {
  1858. /* Check the parameters */
  1859. assert_param(IS_RCC_AHB1_CLOCK_PERIPH(RCC_AHB1Periph));
  1860. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1861. if (NewState != DISABLE)
  1862. {
  1863. RCC->AHB1ENR |= RCC_AHB1Periph;
  1864. }
  1865. else
  1866. {
  1867. RCC->AHB1ENR &= ~RCC_AHB1Periph;
  1868. }
  1869. }
  1870. /**
  1871. * @brief Enables or disables the AHB2 peripheral clock.
  1872. * @note After reset, the peripheral clock (used for registers read/write access)
  1873. * is disabled and the application software has to enable this clock before
  1874. * using it.
  1875. * @param RCC_AHBPeriph: specifies the AHB2 peripheral to gates its clock.
  1876. * This parameter can be any combination of the following values:
  1877. * @arg RCC_AHB2Periph_DCMI: DCMI clock
  1878. * @arg RCC_AHB2Periph_CRYP: CRYP clock
  1879. * @arg RCC_AHB2Periph_HASH: HASH clock
  1880. * @arg RCC_AHB2Periph_RNG: RNG clock
  1881. * @arg RCC_AHB2Periph_OTG_FS: USB OTG FS clock
  1882. * @param NewState: new state of the specified peripheral clock.
  1883. * This parameter can be: ENABLE or DISABLE.
  1884. * @retval None
  1885. */
  1886. void RCC_AHB2PeriphClockCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState)
  1887. {
  1888. /* Check the parameters */
  1889. assert_param(IS_RCC_AHB2_PERIPH(RCC_AHB2Periph));
  1890. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1891. if (NewState != DISABLE)
  1892. {
  1893. RCC->AHB2ENR |= RCC_AHB2Periph;
  1894. }
  1895. else
  1896. {
  1897. RCC->AHB2ENR &= ~RCC_AHB2Periph;
  1898. }
  1899. }
  1900. #if defined(STM32F40_41xxx) || defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx) || defined(STM32F469_479xx)
  1901. /**
  1902. * @brief Enables or disables the AHB3 peripheral clock.
  1903. * @note After reset, the peripheral clock (used for registers read/write access)
  1904. * is disabled and the application software has to enable this clock before
  1905. * using it.
  1906. * @param RCC_AHBPeriph: specifies the AHB3 peripheral to gates its clock.
  1907. * This parameter must be:
  1908. * - RCC_AHB3Periph_FSMC or RCC_AHB3Periph_FMC (STM32F412xG/STM32F413_423xx/STM32F429x/439x devices)
  1909. * - RCC_AHB3Periph_QSPI (STM32F412xG/STM32F413_423xx/STM32F446xx/STM32F469_479xx devices)
  1910. * @param NewState: new state of the specified peripheral clock.
  1911. * This parameter can be: ENABLE or DISABLE.
  1912. * @retval None
  1913. */
  1914. void RCC_AHB3PeriphClockCmd(uint32_t RCC_AHB3Periph, FunctionalState NewState)
  1915. {
  1916. /* Check the parameters */
  1917. assert_param(IS_RCC_AHB3_PERIPH(RCC_AHB3Periph));
  1918. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1919. if (NewState != DISABLE)
  1920. {
  1921. RCC->AHB3ENR |= RCC_AHB3Periph;
  1922. }
  1923. else
  1924. {
  1925. RCC->AHB3ENR &= ~RCC_AHB3Periph;
  1926. }
  1927. }
  1928. #endif /* STM32F40_41xxx || STM32F412xG || STM32F413_423xx || STM32F427_437xx || STM32F429_439xx || STM32F446xx || STM32F469_479xx */
  1929. /**
  1930. * @brief Enables or disables the Low Speed APB (APB1) peripheral clock.
  1931. * @note After reset, the peripheral clock (used for registers read/write access)
  1932. * is disabled and the application software has to enable this clock before
  1933. * using it.
  1934. * @param RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.
  1935. * This parameter can be any combination of the following values:
  1936. * @arg RCC_APB1Periph_TIM2: TIM2 clock
  1937. * @arg RCC_APB1Periph_TIM3: TIM3 clock
  1938. * @arg RCC_APB1Periph_TIM4: TIM4 clock
  1939. * @arg RCC_APB1Periph_TIM5: TIM5 clock
  1940. * @arg RCC_APB1Periph_TIM6: TIM6 clock
  1941. * @arg RCC_APB1Periph_TIM7: TIM7 clock
  1942. * @arg RCC_APB1Periph_TIM12: TIM12 clock
  1943. * @arg RCC_APB1Periph_TIM13: TIM13 clock
  1944. * @arg RCC_APB1Periph_TIM14: TIM14 clock
  1945. * @arg RCC_APB1Periph_LPTIM1: LPTIM1 clock (STM32F410xx and STM32F413_423xx devices)
  1946. * @arg RCC_APB1Periph_WWDG: WWDG clock
  1947. * @arg RCC_APB1Periph_SPI2: SPI2 clock
  1948. * @arg RCC_APB1Periph_SPI3: SPI3 clock
  1949. * @arg RCC_APB1Periph_SPDIF: SPDIF RX clock (STM32F446xx devices)
  1950. * @arg RCC_APB1Periph_USART2: USART2 clock
  1951. * @arg RCC_APB1Periph_USART3: USART3 clock
  1952. * @arg RCC_APB1Periph_UART4: UART4 clock
  1953. * @arg RCC_APB1Periph_UART5: UART5 clock
  1954. * @arg RCC_APB1Periph_I2C1: I2C1 clock
  1955. * @arg RCC_APB1Periph_I2C2: I2C2 clock
  1956. * @arg RCC_APB1Periph_I2C3: I2C3 clock
  1957. * @arg RCC_APB1Periph_FMPI2C1:FMPI2C1 clock
  1958. * @arg RCC_APB1Periph_CAN1: CAN1 clock
  1959. * @arg RCC_APB1Periph_CAN2: CAN2 clock
  1960. * @arg RCC_APB1Periph_CEC: CEC clock (STM32F446xx devices)
  1961. * @arg RCC_APB1Periph_PWR: PWR clock
  1962. * @arg RCC_APB1Periph_DAC: DAC clock
  1963. * @arg RCC_APB1Periph_UART7: UART7 clock
  1964. * @arg RCC_APB1Periph_UART8: UART8 clock
  1965. * @param NewState: new state of the specified peripheral clock.
  1966. * This parameter can be: ENABLE or DISABLE.
  1967. * @retval None
  1968. */
  1969. void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
  1970. {
  1971. /* Check the parameters */
  1972. assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
  1973. assert_param(IS_FUNCTIONAL_STATE(NewState));
  1974. if (NewState != DISABLE)
  1975. {
  1976. RCC->APB1ENR |= RCC_APB1Periph;
  1977. }
  1978. else
  1979. {
  1980. RCC->APB1ENR &= ~RCC_APB1Periph;
  1981. }
  1982. }
  1983. /**
  1984. * @brief Enables or disables the High Speed APB (APB2) peripheral clock.
  1985. * @note After reset, the peripheral clock (used for registers read/write access)
  1986. * is disabled and the application software has to enable this clock before
  1987. * using it.
  1988. * @param RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
  1989. * This parameter can be any combination of the following values:
  1990. * @arg RCC_APB2Periph_TIM1: TIM1 clock
  1991. * @arg RCC_APB2Periph_TIM8: TIM8 clock
  1992. * @arg RCC_APB2Periph_USART1: USART1 clock
  1993. * @arg RCC_APB2Periph_USART6: USART6 clock
  1994. * @arg RCC_APB2Periph_ADC1: ADC1 clock
  1995. * @arg RCC_APB2Periph_ADC2: ADC2 clock
  1996. * @arg RCC_APB2Periph_ADC3: ADC3 clock
  1997. * @arg RCC_APB2Periph_SDIO: SDIO clock
  1998. * @arg RCC_APB2Periph_SPI1: SPI1 clock
  1999. * @arg RCC_APB2Periph_SPI4: SPI4 clock
  2000. * @arg RCC_APB2Periph_SYSCFG: SYSCFG clock
  2001. * @arg RCC_APB2Periph_EXTIT: EXTIIT clock
  2002. * @arg RCC_APB2Periph_TIM9: TIM9 clock
  2003. * @arg RCC_APB2Periph_TIM10: TIM10 clock
  2004. * @arg RCC_APB2Periph_TIM11: TIM11 clock
  2005. * @arg RCC_APB2Periph_SPI5: SPI5 clock
  2006. * @arg RCC_APB2Periph_SPI6: SPI6 clock
  2007. * @arg RCC_APB2Periph_SAI1: SAI1 clock (STM32F42xxx/43xxx/446xx/469xx/479xx/413_423xx devices)
  2008. * @arg RCC_APB2Periph_SAI2: SAI2 clock (STM32F446xx devices)
  2009. * @arg RCC_APB2Periph_LTDC: LTDC clock (STM32F429xx/439xx devices)
  2010. * @arg RCC_APB2Periph_DSI: DSI clock (STM32F469_479xx devices)
  2011. * @arg RCC_APB2Periph_DFSDM1: DFSDM Clock (STM32F412xG and STM32F413_423xx Devices)
  2012. * @arg RCC_APB2Periph_DFSDM2: DFSDM2 Clock (STM32F413_423xx Devices)
  2013. * @arg RCC_APB2Periph_UART9: UART9 Clock (STM32F413_423xx Devices)
  2014. * @arg RCC_APB2Periph_UART10: UART10 Clock (STM32F413_423xx Devices)
  2015. * @param NewState: new state of the specified peripheral clock.
  2016. * This parameter can be: ENABLE or DISABLE.
  2017. * @retval None
  2018. */
  2019. void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
  2020. {
  2021. /* Check the parameters */
  2022. assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
  2023. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2024. if (NewState != DISABLE)
  2025. {
  2026. RCC->APB2ENR |= RCC_APB2Periph;
  2027. }
  2028. else
  2029. {
  2030. RCC->APB2ENR &= ~RCC_APB2Periph;
  2031. }
  2032. }
  2033. /**
  2034. * @brief Forces or releases AHB1 peripheral reset.
  2035. * @param RCC_AHB1Periph: specifies the AHB1 peripheral to reset.
  2036. * This parameter can be any combination of the following values:
  2037. * @arg RCC_AHB1Periph_GPIOA: GPIOA clock
  2038. * @arg RCC_AHB1Periph_GPIOB: GPIOB clock
  2039. * @arg RCC_AHB1Periph_GPIOC: GPIOC clock
  2040. * @arg RCC_AHB1Periph_GPIOD: GPIOD clock
  2041. * @arg RCC_AHB1Periph_GPIOE: GPIOE clock
  2042. * @arg RCC_AHB1Periph_GPIOF: GPIOF clock
  2043. * @arg RCC_AHB1Periph_GPIOG: GPIOG clock
  2044. * @arg RCC_AHB1Periph_GPIOG: GPIOG clock
  2045. * @arg RCC_AHB1Periph_GPIOI: GPIOI clock
  2046. * @arg RCC_AHB1Periph_GPIOJ: GPIOJ clock (STM32F42xxx/43xxx devices)
  2047. * @arg RCC_AHB1Periph_GPIOK: GPIOK clock (STM32F42xxx/43xxxdevices)
  2048. * @arg RCC_AHB1Periph_CRC: CRC clock
  2049. * @arg RCC_AHB1Periph_DMA1: DMA1 clock
  2050. * @arg RCC_AHB1Periph_DMA2: DMA2 clock
  2051. * @arg RCC_AHB1Periph_DMA2D: DMA2D clock (STM32F429xx/439xx devices)
  2052. * @arg RCC_AHB1Periph_ETH_MAC: Ethernet MAC clock
  2053. * @arg RCC_AHB1Periph_OTG_HS: USB OTG HS clock
  2054. * @arg RCC_AHB1Periph_RNG: RNG clock for STM32F410xx devices
  2055. * @param NewState: new state of the specified peripheral reset.
  2056. * This parameter can be: ENABLE or DISABLE.
  2057. * @retval None
  2058. */
  2059. void RCC_AHB1PeriphResetCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState)
  2060. {
  2061. /* Check the parameters */
  2062. assert_param(IS_RCC_AHB1_RESET_PERIPH(RCC_AHB1Periph));
  2063. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2064. if (NewState != DISABLE)
  2065. {
  2066. RCC->AHB1RSTR |= RCC_AHB1Periph;
  2067. }
  2068. else
  2069. {
  2070. RCC->AHB1RSTR &= ~RCC_AHB1Periph;
  2071. }
  2072. }
  2073. /**
  2074. * @brief Forces or releases AHB2 peripheral reset.
  2075. * @param RCC_AHB2Periph: specifies the AHB2 peripheral to reset.
  2076. * This parameter can be any combination of the following values:
  2077. * @arg RCC_AHB2Periph_DCMI: DCMI clock
  2078. * @arg RCC_AHB2Periph_CRYP: CRYP clock
  2079. * @arg RCC_AHB2Periph_HASH: HASH clock
  2080. * @arg RCC_AHB2Periph_RNG: RNG clock for STM32F40_41xxx/STM32F412xG/STM32F413_423xx/STM32F427_437xx/STM32F429_439xx/STM32F469_479xx devices
  2081. * @arg RCC_AHB2Periph_OTG_FS: USB OTG FS clock
  2082. * @param NewState: new state of the specified peripheral reset.
  2083. * This parameter can be: ENABLE or DISABLE.
  2084. * @retval None
  2085. */
  2086. void RCC_AHB2PeriphResetCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState)
  2087. {
  2088. /* Check the parameters */
  2089. assert_param(IS_RCC_AHB2_PERIPH(RCC_AHB2Periph));
  2090. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2091. if (NewState != DISABLE)
  2092. {
  2093. RCC->AHB2RSTR |= RCC_AHB2Periph;
  2094. }
  2095. else
  2096. {
  2097. RCC->AHB2RSTR &= ~RCC_AHB2Periph;
  2098. }
  2099. }
  2100. #if defined(STM32F40_41xxx) || defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx) || defined(STM32F469_479xx)
  2101. /**
  2102. * @brief Forces or releases AHB3 peripheral reset.
  2103. * @param RCC_AHB3Periph: specifies the AHB3 peripheral to reset.
  2104. * This parameter must be:
  2105. * - RCC_AHB3Periph_FSMC or RCC_AHB3Periph_FMC (STM32F412xG, STM32F413_423xx and STM32F429x/439x devices)
  2106. * - RCC_AHB3Periph_QSPI (STM32F412xG/STM32F446xx/STM32F469_479xx devices)
  2107. * @param NewState: new state of the specified peripheral reset.
  2108. * This parameter can be: ENABLE or DISABLE.
  2109. * @retval None
  2110. */
  2111. void RCC_AHB3PeriphResetCmd(uint32_t RCC_AHB3Periph, FunctionalState NewState)
  2112. {
  2113. /* Check the parameters */
  2114. assert_param(IS_RCC_AHB3_PERIPH(RCC_AHB3Periph));
  2115. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2116. if (NewState != DISABLE)
  2117. {
  2118. RCC->AHB3RSTR |= RCC_AHB3Periph;
  2119. }
  2120. else
  2121. {
  2122. RCC->AHB3RSTR &= ~RCC_AHB3Periph;
  2123. }
  2124. }
  2125. #endif /* STM32F40_41xxx || STM32F412xG || STM32F413_423xx || STM32F427_437xx || STM32F429_439xx || STM32F446xx || STM32F469_479xx */
  2126. /**
  2127. * @brief Forces or releases Low Speed APB (APB1) peripheral reset.
  2128. * @param RCC_APB1Periph: specifies the APB1 peripheral to reset.
  2129. * This parameter can be any combination of the following values:
  2130. * @arg RCC_APB1Periph_TIM2: TIM2 clock
  2131. * @arg RCC_APB1Periph_TIM3: TIM3 clock
  2132. * @arg RCC_APB1Periph_TIM4: TIM4 clock
  2133. * @arg RCC_APB1Periph_TIM5: TIM5 clock
  2134. * @arg RCC_APB1Periph_TIM6: TIM6 clock
  2135. * @arg RCC_APB1Periph_TIM7: TIM7 clock
  2136. * @arg RCC_APB1Periph_TIM12: TIM12 clock
  2137. * @arg RCC_APB1Periph_TIM13: TIM13 clock
  2138. * @arg RCC_APB1Periph_TIM14: TIM14 clock
  2139. * @arg RCC_APB1Periph_LPTIM1: LPTIM1 clock (STM32F410xx and STM32F413_423xx devices)
  2140. * @arg RCC_APB1Periph_WWDG: WWDG clock
  2141. * @arg RCC_APB1Periph_SPI2: SPI2 clock
  2142. * @arg RCC_APB1Periph_SPI3: SPI3 clock
  2143. * @arg RCC_APB1Periph_SPDIF: SPDIF RX clock (STM32F446xx devices)
  2144. * @arg RCC_APB1Periph_USART2: USART2 clock
  2145. * @arg RCC_APB1Periph_USART3: USART3 clock
  2146. * @arg RCC_APB1Periph_UART4: UART4 clock
  2147. * @arg RCC_APB1Periph_UART5: UART5 clock
  2148. * @arg RCC_APB1Periph_I2C1: I2C1 clock
  2149. * @arg RCC_APB1Periph_I2C2: I2C2 clock
  2150. * @arg RCC_APB1Periph_I2C3: I2C3 clock
  2151. * @arg RCC_APB1Periph_FMPI2C1:FMPI2C1 clock
  2152. * @arg RCC_APB1Periph_CAN1: CAN1 clock
  2153. * @arg RCC_APB1Periph_CAN2: CAN2 clock
  2154. * @arg RCC_APB1Periph_CEC: CEC clock(STM32F446xx devices)
  2155. * @arg RCC_APB1Periph_PWR: PWR clock
  2156. * @arg RCC_APB1Periph_DAC: DAC clock
  2157. * @arg RCC_APB1Periph_UART7: UART7 clock
  2158. * @arg RCC_APB1Periph_UART8: UART8 clock
  2159. * @param NewState: new state of the specified peripheral reset.
  2160. * This parameter can be: ENABLE or DISABLE.
  2161. * @retval None
  2162. */
  2163. void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
  2164. {
  2165. /* Check the parameters */
  2166. assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
  2167. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2168. if (NewState != DISABLE)
  2169. {
  2170. RCC->APB1RSTR |= RCC_APB1Periph;
  2171. }
  2172. else
  2173. {
  2174. RCC->APB1RSTR &= ~RCC_APB1Periph;
  2175. }
  2176. }
  2177. /**
  2178. * @brief Forces or releases High Speed APB (APB2) peripheral reset.
  2179. * @param RCC_APB2Periph: specifies the APB2 peripheral to reset.
  2180. * This parameter can be any combination of the following values:
  2181. * @arg RCC_APB2Periph_TIM1: TIM1 clock
  2182. * @arg RCC_APB2Periph_TIM8: TIM8 clock
  2183. * @arg RCC_APB2Periph_USART1: USART1 clock
  2184. * @arg RCC_APB2Periph_USART6: USART6 clock
  2185. * @arg RCC_APB2Periph_ADC1: ADC1 clock
  2186. * @arg RCC_APB2Periph_ADC2: ADC2 clock
  2187. * @arg RCC_APB2Periph_ADC3: ADC3 clock
  2188. * @arg RCC_APB2Periph_SDIO: SDIO clock
  2189. * @arg RCC_APB2Periph_SPI1: SPI1 clock
  2190. * @arg RCC_APB2Periph_SPI4: SPI4 clock
  2191. * @arg RCC_APB2Periph_SYSCFG: SYSCFG clock
  2192. * @arg RCC_APB2Periph_TIM9: TIM9 clock
  2193. * @arg RCC_APB2Periph_TIM10: TIM10 clock
  2194. * @arg RCC_APB2Periph_TIM11: TIM11 clock
  2195. * @arg RCC_APB2Periph_SPI5: SPI5 clock
  2196. * @arg RCC_APB2Periph_SPI6: SPI6 clock
  2197. * @arg RCC_APB2Periph_SAI1: SAI1 clock (STM32F42xxx/43xxx/446xx/469xx/479xx/413_423xx devices)
  2198. * @arg RCC_APB2Periph_SAI2: SAI2 clock (STM32F446xx devices)
  2199. * @arg RCC_APB2Periph_LTDC: LTDC clock (STM32F429xx/439xx devices)
  2200. * @arg RCC_APB2Periph_DSI: DSI clock (STM32F469_479xx devices)
  2201. * @arg RCC_APB2Periph_DFSDM1: DFSDM Clock (STM32F412xG and STM32F413_423xx Devices)
  2202. * @arg RCC_APB2Periph_DFSDM2: DFSDM2 Clock (STM32F413_423xx Devices)
  2203. * @arg RCC_APB2Periph_UART9: UART9 Clock (STM32F413_423xx Devices)
  2204. * @arg RCC_APB2Periph_UART10: UART10 Clock (STM32F413_423xx Devices)
  2205. * @param NewState: new state of the specified peripheral reset.
  2206. * This parameter can be: ENABLE or DISABLE.
  2207. * @retval None
  2208. */
  2209. void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
  2210. {
  2211. /* Check the parameters */
  2212. assert_param(IS_RCC_APB2_RESET_PERIPH(RCC_APB2Periph));
  2213. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2214. if (NewState != DISABLE)
  2215. {
  2216. RCC->APB2RSTR |= RCC_APB2Periph;
  2217. }
  2218. else
  2219. {
  2220. RCC->APB2RSTR &= ~RCC_APB2Periph;
  2221. }
  2222. }
  2223. /**
  2224. * @brief Enables or disables the AHB1 peripheral clock during Low Power (Sleep) mode.
  2225. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  2226. * power consumption.
  2227. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  2228. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  2229. * @param RCC_AHBPeriph: specifies the AHB1 peripheral to gates its clock.
  2230. * This parameter can be any combination of the following values:
  2231. * @arg RCC_AHB1Periph_GPIOA: GPIOA clock
  2232. * @arg RCC_AHB1Periph_GPIOB: GPIOB clock
  2233. * @arg RCC_AHB1Periph_GPIOC: GPIOC clock
  2234. * @arg RCC_AHB1Periph_GPIOD: GPIOD clock
  2235. * @arg RCC_AHB1Periph_GPIOE: GPIOE clock
  2236. * @arg RCC_AHB1Periph_GPIOF: GPIOF clock
  2237. * @arg RCC_AHB1Periph_GPIOG: GPIOG clock
  2238. * @arg RCC_AHB1Periph_GPIOG: GPIOG clock
  2239. * @arg RCC_AHB1Periph_GPIOI: GPIOI clock
  2240. * @arg RCC_AHB1Periph_GPIOJ: GPIOJ clock (STM32F42xxx/43xxx devices)
  2241. * @arg RCC_AHB1Periph_GPIOK: GPIOK clock (STM32F42xxx/43xxx devices)
  2242. * @arg RCC_AHB1Periph_CRC: CRC clock
  2243. * @arg RCC_AHB1Periph_BKPSRAM: BKPSRAM interface clock
  2244. * @arg RCC_AHB1Periph_DMA1: DMA1 clock
  2245. * @arg RCC_AHB1Periph_DMA2: DMA2 clock
  2246. * @arg RCC_AHB1Periph_DMA2D: DMA2D clock (STM32F429xx/439xx devices)
  2247. * @arg RCC_AHB1Periph_ETH_MAC: Ethernet MAC clock
  2248. * @arg RCC_AHB1Periph_ETH_MAC_Tx: Ethernet Transmission clock
  2249. * @arg RCC_AHB1Periph_ETH_MAC_Rx: Ethernet Reception clock
  2250. * @arg RCC_AHB1Periph_ETH_MAC_PTP: Ethernet PTP clock
  2251. * @arg RCC_AHB1Periph_OTG_HS: USB OTG HS clock
  2252. * @arg RCC_AHB1Periph_OTG_HS_ULPI: USB OTG HS ULPI clock
  2253. * @param NewState: new state of the specified peripheral clock.
  2254. * This parameter can be: ENABLE or DISABLE.
  2255. * @retval None
  2256. */
  2257. void RCC_AHB1PeriphClockLPModeCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState)
  2258. {
  2259. /* Check the parameters */
  2260. assert_param(IS_RCC_AHB1_LPMODE_PERIPH(RCC_AHB1Periph));
  2261. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2262. if (NewState != DISABLE)
  2263. {
  2264. RCC->AHB1LPENR |= RCC_AHB1Periph;
  2265. }
  2266. else
  2267. {
  2268. RCC->AHB1LPENR &= ~RCC_AHB1Periph;
  2269. }
  2270. }
  2271. /**
  2272. * @brief Enables or disables the AHB2 peripheral clock during Low Power (Sleep) mode.
  2273. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  2274. * power consumption.
  2275. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  2276. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  2277. * @param RCC_AHBPeriph: specifies the AHB2 peripheral to gates its clock.
  2278. * This parameter can be any combination of the following values:
  2279. * @arg RCC_AHB2Periph_DCMI: DCMI clock
  2280. * @arg RCC_AHB2Periph_CRYP: CRYP clock
  2281. * @arg RCC_AHB2Periph_HASH: HASH clock
  2282. * @arg RCC_AHB2Periph_RNG: RNG clock
  2283. * @arg RCC_AHB2Periph_OTG_FS: USB OTG FS clock
  2284. * @param NewState: new state of the specified peripheral clock.
  2285. * This parameter can be: ENABLE or DISABLE.
  2286. * @retval None
  2287. */
  2288. void RCC_AHB2PeriphClockLPModeCmd(uint32_t RCC_AHB2Periph, FunctionalState NewState)
  2289. {
  2290. /* Check the parameters */
  2291. assert_param(IS_RCC_AHB2_PERIPH(RCC_AHB2Periph));
  2292. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2293. if (NewState != DISABLE)
  2294. {
  2295. RCC->AHB2LPENR |= RCC_AHB2Periph;
  2296. }
  2297. else
  2298. {
  2299. RCC->AHB2LPENR &= ~RCC_AHB2Periph;
  2300. }
  2301. }
  2302. #if defined(STM32F40_41xxx) || defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F446xx) || defined(STM32F469_479xx)
  2303. /**
  2304. * @brief Enables or disables the AHB3 peripheral clock during Low Power (Sleep) mode.
  2305. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  2306. * power consumption.
  2307. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  2308. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  2309. * @param RCC_AHBPeriph: specifies the AHB3 peripheral to gates its clock.
  2310. * This parameter must be:
  2311. * - RCC_AHB3Periph_FSMC or RCC_AHB3Periph_FMC (STM32F412xG/STM32F413_423xx/STM32F429x/439x devices)
  2312. * - RCC_AHB3Periph_QSPI (STM32F412xG/STM32F413_423xx/STM32F446xx/STM32F469_479xx devices)
  2313. * @param NewState: new state of the specified peripheral clock.
  2314. * This parameter can be: ENABLE or DISABLE.
  2315. * @retval None
  2316. */
  2317. void RCC_AHB3PeriphClockLPModeCmd(uint32_t RCC_AHB3Periph, FunctionalState NewState)
  2318. {
  2319. /* Check the parameters */
  2320. assert_param(IS_RCC_AHB3_PERIPH(RCC_AHB3Periph));
  2321. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2322. if (NewState != DISABLE)
  2323. {
  2324. RCC->AHB3LPENR |= RCC_AHB3Periph;
  2325. }
  2326. else
  2327. {
  2328. RCC->AHB3LPENR &= ~RCC_AHB3Periph;
  2329. }
  2330. }
  2331. #endif /* STM32F40_41xxx || STM32F412xG || STM32F413_423xx || STM32F427_437xx || STM32F429_439xx || STM32F446xx || STM32F469_479xx */
  2332. /**
  2333. * @brief Enables or disables the APB1 peripheral clock during Low Power (Sleep) mode.
  2334. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  2335. * power consumption.
  2336. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  2337. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  2338. * @param RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.
  2339. * This parameter can be any combination of the following values:
  2340. * @arg RCC_APB1Periph_TIM2: TIM2 clock
  2341. * @arg RCC_APB1Periph_TIM3: TIM3 clock
  2342. * @arg RCC_APB1Periph_TIM4: TIM4 clock
  2343. * @arg RCC_APB1Periph_TIM5: TIM5 clock
  2344. * @arg RCC_APB1Periph_TIM6: TIM6 clock
  2345. * @arg RCC_APB1Periph_TIM7: TIM7 clock
  2346. * @arg RCC_APB1Periph_TIM12: TIM12 clock
  2347. * @arg RCC_APB1Periph_TIM13: TIM13 clock
  2348. * @arg RCC_APB1Periph_TIM14: TIM14 clock
  2349. * @arg RCC_APB1Periph_LPTIM1: LPTIM1 clock (STM32F410xx and STM32F413_423xx devices)
  2350. * @arg RCC_APB1Periph_WWDG: WWDG clock
  2351. * @arg RCC_APB1Periph_SPI2: SPI2 clock
  2352. * @arg RCC_APB1Periph_SPI3: SPI3 clock
  2353. * @arg RCC_APB1Periph_SPDIF: SPDIF RX clock (STM32F446xx devices)
  2354. * @arg RCC_APB1Periph_USART2: USART2 clock
  2355. * @arg RCC_APB1Periph_USART3: USART3 clock
  2356. * @arg RCC_APB1Periph_UART4: UART4 clock
  2357. * @arg RCC_APB1Periph_UART5: UART5 clock
  2358. * @arg RCC_APB1Periph_I2C1: I2C1 clock
  2359. * @arg RCC_APB1Periph_I2C2: I2C2 clock
  2360. * @arg RCC_APB1Periph_I2C3: I2C3 clock
  2361. * @arg RCC_APB1Periph_FMPI2C1: FMPI2C1 clock
  2362. * @arg RCC_APB1Periph_CAN1: CAN1 clock
  2363. * @arg RCC_APB1Periph_CAN2: CAN2 clock
  2364. * @arg RCC_APB1Periph_CEC: CEC clock (STM32F446xx devices)
  2365. * @arg RCC_APB1Periph_PWR: PWR clock
  2366. * @arg RCC_APB1Periph_DAC: DAC clock
  2367. * @arg RCC_APB1Periph_UART7: UART7 clock
  2368. * @arg RCC_APB1Periph_UART8: UART8 clock
  2369. * @param NewState: new state of the specified peripheral clock.
  2370. * This parameter can be: ENABLE or DISABLE.
  2371. * @retval None
  2372. */
  2373. void RCC_APB1PeriphClockLPModeCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
  2374. {
  2375. /* Check the parameters */
  2376. assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
  2377. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2378. if (NewState != DISABLE)
  2379. {
  2380. RCC->APB1LPENR |= RCC_APB1Periph;
  2381. }
  2382. else
  2383. {
  2384. RCC->APB1LPENR &= ~RCC_APB1Periph;
  2385. }
  2386. }
  2387. /**
  2388. * @brief Enables or disables the APB2 peripheral clock during Low Power (Sleep) mode.
  2389. * @note Peripheral clock gating in SLEEP mode can be used to further reduce
  2390. * power consumption.
  2391. * @note After wakeup from SLEEP mode, the peripheral clock is enabled again.
  2392. * @note By default, all peripheral clocks are enabled during SLEEP mode.
  2393. * @param RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
  2394. * This parameter can be any combination of the following values:
  2395. * @arg RCC_APB2Periph_TIM1: TIM1 clock
  2396. * @arg RCC_APB2Periph_TIM8: TIM8 clock
  2397. * @arg RCC_APB2Periph_USART1: USART1 clock
  2398. * @arg RCC_APB2Periph_USART6: USART6 clock
  2399. * @arg RCC_APB2Periph_ADC1: ADC1 clock
  2400. * @arg RCC_APB2Periph_ADC2: ADC2 clock
  2401. * @arg RCC_APB2Periph_ADC3: ADC3 clock
  2402. * @arg RCC_APB2Periph_SDIO: SDIO clock
  2403. * @arg RCC_APB2Periph_SPI1: SPI1 clock
  2404. * @arg RCC_APB2Periph_SPI4: SPI4 clock
  2405. * @arg RCC_APB2Periph_SYSCFG: SYSCFG clock
  2406. * @arg RCC_APB2Periph_EXTIT: EXTIIT clock
  2407. * @arg RCC_APB2Periph_TIM9: TIM9 clock
  2408. * @arg RCC_APB2Periph_TIM10: TIM10 clock
  2409. * @arg RCC_APB2Periph_TIM11: TIM11 clock
  2410. * @arg RCC_APB2Periph_SPI5: SPI5 clock
  2411. * @arg RCC_APB2Periph_SPI6: SPI6 clock
  2412. * @arg RCC_APB2Periph_SAI1: SAI1 clock (STM32F42xxx/43xxx/446xx/469xx/479xx/413_423xx devices)
  2413. * @arg RCC_APB2Periph_SAI2: SAI2 clock (STM32F446xx devices)
  2414. * @arg RCC_APB2Periph_LTDC: LTDC clock (STM32F429xx/439xx devices)
  2415. * @arg RCC_APB2Periph_DSI: DSI clock (STM32F469_479xx devices)
  2416. * @arg RCC_APB2Periph_DFSDM1: DFSDM Clock (STM32F412xG and STM32F413_423xx Devices)
  2417. * @arg RCC_APB2Periph_DFSDM2: DFSDM2 Clock (STM32F413_423xx Devices)
  2418. * @arg RCC_APB2Periph_UART9: UART9 Clock (STM32F413_423xx Devices)
  2419. * @arg RCC_APB2Periph_UART10: UART10 Clock (STM32F413_423xx Devices)
  2420. * @param NewState: new state of the specified peripheral clock.
  2421. * This parameter can be: ENABLE or DISABLE.
  2422. * @retval None
  2423. */
  2424. void RCC_APB2PeriphClockLPModeCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
  2425. {
  2426. /* Check the parameters */
  2427. assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
  2428. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2429. if (NewState != DISABLE)
  2430. {
  2431. RCC->APB2LPENR |= RCC_APB2Periph;
  2432. }
  2433. else
  2434. {
  2435. RCC->APB2LPENR &= ~RCC_APB2Periph;
  2436. }
  2437. }
  2438. /**
  2439. * @brief Configures the External Low Speed oscillator mode (LSE mode).
  2440. * @note This mode is only available for STM32F410xx/STM32F411xx/STM32F446xx/STM32F469_479xx devices.
  2441. * @param Mode: specifies the LSE mode.
  2442. * This parameter can be one of the following values:
  2443. * @arg RCC_LSE_LOWPOWER_MODE: LSE oscillator in low power mode.
  2444. * @arg RCC_LSE_HIGHDRIVE_MODE: LSE oscillator in High Drive mode.
  2445. * @retval None
  2446. */
  2447. void RCC_LSEModeConfig(uint8_t RCC_Mode)
  2448. {
  2449. /* Check the parameters */
  2450. assert_param(IS_RCC_LSE_MODE(RCC_Mode));
  2451. if(RCC_Mode == RCC_LSE_HIGHDRIVE_MODE)
  2452. {
  2453. SET_BIT(RCC->BDCR, RCC_BDCR_LSEMOD);
  2454. }
  2455. else
  2456. {
  2457. CLEAR_BIT(RCC->BDCR, RCC_BDCR_LSEMOD);
  2458. }
  2459. }
  2460. #if defined(STM32F410xx) || defined(STM32F413_423xx)
  2461. /**
  2462. * @brief Configures the LPTIM1 clock Source.
  2463. * @note This feature is only available for STM32F410xx devices.
  2464. * @param RCC_ClockSource: specifies the LPTIM1 clock Source.
  2465. * This parameter can be one of the following values:
  2466. * @arg RCC_LPTIM1CLKSOURCE_PCLK: LPTIM1 clock from APB1 selected.
  2467. * @arg RCC_LPTIM1CLKSOURCE_HSI: LPTIM1 clock from HSI selected.
  2468. * @arg RCC_LPTIM1CLKSOURCE_LSI: LPTIM1 clock from LSI selected.
  2469. * @arg RCC_LPTIM1CLKSOURCE_LSE: LPTIM1 clock from LSE selected.
  2470. * @retval None
  2471. */
  2472. void RCC_LPTIM1ClockSourceConfig(uint32_t RCC_ClockSource)
  2473. {
  2474. /* Check the parameters */
  2475. assert_param(IS_RCC_LPTIM1_CLOCKSOURCE(RCC_ClockSource));
  2476. /* Clear LPTIM1 clock source selection source bits */
  2477. RCC->DCKCFGR2 &= ~RCC_DCKCFGR2_LPTIM1SEL;
  2478. /* Set new LPTIM1 clock source */
  2479. RCC->DCKCFGR2 |= RCC_ClockSource;
  2480. }
  2481. #endif /* STM32F410xx || STM32F413_423xx */
  2482. #if defined(STM32F469_479xx)
  2483. /**
  2484. * @brief Configures the DSI clock Source.
  2485. * @note This feature is only available for STM32F469_479xx devices.
  2486. * @param RCC_ClockSource: specifies the DSI clock Source.
  2487. * This parameter can be one of the following values:
  2488. * @arg RCC_DSICLKSource_PHY: DSI-PHY used as DSI byte lane clock source (usual case).
  2489. * @arg RCC_DSICLKSource_PLLR: PLL_R used as DSI byte lane clock source, used in case DSI PLL and DSI-PHY are off (low power mode).
  2490. * @retval None
  2491. */
  2492. void RCC_DSIClockSourceConfig(uint8_t RCC_ClockSource)
  2493. {
  2494. /* Check the parameters */
  2495. assert_param(IS_RCC_DSI_CLOCKSOURCE(RCC_ClockSource));
  2496. if(RCC_ClockSource == RCC_DSICLKSource_PLLR)
  2497. {
  2498. SET_BIT(RCC->DCKCFGR, RCC_DCKCFGR_DSISEL);
  2499. }
  2500. else
  2501. {
  2502. CLEAR_BIT(RCC->DCKCFGR, RCC_DCKCFGR_DSISEL);
  2503. }
  2504. }
  2505. #endif /* STM32F469_479xx */
  2506. #if defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx) || defined(STM32F469_479xx)
  2507. /**
  2508. * @brief Configures the 48MHz clock Source.
  2509. * @note This feature is only available for STM32F446xx/STM32F469_479xx devices.
  2510. * @param RCC_ClockSource: specifies the 48MHz clock Source.
  2511. * This parameter can be one of the following values:
  2512. * @arg RCC_48MHZCLKSource_PLL: 48MHz from PLL selected.
  2513. * @arg RCC_48MHZCLKSource_PLLSAI: 48MHz from PLLSAI selected.
  2514. * @arg RCC_CK48CLKSOURCE_PLLI2SQ : 48MHz from PLLI2SQ
  2515. * @retval None
  2516. */
  2517. void RCC_48MHzClockSourceConfig(uint8_t RCC_ClockSource)
  2518. {
  2519. /* Check the parameters */
  2520. assert_param(IS_RCC_48MHZ_CLOCKSOURCE(RCC_ClockSource));
  2521. #if defined(STM32F469_479xx)
  2522. if(RCC_ClockSource == RCC_48MHZCLKSource_PLLSAI)
  2523. {
  2524. SET_BIT(RCC->DCKCFGR, RCC_DCKCFGR_CK48MSEL);
  2525. }
  2526. else
  2527. {
  2528. CLEAR_BIT(RCC->DCKCFGR, RCC_DCKCFGR_CK48MSEL);
  2529. }
  2530. #elif defined(STM32F446xx)
  2531. if(RCC_ClockSource == RCC_48MHZCLKSource_PLLSAI)
  2532. {
  2533. SET_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_CK48MSEL);
  2534. }
  2535. else
  2536. {
  2537. CLEAR_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_CK48MSEL);
  2538. }
  2539. #elif defined(STM32F412xG) || defined(STM32F413_423xx)
  2540. if(RCC_ClockSource == RCC_CK48CLKSOURCE_PLLI2SQ)
  2541. {
  2542. SET_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_CK48MSEL);
  2543. }
  2544. else
  2545. {
  2546. CLEAR_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_CK48MSEL);
  2547. }
  2548. #else
  2549. #endif /* STM32F469_479xx */
  2550. }
  2551. /**
  2552. * @brief Configures the SDIO clock Source.
  2553. * @note This feature is only available for STM32F469_479xx/STM32F446xx devices.
  2554. * @param RCC_ClockSource: specifies the SDIO clock Source.
  2555. * This parameter can be one of the following values:
  2556. * @arg RCC_SDIOCLKSource_48MHZ: 48MHz clock selected.
  2557. * @arg RCC_SDIOCLKSource_SYSCLK: system clock selected.
  2558. * @retval None
  2559. */
  2560. void RCC_SDIOClockSourceConfig(uint8_t RCC_ClockSource)
  2561. {
  2562. /* Check the parameters */
  2563. assert_param(IS_RCC_SDIO_CLOCKSOURCE(RCC_ClockSource));
  2564. #if defined(STM32F469_479xx)
  2565. if(RCC_ClockSource == RCC_SDIOCLKSource_SYSCLK)
  2566. {
  2567. SET_BIT(RCC->DCKCFGR, RCC_DCKCFGR_SDIOSEL);
  2568. }
  2569. else
  2570. {
  2571. CLEAR_BIT(RCC->DCKCFGR, RCC_DCKCFGR_SDIOSEL);
  2572. }
  2573. #elif defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx)
  2574. if(RCC_ClockSource == RCC_SDIOCLKSource_SYSCLK)
  2575. {
  2576. SET_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_SDIOSEL);
  2577. }
  2578. else
  2579. {
  2580. CLEAR_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_SDIOSEL);
  2581. }
  2582. #else
  2583. #endif /* STM32F469_479xx */
  2584. }
  2585. #endif /* STM32F412xG || STM32F413_423xx || STM32F446xx || STM32F469_479xx */
  2586. #if defined(STM32F446xx)
  2587. /**
  2588. * @brief Enables or disables the AHB1 clock gating for the specified IPs.
  2589. * @note This feature is only available for STM32F446xx devices.
  2590. * @param RCC_AHB1ClockGating: specifies the AHB1 clock gating.
  2591. * This parameter can be any combination of the following values:
  2592. * @arg RCC_AHB1ClockGating_APB1Bridge: AHB1 to APB1 clock
  2593. * @arg RCC_AHB1ClockGating_APB2Bridge: AHB1 to APB2 clock
  2594. * @arg RCC_AHB1ClockGating_CM4DBG: Cortex M4 ETM clock
  2595. * @arg RCC_AHB1ClockGating_SPARE: Spare clock
  2596. * @arg RCC_AHB1ClockGating_SRAM: SRAM controller clock
  2597. * @arg RCC_AHB1ClockGating_FLITF: Flash interface clock
  2598. * @arg RCC_AHB1ClockGating_RCC: RCC clock
  2599. * @param NewState: new state of the specified peripheral clock.
  2600. * This parameter can be: ENABLE or DISABLE.
  2601. * @retval None
  2602. */
  2603. void RCC_AHB1ClockGatingCmd(uint32_t RCC_AHB1ClockGating, FunctionalState NewState)
  2604. {
  2605. /* Check the parameters */
  2606. assert_param(IS_RCC_AHB1_CLOCKGATING(RCC_AHB1ClockGating));
  2607. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2608. if (NewState != DISABLE)
  2609. {
  2610. RCC->CKGATENR &= ~RCC_AHB1ClockGating;
  2611. }
  2612. else
  2613. {
  2614. RCC->CKGATENR |= RCC_AHB1ClockGating;
  2615. }
  2616. }
  2617. /**
  2618. * @brief Configures the SPDIFRX clock Source.
  2619. * @note This feature is only available for STM32F446xx devices.
  2620. * @param RCC_ClockSource: specifies the SPDIFRX clock Source.
  2621. * This parameter can be one of the following values:
  2622. * @arg RCC_SPDIFRXCLKSource_PLLR: SPDIFRX clock from PLL_R selected.
  2623. * @arg RCC_SPDIFRXCLKSource_PLLI2SP: SPDIFRX clock from PLLI2S_P selected.
  2624. * @retval None
  2625. */
  2626. void RCC_SPDIFRXClockSourceConfig(uint8_t RCC_ClockSource)
  2627. {
  2628. /* Check the parameters */
  2629. assert_param(IS_RCC_SPDIFRX_CLOCKSOURCE(RCC_ClockSource));
  2630. if(RCC_ClockSource == RCC_SPDIFRXCLKSource_PLLI2SP)
  2631. {
  2632. SET_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_SPDIFRXSEL);
  2633. }
  2634. else
  2635. {
  2636. CLEAR_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_SPDIFRXSEL);
  2637. }
  2638. }
  2639. /**
  2640. * @brief Configures the CEC clock Source.
  2641. * @note This feature is only available for STM32F446xx devices.
  2642. * @param RCC_ClockSource: specifies the CEC clock Source.
  2643. * This parameter can be one of the following values:
  2644. * @arg RCC_CECCLKSource_HSIDiv488: CEC clock from HSI/488 selected.
  2645. * @arg RCC_CECCLKSource_LSE: CEC clock from LSE selected.
  2646. * @retval None
  2647. */
  2648. void RCC_CECClockSourceConfig(uint8_t RCC_ClockSource)
  2649. {
  2650. /* Check the parameters */
  2651. assert_param(IS_RCC_CEC_CLOCKSOURCE(RCC_ClockSource));
  2652. if(RCC_ClockSource == RCC_CECCLKSource_LSE)
  2653. {
  2654. SET_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_CECSEL);
  2655. }
  2656. else
  2657. {
  2658. CLEAR_BIT(RCC->DCKCFGR2, RCC_DCKCFGR2_CECSEL);
  2659. }
  2660. }
  2661. #endif /* STM32F446xx */
  2662. #if defined(STM32F410xx) || defined(STM32F412xG) || defined(STM32F413_423xx) || defined(STM32F446xx)
  2663. /**
  2664. * @brief Configures the FMPI2C1 clock Source.
  2665. * @note This feature is only available for STM32F446xx devices.
  2666. * @param RCC_ClockSource: specifies the FMPI2C1 clock Source.
  2667. * This parameter can be one of the following values:
  2668. * @arg RCC_FMPI2C1CLKSource_APB1: FMPI2C1 clock from APB1 selected.
  2669. * @arg RCC_FMPI2C1CLKSource_SYSCLK: FMPI2C1 clock from Sytem clock selected.
  2670. * @arg RCC_FMPI2C1CLKSource_HSI: FMPI2C1 clock from HSI selected.
  2671. * @retval None
  2672. */
  2673. void RCC_FMPI2C1ClockSourceConfig(uint32_t RCC_ClockSource)
  2674. {
  2675. /* Check the parameters */
  2676. assert_param(IS_RCC_FMPI2C1_CLOCKSOURCE(RCC_ClockSource));
  2677. /* Clear FMPI2C1 clock source selection source bits */
  2678. RCC->DCKCFGR2 &= ~RCC_DCKCFGR2_FMPI2C1SEL;
  2679. /* Set new FMPI2C1 clock source */
  2680. RCC->DCKCFGR2 |= RCC_ClockSource;
  2681. }
  2682. #endif /* STM32F410xx || STM32F412xG || STM32F413_423xx || STM32F446xx */
  2683. /**
  2684. * @}
  2685. */
  2686. #if defined(STM32F410xx)
  2687. /**
  2688. * @brief Enables or disables the MCO1.
  2689. * @param NewState: new state of the MCO1.
  2690. * This parameter can be: ENABLE or DISABLE.
  2691. * @retval None
  2692. */
  2693. void RCC_MCO1Cmd(FunctionalState NewState)
  2694. {
  2695. /* Check the parameters */
  2696. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2697. *(__IO uint32_t *) RCC_CFGR_MCO1EN_BB = (uint32_t)NewState;
  2698. }
  2699. /**
  2700. * @brief Enables or disables the MCO2.
  2701. * @param NewState: new state of the MCO2.
  2702. * This parameter can be: ENABLE or DISABLE.
  2703. * @retval None
  2704. */
  2705. void RCC_MCO2Cmd(FunctionalState NewState)
  2706. {
  2707. /* Check the parameters */
  2708. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2709. *(__IO uint32_t *) RCC_CFGR_MCO2EN_BB = (uint32_t)NewState;
  2710. }
  2711. #endif /* STM32F410xx */
  2712. /** @defgroup RCC_Group4 Interrupts and flags management functions
  2713. * @brief Interrupts and flags management functions
  2714. *
  2715. @verbatim
  2716. ===============================================================================
  2717. ##### Interrupts and flags management functions #####
  2718. ===============================================================================
  2719. @endverbatim
  2720. * @{
  2721. */
  2722. /**
  2723. * @brief Enables or disables the specified RCC interrupts.
  2724. * @param RCC_IT: specifies the RCC interrupt sources to be enabled or disabled.
  2725. * This parameter can be any combination of the following values:
  2726. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  2727. * @arg RCC_IT_LSERDY: LSE ready interrupt
  2728. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  2729. * @arg RCC_IT_HSERDY: HSE ready interrupt
  2730. * @arg RCC_IT_PLLRDY: main PLL ready interrupt
  2731. * @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt
  2732. * @arg RCC_IT_PLLSAIRDY: PLLSAI ready interrupt (only for STM32F42xxx/43xxx/446xx/469xx/479xx devices)
  2733. * @param NewState: new state of the specified RCC interrupts.
  2734. * This parameter can be: ENABLE or DISABLE.
  2735. * @retval None
  2736. */
  2737. void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState)
  2738. {
  2739. /* Check the parameters */
  2740. assert_param(IS_RCC_IT(RCC_IT));
  2741. assert_param(IS_FUNCTIONAL_STATE(NewState));
  2742. if (NewState != DISABLE)
  2743. {
  2744. /* Perform Byte access to RCC_CIR[14:8] bits to enable the selected interrupts */
  2745. *(__IO uint8_t *) CIR_BYTE2_ADDRESS |= RCC_IT;
  2746. }
  2747. else
  2748. {
  2749. /* Perform Byte access to RCC_CIR[14:8] bits to disable the selected interrupts */
  2750. *(__IO uint8_t *) CIR_BYTE2_ADDRESS &= (uint8_t)~RCC_IT;
  2751. }
  2752. }
  2753. /**
  2754. * @brief Checks whether the specified RCC flag is set or not.
  2755. * @param RCC_FLAG: specifies the flag to check.
  2756. * This parameter can be one of the following values:
  2757. * @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready
  2758. * @arg RCC_FLAG_HSERDY: HSE oscillator clock ready
  2759. * @arg RCC_FLAG_PLLRDY: main PLL clock ready
  2760. * @arg RCC_FLAG_PLLI2SRDY: PLLI2S clock ready
  2761. * @arg RCC_FLAG_PLLSAIRDY: PLLSAI clock ready (only for STM32F42xxx/43xxx/446xx/469xx/479xx devices)
  2762. * @arg RCC_FLAG_LSERDY: LSE oscillator clock ready
  2763. * @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready
  2764. * @arg RCC_FLAG_BORRST: POR/PDR or BOR reset
  2765. * @arg RCC_FLAG_PINRST: Pin reset
  2766. * @arg RCC_FLAG_PORRST: POR/PDR reset
  2767. * @arg RCC_FLAG_SFTRST: Software reset
  2768. * @arg RCC_FLAG_IWDGRST: Independent Watchdog reset
  2769. * @arg RCC_FLAG_WWDGRST: Window Watchdog reset
  2770. * @arg RCC_FLAG_LPWRRST: Low Power reset
  2771. * @retval The new state of RCC_FLAG (SET or RESET).
  2772. */
  2773. FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
  2774. {
  2775. uint32_t tmp = 0;
  2776. uint32_t statusreg = 0;
  2777. FlagStatus bitstatus = RESET;
  2778. /* Check the parameters */
  2779. assert_param(IS_RCC_FLAG(RCC_FLAG));
  2780. /* Get the RCC register index */
  2781. tmp = RCC_FLAG >> 5;
  2782. if (tmp == 1) /* The flag to check is in CR register */
  2783. {
  2784. statusreg = RCC->CR;
  2785. }
  2786. else if (tmp == 2) /* The flag to check is in BDCR register */
  2787. {
  2788. statusreg = RCC->BDCR;
  2789. }
  2790. else /* The flag to check is in CSR register */
  2791. {
  2792. statusreg = RCC->CSR;
  2793. }
  2794. /* Get the flag position */
  2795. tmp = RCC_FLAG & FLAG_MASK;
  2796. if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)
  2797. {
  2798. bitstatus = SET;
  2799. }
  2800. else
  2801. {
  2802. bitstatus = RESET;
  2803. }
  2804. /* Return the flag status */
  2805. return bitstatus;
  2806. }
  2807. /**
  2808. * @brief Clears the RCC reset flags.
  2809. * The reset flags are: RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  2810. * RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  2811. * @param None
  2812. * @retval None
  2813. */
  2814. void RCC_ClearFlag(void)
  2815. {
  2816. /* Set RMVF bit to clear the reset flags */
  2817. RCC->CSR |= RCC_CSR_RMVF;
  2818. }
  2819. /**
  2820. * @brief Checks whether the specified RCC interrupt has occurred or not.
  2821. * @param RCC_IT: specifies the RCC interrupt source to check.
  2822. * This parameter can be one of the following values:
  2823. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  2824. * @arg RCC_IT_LSERDY: LSE ready interrupt
  2825. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  2826. * @arg RCC_IT_HSERDY: HSE ready interrupt
  2827. * @arg RCC_IT_PLLRDY: main PLL ready interrupt
  2828. * @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt
  2829. * @arg RCC_IT_PLLSAIRDY: PLLSAI clock ready interrupt (only for STM32F42xxx/43xxx/446xx/469xx/479xx devices)
  2830. * @arg RCC_IT_CSS: Clock Security System interrupt
  2831. * @retval The new state of RCC_IT (SET or RESET).
  2832. */
  2833. ITStatus RCC_GetITStatus(uint8_t RCC_IT)
  2834. {
  2835. ITStatus bitstatus = RESET;
  2836. /* Check the parameters */
  2837. assert_param(IS_RCC_GET_IT(RCC_IT));
  2838. /* Check the status of the specified RCC interrupt */
  2839. if ((RCC->CIR & RCC_IT) != (uint32_t)RESET)
  2840. {
  2841. bitstatus = SET;
  2842. }
  2843. else
  2844. {
  2845. bitstatus = RESET;
  2846. }
  2847. /* Return the RCC_IT status */
  2848. return bitstatus;
  2849. }
  2850. /**
  2851. * @brief Clears the RCC's interrupt pending bits.
  2852. * @param RCC_IT: specifies the interrupt pending bit to clear.
  2853. * This parameter can be any combination of the following values:
  2854. * @arg RCC_IT_LSIRDY: LSI ready interrupt
  2855. * @arg RCC_IT_LSERDY: LSE ready interrupt
  2856. * @arg RCC_IT_HSIRDY: HSI ready interrupt
  2857. * @arg RCC_IT_HSERDY: HSE ready interrupt
  2858. * @arg RCC_IT_PLLRDY: main PLL ready interrupt
  2859. * @arg RCC_IT_PLLI2SRDY: PLLI2S ready interrupt
  2860. * @arg RCC_IT_PLLSAIRDY: PLLSAI ready interrupt (only for STM32F42xxx/43xxx/446xx/469xx/479xx devices)
  2861. * @arg RCC_IT_CSS: Clock Security System interrupt
  2862. * @retval None
  2863. */
  2864. void RCC_ClearITPendingBit(uint8_t RCC_IT)
  2865. {
  2866. /* Check the parameters */
  2867. assert_param(IS_RCC_CLEAR_IT(RCC_IT));
  2868. /* Perform Byte access to RCC_CIR[23:16] bits to clear the selected interrupt
  2869. pending bits */
  2870. *(__IO uint8_t *) CIR_BYTE3_ADDRESS = RCC_IT;
  2871. }
  2872. /**
  2873. * @}
  2874. */
  2875. /**
  2876. * @}
  2877. */
  2878. /**
  2879. * @}
  2880. */
  2881. /**
  2882. * @}
  2883. */