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 STM32F0xx Reset and Clock Control</b>
6 *
7 * @version 1.0.0
8 *
9 * @date 29 Jun 2013
10 *
11 * This library supports the Reset and Clock Control System in the STM32F0xx
12 * series of ARM Cortex Microcontrollers by ST Microelectronics.
13 *
14 * LGPL License Terms @ref lgpl_license
15 */
16/*
17 * This file is part of the libopencm3 project.
18 *
19 * Copyright (C) 2009 Federico Ruiz-Ugalde <memeruiz at gmail dot com>
20 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
21 * Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
22 *
23 * This library is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU Lesser General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
27 *
28 * This library is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
32 *
33 * You should have received a copy of the GNU Lesser General Public License
34 * along with this library. If not, see <http://www.gnu.org/licenses/>.
35 */
36
37/**@{*/
38
43
44/* Set the default clock frequencies */
45uint32_t rcc_ahb_frequency = 8000000; /* 8MHz after reset */
46uint32_t rcc_apb1_frequency = 8000000; /* 8MHz after reset */
47
48/*---------------------------------------------------------------------------*/
49/** @brief RCC Clear the Oscillator Ready Interrupt Flag
50 *
51 * Clear the interrupt flag that was set when a clock oscillator became ready
52 * to use.
53 *
54 * @param osc Oscillator ID
55 */
56
58{
59 switch (osc) {
60 case RCC_HSI48:
62 break;
63 case RCC_HSI14:
65 break;
66 case RCC_HSI:
68 break;
69 case RCC_HSE:
71 break;
72 case RCC_PLL:
74 break;
75 case RCC_LSE:
77 break;
78 case RCC_LSI:
80 break;
81 }
82}
83
84/*---------------------------------------------------------------------------*/
85/** @brief RCC Enable the Oscillator Ready Interrupt
86 *
87 * @param osc Oscillator ID
88 */
89
91{
92 switch (osc) {
93 case RCC_HSI48:
95 break;
96 case RCC_HSI14:
98 break;
99 case RCC_HSI:
101 break;
102 case RCC_HSE:
104 break;
105 case RCC_PLL:
107 break;
108 case RCC_LSE:
110 break;
111 case RCC_LSI:
113 break;
114 }
115}
116
117/*---------------------------------------------------------------------------*/
118/** @brief RCC Disable the Oscillator Ready Interrupt
119 *
120 * @param osc Oscillator ID
121 */
122
124{
125 switch (osc) {
126 case RCC_HSI48:
127 RCC_CIR &= ~RCC_CIR_HSI48RDYC;
128 break;
129 case RCC_HSI14:
130 RCC_CIR &= ~RCC_CIR_HSI14RDYC;
131 break;
132 case RCC_HSI:
133 RCC_CIR &= ~RCC_CIR_HSIRDYC;
134 break;
135 case RCC_HSE:
136 RCC_CIR &= ~RCC_CIR_HSERDYC;
137 break;
138 case RCC_PLL:
139 RCC_CIR &= ~RCC_CIR_PLLRDYC;
140 break;
141 case RCC_LSE:
142 RCC_CIR &= ~RCC_CIR_LSERDYC;
143 break;
144 case RCC_LSI:
145 RCC_CIR &= ~RCC_CIR_LSIRDYC;
146 break;
147 }
148}
149
150/*---------------------------------------------------------------------------*/
151/** @brief RCC Read the Oscillator Ready Interrupt Flag
152 *
153 * @param osc Oscillator ID
154 * @returns int. Boolean value for flag set.
155 */
156
158{
159 switch (osc) {
160 case RCC_HSI48:
161 return (RCC_CIR & RCC_CIR_HSI48RDYF) != 0;
162 break;
163 case RCC_HSI14:
164 return (RCC_CIR & RCC_CIR_HSI14RDYF) != 0;
165 break;
166 case RCC_HSI:
167 return (RCC_CIR & RCC_CIR_HSIRDYF) != 0;
168 break;
169 case RCC_HSE:
170 return (RCC_CIR & RCC_CIR_HSERDYF) != 0;
171 break;
172 case RCC_PLL:
173 return (RCC_CIR & RCC_CIR_PLLRDYF) != 0;
174 break;
175 case RCC_LSE:
176 return (RCC_CIR & RCC_CIR_LSERDYF) != 0;
177 break;
178 case RCC_LSI:
179 return (RCC_CIR & RCC_CIR_LSIRDYF) != 0;
180 break;
181 }
182
184}
185
186/*---------------------------------------------------------------------------*/
187/** @brief RCC Clear the Clock Security System Interrupt Flag
188*/
189
191{
193}
194
195/*---------------------------------------------------------------------------*/
196/** @brief RCC Read the Clock Security System Interrupt Flag
197 *
198 * @returns int. Boolean value for flag set.
199 */
200
202{
203 return ((RCC_CIR & RCC_CIR_CSSF) != 0);
204}
205
207{
208 switch (osc) {
209 case RCC_HSI48:
210 return RCC_CR2 & RCC_CR2_HSI48RDY;
211 case RCC_HSI14:
212 return RCC_CR2 & RCC_CR2_HSI14RDY;
213 case RCC_HSI:
214 return RCC_CR & RCC_CR_HSIRDY;
215 case RCC_HSE:
216 return RCC_CR & RCC_CR_HSERDY;
217 case RCC_PLL:
218 return RCC_CR & RCC_CR_PLLRDY;
219 case RCC_LSE:
220 return RCC_BDCR & RCC_BDCR_LSERDY;
221 case RCC_LSI:
222 return RCC_CSR & RCC_CSR_LSIRDY;
223 }
224 return false;
225}
226
228{
229 while (!rcc_is_osc_ready(osc));
230}
231
232/*---------------------------------------------------------------------------*/
233/** @brief RCC Turn on an Oscillator.
234 *
235 * Enable an oscillator and power on. Each oscillator requires an amount of
236 * time to settle to a usable state. Refer to datasheets for time delay
237 * information. A status flag is available to indicate when the oscillator
238 * becomes ready (see @ref rcc_osc_ready_int_flag and @ref
239 * rcc_wait_for_osc_ready).
240 *
241 * @param osc Oscillator ID
242 */
243
244void rcc_osc_on(enum rcc_osc osc)
245{
246 switch (osc) {
247 case RCC_HSI48:
249 break;
250 case RCC_HSI14:
252 break;
253 case RCC_HSI:
255 break;
256 case RCC_HSE:
258 break;
259 case RCC_LSE:
261 break;
262 case RCC_LSI:
264 break;
265 case RCC_PLL:
267 break;
268 }
269}
270
271/*---------------------------------------------------------------------------*/
272/** @brief RCC Turn off an Oscillator.
273 *
274 * Disable an oscillator and power off.
275 *
276 * @note An oscillator cannot be turned off if it is selected as the system
277 * clock.
278 *
279 * @param osc Oscillator ID
280 */
281
282void rcc_osc_off(enum rcc_osc osc)
283{
284 switch (osc) {
285 case RCC_HSI48:
286 RCC_CR2 &= ~RCC_CR2_HSI48ON;
287 break;
288 case RCC_HSI14:
289 RCC_CR2 &= ~RCC_CR2_HSI14ON;
290 break;
291 case RCC_HSI:
292 RCC_CR &= ~RCC_CR_HSION;
293 break;
294 case RCC_HSE:
295 RCC_CR &= ~RCC_CR_HSEON;
296 break;
297 case RCC_LSE:
298 RCC_BDCR &= ~RCC_BDCR_LSEON;
299 break;
300 case RCC_LSI:
301 RCC_CSR &= ~RCC_CSR_LSION;
302 break;
303 case RCC_PLL:
304 /* don't do anything */
305 break;
306 }
307}
308
309/*---------------------------------------------------------------------------*/
310/** @brief RCC Enable the Clock Security System.
311 */
312
314{
316}
317
318/*---------------------------------------------------------------------------*/
319/** @brief RCC Disable the Clock Security System.
320 */
321
323{
324 RCC_CR &= ~RCC_CR_CSSON;
325}
326
327/*---------------------------------------------------------------------------*/
328/** @brief RCC Set the Source for the System Clock.
329 *
330 * @param clk Oscillator ID. Only HSE, LSE and PLL have
331 * effect.
332 */
333
335{
336 switch (clk) {
337 case RCC_HSI:
338 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_SW) | RCC_CFGR_SW_HSI;
339 break;
340 case RCC_HSE:
341 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_SW) | RCC_CFGR_SW_HSE;
342 break;
343 case RCC_PLL:
344 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_SW) | RCC_CFGR_SW_PLL;
345 break;
346 case RCC_HSI48:
347 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_SW) | RCC_CFGR_SW_HSI48;
348 break;
349 case RCC_LSI:
350 case RCC_LSE:
351 case RCC_HSI14:
352 /* do nothing */
353 break;
354 }
355}
356
357/*---------------------------------------------------------------------------*/
358/** @brief RCC Set the Source for the USB Clock.
359 *
360 * @param clk Oscillator ID. Only HSI48 or PLL have
361 * effect.
362 */
364{
365 switch (clk) {
366 case RCC_PLL:
368 break;
369 case RCC_HSI48:
370 RCC_CFGR3 &= ~RCC_CFGR3_USBSW;
371 break;
372 case RCC_HSI:
373 case RCC_HSE:
374 case RCC_LSI:
375 case RCC_LSE:
376 case RCC_HSI14:
377 /* do nothing */
378 break;
379 }
380}
381
382/*---------------------------------------------------------------------------*/
383/** @brief RCC Enable the RTC clock
384
385*/
386
388{
390}
391
392/*---------------------------------------------------------------------------*/
393/** @brief RCC Disable the RTC clock
394
395*/
396
398{
399 RCC_BDCR &= ~RCC_BDCR_RTCEN;
400}
401
402/*---------------------------------------------------------------------------*/
403/** @brief RCC Set the Source for the RTC clock
404
405@param[in] clk RTC clock source. Only HSE/32, LSE and LSI.
406*/
407
409{
410 switch (clk) {
411 case RCC_HSE:
412 RCC_BDCR = (RCC_BDCR & ~RCC_BDCR_RTCSEL) | RCC_BDCR_RTCSEL_HSE;
413 break;
414 case RCC_LSE:
415 RCC_BDCR = (RCC_BDCR & ~RCC_BDCR_RTCSEL) | RCC_BDCR_RTCSEL_LSE;
416 break;
417 case RCC_LSI:
418 RCC_BDCR = (RCC_BDCR & ~RCC_BDCR_RTCSEL) | RCC_BDCR_RTCSEL_LSI;
419 break;
420 default:
421 /* do nothing */
422 break;
423 }
424}
425
426/*---------------------------------------------------------------------------*/
427/** @brief RCC Set the PLL Multiplication Factor.
428 *
429 * @note This only has effect when the PLL is disabled.
430 *
431 * @param[in] mul Unsigned int32. PLL multiplication factor @ref rcc_cfgr_pmf
432 */
433
435{
436 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PLLMUL) | mul;
437}
438
439/*---------------------------------------------------------------------------*/
440/** @brief RCC Set the PLL Clock Source.
441
442@note This only has effect when the PLL is disabled.
443
444@param[in] pllsrc Unsigned int32. PLL clock source @ref rcc_cfgr_pcs
445*/
446
447void rcc_set_pll_source(uint32_t pllsrc)
448{
449 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PLLSRC) |
450 (pllsrc << 16);
451}
452
453/*---------------------------------------------------------------------------*/
454/** @brief RCC Set the HSE Frequency Divider used as PLL Clock Source.
455
456@note This only has effect when the PLL is disabled.
457
458@param[in] pllxtpre Unsigned int32. HSE division factor @ref rcc_cfgr_hsepre
459*/
460
461void rcc_set_pllxtpre(uint32_t pllxtpre)
462{
463 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PLLXTPRE) |
464 (pllxtpre << 17);
465}
466
467/*---------------------------------------------------------------------------*/
468/** @brief RCC Set the APB Prescale Factor.
469 *
470 * @param[in] ppre Unsigned int32. APB prescale factor @ref rcc_cfgr_apb1pre
471 */
472
473void rcc_set_ppre(uint32_t ppre)
474{
475 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_PPRE) | ppre;
476}
477
478/*---------------------------------------------------------------------------*/
479/** @brief RCC Set the AHB Prescale Factor.
480 *
481 * @param[in] hpre Unsigned int32. AHB prescale factor @ref rcc_cfgr_ahbpre
482 */
483
484void rcc_set_hpre(uint32_t hpre)
485{
486 RCC_CFGR = (RCC_CFGR & ~RCC_CFGR_HPRE) | hpre;
487}
488
489/**
490 * Set PLL Source pre-divider **CAUTION**.
491 * On F03x and F05, prediv only applies to HSE source. On others, this
492 * is _after_ source selection. See also f3.
493 * @param[in] prediv division by prediv+1 @ref rcc_cfgr2_prediv
494 */
495void rcc_set_prediv(uint32_t prediv)
496{
497 RCC_CFGR2 = (RCC_CFGR2 & ~RCC_CFGR2_PREDIV) | prediv;
498}
499
500
501/*---------------------------------------------------------------------------*/
502/** @brief RCC Get the System Clock Source.
503 *
504 * @returns current system clock source
505 */
506
508{
509 /* Return the clock source which is used as system clock. */
510 switch (RCC_CFGR & RCC_CFGR_SWS) {
511 case RCC_CFGR_SWS_HSI:
512 return RCC_HSI;
513 case RCC_CFGR_SWS_HSE:
514 return RCC_HSE;
515 case RCC_CFGR_SWS_PLL:
516 return RCC_PLL;
518 return RCC_HSI48;
519 }
520
522}
523
524void rcc_set_i2c_clock_hsi(uint32_t i2c)
525{
526 if (i2c == I2C1) {
527 RCC_CFGR3 &= ~RCC_CFGR3_I2C1SW;
528 }
529}
530
531void rcc_set_i2c_clock_sysclk(uint32_t i2c)
532{
533 if (i2c == I2C1) {
535 }
536}
537
538uint32_t rcc_get_i2c_clocks(void)
539{
541}
542
543/*---------------------------------------------------------------------------*/
544/** @brief RCC Get the USB Clock Source.
545 *
546 * @returns Currently selected USB clock source
547 */
548
550{
552}
553
554/**
555 * Set System Clock PLL at 48MHz from HSE at 8MHz.
556 */
558{
562
565
568
569 /* PLL: 8MHz * 6 = 48MHz */
573
577
578 rcc_apb1_frequency = 48000000;
579 rcc_ahb_frequency = 48000000;
580}
581
582/**
583 * Set System Clock PLL at 48MHz from HSI
584 */
586{
590
593
596
597 /* 8MHz * 12 / 2 = 48MHz */
600
604
605 rcc_apb1_frequency = 48000000;
606 rcc_ahb_frequency = 48000000;
607}
608
609/**
610 * Set System Clock HSI48 at 48MHz
611 */
613{
616
619
622
624
625 rcc_apb1_frequency = 48000000;
626 rcc_ahb_frequency = 48000000;
627}
628
629static uint32_t rcc_get_usart_clksel_freq(uint8_t shift) {
630 uint8_t clksel = (RCC_CFGR3 >> shift) & RCC_CFGR3_USARTxSW_MASK;
631 uint8_t hpre = (RCC_CFGR >> RCC_CFGR_HPRE_SHIFT) & RCC_CFGR_HPRE_MASK;
632 switch (clksel) {
634 return rcc_apb1_frequency;
638 return 32768;
640 return 8000000U;
641 }
643}
644
645/*---------------------------------------------------------------------------*/
646/** @brief Get the peripheral clock speed for the USART at base specified.
647 * @param usart Base address of USART to get clock frequency for.
648 */
649uint32_t rcc_get_usart_clk_freq(uint32_t usart)
650{
651 if (usart == USART1_BASE) {
653 } else if (usart == USART2_BASE) {
655 } else if (usart == USART3_BASE) {
657 } else {
658 return rcc_apb1_frequency;
659 }
660}
661
662/*---------------------------------------------------------------------------*/
663/** @brief Get the peripheral clock speed for the Timer at base specified.
664 * @param timer Base address of TIM to get clock frequency for.
665 */
666uint32_t rcc_get_timer_clk_freq(uint32_t timer __attribute__((unused)))
667{
668 uint8_t ppre = (RCC_CFGR >> RCC_CFGR_PPRE_SHIFT) & RCC_CFGR_PPRE_MASK;
669 return (ppre == RCC_CFGR_PPRE_NODIV) ? rcc_apb1_frequency
670 : 2 * rcc_apb1_frequency;
671}
672
673/*---------------------------------------------------------------------------*/
674/** @brief Get the peripheral clock speed for the I2C device at base specified.
675 * @param i2c Base address of I2C to get clock frequency for.
676 */
677uint32_t rcc_get_i2c_clk_freq(uint32_t i2c)
678{
679 if (i2c == I2C1_BASE) {
681 uint8_t hpre = (RCC_CFGR >> RCC_CFGR_HPRE_SHIFT) & RCC_CFGR_HPRE_MASK;
683 } else {
684 return 8000000U;
685 }
686 } else {
687 return rcc_apb1_frequency;
688 }
689}
690
691/*---------------------------------------------------------------------------*/
692/** @brief Get the peripheral clock speed for the SPI device at base specified.
693 * @param spi Base address of SPI device to get clock frequency for (e.g. SPI1_BASE).
694 */
695uint32_t rcc_get_spi_clk_freq(uint32_t spi __attribute__((unused))) {
696 return rcc_apb1_frequency;
697}
698/**@}*/
699
#define cm3_assert_not_reached()
Check if unreachable code is reached.
Definition: assert.h:102
void flash_prefetch_enable(void)
This buffer is used for instruction fetches and may or may not be enabled by default,...
void flash_set_ws(uint32_t ws)
Set the Number of Wait States.
#define FLASH_ACR_LATENCY_024_048MHZ
Definition: f0/flash.h:66
#define I2C1
Definition: i2c_common_v2.h:44
#define RCC_CFGR3_USART1SW_SHIFT
Definition: f0/rcc.h:394
#define RCC_CFGR3_USART2SW_SHIFT
Definition: f0/rcc.h:393
#define RCC_CFGR3_USART3SW_SHIFT
Definition: f0/rcc.h:392
#define RCC_CFGR3_USARTxSW_PCLK
Definition: f0/rcc.h:400
#define RCC_CFGR3_USARTxSW_LSE
Definition: f0/rcc.h:402
#define RCC_CFGR3_USARTxSW_HSI
Definition: f0/rcc.h:403
#define RCC_CFGR3_USARTxSW_SYSCLK
Definition: f0/rcc.h:401
#define RCC_CFGR_HPRE_NODIV
Definition: f0/rcc.h:167
#define RCC_CFGR_PPRE_NODIV
Definition: f0/rcc.h:155
#define RCC_CFGR_PLLXTPRE_HSE_CLK
Definition: f0/rcc.h:135
#define RCC_CFGR_PLLSRC_HSE_CLK
Definition: f0/rcc.h:144
#define RCC_CFGR_PLLSRC_HSI_CLK_DIV2
Definition: f0/rcc.h:143
#define RCC_CFGR_PLLMUL_MUL6
Definition: f0/rcc.h:118
#define RCC_CFGR_PLLMUL_MUL12
Definition: f0/rcc.h:124
#define RCC_BDCR_LSEON
Definition: f0/rcc.h:332
#define RCC_BDCR_RTCSEL_LSE
Definition: f0/rcc.h:321
#define RCC_CFGR_PPRE_SHIFT
Definition: f0/rcc.h:150
#define RCC_CIR_HSI48RDYF
Definition: f0/rcc.h:210
#define RCC_CIR_PLLRDYF
Definition: f0/rcc.h:212
#define RCC_CIR
Definition: f0/rcc.h:50
#define RCC_CIR_HSERDYF
Definition: f0/rcc.h:213
#define RCC_CIR_LSERDYC
Definition: f0/rcc.h:200
#define RCC_CFGR_SWS
Definition: f0/rcc.h:179
#define RCC_CIR_HSI14RDYIE
Definition: f0/rcc.h:203
#define RCC_CIR_PLLRDYIE
Definition: f0/rcc.h:204
#define RCC_CIR_PLLRDYC
Definition: f0/rcc.h:197
#define RCC_CR2_HSI14RDY
Definition: f0/rcc.h:421
#define RCC_CFGR_SWS_PLL
Definition: f0/rcc.h:182
#define RCC_CFGR_SWS_HSI48
Definition: f0/rcc.h:183
#define RCC_CR
Definition: f0/rcc.h:48
#define RCC_CFGR_HPRE_MASK
Definition: f0/rcc.h:164
#define RCC_CIR_CSSC
Definition: f0/rcc.h:194
#define RCC_CFGR3_USBSW
Definition: f0/rcc.h:408
#define RCC_CIR_HSI14RDYF
Definition: f0/rcc.h:211
#define RCC_CIR_HSERDYIE
Definition: f0/rcc.h:205
#define RCC_CFGR2
Definition: f0/rcc.h:59
#define RCC_BDCR_RTCSEL_LSI
Definition: f0/rcc.h:322
#define RCC_CIR_HSI48RDYC
Definition: f0/rcc.h:195
#define RCC_CFGR_SWS_HSI
Definition: f0/rcc.h:180
rcc_osc
Definition: f0/rcc.h:436
#define RCC_CFGR3
Definition: f0/rcc.h:60
#define RCC_CIR_LSERDYIE
Definition: f0/rcc.h:207
#define RCC_CSR
Definition: f0/rcc.h:57
#define RCC_CFGR_PPRE_MASK
Definition: f0/rcc.h:152
#define RCC_BDCR_RTCEN
Definition: f0/rcc.h:317
#define RCC_CSR_LSION
Definition: f0/rcc.h:349
#define RCC_CR_HSERDY
Definition: f0/rcc.h:73
#define RCC_CIR_LSIRDYIE
Definition: f0/rcc.h:208
#define RCC_CFGR_SW_PLL
Definition: f0/rcc.h:189
#define RCC_CFGR
Definition: f0/rcc.h:49
#define RCC_CIR_HSERDYC
Definition: f0/rcc.h:198
#define RCC_CIR_LSIRDYC
Definition: f0/rcc.h:201
#define RCC_CR2
Definition: f0/rcc.h:61
#define RCC_CR_HSIRDY
Definition: f0/rcc.h:79
#define RCC_CFGR3_USARTxSW_MASK
Definition: f0/rcc.h:405
#define RCC_BDCR_LSERDY
Definition: f0/rcc.h:331
#define RCC_CFGR_SW_HSI48
Definition: f0/rcc.h:190
#define RCC_CSR_LSIRDY
Definition: f0/rcc.h:348
#define RCC_CIR_HSI14RDYC
Definition: f0/rcc.h:196
#define RCC_BDCR
Definition: f0/rcc.h:56
#define RCC_CFGR_HPRE_SHIFT
Definition: f0/rcc.h:162
#define RCC_CIR_LSERDYF
Definition: f0/rcc.h:215
#define RCC_CIR_HSIRDYIE
Definition: f0/rcc.h:206
#define RCC_BDCR_RTCSEL_HSE
Definition: f0/rcc.h:323
#define RCC_CIR_LSIRDYF
Definition: f0/rcc.h:216
#define RCC_CFGR_SW_HSI
Definition: f0/rcc.h:187
#define RCC_CR_CSSON
Definition: f0/rcc.h:71
#define RCC_CR2_HSI48ON
Definition: f0/rcc.h:415
#define RCC_CR2_HSI48RDY
Definition: f0/rcc.h:414
#define RCC_CR_PLLON
Definition: f0/rcc.h:70
#define RCC_CIR_HSIRDYC
Definition: f0/rcc.h:199
#define RCC_CIR_HSIRDYF
Definition: f0/rcc.h:214
#define RCC_CIR_CSSF
Definition: f0/rcc.h:209
#define RCC_CR_HSEON
Definition: f0/rcc.h:74
#define RCC_CFGR_SWS_HSE
Definition: f0/rcc.h:181
#define RCC_CFGR3_I2C1SW
Definition: f0/rcc.h:410
#define RCC_CR_HSION
Definition: f0/rcc.h:80
#define RCC_CR2_HSI14ON
Definition: f0/rcc.h:422
#define RCC_CR_PLLRDY
Definition: f0/rcc.h:69
#define RCC_CFGR_SW_HSE
Definition: f0/rcc.h:188
uint16_t rcc_get_div_from_hpre(uint8_t div_val)
This will return the divisor 1/2/4/8/16/64/128/256/512 which is set as a 4-bit value,...
#define RCC_CIR_HSI48RDYIE
Definition: f0/rcc.h:202
@ RCC_HSI
Definition: f0/rcc.h:437
@ RCC_HSI48
Definition: f0/rcc.h:437
@ RCC_LSI
Definition: f0/rcc.h:437
@ RCC_PLL
Definition: f0/rcc.h:437
@ RCC_LSE
Definition: f0/rcc.h:437
@ RCC_HSE
Definition: f0/rcc.h:437
@ RCC_HSI14
Definition: f0/rcc.h:437
int rcc_osc_ready_int_flag(enum rcc_osc osc)
RCC Read the Oscillator Ready Interrupt Flag.
Definition: rcc.c:157
void rcc_set_ppre(uint32_t ppre)
RCC Set the APB Prescale Factor.
Definition: rcc.c:473
void rcc_set_sysclk_source(enum rcc_osc clk)
RCC Set the Source for the System Clock.
Definition: rcc.c:334
int rcc_css_int_flag(void)
RCC Read the Clock Security System Interrupt Flag.
Definition: rcc.c:201
void rcc_set_i2c_clock_sysclk(uint32_t i2c)
Definition: rcc.c:531
void rcc_osc_ready_int_clear(enum rcc_osc osc)
RCC Clear the Oscillator Ready Interrupt Flag.
Definition: rcc.c:57
void rcc_wait_for_osc_ready(enum rcc_osc osc)
Wait for Oscillator Ready.
Definition: rcc.c:227
void rcc_css_disable(void)
RCC Disable the Clock Security System.
Definition: rcc.c:322
enum rcc_osc rcc_system_clock_source(void)
RCC Get the System Clock Source.
Definition: rcc.c:507
bool rcc_is_osc_ready(enum rcc_osc osc)
Is the given oscillator ready?
Definition: rcc.c:206
static uint32_t rcc_get_usart_clksel_freq(uint8_t shift)
Definition: rcc.c:629
uint32_t rcc_get_spi_clk_freq(uint32_t spi)
Get the peripheral clock speed for the SPI device at base specified.
Definition: rcc.c:695
void rcc_set_pll_source(uint32_t pllsrc)
RCC Set the PLL Clock Source.
Definition: rcc.c:447
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
Definition: rcc.c:666
enum rcc_osc rcc_usb_clock_source(void)
RCC Get the USB Clock Source.
Definition: rcc.c:549
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
Definition: rcc.c:649
void rcc_set_usbclk_source(enum rcc_osc clk)
RCC Set the Source for the USB Clock.
Definition: rcc.c:363
void rcc_set_prediv(uint32_t prediv)
Set PLL Source pre-divider CAUTION.
Definition: rcc.c:495
void rcc_osc_ready_int_enable(enum rcc_osc osc)
RCC Enable the Oscillator Ready Interrupt.
Definition: rcc.c:90
void rcc_set_rtc_clock_source(enum rcc_osc clk)
RCC Set the Source for the RTC clock.
Definition: rcc.c:408
void rcc_clock_setup_in_hse_8mhz_out_48mhz(void)
Set System Clock PLL at 48MHz from HSE at 8MHz.
Definition: rcc.c:557
void rcc_disable_rtc_clock(void)
RCC Disable the RTC clock.
Definition: rcc.c:397
void rcc_osc_ready_int_disable(enum rcc_osc osc)
RCC Disable the Oscillator Ready Interrupt.
Definition: rcc.c:123
void rcc_osc_on(enum rcc_osc osc)
RCC Turn on an Oscillator.
Definition: rcc.c:244
uint32_t rcc_ahb_frequency
Definition: rcc.c:45
void rcc_osc_off(enum rcc_osc osc)
RCC Turn off an Oscillator.
Definition: rcc.c:282
void rcc_clock_setup_in_hsi48_out_48mhz(void)
Set System Clock HSI48 at 48MHz.
Definition: rcc.c:612
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:677
void rcc_set_pll_multiplication_factor(uint32_t mul)
RCC Set the PLL Multiplication Factor.
Definition: rcc.c:434
uint32_t rcc_apb1_frequency
Definition: rcc.c:46
uint32_t rcc_get_i2c_clocks(void)
Definition: rcc.c:538
void rcc_css_int_clear(void)
RCC Clear the Clock Security System Interrupt Flag.
Definition: rcc.c:190
void rcc_enable_rtc_clock(void)
RCC Enable the RTC clock.
Definition: rcc.c:387
void rcc_set_i2c_clock_hsi(uint32_t i2c)
Definition: rcc.c:524
void rcc_clock_setup_in_hsi_out_48mhz(void)
Set System Clock PLL at 48MHz from HSI.
Definition: rcc.c:585
void rcc_css_enable(void)
RCC Enable the Clock Security System.
Definition: rcc.c:313
void rcc_set_hpre(uint32_t hpre)
RCC Set the AHB Prescale Factor.
Definition: rcc.c:484
void rcc_set_pllxtpre(uint32_t pllxtpre)
RCC Set the HSE Frequency Divider used as PLL Clock Source.
Definition: rcc.c:461
#define USART1_BASE
#define USART3_BASE
#define I2C1_BASE
#define USART2_BASE