libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
rcc.c
Go to the documentation of this file.
1/** @defgroup rcc_file RCC peripheral API
2
3@ingroup peripheral_apis
4
5@brief <b>libopencm3 STM32F1xx Reset and Clock Control</b>
6
7@version 1.0.0
8
9@author @htmlonly &copy; @endhtmlonly 2009
10Federico Ruiz-Ugalde <memeruiz at gmail dot com>
11@author @htmlonly &copy; @endhtmlonly 2009 Uwe Hermann <uwe@hermann-uwe.de>
12@author @htmlonly &copy; @endhtmlonly 2010 Thomas Otto <tommi@viadmin.org>
13
14@date 18 August 2012
15
16This library supports the Reset and Clock Control System in the STM32F1xx
17series of ARM Cortex Microcontrollers by ST Microelectronics.
18
19@note Full support for connection line devices is not yet provided.
20
21Clock settings and resets for many peripherals are given here rather than in
22the corresponding peripheral library.
23
24The library also provides a number of common configurations for the processor
25system clock. Not all possible configurations are included.
26
27LGPL License Terms @ref lgpl_license
28 */
29/*
30 * This file is part of the libopencm3 project.
31 *
32 * Copyright (C) 2009 Federico Ruiz-Ugalde <memeruiz at gmail dot com>
33 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
34 * Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
35 *
36 * This library is free software: you can redistribute it and/or modify
37 * it under the terms of the GNU Lesser General Public License as published by
38 * the Free Software Foundation, either version 3 of the License, or
39 * (at your option) any later version.
40 *
41 * This library is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU Lesser General Public License for more details.
45 *
46 * You should have received a copy of the GNU Lesser General Public License
47 * along with this library. If not, see <http://www.gnu.org/licenses/>.
48 */
49
50/**@{*/
51
55
56/** Set the default clock frequencies */
57uint32_t rcc_apb1_frequency = 8000000;
58uint32_t rcc_apb2_frequency = 8000000;
59uint32_t rcc_ahb_frequency = 8000000;
60
62 {
63 /* hse-12, pll to 72 */
66 .prediv1 = RCC_CFGR2_PREDIV_NODIV,
67 .hpre = RCC_CFGR_HPRE_NODIV,
68 .ppre1 = RCC_CFGR_PPRE_DIV2,
69 .ppre2 = RCC_CFGR_PPRE_NODIV,
70 .adcpre = RCC_CFGR_ADCPRE_DIV6,
71 .flash_waitstates = 2,
72 .ahb_frequency = 72000000,
73 .apb1_frequency = 36000000,
74 .apb2_frequency = 72000000,
75 },
76 {
77 /* hse16, pll to 72 */
79 .pll_source = RCC_CFGR_PLLSRC_HSE_CLK,
80 .hpre = RCC_CFGR_HPRE_NODIV,
81 .ppre1 = RCC_CFGR_PPRE_DIV2,
82 .ppre2 = RCC_CFGR_PPRE_NODIV,
83 .adcpre = RCC_CFGR_ADCPRE_DIV6,
84 .flash_waitstates = 2,
85 .prediv1 = RCC_CFGR2_PREDIV_DIV2,
86 .ahb_frequency = 72e6,
87 .apb1_frequency = 36e6,
88 .apb2_frequency = 72e6,
89 },
90 {
91 /* hse25 to 72, this was a f105 config originally! intention preserved */
93 .pll_source = RCC_CFGR_PLLSRC_PREDIV1_CLK,
94 .hpre = RCC_CFGR_HPRE_NODIV,
95 .ppre1 = RCC_CFGR_PPRE_DIV2,
96 .ppre2 = RCC_CFGR_PPRE_NODIV,
97 .adcpre = RCC_CFGR_ADCPRE_DIV6,
98 .flash_waitstates = 2,
99 .prediv1 = RCC_CFGR2_PREDIV_DIV5,
100 .prediv1_source = RCC_CFGR2_PREDIV1SRC_PLL2_CLK,
102 .prediv2 = RCC_CFGR2_PREDIV2_DIV5,
104 .ahb_frequency = 72e6,
105 .apb1_frequency = 36e6,
106 .apb2_frequency = 72e6,
107 },
108 {
109 /* hse8, pll to 24 (f100 value line max) */
111 .pll_source = RCC_CFGR_PLLSRC_HSE_CLK,
112 .hpre = RCC_CFGR_HPRE_NODIV,
113 .ppre1 = RCC_CFGR_PPRE_NODIV,
114 .ppre2 = RCC_CFGR_PPRE_NODIV,
115 .adcpre = RCC_CFGR_ADCPRE_DIV2,
116 .flash_waitstates = 0,
117 .prediv1 = RCC_CFGR2_PREDIV_NODIV,
118 .ahb_frequency = 24e6,
119 .apb1_frequency = 24e6,
120 .apb2_frequency = 24e6,
121 },
122 {
123 /* hse8, pll to 72 */
125 .pll_source = RCC_CFGR_PLLSRC_HSE_CLK,
126 .hpre = RCC_CFGR_HPRE_NODIV,
127 .ppre1 = RCC_CFGR_PPRE_DIV2,
128 .ppre2 = RCC_CFGR_PPRE_NODIV,
129 .adcpre = RCC_CFGR_ADCPRE_DIV8,
130 .flash_waitstates = 2,
131 .prediv1 = RCC_CFGR2_PREDIV_NODIV,
132 .ahb_frequency = 72e6,
133 .apb1_frequency = 36e6,
134 .apb2_frequency = 72e6,
135 },
136};
137
139 {
140 /* hsi to 24Mhz, max for f100 */
143 .prediv1 = RCC_CFGR2_PREDIV_NODIV,
144 .hpre = RCC_CFGR_HPRE_NODIV,
145 .ppre1 = RCC_CFGR_PPRE_NODIV,
146 .ppre2 = RCC_CFGR_PPRE_NODIV,
147 .adcpre = RCC_CFGR_ADCPRE_DIV2,
148 .flash_waitstates = 0,
149 .ahb_frequency = 24e6,
150 .apb1_frequency = 24e6,
151 .apb2_frequency = 24e6,
152 },
153 {
154 /* hsi to 48Mhz, allows usb, but out of spec */
155 .pll_source = RCC_CFGR_PLLSRC_HSI_CLK_DIV2,
157 .prediv1 = RCC_CFGR2_PREDIV_NODIV,
158 .hpre = RCC_CFGR_HPRE_NODIV,
159 .ppre1 = RCC_CFGR_PPRE_DIV2,
160 .ppre2 = RCC_CFGR_PPRE_NODIV,
161 .adcpre = RCC_CFGR_ADCPRE_DIV8,
163 .flash_waitstates = 1,
164 .ahb_frequency = 48e6,
165 .apb1_frequency = 24e6,
166 .apb2_frequency = 48e6,
167 },
168 {
169 /* hsi to 64Mhz, max possible from hsi */
170 .pll_source = RCC_CFGR_PLLSRC_HSI_CLK_DIV2,
172 .prediv1 = RCC_CFGR2_PREDIV_NODIV,
173 .hpre = RCC_CFGR_HPRE_NODIV,
174 .ppre1 = RCC_CFGR_PPRE_DIV2,
175 .ppre2 = RCC_CFGR_PPRE_NODIV,
176 .adcpre = RCC_CFGR_ADCPRE_DIV8,
177 .flash_waitstates = 2,
178 .ahb_frequency = 64e6,
179 .apb1_frequency = 32e6,
180 .apb2_frequency = 64e6,
181 },
182};
183
184/*---------------------------------------------------------------------------*/
185/** @brief RCC Clear the Oscillator Ready Interrupt Flag
186
187Clear the interrupt flag that was set when a clock oscillator became ready to
188use.
189
190@param[in] osc Oscillator ID
191*/
192
194{
195 switch (osc) {
196 case RCC_PLL:
198 break;
199 case RCC_PLL2:
201 break;
202 case RCC_PLL3:
204 break;
205 case RCC_HSE:
207 break;
208 case RCC_HSI:
210 break;
211 case RCC_LSE:
213 break;
214 case RCC_LSI:
216 break;
217 }
218}
219
220/*---------------------------------------------------------------------------*/
221/** @brief RCC Enable the Oscillator Ready Interrupt
222
223@param osc Oscillator ID
224*/
225
227{
228 switch (osc) {
229 case RCC_PLL:
231 break;
232 case RCC_PLL2:
234 break;
235 case RCC_PLL3:
237 break;
238 case RCC_HSE:
240 break;
241 case RCC_HSI:
243 break;
244 case RCC_LSE:
246 break;
247 case RCC_LSI:
249 break;
250 }
251}
252
253/*---------------------------------------------------------------------------*/
254/** @brief RCC Disable the Oscillator Ready Interrupt
255
256@param[in] osc Oscillator ID
257*/
258
260{
261 switch (osc) {
262 case RCC_PLL:
263 RCC_CIR &= ~RCC_CIR_PLLRDYIE;
264 break;
265 case RCC_PLL2:
266 RCC_CIR &= ~RCC_CIR_PLL2RDYIE;
267 break;
268 case RCC_PLL3:
269 RCC_CIR &= ~RCC_CIR_PLL3RDYIE;
270 break;
271 case RCC_HSE:
272 RCC_CIR &= ~RCC_CIR_HSERDYIE;
273 break;
274 case RCC_HSI:
275 RCC_CIR &= ~RCC_CIR_HSIRDYIE;
276 break;
277 case RCC_LSE:
278 RCC_CIR &= ~RCC_CIR_LSERDYIE;
279 break;
280 case RCC_LSI:
281 RCC_CIR &= ~RCC_CIR_LSIRDYIE;
282 break;
283 }
284}
285
286/*---------------------------------------------------------------------------*/
287/** @brief RCC Read the Oscillator Ready Interrupt Flag
288
289@param[in] osc Oscillator ID
290@returns int. Boolean value for flag set.
291*/
292
294{
295 switch (osc) {
296 case RCC_PLL:
297 return ((RCC_CIR & RCC_CIR_PLLRDYF) != 0);
298 break;
299 case RCC_PLL2:
300 return ((RCC_CIR & RCC_CIR_PLL2RDYF) != 0);
301 break;
302 case RCC_PLL3:
303 return ((RCC_CIR & RCC_CIR_PLL3RDYF) != 0);
304 break;
305 case RCC_HSE:
306 return ((RCC_CIR & RCC_CIR_HSERDYF) != 0);
307 break;
308 case RCC_HSI:
309 return ((RCC_CIR & RCC_CIR_HSIRDYF) != 0);
310 break;
311 case RCC_LSE:
312 return ((RCC_CIR & RCC_CIR_LSERDYF) != 0);
313 break;
314 case RCC_LSI:
315 return ((RCC_CIR & RCC_CIR_LSIRDYF) != 0);
316 break;
317 }
318
320}
321
322/*---------------------------------------------------------------------------*/
323/** @brief RCC Clear the Clock Security System Interrupt Flag
324
325*/
326
328{
330}
331
332/*---------------------------------------------------------------------------*/
333/** @brief RCC Read the Clock Security System Interrupt Flag
334
335@returns int. Boolean value for flag set.
336*/
337
339{
340 return ((RCC_CIR & RCC_CIR_CSSF) != 0);
341}
342
344{
345 switch (osc) {
346 case RCC_PLL:
347 return RCC_CR & RCC_CR_PLLRDY;
348 case RCC_PLL2:
349 return RCC_CR & RCC_CR_PLL2RDY;
350 case RCC_PLL3:
351 return RCC_CR & RCC_CR_PLL3RDY;
352 case RCC_HSE:
353 return RCC_CR & RCC_CR_HSERDY;
354 case RCC_HSI:
355 return RCC_CR & RCC_CR_HSIRDY;
356 case RCC_LSE:
357 return RCC_BDCR & RCC_BDCR_LSERDY;
358 case RCC_LSI:
359 return RCC_CSR & RCC_CSR_LSIRDY;
360 }
361 return false;
362}
363
365{
366 while (!rcc_is_osc_ready(osc));
367}
368
369/*---------------------------------------------------------------------------*/
370/** @brief RCC Turn on an Oscillator.
371
372Enable an oscillator and power on. Each oscillator requires an amount of time
373to settle to a usable state. Refer to datasheets for time delay information. A
374status flag is available to indicate when the oscillator becomes ready (see
375@ref rcc_osc_ready_int_flag and @ref rcc_wait_for_osc_ready).
376
377@note The LSE clock is in the backup domain and cannot be enabled until the
378backup domain write protection has been removed (see @ref
379pwr_disable_backup_domain_write_protect).
380
381@param[in] osc Oscillator ID
382*/
383
384void rcc_osc_on(enum rcc_osc osc)
385{
386 switch (osc) {
387 case RCC_PLL:
389 break;
390 case RCC_PLL2:
392 break;
393 case RCC_PLL3:
395 break;
396 case RCC_HSE:
398 break;
399 case RCC_HSI:
401 break;
402 case RCC_LSE:
404 break;
405 case RCC_LSI:
407 break;
408 }
409}
410
411/*---------------------------------------------------------------------------*/
412/** @brief RCC Turn off an Oscillator.
413
414Disable an oscillator and power off.
415
416@note An oscillator cannot be turned off if it is selected as the system clock.
417@note The LSE clock is in the backup domain and cannot be disabled until the
418backup domain write protection has been removed (see
419@ref pwr_disable_backup_domain_write_protect) or the backup domain has been
420(see reset @ref rcc_backupdomain_reset).
421
422@param[in] osc Oscillator ID
423*/
424
425void rcc_osc_off(enum rcc_osc osc)
426{
427 switch (osc) {
428 case RCC_PLL:
429 RCC_CR &= ~RCC_CR_PLLON;
430 break;
431 case RCC_PLL2:
432 RCC_CR &= ~RCC_CR_PLL2ON;
433 break;
434 case RCC_PLL3:
435 RCC_CR &= ~RCC_CR_PLL3ON;
436 break;
437 case RCC_HSE:
438 RCC_CR &= ~RCC_CR_HSEON;
439 break;
440 case RCC_HSI:
441 RCC_CR &= ~RCC_CR_HSION;
442 break;
443 case RCC_LSE:
444 RCC_BDCR &= ~RCC_BDCR_LSEON;
445 break;
446 case RCC_LSI:
447 RCC_CSR &= ~RCC_CSR_LSION;
448 break;
449 }
450}
451
452/*---------------------------------------------------------------------------*/
453/** @brief RCC Enable the Clock Security System.
454
455*/
456
458{
460}
461
462/*---------------------------------------------------------------------------*/
463/** @brief RCC Disable the Clock Security System.
464
465*/
466
468{
469 RCC_CR &= ~RCC_CR_CSSON;
470}
471
472/*---------------------------------------------------------------------------*/
473/** @brief RCC Set the Source for the System Clock.
474
475@param[in] clk Unsigned int32. System Clock Selection @ref rcc_cfgr_scs
476*/
477
478void rcc_set_sysclk_source(uint32_t clk)
479{
480 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_SW) |
481 (clk << RCC_CFGR_SW_SHIFT);
482}
483
484/*---------------------------------------------------------------------------*/
485/** @brief RCC Set the PLL Multiplication Factor.
486
487@note This only has effect when the PLL is disabled.
488
489@param[in] mul Unsigned int32. PLL multiplication factor @ref rcc_cfgr_pmf
490*/
491
493{
494 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PLLMUL) |
495 (mul << RCC_CFGR_PLLMUL_SHIFT);
496}
497
498/*---------------------------------------------------------------------------*/
499/** @brief RCC Set the PLL2 Multiplication Factor.
500
501@note This only has effect when the PLL is disabled.
502
503@param[in] mul Unsigned int32. PLL multiplication factor @ref rcc_cfgr_pmf
504*/
505
507{
508 RCC_CFGR2 = (RCC_CFGR2 & ~RCC_CFGR2_PLL2MUL) |
510}
511
512/*---------------------------------------------------------------------------*/
513/** @brief RCC Set the PLL3 Multiplication Factor.
514
515@note This only has effect when the PLL is disabled.
516
517@param[in] mul Unsigned int32. PLL multiplication factor @ref rcc_cfgr_pmf
518*/
519
521{
522 RCC_CFGR2 = (RCC_CFGR2 & ~RCC_CFGR2_PLL3MUL) |
524}
525
526/*---------------------------------------------------------------------------*/
527/** @brief RCC Set the PLL Clock Source.
528
529@note This only has effect when the PLL is disabled.
530
531@param[in] pllsrc Unsigned int32. PLL clock source @ref rcc_cfgr_pcs
532*/
533
534void rcc_set_pll_source(uint32_t pllsrc)
535{
536 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PLLSRC) |
537 (pllsrc << 16);
538}
539
540/*---------------------------------------------------------------------------*/
541/** @brief RCC Set the HSE Frequency Divider used as PLL Clock Source.
542
543@note This only has effect when the PLL is disabled.
544
545@param[in] pllxtpre Unsigned int32. HSE division factor @ref rcc_cfgr_hsepre
546*/
547
548void rcc_set_pllxtpre(uint32_t pllxtpre)
549{
550 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PLLXTPRE) |
551 (pllxtpre << 17);
552}
553
554/*---------------------------------------------------------------------------*/
555/** @brief RCC RTC Clock Enabled Flag
556
557@returns uint32_t. Nonzero if the RTC Clock is enabled.
558*/
559
561{
562 return RCC_BDCR & RCC_BDCR_RTCEN;
563}
564
565/*---------------------------------------------------------------------------*/
566/** @brief RCC Enable the RTC clock
567
568*/
569
571{
573}
574
575/*---------------------------------------------------------------------------*/
576/** @brief RCC Set the Source for the RTC clock
577
578@param[in] clock_source RTC clock source. Only HSE/128, LSE and LSI.
579*/
580
581void rcc_set_rtc_clock_source(enum rcc_osc clock_source)
582{
583 uint32_t reg32;
584
585 switch (clock_source) {
586 case RCC_LSE:
587 /* Turn the LSE on and wait while it stabilises. */
589 while ((reg32 = (RCC_BDCR & RCC_BDCR_LSERDY)) == 0);
590
591 /* Choose LSE as the RTC clock source. */
592 RCC_BDCR &= ~((1 << 8) | (1 << 9));
593 RCC_BDCR |= (1 << 8);
594 break;
595 case RCC_LSI:
596 /* Turn the LSI on and wait while it stabilises. */
598 while ((reg32 = (RCC_CSR & RCC_CSR_LSIRDY)) == 0);
599
600 /* Choose LSI as the RTC clock source. */
601 RCC_BDCR &= ~((1 << 8) | (1 << 9));
602 RCC_BDCR |= (1 << 9);
603 break;
604 case RCC_HSE:
605 /* Turn the HSE on and wait while it stabilises. */
607 while ((reg32 = (RCC_CR & RCC_CR_HSERDY)) == 0);
608
609 /* Choose HSE as the RTC clock source. */
610 RCC_BDCR &= ~((1 << 8) | (1 << 9));
611 RCC_BDCR |= (1 << 9) | (1 << 8);
612 break;
613 case RCC_PLL:
614 case RCC_PLL2:
615 case RCC_PLL3:
616 case RCC_HSI:
617 /* Unusable clock source, here to prevent warnings. */
618 /* Turn off clock sources to RTC. */
619 RCC_BDCR &= ~((1 << 8) | (1 << 9));
620 break;
621 }
622}
623
624/*---------------------------------------------------------------------------*/
625/** @brief ADC Setup the A/D Clock
626
627The ADC's have a common clock prescale setting.
628
629@param[in] adcpre uint32_t. Prescale divider taken from @ref rcc_cfgr_adcpre
630*/
631
632void rcc_set_adcpre(uint32_t adcpre)
633{
634 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_ADCPRE) |
636}
637
638/*---------------------------------------------------------------------------*/
639/** @brief RCC Set the APB2 Prescale Factor.
640
641@param[in] ppre2 Unsigned int32. APB2 prescale factor @ref rcc_cfgr_apb2pre
642*/
643
644void rcc_set_ppre2(uint32_t ppre2)
645{
646 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PPRE2) |
648}
649
650/*---------------------------------------------------------------------------*/
651/** @brief RCC Set the APB1 Prescale Factor.
652
653@note The APB1 clock frequency must not exceed 36MHz.
654
655@param[in] ppre1 Unsigned int32. APB1 prescale factor @ref rcc_cfgr_apb1pre
656*/
657
658void rcc_set_ppre1(uint32_t ppre1)
659{
660 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PPRE1) |
662
663}
664
665/*---------------------------------------------------------------------------*/
666/** @brief RCC Set the AHB Prescale Factor.
667
668@param[in] hpre Unsigned int32. AHB prescale factor @ref rcc_cfgr_ahbpre
669*/
670
671void rcc_set_hpre(uint32_t hpre)
672{
673 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_HPRE) |
675
676}
677
678/*---------------------------------------------------------------------------*/
679/** @brief RCC Set the USB Prescale Factor.
680
681The prescale factor can be set to 1 (no prescale) for use when the PLL clock is
68248MHz, or 1.5 to generate the 48MHz USB clock from a 72MHz PLL clock.
683
684@note This bit cannot be reset while the USB clock is enabled.
685
686@param[in] usbpre Unsigned int32. USB prescale factor @ref rcc_cfgr_usbpre
687*/
688
689void rcc_set_usbpre(uint32_t usbpre)
690{
691 if (usbpre) {
693 } else {
694 RCC_CFGR &= ~RCC_CFGR_USBPRE;
695 }
696}
697
698void rcc_set_prediv1(uint32_t prediv)
699{
700 RCC_CFGR2 = (RCC_CFGR2 & ~RCC_CFGR2_PREDIV1) |
701 (prediv << RCC_CFGR2_PREDIV1_SHIFT);
702}
703
704void rcc_set_prediv2(uint32_t prediv)
705{
706 RCC_CFGR2 = (RCC_CFGR2 & ~RCC_CFGR2_PREDIV2) |
707 (prediv << RCC_CFGR2_PREDIV2_SHIFT);
708}
709
710void rcc_set_prediv1_source(uint32_t rccsrc)
711{
712 if (rccsrc) {
714 } else {
715 RCC_CFGR2 &= ~RCC_CFGR2_PREDIV1SRC;
716 }
717}
718
719/*---------------------------------------------------------------------------*/
720/** @brief RCC Get the System Clock Source.
721
722@returns Unsigned int32. System clock source:
723@li 00 indicates HSE
724@li 01 indicates LSE
725@li 02 indicates PLL
726*/
727
729{
730 /* Return the clock source which is used as system clock. */
732}
733
734/*---------------------------------------------------------------------------*/
735/*
736 * These functions are setting up the whole clock system for the most common
737 * input clock and output clock configurations.
738 */
739/*---------------------------------------------------------------------------*/
740/** @brief RCC Set System Clock PLL at 64MHz from HSI
741
742*/
743
745{
746 /* Enable internal high-speed oscillator. */
749
750 /* Select HSI as SYSCLK source. */
752
753 /*
754 * Set prescalers for AHB, ADC, APB1, APB2.
755 * Do this before touching the PLL (TODO: why?).
756 */
757 rcc_set_hpre(RCC_CFGR_HPRE_NODIV); /* Set. 64MHz Max. 72MHz */
758 rcc_set_adcpre(RCC_CFGR_ADCPRE_DIV8); /* Set. 8MHz Max. 14MHz */
759 rcc_set_ppre1(RCC_CFGR_PPRE_DIV2); /* Set. 32MHz Max. 36MHz */
760 rcc_set_ppre2(RCC_CFGR_PPRE_NODIV); /* Set. 64MHz Max. 72MHz */
761
762 /*
763 * Sysclk is running with 64MHz -> 2 waitstates.
764 * 0WS from 0-24MHz
765 * 1WS from 24-48MHz
766 * 2WS from 48-72MHz
767 */
769
770 /*
771 * Set the PLL multiplication factor to 16.
772 * 8MHz (internal) * 16 (multiplier) / 2 (PLLSRC_HSI_CLK_DIV2) = 64MHz
773 */
775
776 /* Select HSI/2 as PLL source. */
778
779 /* Enable PLL oscillator and wait for it to stabilize. */
782
783 /* Select PLL as SYSCLK source. */
785
786 /* Set the peripheral clock frequencies used */
787 rcc_ahb_frequency = 64000000;
788 rcc_apb1_frequency = 32000000;
789 rcc_apb2_frequency = 64000000;
790}
791
792/*---------------------------------------------------------------------------*/
793/** @brief RCC Set System Clock PLL at 48MHz from HSI
794
795*/
796
798{
799 /* Enable internal high-speed oscillator. */
802
803 /* Select HSI as SYSCLK source. */
805
806 /*
807 * Set prescalers for AHB, ADC, APB1, APB2.
808 * Do this before touching the PLL (TODO: why?).
809 */
810 rcc_set_hpre(RCC_CFGR_HPRE_NODIV); /*Set.48MHz Max.72MHz */
811 rcc_set_adcpre(RCC_CFGR_ADCPRE_DIV8); /*Set. 6MHz Max.14MHz */
812 rcc_set_ppre1(RCC_CFGR_PPRE_DIV2); /*Set.24MHz Max.36MHz */
813 rcc_set_ppre2(RCC_CFGR_PPRE_NODIV); /*Set.48MHz Max.72MHz */
814 rcc_set_usbpre(RCC_CFGR_USBPRE_PLL_CLK_NODIV); /*Set.48MHz Max.48MHz */
815
816 /*
817 * Sysclk runs with 48MHz -> 1 waitstates.
818 * 0WS from 0-24MHz
819 * 1WS from 24-48MHz
820 * 2WS from 48-72MHz
821 */
823
824 /*
825 * Set the PLL multiplication factor to 12.
826 * 8MHz (internal) * 12 (multiplier) / 2 (PLLSRC_HSI_CLK_DIV2) = 48MHz
827 */
829
830 /* Select HSI/2 as PLL source. */
832
833 /* Enable PLL oscillator and wait for it to stabilize. */
836
837 /* Select PLL as SYSCLK source. */
839
840 /* Set the peripheral clock frequencies used */
841 rcc_ahb_frequency = 48000000;
842 rcc_apb1_frequency = 24000000;
843 rcc_apb2_frequency = 48000000;
844}
845
846/*---------------------------------------------------------------------------*/
847/** @brief RCC Set System Clock PLL at 24MHz from HSI
848
849*/
850
852{
853 /* Enable internal high-speed oscillator. */
856
857 /* Select HSI as SYSCLK source. */
859
860 /*
861 * Set prescalers for AHB, ADC, APB1, APB2.
862 * Do this before touching the PLL (TODO: why?).
863 */
864 rcc_set_hpre(RCC_CFGR_HPRE_NODIV); /* Set. 24MHz Max. 24MHz */
865 rcc_set_adcpre(RCC_CFGR_ADCPRE_DIV2); /* Set. 12MHz Max. 12MHz */
866 rcc_set_ppre1(RCC_CFGR_PPRE_NODIV); /* Set. 24MHz Max. 24MHz */
867 rcc_set_ppre2(RCC_CFGR_PPRE_NODIV); /* Set. 24MHz Max. 24MHz */
868
869 /*
870 * Sysclk is (will be) running with 24MHz -> 0 waitstates.
871 * 0WS from 0-24MHz
872 * 1WS from 24-48MHz
873 * 2WS from 48-72MHz
874 */
876
877 /*
878 * Set the PLL multiplication factor to 6.
879 * 8MHz (internal) * 6 (multiplier) / 2 (PLLSRC_HSI_CLK_DIV2) = 24MHz
880 */
882
883 /* Select HSI/2 as PLL source. */
885
886 /* Enable PLL oscillator and wait for it to stabilize. */
889
890 /* Select PLL as SYSCLK source. */
892
893 /* Set the peripheral clock frequencies used */
894 rcc_ahb_frequency = 24000000;
895 rcc_apb1_frequency = 24000000;
896 rcc_apb2_frequency = 24000000;
897}
898
899/*---------------------------------------------------------------------------*/
900/** @brief RCC Set System Clock PLL at 24MHz from HSE at 8MHz
901
902*/
903
905{
906 /* Enable internal high-speed oscillator. */
909
910 /* Select HSI as SYSCLK source. */
912
913 /* Enable external high-speed oscillator 8MHz. */
917
918 /*
919 * Set prescalers for AHB, ADC, APB1, APB2.
920 * Do this before touching the PLL (TODO: why?).
921 */
922 rcc_set_hpre(RCC_CFGR_HPRE_NODIV); /* Set. 24MHz Max. 72MHz */
923 rcc_set_adcpre(RCC_CFGR_ADCPRE_DIV2); /* Set. 12MHz Max. 14MHz */
924 rcc_set_ppre1(RCC_CFGR_PPRE_NODIV); /* Set. 24MHz Max. 36MHz */
925 rcc_set_ppre2(RCC_CFGR_PPRE_NODIV); /* Set. 24MHz Max. 72MHz */
926
927 /*
928 * Sysclk runs with 24MHz -> 0 waitstates.
929 * 0WS from 0-24MHz
930 * 1WS from 24-48MHz
931 * 2WS from 48-72MHz
932 */
934
935 /*
936 * Set the PLL multiplication factor to 3.
937 * 8MHz (external) * 3 (multiplier) = 24MHz
938 */
940
941 /* Select HSE as PLL source. */
943
944 /*
945 * External frequency undivided before entering PLL
946 * (only valid/needed for HSE).
947 */
949
950 /* Enable PLL oscillator and wait for it to stabilize. */
953
954 /* Select PLL as SYSCLK source. */
956
957 /* Set the peripheral clock frequencies used */
958 rcc_ahb_frequency = 24000000;
959 rcc_apb1_frequency = 24000000;
960 rcc_apb2_frequency = 24000000;
961}
962
963/*---------------------------------------------------------------------------*/
964/** @brief RCC Set System Clock PLL at 72MHz from HSE at 8MHz
965
966*/
967
969{
970 /* Enable internal high-speed oscillator. */
973
974 /* Select HSI as SYSCLK source. */
976
977 /* Enable external high-speed oscillator 8MHz. */
981
982 /*
983 * Set prescalers for AHB, ADC, APB1, APB2.
984 * Do this before touching the PLL (TODO: why?).
985 */
986 rcc_set_hpre(RCC_CFGR_HPRE_NODIV); /* Set. 72MHz Max. 72MHz */
987 rcc_set_adcpre(RCC_CFGR_ADCPRE_DIV8); /* Set. 9MHz Max. 14MHz */
988 rcc_set_ppre1(RCC_CFGR_PPRE_DIV2); /* Set. 36MHz Max. 36MHz */
989 rcc_set_ppre2(RCC_CFGR_PPRE_NODIV); /* Set. 72MHz Max. 72MHz */
990
991 /*
992 * Sysclk runs with 72MHz -> 2 waitstates.
993 * 0WS from 0-24MHz
994 * 1WS from 24-48MHz
995 * 2WS from 48-72MHz
996 */
998
999 /*
1000 * Set the PLL multiplication factor to 9.
1001 * 8MHz (external) * 9 (multiplier) = 72MHz
1002 */
1004
1005 /* Select HSE as PLL source. */
1007
1008 /*
1009 * External frequency undivided before entering PLL
1010 * (only valid/needed for HSE).
1011 */
1013
1014 /* Enable PLL oscillator and wait for it to stabilize. */
1017
1018 /* Select PLL as SYSCLK source. */
1020
1021 /* Set the peripheral clock frequencies used */
1022 rcc_ahb_frequency = 72000000;
1023 rcc_apb1_frequency = 36000000;
1024 rcc_apb2_frequency = 72000000;
1025}
1026
1027/*---------------------------------------------------------------------------*/
1028/** @brief RCC Set System Clock PLL at 72MHz from HSE at 12MHz
1029
1030*/
1031
1033{
1034 /* Enable internal high-speed oscillator. */
1037
1038 /* Select HSI as SYSCLK source. */
1040
1041 /* Enable external high-speed oscillator 16MHz. */
1045
1046 /*
1047 * Set prescalers for AHB, ADC, APB1, APB2.
1048 * Do this before touching the PLL (TODO: why?).
1049 */
1050 rcc_set_hpre(RCC_CFGR_HPRE_NODIV); /* Set. 72MHz Max. 72MHz */
1051 rcc_set_adcpre(RCC_CFGR_ADCPRE_DIV6); /* Set. 12MHz Max. 14MHz */
1052 rcc_set_ppre1(RCC_CFGR_PPRE_DIV2); /* Set. 36MHz Max. 36MHz */
1053 rcc_set_ppre2(RCC_CFGR_PPRE_NODIV); /* Set. 72MHz Max. 72MHz */
1054
1055 /*
1056 * Sysclk runs with 72MHz -> 2 waitstates.
1057 * 0WS from 0-24MHz
1058 * 1WS from 24-48MHz
1059 * 2WS from 48-72MHz
1060 */
1062
1063 /*
1064 * Set the PLL multiplication factor to 9.
1065 * 12MHz (external) * 6 (multiplier) / 1 (PLLXTPRE_HSE_CLK) = 72MHz
1066 */
1068
1069 /* Select HSI as PLL source. */
1071
1072 /*
1073 * Divide external frequency by 2 before entering PLL
1074 * (only valid/needed for HSE).
1075 */
1077
1078 /* Enable PLL oscillator and wait for it to stabilize. */
1081
1082 /* Select PLL as SYSCLK source. */
1084
1085 /* Set the peripheral clock frequencies used */
1086 rcc_ahb_frequency = 72000000;
1087 rcc_apb1_frequency = 36000000;
1088 rcc_apb2_frequency = 72000000;
1089}
1090
1091/*---------------------------------------------------------------------------*/
1092/** @brief RCC Set System Clock PLL at 72MHz from HSE at 16MHz
1093
1094*/
1095
1097{
1098 /* Enable internal high-speed oscillator. */
1101
1102 /* Select HSI as SYSCLK source. */
1104
1105 /* Enable external high-speed oscillator 16MHz. */
1109
1110 /*
1111 * Set prescalers for AHB, ADC, APB1, APB2.
1112 * Do this before touching the PLL (TODO: why?).
1113 */
1114 rcc_set_hpre(RCC_CFGR_HPRE_NODIV); /* Set. 72MHz Max. 72MHz */
1115 rcc_set_adcpre(RCC_CFGR_ADCPRE_DIV6); /* Set. 12MHz Max. 14MHz */
1116 rcc_set_ppre1(RCC_CFGR_PPRE_DIV2); /* Set. 36MHz Max. 36MHz */
1117 rcc_set_ppre2(RCC_CFGR_PPRE_NODIV); /* Set. 72MHz Max. 72MHz */
1118
1119 /*
1120 * Sysclk runs with 72MHz -> 2 waitstates.
1121 * 0WS from 0-24MHz
1122 * 1WS from 24-48MHz
1123 * 2WS from 48-72MHz
1124 */
1126
1127 /*
1128 * Set the PLL multiplication factor to 9.
1129 * 16MHz (external) * 9 (multiplier) / 2 (PLLXTPRE_HSE_CLK_DIV2) = 72MHz
1130 */
1132
1133 /* Select HSI as PLL source. */
1135
1136 /*
1137 * Divide external frequency by 2 before entering PLL
1138 * (only valid/needed for HSE).
1139 */
1141
1142 /* Enable PLL oscillator and wait for it to stabilize. */
1145
1146 /* Select PLL as SYSCLK source. */
1148
1149 /* Set the peripheral clock frequencies used */
1150 rcc_ahb_frequency = 72000000;
1151 rcc_apb1_frequency = 36000000;
1152 rcc_apb2_frequency = 72000000;
1153}
1154
1155/*---------------------------------------------------------------------------*/
1156/** @brief RCC Set System Clock PLL at 72MHz from HSE at 25MHz
1157
1158*/
1159
1161{
1162 /* Enable external high-speed oscillator 25MHz. */
1166
1167 /*
1168 * Sysclk runs with 72MHz -> 2 waitstates.
1169 * 0WS from 0-24MHz
1170 * 1WS from 24-48MHz
1171 * 2WS from 48-72MHz
1172 */
1174
1175 /*
1176 * Set prescalers for AHB, ADC, APB1, APB2.
1177 * Do this before touching the PLL (TODO: why?).
1178 */
1179 rcc_set_hpre(RCC_CFGR_HPRE_NODIV); /* Set. 72MHz Max. 72MHz */
1180 rcc_set_adcpre(RCC_CFGR_ADCPRE_DIV6); /* Set. 12MHz Max. 14MHz */
1181 rcc_set_ppre1(RCC_CFGR_PPRE_DIV2); /* Set. 36MHz Max. 36MHz */
1182 rcc_set_ppre2(RCC_CFGR_PPRE_NODIV); /* Set. 72MHz Max. 72MHz */
1183
1184 /* Set pll2 prediv and multiplier */
1187
1188 /* Enable PLL2 oscillator and wait for it to stabilize */
1191
1192 /* Set pll1 prediv/multiplier, prediv1 src, and usb predivider */
1199
1200 /* enable PLL1 and wait for it to stabilize */
1203
1204 /* Select PLL as SYSCLK source. */
1206
1207 /* Set the peripheral clock frequencies used */
1208 rcc_ahb_frequency = 72000000;
1209 rcc_apb1_frequency = 36000000;
1210 rcc_apb2_frequency = 72000000;
1211}
1212
1213void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
1214{
1215 if (clock->pll_source == RCC_CFGR_PLLSRC_HSE_CLK) {
1218 } else {
1221 }
1222 rcc_set_hpre(clock->hpre);
1223 rcc_set_ppre1(clock->ppre1);
1224 rcc_set_ppre2(clock->ppre2);
1225 rcc_set_adcpre(clock->adcpre);
1226 rcc_set_usbpre(clock->usbpre);
1228
1231
1232 /*
1233 * Magically handle F105/7 parts too.
1234 * xtpre == prediv1 bit 0.
1235 */
1236 if (clock->prediv1 > RCC_CFGR2_PREDIV_DIV2) {
1237 rcc_set_prediv1(clock->prediv1);
1238 } else {
1239 rcc_set_pllxtpre(clock->prediv1);
1240 }
1241 if (clock->prediv1_source) {
1243 }
1244
1245 /*
1246 * Magically handle other plls/prescalers on other parts
1247 */
1248 if (clock->prediv2) {
1249 rcc_set_prediv2(clock->prediv2);
1250 }
1251 if (clock->pll2_mul) {
1255 }
1256 if (clock->pll3_mul) {
1260 }
1261
1262 /* Enable PLL oscillator and wait for it to stabilize. */
1265
1266 /* Select PLL as SYSCLK source. */
1268
1269 /* Set the peripheral clock frequencies used. */
1273}
1274
1275
1276/*---------------------------------------------------------------------------*/
1277/** @brief RCC Reset the Backup Domain
1278
1279The backup domain registers are reset to disable RTC controls and clear user
1280data.
1281*/
1282
1284{
1285 /* Set the backup domain software reset. */
1287
1288 /* Clear the backup domain software reset. */
1289 RCC_BDCR &= ~RCC_BDCR_BDRST;
1290}
1291
1292/*---------------------------------------------------------------------------*/
1293/** @brief Get the peripheral clock speed for the USART at base specified.
1294 * @param usart Base address of USART to get clock frequency for.
1295 */
1296uint32_t rcc_get_usart_clk_freq(uint32_t usart)
1297{
1298 if (usart == USART1_BASE) {
1299 return rcc_apb2_frequency;
1300 } else {
1301 return rcc_apb1_frequency;
1302 }
1303}
1304
1305/*---------------------------------------------------------------------------*/
1306/** @brief Get the peripheral clock speed for the Timer at base specified.
1307 * @param timer Base address of TIM to get clock frequency for.
1308 */
1309uint32_t rcc_get_timer_clk_freq(uint32_t timer)
1310{
1311 /* Handle APB1 timer clocks. */
1312 if (timer >= TIM2_BASE && timer <= TIM14_BASE) {
1315 : 2 * rcc_apb1_frequency;
1316 } else {
1319 : 2 * rcc_apb2_frequency;
1320 }
1322}
1323
1324/*---------------------------------------------------------------------------*/
1325/** @brief Get the peripheral clock speed for the I2C device at base specified.
1326 * @param i2c Base address of I2C to get clock frequency for.
1327 */
1328uint32_t rcc_get_i2c_clk_freq(uint32_t i2c __attribute__((unused)))
1329{
1330 return rcc_apb1_frequency;
1331}
1332/**@}*/
1333
#define cm3_assert_not_reached()
Check if unreachable code is reached.
Definition: assert.h:102
void flash_set_ws(uint32_t ws)
Set the Number of Wait States.
#define FLASH_ACR_LATENCY_0WS
Definition: f1/flash.h:74
#define FLASH_ACR_LATENCY_2WS
Definition: f1/flash.h:76
#define FLASH_ACR_LATENCY_1WS
Definition: f1/flash.h:75
#define RCC_CFGR_ADCPRE_DIV8
Definition: f1/rcc.h:191
#define RCC_CFGR_ADCPRE_DIV6
Definition: f1/rcc.h:190
#define RCC_CFGR_ADCPRE_DIV2
Definition: f1/rcc.h:188
#define RCC_CFGR_HPRE_NODIV
Definition: f1/rcc.h:214
#define RCC_CFGR_PPRE_DIV2
Definition: f1/rcc.h:203
#define RCC_CFGR_PPRE_NODIV
Definition: f1/rcc.h:202
#define RCC_CFGR_PPRE2_HCLK_NODIV
Definition: f1/rcc.h:250
#define RCC_CFGR_PPRE1_HCLK_NODIV
Definition: f1/rcc.h:256
#define RCC_CFGR_PLLXTPRE_HSE_CLK_DIV2
Definition: f1/rcc.h:169
#define RCC_CFGR_PLLXTPRE_HSE_CLK
Definition: f1/rcc.h:168
#define RCC_CFGR_PLLSRC_HSE_CLK
Definition: f1/rcc.h:178
#define RCC_CFGR_PLLSRC_PREDIV1_CLK
Definition: f1/rcc.h:179
#define RCC_CFGR_PLLSRC_HSI_CLK_DIV2
Definition: f1/rcc.h:177
#define RCC_CFGR_PLLMUL_PLL_CLK_MUL16
Definition: f1/rcc.h:158
#define RCC_CFGR_PLLMUL_PLL_CLK_MUL3
Definition: f1/rcc.h:144
#define RCC_CFGR_PLLMUL_PLL_CLK_MUL6
Definition: f1/rcc.h:147
#define RCC_CFGR_PLLMUL_PLL_CLK_MUL9
Definition: f1/rcc.h:150
#define RCC_CFGR_PLLMUL_PLL_CLK_MUL12
Definition: f1/rcc.h:153
#define RCC_CFGR_SW_SYSCLKSEL_HSICLK
Definition: f1/rcc.h:235
#define RCC_CFGR_SW_SYSCLKSEL_PLLCLK
Definition: f1/rcc.h:237
#define RCC_CFGR_SW_SYSCLKSEL_HSECLK
Definition: f1/rcc.h:236
#define RCC_CFGR_USBPRE_PLL_CLK_NODIV
Definition: f1/rcc.h:131
#define RCC_BDCR_LSEON
Definition: f1/rcc.h:447
#define RCC_CFGR2_PREDIV1SRC_PLL2_CLK
Definition: f1/rcc.h:487
#define RCC_CIR_PLLRDYF
Definition: f1/rcc.h:303
#define RCC_CIR
Definition: f1/rcc.h:50
#define RCC_CFGR2_PLL2MUL_PLL2_CLK_MUL8
Definition: f1/rcc.h:514
#define RCC_CIR_HSERDYF
Definition: f1/rcc.h:304
#define RCC_CFGR_PPRE1_MASK
Definition: f1/rcc.h:197
#define RCC_CIR_LSERDYC
Definition: f1/rcc.h:285
#define RCC_CFGR_PPRE2_SHIFT
Definition: f1/rcc.h:194
#define RCC_CFGR_SWS
Definition: f1/rcc.h:102
#define RCC_CIR_PLLRDYIE
Definition: f1/rcc.h:291
#define RCC_CIR_PLLRDYC
Definition: f1/rcc.h:282
#define RCC_CR_PLL2RDY
Definition: f1/rcc.h:65
#define RCC_CR_PLL2ON
Definition: f1/rcc.h:66
#define RCC_CFGR2_PREDIV1_SHIFT
Definition: f1/rcc.h:499
#define RCC_BDCR_BDRST
Definition: f1/rcc.h:442
#define RCC_CR
Definition: f1/rcc.h:48
#define RCC_CR_PLL3RDY
Definition: f1/rcc.h:63
#define RCC_CFGR_PPRE2_MASK
Definition: f1/rcc.h:195
#define RCC_CIR_CSSC
Definition: f1/rcc.h:277
#define RCC_CFGR2_PREDIV_DIV5
Definition: f1/rcc.h:529
#define RCC_CIR_HSERDYIE
Definition: f1/rcc.h:292
#define RCC_CFGR2
Definition: f1/rcc.h:59
rcc_osc
Definition: f1/rcc.h:567
#define RCC_CIR_LSERDYIE
Definition: f1/rcc.h:294
#define RCC_CSR
Definition: f1/rcc.h:57
#define RCC_CIR_PLL2RDYIE
Definition: f1/rcc.h:290
#define RCC_BDCR_RTCEN
Definition: f1/rcc.h:443
#define RCC_CFGR2_PLL3MUL_SHIFT
Definition: f1/rcc.h:490
#define RCC_CR_PLL3ON
Definition: f1/rcc.h:64
#define RCC_CSR_LSION
Definition: f1/rcc.h:462
#define RCC_CR_HSERDY
Definition: f1/rcc.h:71
#define RCC_CIR_LSIRDYIE
Definition: f1/rcc.h:295
#define RCC_CFGR2_PREDIV_NODIV
Definition: f1/rcc.h:525
#define RCC_CFGR2_PREDIV_DIV2
Definition: f1/rcc.h:526
#define RCC_CFGR
Definition: f1/rcc.h:49
#define RCC_CIR_PLL3RDYF
Definition: f1/rcc.h:301
#define RCC_CIR_PLL3RDYIE
Definition: f1/rcc.h:289
#define RCC_CIR_HSERDYC
Definition: f1/rcc.h:283
#define RCC_CIR_LSIRDYC
Definition: f1/rcc.h:286
#define RCC_CR_HSIRDY
Definition: f1/rcc.h:75
#define RCC_CFGR_USBPRE_PLL_VCO_CLK_DIV3
Definition: f1/rcc.h:135
#define RCC_CIR_PLL3RDYC
Definition: f1/rcc.h:280
#define RCC_CFGR2_PREDIV1SRC
Definition: f1/rcc.h:488
#define RCC_CFGR_SWS_SHIFT
Definition: f1/rcc.h:101
#define RCC_BDCR_LSERDY
Definition: f1/rcc.h:446
#define RCC_CSR_LSIRDY
Definition: f1/rcc.h:461
#define RCC_CFGR_PLLMUL_SHIFT
Definition: f1/rcc.h:83
#define RCC_BDCR
Definition: f1/rcc.h:56
#define RCC_CFGR2_PLL2MUL_SHIFT
Definition: f1/rcc.h:493
#define RCC_CFGR_HPRE_SHIFT
Definition: f1/rcc.h:98
#define RCC_CFGR2_PREDIV2_DIV5
Definition: f1/rcc.h:547
#define RCC_CIR_LSERDYF
Definition: f1/rcc.h:306
#define RCC_CFGR_SW_SHIFT
Definition: f1/rcc.h:104
#define RCC_CIR_HSIRDYIE
Definition: f1/rcc.h:293
#define RCC_CIR_LSIRDYF
Definition: f1/rcc.h:307
#define RCC_CR_CSSON
Definition: f1/rcc.h:69
#define RCC_CFGR2_PREDIV2_SHIFT
Definition: f1/rcc.h:496
#define RCC_CR_PLLON
Definition: f1/rcc.h:68
#define RCC_CIR_HSIRDYC
Definition: f1/rcc.h:284
#define RCC_CIR_HSIRDYF
Definition: f1/rcc.h:305
#define RCC_CIR_CSSF
Definition: f1/rcc.h:298
#define RCC_CIR_PLL2RDYF
Definition: f1/rcc.h:302
#define RCC_CR_HSEON
Definition: f1/rcc.h:72
#define RCC_CIR_PLL2RDYC
Definition: f1/rcc.h:281
#define RCC_CFGR_USBPRE
Definition: f1/rcc.h:81
#define RCC_CFGR_ADCPRE_SHIFT
Definition: f1/rcc.h:89
#define RCC_CR_HSION
Definition: f1/rcc.h:76
#define RCC_CR_PLLRDY
Definition: f1/rcc.h:67
#define RCC_CFGR_PPRE1_SHIFT
Definition: f1/rcc.h:196
@ RCC_CLOCK_HSE_END
Definition: f1/rcc.h:717
@ RCC_HSI
Definition: f1/rcc.h:568
@ RCC_PLL2
Definition: f1/rcc.h:568
@ RCC_LSI
Definition: f1/rcc.h:568
@ RCC_PLL
Definition: f1/rcc.h:568
@ RCC_LSE
Definition: f1/rcc.h:568
@ RCC_HSE
Definition: f1/rcc.h:568
@ RCC_PLL3
Definition: f1/rcc.h:568
@ RCC_CLOCK_HSI_END
Definition: f1/rcc.h:708
int rcc_osc_ready_int_flag(enum rcc_osc osc)
RCC Read the Oscillator Ready Interrupt Flag.
Definition: rcc.c:293
int rcc_css_int_flag(void)
RCC Read the Clock Security System Interrupt Flag.
Definition: rcc.c:338
void rcc_set_adcpre(uint32_t adcpre)
ADC Setup the A/D Clock.
Definition: rcc.c:632
void rcc_set_rtc_clock_source(enum rcc_osc clock_source)
RCC Set the Source for the RTC clock.
Definition: rcc.c:581
void rcc_osc_ready_int_clear(enum rcc_osc osc)
RCC Clear the Oscillator Ready Interrupt Flag.
Definition: rcc.c:193
void rcc_wait_for_osc_ready(enum rcc_osc osc)
Wait for Oscillator Ready.
Definition: rcc.c:364
void rcc_css_disable(void)
RCC Disable the Clock Security System.
Definition: rcc.c:467
bool rcc_is_osc_ready(enum rcc_osc osc)
Is the given oscillator ready?
Definition: rcc.c:343
void rcc_clock_setup_in_hse_8mhz_out_24mhz(void)
RCC Set System Clock PLL at 24MHz from HSE at 8MHz.
Definition: rcc.c:904
void rcc_set_sysclk_source(uint32_t clk)
RCC Set the Source for the System Clock.
Definition: rcc.c:478
void rcc_set_prediv1_source(uint32_t rccsrc)
Definition: rcc.c:710
uint32_t rcc_apb2_frequency
Definition: rcc.c:58
void rcc_set_pll_source(uint32_t pllsrc)
RCC Set the PLL Clock Source.
Definition: rcc.c:534
void rcc_set_prediv1(uint32_t prediv)
Definition: rcc.c:698
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
Definition: rcc.c:1309
uint32_t rcc_system_clock_source(void)
RCC Get the System Clock Source.
Definition: rcc.c:728
void rcc_set_prediv2(uint32_t prediv)
Definition: rcc.c:704
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
Definition: rcc.c:1296
void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
Switch sysclock to PLL with the given parameters.
Definition: rcc.c:1213
const struct rcc_clock_scale rcc_hsi_configs[RCC_CLOCK_HSI_END]
Definition: rcc.c:138
void rcc_set_pll3_multiplication_factor(uint32_t mul)
RCC Set the PLL3 Multiplication Factor.
Definition: rcc.c:520
void rcc_clock_setup_in_hsi_out_24mhz(void)
RCC Set System Clock PLL at 24MHz from HSI.
Definition: rcc.c:851
void rcc_set_pll2_multiplication_factor(uint32_t mul)
RCC Set the PLL2 Multiplication Factor.
Definition: rcc.c:506
void rcc_osc_ready_int_enable(enum rcc_osc osc)
RCC Enable the Oscillator Ready Interrupt.
Definition: rcc.c:226
void rcc_clock_setup_in_hse_8mhz_out_72mhz(void)
RCC Set System Clock PLL at 72MHz from HSE at 8MHz.
Definition: rcc.c:968
void rcc_osc_ready_int_disable(enum rcc_osc osc)
RCC Disable the Oscillator Ready Interrupt.
Definition: rcc.c:259
void rcc_osc_on(enum rcc_osc osc)
RCC Turn on an Oscillator.
Definition: rcc.c:384
uint32_t rcc_ahb_frequency
Definition: rcc.c:59
void rcc_osc_off(enum rcc_osc osc)
RCC Turn off an Oscillator.
Definition: rcc.c:425
uint32_t rcc_get_i2c_clk_freq(uint32_t i2c)
Get the peripheral clock speed for the I2C device at base specified.
Definition: rcc.c:1328
void rcc_set_pll_multiplication_factor(uint32_t mul)
RCC Set the PLL Multiplication Factor.
Definition: rcc.c:492
const struct rcc_clock_scale rcc_hse_configs[RCC_CLOCK_HSE_END]
Definition: rcc.c:61
void rcc_backupdomain_reset(void)
RCC Reset the Backup Domain.
Definition: rcc.c:1283
uint32_t rcc_apb1_frequency
Set the default clock frequencies.
Definition: rcc.c:57
void rcc_set_ppre1(uint32_t ppre1)
RCC Set the APB1 Prescale Factor.
Definition: rcc.c:658
void rcc_css_int_clear(void)
RCC Clear the Clock Security System Interrupt Flag.
Definition: rcc.c:327
void rcc_enable_rtc_clock(void)
RCC Enable the RTC clock.
Definition: rcc.c:570
void rcc_set_ppre2(uint32_t ppre2)
RCC Set the APB2 Prescale Factor.
Definition: rcc.c:644
void rcc_set_usbpre(uint32_t usbpre)
RCC Set the USB Prescale Factor.
Definition: rcc.c:689
void rcc_clock_setup_in_hsi_out_48mhz(void)
RCC Set System Clock PLL at 48MHz from HSI.
Definition: rcc.c:797
void rcc_css_enable(void)
RCC Enable the Clock Security System.
Definition: rcc.c:457
void rcc_set_hpre(uint32_t hpre)
RCC Set the AHB Prescale Factor.
Definition: rcc.c:671
void rcc_set_pllxtpre(uint32_t pllxtpre)
RCC Set the HSE Frequency Divider used as PLL Clock Source.
Definition: rcc.c:548
void rcc_clock_setup_in_hse_12mhz_out_72mhz(void)
RCC Set System Clock PLL at 72MHz from HSE at 12MHz.
Definition: rcc.c:1032
void rcc_clock_setup_in_hse_25mhz_out_72mhz(void)
RCC Set System Clock PLL at 72MHz from HSE at 25MHz.
Definition: rcc.c:1160
void rcc_clock_setup_in_hsi_out_64mhz(void)
RCC Set System Clock PLL at 64MHz from HSI.
Definition: rcc.c:744
void rcc_clock_setup_in_hse_16mhz_out_72mhz(void)
RCC Set System Clock PLL at 72MHz from HSE at 16MHz.
Definition: rcc.c:1096
uint32_t rcc_rtc_clock_enabled_flag(void)
RCC RTC Clock Enabled Flag.
Definition: rcc.c:560
#define TIM2_BASE
#define USART1_BASE
#define TIM14_BASE
uint8_t ppre1
Definition: f1/rcc.h:725
uint8_t flash_waitstates
Definition: f1/rcc.h:728
uint8_t prediv1
Definition: f1/rcc.h:729
uint8_t prediv2
Definition: f1/rcc.h:731
uint8_t ppre2
Definition: f1/rcc.h:726
uint8_t pll3_mul
Definition: f1/rcc.h:733
uint8_t adcpre
Definition: f1/rcc.h:727
uint32_t apb1_frequency
Definition: f1/rcc.h:736
uint8_t pll_mul
Definition: f1/rcc.h:722
uint32_t ahb_frequency
Definition: f1/rcc.h:735
uint8_t usbpre
Definition: f1/rcc.h:734
uint8_t prediv1_source
Definition: f1/rcc.h:730
uint8_t hpre
Definition: f1/rcc.h:724
uint32_t apb2_frequency
Definition: f1/rcc.h:737
uint8_t pll_source
Definition: f1/rcc.h:723
uint8_t pll2_mul
Definition: f1/rcc.h:732