n32g45x_rcc.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_rcc.c
  29. * @author Nations
  30. * @version v1.0.2
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #include "n32g45x_rcc.h"
  35. /** @addtogroup N32G45X_StdPeriph_Driver
  36. * @{
  37. */
  38. /** @addtogroup RCC
  39. * @brief RCC driver modules
  40. * @{
  41. */
  42. /** @addtogroup RCC_Private_TypesDefinitions
  43. * @{
  44. */
  45. /**
  46. * @}
  47. */
  48. /** @addtogroup RCC_Private_Defines
  49. * @{
  50. */
  51. /* ------------ RCC registers bit address in the alias region ----------- */
  52. #define RCC_OFFSET (RCC_BASE - PERIPH_BASE)
  53. /* --- CTRL Register ---*/
  54. /* Alias word address of HSIEN bit */
  55. #define CTRL_OFFSET (RCC_OFFSET + 0x00)
  56. #define HSIEN_BITN 0x00
  57. #define CTRL_HSIEN_BB (PERIPH_BB_BASE + (CTRL_OFFSET * 32) + (HSIEN_BITN * 4))
  58. /* Alias word address of PLLEN bit */
  59. #define PLLEN_BITN 0x18
  60. #define CTRL_PLLEN_BB (PERIPH_BB_BASE + (CTRL_OFFSET * 32) + (PLLEN_BITN * 4))
  61. /* Alias word address of CLKSSEN bit */
  62. #define CLKSSEN_BITN 0x13
  63. #define CTRL_CLKSSEN_BB (PERIPH_BB_BASE + (CTRL_OFFSET * 32) + (CLKSSEN_BITN * 4))
  64. /* --- CFG Register ---*/
  65. /* Alias word address of USBPRES bit */
  66. #define CFG_OFFSET (RCC_OFFSET + 0x04)
  67. #define USBPRES_BITN 0x16
  68. #define CFG_USBPRES_BB (PERIPH_BB_BASE + (CFG_OFFSET * 32) + (USBPRES_BITN * 4))
  69. #define USBPRE_Bit1Number 0x17
  70. #define CFGR_USBPRE_BB_BIT1 (PERIPH_BB_BASE + (CFG_OFFSET * 32) + (USBPRE_Bit1Number * 4))
  71. /* --- BDCTRL Register ---*/
  72. /* Alias word address of RTCEN bit */
  73. #define BDCTRL_OFFSET (RCC_OFFSET + 0x20)
  74. #define RTCEN_BITN 0x0F
  75. #define BDCTRL_RTCEN_BB (PERIPH_BB_BASE + (BDCTRL_OFFSET * 32) + (RTCEN_BITN * 4))
  76. /* Alias word address of BDSFTRST bit */
  77. #define BDSFTRST_BITN 0x10
  78. #define BDCTRL_BDSFTRST_BB (PERIPH_BB_BASE + (BDCTRL_OFFSET * 32) + (BDSFTRST_BITN * 4))
  79. /* --- CTRLSTS Register ---*/
  80. /* Alias word address of LSIEN bit */
  81. #define CTRLSTS_OFFSET (RCC_OFFSET + 0x24)
  82. #define LSIEN_BITNUMBER 0x00
  83. #define CTRLSTS_LSIEN_BB (PERIPH_BB_BASE + (CTRLSTS_OFFSET * 32) + (LSIEN_BITNUMBER * 4))
  84. /* ---------------------- RCC registers bit mask ------------------------ */
  85. /* CTRL register bit mask */
  86. #define CTRL_HSEBP_RESET ((uint32_t)0xFFFBFFFF)
  87. #define CTRL_HSEBP_SET ((uint32_t)0x00040000)
  88. #define CTRL_HSEEN_RESET ((uint32_t)0xFFFEFFFF)
  89. #define CTRL_HSEEN_SET ((uint32_t)0x00010000)
  90. #define CTRL_HSITRIM_MASK ((uint32_t)0xFFFFFF07)
  91. /* CFG register bit mask */
  92. #define CFG_PLL_MASK ((uint32_t)0xF7C0FFFF)
  93. #define CFG_PLLMULFCT_MASK ((uint32_t)0x083C0000)
  94. #define CFG_PLLSRC_MASK ((uint32_t)0x00010000)
  95. #define CFG_PLLHSEPRES_MASK ((uint32_t)0x00020000)
  96. #define CFG_SCLKSTS_MASK ((uint32_t)0x0000000C)
  97. #define CFG_SCLKSW_MASK ((uint32_t)0xFFFFFFFC)
  98. #define CFG_AHBPRES_RESET_MASK ((uint32_t)0xFFFFFF0F)
  99. #define CFG_AHBPRES_SET_MASK ((uint32_t)0x000000F0)
  100. #define CFG_APB1PRES_RESET_MASK ((uint32_t)0xFFFFF8FF)
  101. #define CFG_APB1PRES_SET_MASK ((uint32_t)0x00000700)
  102. #define CFG_APB2PRES_RESET_MASK ((uint32_t)0xFFFFC7FF)
  103. #define CFG_APB2PRES_SET_MASK ((uint32_t)0x00003800)
  104. /* CFG2 register bit mask */
  105. #define CFG2_TIM18CLKSEL_SET_MASK ((uint32_t)0x20000000)
  106. #define CFG2_TIM18CLKSEL_RESET_MASK ((uint32_t)0xDFFFFFFF)
  107. #define CFG2_RNGCPRES_SET_MASK ((uint32_t)0x1F000000)
  108. #define CFG2_RNGCPRES_RESET_MASK ((uint32_t)0xE0FFFFFF)
  109. #define CFG2_ADC1MSEL_SET_MASK ((uint32_t)0x00000400)
  110. #define CFG2_ADC1MSEL_RESET_MASK ((uint32_t)0xFFFFFBFF)
  111. #define CFG2_ADC1MPRES_SET_MASK ((uint32_t)0x0000F800)
  112. #define CFG2_ADC1MPRES_RESET_MASK ((uint32_t)0xFFFF07FF)
  113. #define CFG2_ADCPLLPRES_SET_MASK ((uint32_t)0x000001F0)
  114. #define CFG2_ADCPLLPRES_RESET_MASK ((uint32_t)0xFFFFFE0F)
  115. #define CFG2_ADCHPRES_SET_MASK ((uint32_t)0x0000000F)
  116. #define CFG2_ADCHPRES_RESET_MASK ((uint32_t)0xFFFFFFF0)
  117. /* CFG3 register bit mask */
  118. #define CFGR3_TRNG1MSEL_SET_MASK ((uint32_t)0x00020000)
  119. #define CFGR3_TRNG1MSEL_RESET_MASK ((uint32_t)0xFFFDFFFF)
  120. #define CFGR3_TRNG1MPRES_SET_MASK ((uint32_t)0x0000F800)
  121. #define CFGR3_TRNG1MPRES_RESET_MASK ((uint32_t)0xFFFF07FF)
  122. /* CTRLSTS register bit mask */
  123. #define CSR_RMRSTF_SET ((uint32_t)0x01000000)
  124. #define CSR_RMVF_Reset ((uint32_t)0xfeffffff)
  125. /* RCC Flag Mask */
  126. #define FLAG_MASK ((uint8_t)0x1F)
  127. /* CLKINT register byte 2 (Bits[15:8]) base address */
  128. #define CLKINT_BYTE2_ADDR ((uint32_t)0x40021009)
  129. /* CLKINT register byte 3 (Bits[23:16]) base address */
  130. #define CLKINT_BYTE3_ADDR ((uint32_t)0x4002100A)
  131. /* CFG register byte 4 (Bits[31:24]) base address */
  132. #define CFG_BYTE4_ADDR ((uint32_t)0x40021007)
  133. /* BDCTRL register base address */
  134. #define BDCTRL_ADDR (PERIPH_BASE + BDCTRL_OFFSET)
  135. /**
  136. * @}
  137. */
  138. /** @addtogroup RCC_Private_Macros
  139. * @{
  140. */
  141. /**
  142. * @}
  143. */
  144. /** @addtogroup RCC_Private_Variables
  145. * @{
  146. */
  147. static const uint8_t s_ApbAhbPresTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
  148. static const uint8_t s_AdcHclkPresTable[16] = {1, 2, 4, 6, 8, 10, 12, 16, 32, 32, 32, 32, 32, 32, 32, 32};
  149. static const uint16_t s_AdcPllClkPresTable[16] = {1, 2, 4, 6, 8, 10, 12, 16, 32, 64, 128, 256, 256, 256, 256, 256};
  150. /**
  151. * @}
  152. */
  153. /** @addtogroup RCC_Private_FunctionPrototypes
  154. * @{
  155. */
  156. /**
  157. * @}
  158. */
  159. /** @addtogroup RCC_Private_Functions
  160. * @{
  161. */
  162. /**
  163. * @brief Resets the RCC clock configuration to the default reset state.
  164. */
  165. void RCC_DeInit(void)
  166. {
  167. /* Set HSIEN bit */
  168. RCC->CTRL |= (uint32_t)0x00000001;
  169. /* Reset SW, HPRE, PPRE1, PPRE2 and MCO bits */
  170. RCC->CFG &= (uint32_t)0xF8FFC000;
  171. /* Reset HSEON, CLKSSEN and PLLEN bits */
  172. RCC->CTRL &= (uint32_t)0xFEF6FFFF;
  173. /* Reset HSEBYP bit */
  174. RCC->CTRL &= (uint32_t)0xFFFBFFFF;
  175. /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRES/OTGFSPRE bits */
  176. RCC->CFG &= (uint32_t)0xF700FFFF;
  177. /* Reset CFG2 register */
  178. RCC->CFG2 = 0x00003800;
  179. /* Reset CFG3 register */
  180. RCC->CFG3 = 0x00003840;
  181. /* Disable all interrupts and clear pending bits */
  182. RCC->CLKINT = 0x009F0000;
  183. }
  184. /**
  185. * @brief Configures the External High Speed oscillator (HSE).
  186. * @note HSE can not be stopped if it is used directly or through the PLL as system clock.
  187. * @param RCC_HSE specifies the new state of the HSE.
  188. * This parameter can be one of the following values:
  189. * @arg RCC_HSE_DISABLE HSE oscillator OFF
  190. * @arg RCC_HSE_ENABLE HSE oscillator ON
  191. * @arg RCC_HSE_BYPASS HSE oscillator bypassed with external clock
  192. */
  193. void RCC_ConfigHse(uint32_t RCC_HSE)
  194. {
  195. /* Check the parameters */
  196. assert_param(IS_RCC_HSE(RCC_HSE));
  197. /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/
  198. /* Reset HSEON bit */
  199. RCC->CTRL &= CTRL_HSEEN_RESET;
  200. /* Reset HSEBYP bit */
  201. RCC->CTRL &= CTRL_HSEBP_RESET;
  202. /* Configure HSE (RC_HSE_DISABLE is already covered by the code section above) */
  203. switch (RCC_HSE)
  204. {
  205. case RCC_HSE_ENABLE:
  206. /* Set HSEON bit */
  207. RCC->CTRL |= CTRL_HSEEN_SET;
  208. break;
  209. case RCC_HSE_BYPASS:
  210. /* Set HSEBYP and HSEON bits */
  211. RCC->CTRL |= CTRL_HSEBP_SET | CTRL_HSEEN_SET;
  212. break;
  213. default:
  214. break;
  215. }
  216. }
  217. /**
  218. * @brief Waits for HSE start-up.
  219. * @return An ErrorStatus enumuration value:
  220. * - SUCCESS: HSE oscillator is stable and ready to use
  221. * - ERROR: HSE oscillator not yet ready
  222. */
  223. ErrorStatus RCC_WaitHseStable(void)
  224. {
  225. __IO uint32_t StartUpCounter = 0;
  226. ErrorStatus status = ERROR;
  227. FlagStatus HSEStatus = RESET;
  228. /* Wait till HSE is ready and if Time out is reached exit */
  229. do
  230. {
  231. HSEStatus = RCC_GetFlagStatus(RCC_FLAG_HSERD);
  232. StartUpCounter++;
  233. } while ((StartUpCounter != HSE_STARTUP_TIMEOUT) && (HSEStatus == RESET));
  234. if (RCC_GetFlagStatus(RCC_FLAG_HSERD) != RESET)
  235. {
  236. status = SUCCESS;
  237. }
  238. else
  239. {
  240. status = ERROR;
  241. }
  242. return (status);
  243. }
  244. /**
  245. * @brief Adjusts the Internal High Speed oscillator (HSI) calibration value.
  246. * @param HSICalibrationValue specifies the calibration trimming value.
  247. * This parameter must be a number between 0 and 0x1F.
  248. */
  249. void RCC_SetHsiCalibValue(uint8_t HSICalibrationValue)
  250. {
  251. uint32_t tmpregister = 0;
  252. /* Check the parameters */
  253. assert_param(IS_RCC_CALIB_VALUE(HSICalibrationValue));
  254. tmpregister = RCC->CTRL;
  255. /* Clear HSITRIM[4:0] bits */
  256. tmpregister &= CTRL_HSITRIM_MASK;
  257. /* Set the HSITRIM[4:0] bits according to HSICalibrationValue value */
  258. tmpregister |= (uint32_t)HSICalibrationValue << 3;
  259. /* Store the new value */
  260. RCC->CTRL = tmpregister;
  261. }
  262. /**
  263. * @brief Enables or disables the Internal High Speed oscillator (HSI).
  264. * @note HSI can not be stopped if it is used directly or through the PLL as system clock.
  265. * @param Cmd new state of the HSI. This parameter can be: ENABLE or DISABLE.
  266. */
  267. void RCC_EnableHsi(FunctionalState Cmd)
  268. {
  269. /* Check the parameters */
  270. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  271. *(__IO uint32_t*)CTRL_HSIEN_BB = (uint32_t)Cmd;
  272. }
  273. /**
  274. * @brief Configures the PLL clock source and multiplication factor.
  275. * @note This function must be used only when the PLL is disabled.
  276. * @param RCC_PLLSource specifies the PLL entry clock source.
  277. * this parameter can be one of the following values:
  278. * @arg RCC_PLL_SRC_HSI_DIV2 HSI oscillator clock divided by 2 selected as PLL clock entry
  279. * @arg RCC_PLL_SRC_HSE_DIV1 HSE oscillator clock selected as PLL clock entry
  280. * @arg RCC_PLL_SRC_HSE_DIV2 HSE oscillator clock divided by 2 selected as PLL clock entry
  281. * @param RCC_PLLMul specifies the PLL multiplication factor.
  282. * this parameter can be RCC_PLLMul_x where x:[2,32]
  283. */
  284. void RCC_ConfigPll(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul)
  285. {
  286. uint32_t tmpregister = 0;
  287. /* Check the parameters */
  288. assert_param(IS_RCC_PLL_SRC(RCC_PLLSource));
  289. assert_param(IS_RCC_PLL_MUL(RCC_PLLMul));
  290. tmpregister = RCC->CFG;
  291. /* Clear PLLSRC, PLLXTPRE and PLLMUL[4:0] bits */
  292. tmpregister &= CFG_PLL_MASK;
  293. /* Set the PLL configuration bits */
  294. tmpregister |= RCC_PLLSource | RCC_PLLMul;
  295. /* Store the new value */
  296. RCC->CFG = tmpregister;
  297. }
  298. /**
  299. * @brief Enables or disables the PLL.
  300. * @note The PLL can not be disabled if it is used as system clock.
  301. * @param Cmd new state of the PLL. This parameter can be: ENABLE or DISABLE.
  302. */
  303. void RCC_EnablePll(FunctionalState Cmd)
  304. {
  305. /* Check the parameters */
  306. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  307. *(__IO uint32_t*)CTRL_PLLEN_BB = (uint32_t)Cmd;
  308. }
  309. /**
  310. * @brief Configures the system clock (SYSCLK).
  311. * @param RCC_SYSCLKSource specifies the clock source used as system clock.
  312. * This parameter can be one of the following values:
  313. * @arg RCC_SYSCLK_SRC_HSI HSI selected as system clock
  314. * @arg RCC_SYSCLK_SRC_HSE HSE selected as system clock
  315. * @arg RCC_SYSCLK_SRC_PLLCLK PLL selected as system clock
  316. */
  317. void RCC_ConfigSysclk(uint32_t RCC_SYSCLKSource)
  318. {
  319. uint32_t tmpregister = 0;
  320. /* Check the parameters */
  321. assert_param(IS_RCC_SYSCLK_SRC(RCC_SYSCLKSource));
  322. tmpregister = RCC->CFG;
  323. /* Clear SW[1:0] bits */
  324. tmpregister &= CFG_SCLKSW_MASK;
  325. /* Set SW[1:0] bits according to RCC_SYSCLKSource value */
  326. tmpregister |= RCC_SYSCLKSource;
  327. /* Store the new value */
  328. RCC->CFG = tmpregister;
  329. }
  330. /**
  331. * @brief Returns the clock source used as system clock.
  332. * @return The clock source used as system clock. The returned value can
  333. * be one of the following:
  334. * - 0x00: HSI used as system clock
  335. * - 0x04: HSE used as system clock
  336. * - 0x08: PLL used as system clock
  337. */
  338. uint8_t RCC_GetSysclkSrc(void)
  339. {
  340. return ((uint8_t)(RCC->CFG & CFG_SCLKSTS_MASK));
  341. }
  342. /**
  343. * @brief Configures the AHB clock (HCLK).
  344. * @param RCC_SYSCLK defines the AHB clock divider. This clock is derived from
  345. * the system clock (SYSCLK).
  346. * This parameter can be one of the following values:
  347. * @arg RCC_SYSCLK_DIV1 AHB clock = SYSCLK
  348. * @arg RCC_SYSCLK_DIV2 AHB clock = SYSCLK/2
  349. * @arg RCC_SYSCLK_DIV4 AHB clock = SYSCLK/4
  350. * @arg RCC_SYSCLK_DIV8 AHB clock = SYSCLK/8
  351. * @arg RCC_SYSCLK_DIV16 AHB clock = SYSCLK/16
  352. * @arg RCC_SYSCLK_DIV64 AHB clock = SYSCLK/64
  353. * @arg RCC_SYSCLK_DIV128 AHB clock = SYSCLK/128
  354. * @arg RCC_SYSCLK_DIV256 AHB clock = SYSCLK/256
  355. * @arg RCC_SYSCLK_DIV512 AHB clock = SYSCLK/512
  356. */
  357. void RCC_ConfigHclk(uint32_t RCC_SYSCLK)
  358. {
  359. uint32_t tmpregister = 0;
  360. /* Check the parameters */
  361. assert_param(IS_RCC_SYSCLK_DIV(RCC_SYSCLK));
  362. tmpregister = RCC->CFG;
  363. /* Clear HPRE[3:0] bits */
  364. tmpregister &= CFG_AHBPRES_RESET_MASK;
  365. /* Set HPRE[3:0] bits according to RCC_SYSCLK value */
  366. tmpregister |= RCC_SYSCLK;
  367. /* Store the new value */
  368. RCC->CFG = tmpregister;
  369. }
  370. /**
  371. * @brief Configures the Low Speed APB clock (PCLK1).
  372. * @param RCC_HCLK defines the APB1 clock divider. This clock is derived from
  373. * the AHB clock (HCLK).
  374. * This parameter can be one of the following values:
  375. * @arg RCC_HCLK_DIV1 APB1 clock = HCLK
  376. * @arg RCC_HCLK_DIV2 APB1 clock = HCLK/2
  377. * @arg RCC_HCLK_DIV4 APB1 clock = HCLK/4
  378. * @arg RCC_HCLK_DIV8 APB1 clock = HCLK/8
  379. * @arg RCC_HCLK_DIV16 APB1 clock = HCLK/16
  380. */
  381. void RCC_ConfigPclk1(uint32_t RCC_HCLK)
  382. {
  383. uint32_t tmpregister = 0;
  384. /* Check the parameters */
  385. assert_param(IS_RCC_HCLK_DIV(RCC_HCLK));
  386. tmpregister = RCC->CFG;
  387. /* Clear PPRE1[2:0] bits */
  388. tmpregister &= CFG_APB1PRES_RESET_MASK;
  389. /* Set PPRE1[2:0] bits according to RCC_HCLK value */
  390. tmpregister |= RCC_HCLK;
  391. /* Store the new value */
  392. RCC->CFG = tmpregister;
  393. }
  394. /**
  395. * @brief Configures the High Speed APB clock (PCLK2).
  396. * @param RCC_HCLK defines the APB2 clock divider. This clock is derived from
  397. * the AHB clock (HCLK).
  398. * This parameter can be one of the following values:
  399. * @arg RCC_HCLK_DIV1 APB2 clock = HCLK
  400. * @arg RCC_HCLK_DIV2 APB2 clock = HCLK/2
  401. * @arg RCC_HCLK_DIV4 APB2 clock = HCLK/4
  402. * @arg RCC_HCLK_DIV8 APB2 clock = HCLK/8
  403. * @arg RCC_HCLK_DIV16 APB2 clock = HCLK/16
  404. */
  405. void RCC_ConfigPclk2(uint32_t RCC_HCLK)
  406. {
  407. uint32_t tmpregister = 0;
  408. /* Check the parameters */
  409. assert_param(IS_RCC_HCLK_DIV(RCC_HCLK));
  410. tmpregister = RCC->CFG;
  411. /* Clear PPRE2[2:0] bits */
  412. tmpregister &= CFG_APB2PRES_RESET_MASK;
  413. /* Set PPRE2[2:0] bits according to RCC_HCLK value */
  414. tmpregister |= RCC_HCLK << 3;
  415. /* Store the new value */
  416. RCC->CFG = tmpregister;
  417. }
  418. /**
  419. * @brief Enables or disables the specified RCC interrupts.
  420. * @param RccInt specifies the RCC interrupt sources to be enabled or disabled.
  421. *
  422. * this parameter can be any combination of the following values
  423. * @arg RCC_INT_LSIRDIF LSI ready interrupt
  424. * @arg RCC_INT_LSERDIF LSE ready interrupt
  425. * @arg RCC_INT_HSIRDIF HSI ready interrupt
  426. * @arg RCC_INT_HSERDIF HSE ready interrupt
  427. * @arg RCC_INT_PLLRDIF PLL ready interrupt
  428. *
  429. * @param Cmd new state of the specified RCC interrupts.
  430. * This parameter can be: ENABLE or DISABLE.
  431. */
  432. void RCC_ConfigInt(uint8_t RccInt, FunctionalState Cmd)
  433. {
  434. /* Check the parameters */
  435. assert_param(IS_RCC_INT(RccInt));
  436. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  437. if (Cmd != DISABLE)
  438. {
  439. /* Perform Byte access to RCC_CLKINT bits to enable the selected interrupts */
  440. *(__IO uint8_t*)CLKINT_BYTE2_ADDR |= RccInt;
  441. }
  442. else
  443. {
  444. /* Perform Byte access to RCC_CLKINT bits to disable the selected interrupts */
  445. *(__IO uint8_t*)CLKINT_BYTE2_ADDR &= (uint8_t)~RccInt;
  446. }
  447. }
  448. /**
  449. * @brief Configures the USB clock (USBCLK).
  450. * @param RCC_USBCLKSource specifies the USB clock source. This clock is
  451. * derived from the PLL output.
  452. * This parameter can be one of the following values:
  453. * @arg RCC_USBCLK_SRC_PLLCLK_DIV1_5 PLL clock divided by 1,5 selected as USB clock source
  454. * @arg RCC_USBCLK_SRC_PLLCLK_DIV1 PLL clock selected as USB clock source
  455. * @arg RCC_USBCLK_SRC_PLLCLK_DIV2 PLL clock divided by 2 selected as USB clock source
  456. * @arg RCC_USBCLK_SRC_PLLCLK_DIV3 PLL clock divided by 3 selected as USB clock source
  457. */
  458. void RCC_ConfigUsbClk(uint32_t RCC_USBCLKSource)
  459. {
  460. /* Check the parameters */
  461. assert_param(IS_RCC_USBCLK_SRC(RCC_USBCLKSource));
  462. *(__IO uint32_t*)CFG_USBPRES_BB = RCC_USBCLKSource;
  463. *(__IO uint32_t*)CFGR_USBPRE_BB_BIT1 = RCC_USBCLKSource >> 1;
  464. }
  465. /**
  466. * @brief Configures the TIM1/8 clock (TIM1/8CLK).
  467. * @param RCC_TIM18CLKSource specifies the TIM1/8 clock source.
  468. * This parameter can be one of the following values:
  469. * @arg RCC_TIM18CLK_SRC_TIM18CLK
  470. * @arg RCC_TIM18CLKSource_AHBCLK
  471. */
  472. void RCC_ConfigTim18Clk(uint32_t RCC_TIM18CLKSource)
  473. {
  474. uint32_t tmpregister = 0;
  475. /* Check the parameters */
  476. assert_param(IS_RCC_TIM18CLKSRC(RCC_TIM18CLKSource));
  477. tmpregister = RCC->CFG2;
  478. /* Clear TIMCLK_SEL bits */
  479. tmpregister &= CFG2_TIM18CLKSEL_RESET_MASK;
  480. /* Set TIMCLK_SEL bits according to RCC_TIM18CLKSource value */
  481. tmpregister |= RCC_TIM18CLKSource;
  482. /* Store the new value */
  483. RCC->CFG2 = tmpregister;
  484. }
  485. /**
  486. * @brief Configures the RNGCCLK prescaler.
  487. * @param RCC_RNGCCLKPrescaler specifies the RNGCCLK prescaler.
  488. * This parameter can be one of the following values:
  489. * @arg RCC_RNGCCLK_SYSCLK_DIV1 RNGCPRE[24:28] = 00000, SYSCLK Divided By 1
  490. * @arg RCC_RNGCCLK_SYSCLK_DIV2 RNGCPRE[24:28] = 00001, SYSCLK Divided By 2
  491. * @arg RCC_RNGCCLK_SYSCLK_DIV3 RNGCPRE[24:28] = 00002, SYSCLK Divided By 3
  492. * ...
  493. * @arg RCC_RNGCCLK_SYSCLK_DIV31 RNGCPRE[24:28] = 11110, SYSCLK Divided By 31
  494. * @arg RCC_RNGCCLK_SYSCLK_DIV32 RNGCPRE[24:28] = 11111, SYSCLK Divided By 32
  495. */
  496. void RCC_ConfigRngcClk(uint32_t RCC_RNGCCLKPrescaler)
  497. {
  498. uint32_t tmpregister = 0;
  499. /* Check the parameters */
  500. assert_param(IS_RCC_RNGCCLKPRE(RCC_RNGCCLKPrescaler));
  501. tmpregister = RCC->CFG2;
  502. /* Clear RNGCPRE[3:0] bits */
  503. tmpregister &= CFG2_RNGCPRES_RESET_MASK;
  504. /* Set RNGCPRE[3:0] bits according to RCC_RNGCCLKPrescaler value */
  505. tmpregister |= RCC_RNGCCLKPrescaler;
  506. /* Store the new value */
  507. RCC->CFG2 = tmpregister;
  508. }
  509. /**
  510. * @brief Configures the ADCx 1M clock (ADC1MCLK).
  511. * @param RCC_ADC1MCLKSource specifies the ADC1M clock source.
  512. * This parameter can be on of the following values:
  513. * @arg RCC_ADC1MCLK_SRC_HSI
  514. * @arg RCC_ADC1MCLK_SRC_HSE
  515. *
  516. * @param RCC_ADC1MPrescaler specifies the ADC1M clock prescaler.
  517. * This parameter can be on of the following values:
  518. * @arg RCC_ADC1MCLK_DIV1 ADC1M clock = RCC_ADC1MCLKSource_xxx/1
  519. * @arg RCC_ADC1MCLK_DIV2 ADC1M clock = RCC_ADC1MCLKSource_xxx/2
  520. * @arg RCC_ADC1MCLK_DIV3 ADC1M clock = RCC_ADC1MCLKSource_xxx/3
  521. * ...
  522. * @arg RCC_ADC1MCLK_DIV31 ADC1M clock = RCC_ADC1MCLKSource_xxx/31
  523. * @arg RCC_ADC1MCLK_DIV32 ADC1M clock = RCC_ADC1MCLKSource_xxx/32
  524. */
  525. void RCC_ConfigAdc1mClk(uint32_t RCC_ADC1MCLKSource, uint32_t RCC_ADC1MPrescaler)
  526. {
  527. uint32_t tmpregister = 0;
  528. /* Check the parameters */
  529. assert_param(IS_RCC_ADC1MCLKSRC(RCC_ADC1MCLKSource));
  530. assert_param(IS_RCC_ADC1MCLKPRE(RCC_ADC1MPrescaler));
  531. tmpregister = RCC->CFG2;
  532. /* Clear ADC1MSEL and ADC1MPRE[4:0] bits */
  533. tmpregister &= CFG2_ADC1MSEL_RESET_MASK;
  534. tmpregister &= CFG2_ADC1MPRES_RESET_MASK;
  535. /* Set ADC1MSEL bits according to RCC_ADC1MCLKSource value */
  536. tmpregister |= RCC_ADC1MCLKSource;
  537. /* Set ADC1MPRE[4:0] bits according to RCC_ADC1MPrescaler value */
  538. tmpregister |= RCC_ADC1MPrescaler;
  539. /* Store the new value */
  540. RCC->CFG2 = tmpregister;
  541. }
  542. /**
  543. * @brief Configures the ADCPLLCLK prescaler, and enable/disable ADCPLLCLK.
  544. * @param RCC_ADCPLLCLKPrescaler specifies the ADCPLLCLK prescaler.
  545. * This parameter can be on of the following values:
  546. * @arg RCC_ADCPLLCLK_DISABLE ADCPLLCLKPRES[4:0] = 0xxxx, ADC Pll Clock Disable
  547. * @arg RCC_ADCPLLCLK_DIV1 ADCPLLCLKPRES[4:0] = 10000, Pll Clock Divided By 1
  548. * @arg RCC_ADCPLLCLK_DIV2 ADCPLLCLKPRES[4:0] = 10001, Pll Clock Divided By 2
  549. * @arg RCC_ADCPLLCLK_DIV4 ADCPLLCLKPRES[4:0] = 10010, Pll Clock Divided By 4
  550. * @arg RCC_ADCPLLCLK_DIV6 ADCPLLCLKPRES[4:0] = 10011, Pll Clock Divided By 6
  551. * @arg RCC_ADCPLLCLK_DIV8 ADCPLLCLKPRES[4:0] = 10100, Pll Clock Divided By 8
  552. * @arg RCC_ADCPLLCLK_DIV10 ADCPLLCLKPRES[4:0] = 10101, Pll Clock Divided By 10
  553. * @arg RCC_ADCPLLCLK_DIV12 ADCPLLCLKPRES[4:0] = 10110, Pll Clock Divided By 12
  554. * @arg RCC_ADCPLLCLK_DIV16 ADCPLLCLKPRES[4:0] = 10111, Pll Clock Divided By 16
  555. * @arg RCC_ADCPLLCLK_DIV32 ADCPLLCLKPRES[4:0] = 11000, Pll Clock Divided By 32
  556. * @arg RCC_ADCPLLCLK_DIV64 ADCPLLCLKPRES[4:0] = 11001, Pll Clock Divided By 64
  557. * @arg RCC_ADCPLLCLK_DIV128 ADCPLLCLKPRES[4:0] = 11010, Pll Clock Divided By 128
  558. * @arg RCC_ADCPLLCLK_DIV256 ADCPLLCLKPRES[4:0] = 11011, Pll Clock Divided By 256
  559. * @arg RCC_ADCPLLCLK_DIV256 ADCPLLCLKPRES[4:0] = others, Pll Clock Divided By 256
  560. *
  561. * @param Cmd specifies the ADCPLLCLK enable/disable selection.
  562. * This parameter can be on of the following values:
  563. * @arg ENABLE enable ADCPLLCLK
  564. * @arg DISABLE disable ADCPLLCLK
  565. */
  566. void RCC_ConfigAdcPllClk(uint32_t RCC_ADCPLLCLKPrescaler, FunctionalState Cmd)
  567. {
  568. uint32_t tmpregister = 0;
  569. /* Check the parameters */
  570. assert_param(IS_RCC_ADCPLLCLKPRE(RCC_ADCPLLCLKPrescaler));
  571. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  572. tmpregister = RCC->CFG2;
  573. /* Clear ADCPLLPRES[4:0] bits */
  574. tmpregister &= CFG2_ADCPLLPRES_RESET_MASK;
  575. if (Cmd != DISABLE)
  576. {
  577. tmpregister |= RCC_ADCPLLCLKPrescaler;
  578. }
  579. else
  580. {
  581. tmpregister |= RCC_ADCPLLCLKPrescaler;
  582. tmpregister &= RCC_ADCPLLCLK_DISABLE;
  583. }
  584. /* Store the new value */
  585. RCC->CFG2 = tmpregister;
  586. }
  587. /**
  588. * @brief Configures the ADCHCLK prescaler.
  589. * @param RCC_ADCHCLKPrescaler specifies the ADCHCLK prescaler.
  590. * This parameter can be on of the following values:
  591. * @arg RCC_ADCHCLK_DIV1 ADCHCLKPRE[3:0] = 0000, HCLK Clock Divided By 1
  592. * @arg RCC_ADCHCLK_DIV2 ADCHCLKPRE[3:0] = 0001, HCLK Clock Divided By 2
  593. * @arg RCC_ADCHCLK_DIV4 ADCHCLKPRE[3:0] = 0010, HCLK Clock Divided By 4
  594. * @arg RCC_ADCHCLK_DIV6 ADCHCLKPRE[3:0] = 0011, HCLK Clock Divided By 6
  595. * @arg RCC_ADCHCLK_DIV8 ADCHCLKPRE[3:0] = 0100, HCLK Clock Divided By 8
  596. * @arg RCC_ADCHCLK_DIV10 ADCHCLKPRE[3:0] = 0101, HCLK Clock Divided By 10
  597. * @arg RCC_ADCHCLK_DIV12 ADCHCLKPRE[3:0] = 0110, HCLK Clock Divided By 12
  598. * @arg RCC_ADCHCLK_DIV16 ADCHCLKPRE[3:0] = 0111, HCLK Clock Divided By 16
  599. * @arg RCC_ADCHCLK_DIV32 ADCHCLKPRE[3:0] = 1000, HCLK Clock Divided By 32
  600. * @arg RCC_ADCHCLK_DIV32 ADCHCLKPRE[3:0] = others, HCLK Clock Divided By 32
  601. */
  602. void RCC_ConfigAdcHclk(uint32_t RCC_ADCHCLKPrescaler)
  603. {
  604. uint32_t tmpregister = 0;
  605. /* Check the parameters */
  606. assert_param(IS_RCC_ADCHCLKPRE(RCC_ADCHCLKPrescaler));
  607. tmpregister = RCC->CFG2;
  608. /* Clear ADCHPRE[3:0] bits */
  609. tmpregister &= CFG2_ADCHPRES_RESET_MASK;
  610. /* Set ADCHPRE[3:0] bits according to RCC_ADCHCLKPrescaler value */
  611. tmpregister |= RCC_ADCHCLKPrescaler;
  612. /* Store the new value */
  613. RCC->CFG2 = tmpregister;
  614. }
  615. /**
  616. * @brief Configures the TRNG 1M clock (TRNG1MCLK).
  617. * @param RCC_TRNG1MCLKSource specifies the TRNG1M clock source.
  618. * This parameter can be on of the following values:
  619. * @arg RCC_TRNG1MCLK_SRC_HSI
  620. * @arg RCC_TRNG1MCLK_SRC_HSE
  621. *
  622. * @param RCC_TRNG1MPrescaler specifies the TRNG1M prescaler.
  623. * This parameter can be on of the following values:
  624. * @arg RCC_TRNG1MCLKDiv_2 TRNG1M clock = RCC_TRNG1MCLKSource_xxx/2
  625. * @arg RCC_TRNG1MCLKDiv_4 TRNG1M clock = RCC_TRNG1MCLKSource_xxx/4
  626. * @arg RCC_TRNG1MCLKDiv_6 TRNG1M clock = RCC_TRNG1MCLKSource_xxx/6
  627. * ...
  628. * @arg RCC_TRNG1MCLKDiv_30 TRNG1M clock = RCC_TRNG1MCLKSource_xxx/30
  629. * @arg RCC_TRNG1MCLKDiv_32 TRNG1M clock = RCC_TRNG1MCLKSource_xxx/32
  630. */
  631. void RCC_ConfigTrng1mClk(uint32_t RCC_TRNG1MCLKSource, uint32_t RCC_TRNG1MPrescaler)
  632. {
  633. uint32_t tmpregister = 0;
  634. /* Check the parameters */
  635. assert_param(IS_RCC_TRNG1MCLK_SRC(RCC_TRNG1MCLKSource));
  636. assert_param(IS_RCC_TRNG1MCLKPRE(RCC_TRNG1MPrescaler));
  637. tmpregister = RCC->CFG3;
  638. /* Clear TRNG1MSEL and TRNG1MPRE[4:0] bits */
  639. tmpregister &= CFGR3_TRNG1MSEL_RESET_MASK;
  640. tmpregister &= CFGR3_TRNG1MPRES_RESET_MASK;
  641. /* Set TRNG1MSEL bits according to RCC_TRNG1MCLKSource value */
  642. tmpregister |= RCC_TRNG1MCLKSource;
  643. /* Set TRNG1MPRE[4:0] bits according to RCC_TRNG1MPrescaler value */
  644. tmpregister |= RCC_TRNG1MPrescaler;
  645. /* Store the new value */
  646. RCC->CFG3 = tmpregister;
  647. }
  648. /**
  649. * @brief Enable/disable TRNG clock (TRNGCLK).
  650. * @param Cmd specifies the TRNGCLK enable/disable selection.
  651. * This parameter can be on of the following values:
  652. * @arg ENABLE enable TRNGCLK
  653. * @arg DISABLE disable TRNGCLK
  654. */
  655. void RCC_EnableTrng1mClk(FunctionalState Cmd)
  656. {
  657. /* Check the parameters */
  658. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  659. if (Cmd != DISABLE)
  660. {
  661. RCC->CFG3 |= RCC_TRNG1MCLK_ENABLE;
  662. }
  663. else
  664. {
  665. RCC->CFG3 &= RCC_TRNG1MCLK_DISABLE;
  666. }
  667. }
  668. /**
  669. * @brief Configures the External Low Speed oscillator (LSE).
  670. * @param RCC_LSE specifies the new state of the LSE.
  671. * This parameter can be one of the following values:
  672. * @arg RCC_LSE_DISABLE LSE oscillator OFF
  673. * @arg RCC_LSE_ENABLE LSE oscillator ON
  674. * @arg RCC_LSE_BYPASS LSE oscillator bypassed with external clock
  675. */
  676. void RCC_ConfigLse(uint8_t RCC_LSE)
  677. {
  678. /* Check the parameters */
  679. assert_param(IS_RCC_LSE(RCC_LSE));
  680. /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/
  681. /* Reset LSEON bit */
  682. *(__IO uint8_t*)BDCTRL_ADDR = RCC_LSE_DISABLE;
  683. /* Reset LSEBYP bit */
  684. *(__IO uint8_t*)BDCTRL_ADDR = RCC_LSE_DISABLE;
  685. /* Configure LSE (RCC_LSE_DISABLE is already covered by the code section above) */
  686. switch (RCC_LSE)
  687. {
  688. case RCC_LSE_ENABLE:
  689. /* Set LSEON bit */
  690. *(__IO uint8_t*)BDCTRL_ADDR = RCC_LSE_ENABLE;
  691. break;
  692. case RCC_LSE_BYPASS:
  693. /* Set LSEBYP and LSEON bits */
  694. *(__IO uint8_t*)BDCTRL_ADDR = RCC_LSE_BYPASS | RCC_LSE_ENABLE;
  695. break;
  696. default:
  697. break;
  698. }
  699. }
  700. /**
  701. * @brief Enables or disables the Internal Low Speed oscillator (LSI).
  702. * @note LSI can not be disabled if the IWDG is running.
  703. * @param Cmd new state of the LSI. This parameter can be: ENABLE or DISABLE.
  704. */
  705. void RCC_EnableLsi(FunctionalState Cmd)
  706. {
  707. /* Check the parameters */
  708. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  709. *(__IO uint32_t*)CTRLSTS_LSIEN_BB = (uint32_t)Cmd;
  710. }
  711. /**
  712. * @brief Configures the RTC clock (RTCCLK).
  713. * @note Once the RTC clock is selected it can't be changed unless the Backup domain is reset.
  714. * @param RCC_RTCCLKSource specifies the RTC clock source.
  715. * This parameter can be one of the following values:
  716. * @arg RCC_RTCCLK_SRC_LSE LSE selected as RTC clock
  717. * @arg RCC_RTCCLK_SRC_LSI LSI selected as RTC clock
  718. * @arg RCC_RTCCLK_SRC_HSE_DIV128 HSE clock divided by 128 selected as RTC clock
  719. */
  720. void RCC_ConfigRtcClk(uint32_t RCC_RTCCLKSource)
  721. {
  722. /* Check the parameters */
  723. assert_param(IS_RCC_RTCCLK_SRC(RCC_RTCCLKSource));
  724. /* Clear the RTC clock source */
  725. RCC->BDCTRL &= (~0x00000300);
  726. /* Select the RTC clock source */
  727. RCC->BDCTRL |= RCC_RTCCLKSource;
  728. }
  729. /**
  730. * @brief Enables or disables the RTC clock.
  731. * @note This function must be used only after the RTC clock was selected using the RCC_ConfigRtcClk function.
  732. * @param Cmd new state of the RTC clock. This parameter can be: ENABLE or DISABLE.
  733. */
  734. void RCC_EnableRtcClk(FunctionalState Cmd)
  735. {
  736. /* Check the parameters */
  737. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  738. *(__IO uint32_t*)BDCTRL_RTCEN_BB = (uint32_t)Cmd;
  739. }
  740. /**
  741. * @brief Returns the frequencies of different on chip clocks.
  742. * @param RCC_Clocks pointer to a RCC_ClocksType structure which will hold
  743. * the clocks frequencies.
  744. * @note The result of this function could be not correct when using
  745. * fractional value for HSE crystal.
  746. */
  747. void RCC_GetClocksFreqValue(RCC_ClocksType* RCC_Clocks)
  748. {
  749. uint32_t tmp = 0, pllclk = 0, pllmull = 0, pllsource = 0, presc = 0;
  750. /* Get PLL clock source and multiplication factor ----------------------*/
  751. pllmull = RCC->CFG & CFG_PLLMULFCT_MASK;
  752. pllsource = RCC->CFG & CFG_PLLSRC_MASK;
  753. if ((pllmull & RCC_CFG_PLLMULFCT_4) == 0)
  754. {
  755. pllmull = (pllmull >> 18) + 2; // PLLMUL[4]=0
  756. }
  757. else
  758. {
  759. pllmull = ((pllmull >> 18) - 496) + 1; // PLLMUL[4]=1
  760. }
  761. if (pllsource == 0x00)
  762. { /* HSI oscillator clock divided by 2 selected as PLL clock entry */
  763. pllclk = (HSI_VALUE >> 1) * pllmull;
  764. }
  765. else
  766. {
  767. /* HSE selected as PLL clock entry */
  768. if ((RCC->CFG & CFG_PLLHSEPRES_MASK) != (uint32_t)RESET)
  769. { /* HSE oscillator clock divided by 2 */
  770. pllclk = (HSE_VALUE >> 1) * pllmull;
  771. }
  772. else
  773. {
  774. pllclk = HSE_VALUE * pllmull;
  775. }
  776. }
  777. /* Get SYSCLK source -------------------------------------------------------*/
  778. tmp = RCC->CFG & CFG_SCLKSTS_MASK;
  779. switch (tmp)
  780. {
  781. case 0x00: /* HSI used as system clock */
  782. RCC_Clocks->SysclkFreq = HSI_VALUE;
  783. break;
  784. case 0x04: /* HSE used as system clock */
  785. RCC_Clocks->SysclkFreq = HSE_VALUE;
  786. break;
  787. case 0x08: /* PLL used as system clock */
  788. RCC_Clocks->SysclkFreq = pllclk;
  789. break;
  790. default:
  791. RCC_Clocks->SysclkFreq = HSI_VALUE;
  792. break;
  793. }
  794. /* Compute HCLK, PCLK1, PCLK2 and ADCCLK clocks frequencies ----------------*/
  795. /* Get HCLK prescaler */
  796. tmp = RCC->CFG & CFG_AHBPRES_SET_MASK;
  797. tmp = tmp >> 4;
  798. presc = s_ApbAhbPresTable[tmp];
  799. /* HCLK clock frequency */
  800. RCC_Clocks->HclkFreq = RCC_Clocks->SysclkFreq >> presc;
  801. /* Get PCLK1 prescaler */
  802. tmp = RCC->CFG & CFG_APB1PRES_SET_MASK;
  803. tmp = tmp >> 8;
  804. presc = s_ApbAhbPresTable[tmp];
  805. /* PCLK1 clock frequency */
  806. RCC_Clocks->Pclk1Freq = RCC_Clocks->HclkFreq >> presc;
  807. /* Get PCLK2 prescaler */
  808. tmp = RCC->CFG & CFG_APB2PRES_SET_MASK;
  809. tmp = tmp >> 11;
  810. presc = s_ApbAhbPresTable[tmp];
  811. /* PCLK2 clock frequency */
  812. RCC_Clocks->Pclk2Freq = RCC_Clocks->HclkFreq >> presc;
  813. /* Get ADCHCLK prescaler */
  814. tmp = RCC->CFG2 & CFG2_ADCHPRES_SET_MASK;
  815. presc = s_AdcHclkPresTable[tmp];
  816. /* ADCHCLK clock frequency */
  817. RCC_Clocks->AdcHclkFreq = RCC_Clocks->HclkFreq / presc;
  818. /* Get ADCPLLCLK prescaler */
  819. tmp = RCC->CFG2 & CFG2_ADCPLLPRES_SET_MASK;
  820. tmp = tmp >> 4;
  821. presc = s_AdcPllClkPresTable[(tmp & 0xF)]; // ignore BIT5
  822. /* ADCPLLCLK clock frequency */
  823. RCC_Clocks->AdcPllClkFreq = pllclk / presc;
  824. }
  825. /**
  826. * @brief Enables or disables the AHB peripheral clock.
  827. * @param RCC_AHBPeriph specifies the AHB peripheral to gates its clock.
  828. *
  829. * this parameter can be any combination of the following values:
  830. * @arg RCC_AHB_PERIPH_DMA1
  831. * @arg RCC_AHB_PERIPH_DMA2
  832. * @arg RCC_AHB_PERIPH_SRAM
  833. * @arg RCC_AHB_PERIPH_FLITF
  834. * @arg RCC_AHB_PERIPH_CRC
  835. * @arg RCC_AHB_PERIPH_RNGC
  836. * @arg RCC_AHB_PERIPH_SDIO
  837. * @arg RCC_AHB_PERIPH_SAC
  838. * @arg RCC_AHB_PERIPH_ADC1
  839. * @arg RCC_AHB_PERIPH_ADC2
  840. * @arg RCC_AHB_PERIPH_ADC3
  841. * @arg RCC_AHB_PERIPH_ADC4
  842. * @arg RCC_AHB_PERIPH_ETHMAC
  843. * @arg RCC_AHB_PERIPH_QSPI
  844. *
  845. * @note SRAM and FLITF clock can be disabled only during sleep mode.
  846. * @param Cmd new state of the specified peripheral clock.
  847. * This parameter can be: ENABLE or DISABLE.
  848. */
  849. void RCC_EnableAHBPeriphClk(uint32_t RCC_AHBPeriph, FunctionalState Cmd)
  850. {
  851. /* Check the parameters */
  852. assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));
  853. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  854. if (Cmd != DISABLE)
  855. {
  856. RCC->AHBPCLKEN |= RCC_AHBPeriph;
  857. }
  858. else
  859. {
  860. RCC->AHBPCLKEN &= ~RCC_AHBPeriph;
  861. }
  862. }
  863. /**
  864. * @brief Enables or disables the High Speed APB (APB2) peripheral clock.
  865. * @param RCC_APB2Periph specifies the APB2 peripheral to gates its clock.
  866. * This parameter can be any combination of the following values:
  867. * @arg RCC_APB2_PERIPH_AFIO, RCC_APB2_PERIPH_GPIOA, RCC_APB2_PERIPH_GPIOB,
  868. * RCC_APB2_PERIPH_GPIOC, RCC_APB2_PERIPH_GPIOD, RCC_APB2_PERIPH_GPIOE,
  869. * RCC_APB2_PERIPH_GPIOF, RCC_APB2_PERIPH_GPIOG, RCC_APB2_PERIPH_TIM1,
  870. * RCC_APB2_PERIPH_SPI1, RCC_APB2_PERIPH_TIM8, RCC_APB2_PERIPH_USART1,
  871. * RCC_APB2_PERIPH_DVP, RCC_APB2_PERIPH_UART6, RCC_APB2_PERIPH_UART7,
  872. * RCC_APB2_PERIPH_I2C3, RCC_APB2_PERIPH_I2C4
  873. * @param Cmd new state of the specified peripheral clock.
  874. * This parameter can be: ENABLE or DISABLE.
  875. */
  876. void RCC_EnableAPB2PeriphClk(uint32_t RCC_APB2Periph, FunctionalState Cmd)
  877. {
  878. /* Check the parameters */
  879. assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
  880. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  881. if (Cmd != DISABLE)
  882. {
  883. RCC->APB2PCLKEN |= RCC_APB2Periph;
  884. }
  885. else
  886. {
  887. RCC->APB2PCLKEN &= ~RCC_APB2Periph;
  888. }
  889. }
  890. /**
  891. * @brief Enables or disables the Low Speed APB (APB1) peripheral clock.
  892. * @param RCC_APB1Periph specifies the APB1 peripheral to gates its clock.
  893. * This parameter can be any combination of the following values:
  894. * @arg RCC_APB1_PERIPH_TIM2, RCC_APB1_PERIPH_TIM3, RCC_APB1_PERIPH_TIM4,
  895. * RCC_APB1_PERIPH_TIM5, RCC_APB1_PERIPH_TIM6, RCC_APB1_PERIPH_TIM7,
  896. * RCC_APB1_PERIPH_COMP, RCC_APB1_PERIPH_COMP_FILT, RCC_APB1_PERIPH_TSC,
  897. * RCC_APB1_PERIPH_WWDG, RCC_APB1_PERIPH_SPI2, RCC_APB1_PERIPH_SPI3,
  898. * RCC_APB1_PERIPH_USART2, RCC_APB1_PERIPH_USART3, RCC_APB1_PERIPH_UART4,
  899. * RCC_APB1_PERIPH_UART5, RCC_APB1_PERIPH_I2C1, RCC_APB1_PERIPH_I2C2,
  900. * RCC_APB1_PERIPH_USB, RCC_APB1_PERIPH_CAN1, RCC_APB1_PERIPH_CAN2, RCC_APB1_PERIPH_BKP,
  901. * RCC_APB1_PERIPH_PWR, RCC_APB1_PERIPH_DAC, RCC_APB1_PERIPH_OPAMP
  902. *
  903. * @param Cmd new state of the specified peripheral clock.
  904. * This parameter can be: ENABLE or DISABLE.
  905. */
  906. void RCC_EnableAPB1PeriphClk(uint32_t RCC_APB1Periph, FunctionalState Cmd)
  907. {
  908. /* Check the parameters */
  909. assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
  910. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  911. if (Cmd != DISABLE)
  912. {
  913. RCC->APB1PCLKEN |= RCC_APB1Periph;
  914. }
  915. else
  916. {
  917. RCC->APB1PCLKEN &= ~RCC_APB1Periph;
  918. }
  919. }
  920. /**
  921. * @brief Forces or releases AHB peripheral reset.
  922. * @param RCC_AHBPeriph specifies the AHB peripheral to reset.
  923. * This parameter can be any combination of the following values:
  924. * @arg RCC_AHB_PERIPH_QSPI.
  925. * RCC_AHB_PERIPH_ETHMAC.
  926. * RCC_AHB_PERIPH_ADC4.
  927. * RCC_AHB_PERIPH_ADC3.
  928. * RCC_AHB_PERIPH_ADC2.
  929. * RCC_AHB_PERIPH_ADC1.
  930. * RCC_AHB_PERIPH_SAC.
  931. * RCC_AHB_PERIPH_RNGC.
  932. * @param Cmd new state of the specified peripheral reset. This parameter can be ENABLE or DISABLE.
  933. */
  934. void RCC_EnableAHBPeriphReset(uint32_t RCC_AHBPeriph, FunctionalState Cmd)
  935. {
  936. /* Check the parameters */
  937. assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));
  938. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  939. if (Cmd != DISABLE)
  940. {
  941. RCC->AHBPRST |= RCC_AHBPeriph;
  942. }
  943. else
  944. {
  945. RCC->AHBPRST &= ~RCC_AHBPeriph;
  946. }
  947. }
  948. /**
  949. * @brief Forces or releases High Speed APB (APB2) peripheral reset.
  950. * @param RCC_APB2Periph specifies the APB2 peripheral to reset.
  951. * This parameter can be any combination of the following values:
  952. * @arg RCC_APB2_PERIPH_AFIO, RCC_APB2_PERIPH_GPIOA, RCC_APB2_PERIPH_GPIOB,
  953. * RCC_APB2_PERIPH_GPIOC, RCC_APB2_PERIPH_GPIOD, RCC_APB2_PERIPH_GPIOE,
  954. * RCC_APB2_PERIPH_GPIOF, RCC_APB2_PERIPH_GPIOG, RCC_APB2_PERIPH_TIM1,
  955. * RCC_APB2_PERIPH_SPI1, RCC_APB2_PERIPH_TIM8, RCC_APB2_PERIPH_USART1,
  956. * RCC_APB2_PERIPH_DVP, RCC_APB2_PERIPH_UART6, RCC_APB2_PERIPH_UART7,
  957. * RCC_APB2_PERIPH_I2C3, RCC_APB2_PERIPH_I2C4
  958. * @param Cmd new state of the specified peripheral reset.
  959. * This parameter can be: ENABLE or DISABLE.
  960. */
  961. void RCC_EnableAPB2PeriphReset(uint32_t RCC_APB2Periph, FunctionalState Cmd)
  962. {
  963. /* Check the parameters */
  964. assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));
  965. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  966. if (Cmd != DISABLE)
  967. {
  968. RCC->APB2PRST |= RCC_APB2Periph;
  969. }
  970. else
  971. {
  972. RCC->APB2PRST &= ~RCC_APB2Periph;
  973. }
  974. }
  975. /**
  976. * @brief Forces or releases Low Speed APB (APB1) peripheral reset.
  977. * @param RCC_APB1Periph specifies the APB1 peripheral to reset.
  978. * This parameter can be any combination of the following values:
  979. * @arg RCC_APB1_PERIPH_TIM2, RCC_APB1_PERIPH_TIM3, RCC_APB1_PERIPH_TIM4,
  980. * RCC_APB1_PERIPH_TIM5, RCC_APB1_PERIPH_TIM6, RCC_APB1_PERIPH_TIM7,
  981. * RCC_APB1_PERIPH_TSC, RCC_APB1_PERIPH_WWDG, RCC_APB1_PERIPH_SPI2,
  982. * RCC_APB1_PERIPH_SPI3, RCC_APB1_PERIPH_USART2, RCC_APB1_PERIPH_USART3,
  983. * RCC_APB1_PERIPH_UART4, RCC_APB1_PERIPH_UART5, RCC_APB1_PERIPH_I2C1,
  984. * RCC_APB1_PERIPH_I2C2, RCC_APB1_PERIPH_USB, RCC_APB1_PERIPH_CAN1,
  985. * RCC_APB1_PERIPH_CAN2, RCC_APB1_PERIPH_BKP, RCC_APB1_PERIPH_PWR,
  986. * RCC_APB1_PERIPH_DAC
  987. * @param Cmd new state of the specified peripheral clock.
  988. * This parameter can be: ENABLE or DISABLE.
  989. */
  990. void RCC_EnableAPB1PeriphReset(uint32_t RCC_APB1Periph, FunctionalState Cmd)
  991. {
  992. /* Check the parameters */
  993. assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));
  994. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  995. if (Cmd != DISABLE)
  996. {
  997. RCC->APB1PRST |= RCC_APB1Periph;
  998. }
  999. else
  1000. {
  1001. RCC->APB1PRST &= ~RCC_APB1Periph;
  1002. }
  1003. }
  1004. /**
  1005. * @brief BOR reset enable.
  1006. * @param Cmd new state of the BOR reset.
  1007. * This parameter can be: ENABLE or DISABLE.
  1008. */
  1009. void RCC_EnableBORReset(FunctionalState Cmd)
  1010. {
  1011. /* Check the parameters */
  1012. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  1013. if (Cmd != DISABLE)
  1014. {
  1015. RCC->CFG3 |= RCC_BOR_RST_ENABLE;
  1016. }
  1017. else
  1018. {
  1019. RCC->CFG3 &= ~RCC_BOR_RST_ENABLE;
  1020. }
  1021. }
  1022. /**
  1023. * @brief Forces or releases the Backup domain reset.
  1024. * @param Cmd new state of the Backup domain reset.
  1025. * This parameter can be: ENABLE or DISABLE.
  1026. */
  1027. void RCC_EnableBackupReset(FunctionalState Cmd)
  1028. {
  1029. /* Check the parameters */
  1030. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  1031. *(__IO uint32_t*)BDCTRL_BDSFTRST_BB = (uint32_t)Cmd;
  1032. }
  1033. /**
  1034. * @brief Enables or disables the Clock Security System.
  1035. * @param Cmd new state of the Clock Security System..
  1036. * This parameter can be: ENABLE or DISABLE.
  1037. */
  1038. void RCC_EnableClockSecuritySystem(FunctionalState Cmd)
  1039. {
  1040. /* Check the parameters */
  1041. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  1042. *(__IO uint32_t*)CTRL_CLKSSEN_BB = (uint32_t)Cmd;
  1043. }
  1044. /**
  1045. * @brief Configures the MCO PLL clock prescaler.
  1046. * @param RCC_MCOPLLCLKPrescaler specifies the MCO PLL clock prescaler.
  1047. * This parameter can be on of the following values:
  1048. * @arg RCC_MCO_PLLCLK_DIV2 MCOPRE[3:0] = 0010, PLL Clock Divided By 2
  1049. * @arg RCC_MCO_PLLCLK_DIV3 MCOPRE[3:0] = 0011, PLL Clock Divided By 3
  1050. * @arg RCC_MCO_PLLCLK_DIV4 MCOPRE[3:0] = 0100, PLL Clock Divided By 4
  1051. * @arg RCC_MCO_PLLCLK_DIV5 MCOPRE[3:0] = 0101, PLL Clock Divided By 5
  1052. * ...
  1053. * @arg RCC_MCO_PLLCLK_DIV13 MCOPRE[3:0] = 1101, PLL Clock Divided By 13
  1054. * @arg RCC_MCO_PLLCLK_DIV14 MCOPRE[3:0] = 1110, PLL Clock Divided By 14
  1055. * @arg RCC_MCO_PLLCLK_DIV15 MCOPRE[3:0] = 1111, PLL Clock Divided By 15
  1056. */
  1057. void RCC_ConfigMcoPllClk(uint32_t RCC_MCOPLLCLKPrescaler)
  1058. {
  1059. uint32_t tmpregister = 0;
  1060. /* Check the parameters */
  1061. assert_param(IS_RCC_MCOPLLCLKPRE(RCC_MCOPLLCLKPrescaler));
  1062. tmpregister = RCC->CFG;
  1063. /* Clear MCOPRE[3:0] bits */
  1064. tmpregister &= ((uint32_t)0x0FFFFFFF);
  1065. /* Set MCOPRE[3:0] bits according to RCC_ADCHCLKPrescaler value */
  1066. tmpregister |= RCC_MCOPLLCLKPrescaler;
  1067. /* Store the new value */
  1068. RCC->CFG = tmpregister;
  1069. }
  1070. /**
  1071. * @brief Selects the clock source to output on MCO pin.
  1072. * @param RCC_MCO specifies the clock source to output.
  1073. *
  1074. * this parameter can be one of the following values:
  1075. * @arg RCC_MCO_NOCLK No clock selected
  1076. * @arg RCC_MCO_SYSCLK System clock selected
  1077. * @arg RCC_MCO_HSI HSI oscillator clock selected
  1078. * @arg RCC_MCO_HSE HSE oscillator clock selected
  1079. * @arg RCC_MCO_PLLCLK PLL clock divided by xx selected
  1080. *
  1081. */
  1082. void RCC_ConfigMco(uint8_t RCC_MCO)
  1083. {
  1084. uint32_t tmpregister = 0;
  1085. /* Check the parameters */
  1086. assert_param(IS_RCC_MCO(RCC_MCO));
  1087. tmpregister = RCC->CFG;
  1088. /* Clear MCO[2:0] bits */
  1089. tmpregister &= ((uint32_t)0xF8FFFFFF);
  1090. /* Set MCO[2:0] bits according to RCC_MCO value */
  1091. tmpregister |= ((uint32_t)(RCC_MCO << 24));
  1092. /* Store the new value */
  1093. RCC->CFG = tmpregister;
  1094. }
  1095. /**
  1096. * @brief Checks whether the specified RCC flag is set or not.
  1097. * @param RCC_FLAG specifies the flag to check.
  1098. *
  1099. * this parameter can be one of the following values:
  1100. * @arg RCC_FLAG_HSIRD HSI oscillator clock ready
  1101. * @arg RCC_FLAG_HSERD HSE oscillator clock ready
  1102. * @arg RCC_FLAG_PLLRD PLL clock ready
  1103. * @arg RCC_FLAG_LSERD LSE oscillator clock ready
  1104. * @arg RCC_FLAG_LSIRD LSI oscillator clock ready
  1105. * @arg RCC_FLAG_BORRST BOR reset flag
  1106. * @arg RCC_FLAG_RETEMC Retention EMC reset flag
  1107. * @arg RCC_FLAG_BKPEMC BackUp EMC reset flag
  1108. * @arg RCC_FLAG_RAMRST RAM reset flag
  1109. * @arg RCC_FLAG_MMURST Mmu reset flag
  1110. * @arg RCC_FLAG_PINRST Pin reset
  1111. * @arg RCC_FLAG_PORRST POR/PDR reset
  1112. * @arg RCC_FLAG_SFTRST Software reset
  1113. * @arg RCC_FLAG_IWDGRST Independent Watchdog reset
  1114. * @arg RCC_FLAG_WWDGRST Window Watchdog reset
  1115. * @arg RCC_FLAG_LPWRRST Low Power reset
  1116. *
  1117. * @return The new state of RCC_FLAG (SET or RESET).
  1118. */
  1119. FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)
  1120. {
  1121. uint32_t tmp = 0;
  1122. uint32_t statusreg = 0;
  1123. FlagStatus bitstatus = RESET;
  1124. /* Check the parameters */
  1125. assert_param(IS_RCC_FLAG(RCC_FLAG));
  1126. /* Get the RCC register index */
  1127. tmp = RCC_FLAG >> 5;
  1128. if (tmp == 1) /* The flag to check is in CTRL register */
  1129. {
  1130. statusreg = RCC->CTRL;
  1131. }
  1132. else if (tmp == 2) /* The flag to check is in BDCTRL register */
  1133. {
  1134. statusreg = RCC->BDCTRL;
  1135. }
  1136. else /* The flag to check is in CTRLSTS register */
  1137. {
  1138. statusreg = RCC->CTRLSTS;
  1139. }
  1140. /* Get the flag position */
  1141. tmp = RCC_FLAG & FLAG_MASK;
  1142. if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)
  1143. {
  1144. bitstatus = SET;
  1145. }
  1146. else
  1147. {
  1148. bitstatus = RESET;
  1149. }
  1150. /* Return the flag status */
  1151. return bitstatus;
  1152. }
  1153. /**
  1154. * @brief Clears the RCC reset flags.
  1155. * @note The reset flags are: RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,
  1156. * RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST
  1157. */
  1158. void RCC_ClrFlag(void)
  1159. {
  1160. /* Set RMVF bit to clear the reset flags */
  1161. RCC->CTRLSTS |= CSR_RMRSTF_SET;
  1162. /* RMVF bit should be reset */
  1163. RCC->CTRLSTS &= CSR_RMVF_Reset;
  1164. }
  1165. /**
  1166. * @brief Checks whether the specified RCC interrupt has occurred or not.
  1167. * @param RccInt specifies the RCC interrupt source to check.
  1168. *
  1169. * this parameter can be one of the following values:
  1170. * @arg RCC_INT_LSIRDIF LSI ready interrupt
  1171. * @arg RCC_INT_LSERDIF LSE ready interrupt
  1172. * @arg RCC_INT_HSIRDIF HSI ready interrupt
  1173. * @arg RCC_INT_HSERDIF HSE ready interrupt
  1174. * @arg RCC_INT_PLLRDIF PLL ready interrupt
  1175. *
  1176. * @arg RCC_INT_CLKSSIF Clock Security System interrupt
  1177. *
  1178. * @return The new state of RccInt (SET or RESET).
  1179. */
  1180. INTStatus RCC_GetIntStatus(uint8_t RccInt)
  1181. {
  1182. INTStatus bitstatus = RESET;
  1183. /* Check the parameters */
  1184. assert_param(IS_RCC_GET_INT(RccInt));
  1185. /* Check the status of the specified RCC interrupt */
  1186. if ((RCC->CLKINT & RccInt) != (uint32_t)RESET)
  1187. {
  1188. bitstatus = SET;
  1189. }
  1190. else
  1191. {
  1192. bitstatus = RESET;
  1193. }
  1194. /* Return the RccInt status */
  1195. return bitstatus;
  1196. }
  1197. /**
  1198. * @brief Clears the RCC's interrupt pending bits.
  1199. * @param RccInt specifies the interrupt pending bit to clear.
  1200. *
  1201. * this parameter can be any combination of the
  1202. * following values:
  1203. * @arg RCC_INT_LSIRDIF LSI ready interrupt
  1204. * @arg RCC_INT_LSERDIF LSE ready interrupt
  1205. * @arg RCC_INT_HSIRDIF HSI ready interrupt
  1206. * @arg RCC_INT_HSERDIF HSE ready interrupt
  1207. * @arg RCC_INT_PLLRDIF PLL ready interrupt
  1208. *
  1209. * @arg RCC_INT_CLKSSIF Clock Security System interrupt
  1210. */
  1211. void RCC_ClrIntPendingBit(uint8_t RccInt)
  1212. {
  1213. /* Check the parameters */
  1214. assert_param(IS_RCC_CLR_INT(RccInt));
  1215. /* Perform Byte access to RCC_CLKINT[23:16] bits to clear the selected interrupt
  1216. pending bits */
  1217. *(__IO uint8_t*)CLKINT_BYTE3_ADDR = RccInt;
  1218. }
  1219. /**
  1220. * @}
  1221. */
  1222. /**
  1223. * @}
  1224. */
  1225. /**
  1226. * @}
  1227. */