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 STM32G0xx Reset and Clock Control</b>
6 *
7 * @author @htmlonly &copy; @endhtmlonly 2019 Guillaume Revaillot <g.revaillot@gmail.com>
8 *
9 * @date 10 January 2019
10 *
11 * This library supports the Reset and Clock Control System in the STM32 series
12 * of ARM Cortex Microcontrollers by ST Microelectronics.
13 *
14 * LGPL License Terms @ref lgpl_license
15 */
16
17/*
18 * This file is part of the libopencm3 project.
19 *
20 * This library is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with this library. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34/**@{*/
35
40
41/* Set the default clock frequencies after reset. */
42uint32_t rcc_ahb_frequency = 16000000;
43uint32_t rcc_apb1_frequency = 16000000;
44
47 /* 32khz from lsi, scale2, 0ws */
49 .hpre = RCC_CFGR_HPRE_NODIV,
50 .ppre = RCC_CFGR_PPRE_NODIV,
51 .flash_waitstates = FLASH_ACR_LATENCY_0WS,
52 .voltage_scale = PWR_SCALE2,
53 .ahb_frequency = 32000,
54 .apb_frequency = 32000,
55 },
57 /* 4mhz from hsi/4, scale2, 0ws */
58 .sysclock_source = RCC_HSI,
59 .hsisys_div = RCC_CR_HSIDIV_DIV4,
60 .hpre = RCC_CFGR_HPRE_NODIV,
61 .ppre = RCC_CFGR_PPRE_NODIV,
62 .flash_waitstates = FLASH_ACR_LATENCY_0WS,
63 .voltage_scale = PWR_SCALE2,
64 .ahb_frequency = 4000000,
65 .apb_frequency = 4000000,
66 },
68 /* 16mhz from hsi, scale2, 0ws */
69 .sysclock_source = RCC_HSI,
70 .hsisys_div = RCC_CR_HSIDIV_DIV1,
71 .hpre = RCC_CFGR_HPRE_NODIV,
72 .ppre = RCC_CFGR_PPRE_NODIV,
73 .flash_waitstates = FLASH_ACR_LATENCY_0WS,
74 .voltage_scale = PWR_SCALE2,
75 .ahb_frequency = 16000000,
76 .apb_frequency = 16000000,
77 },
79 /* 32mhz from hsi via pll @ 128mhz / 4, scale1, 1ws */
80 .sysclock_source = RCC_PLL,
81 .pll_source = RCC_PLLCFGR_PLLSRC_HSI16,
82 .pll_div = RCC_PLLCFGR_PLLM_DIV(1),
83 .pll_mul = RCC_PLLCFGR_PLLN_MUL(8),
84 .pllp_div = RCC_PLLCFGR_PLLP_DIV(4),
85 .pllq_div = RCC_PLLCFGR_PLLQ_DIV(4),
86 .pllr_div = RCC_PLLCFGR_PLLR_DIV(4),
87 .hpre = RCC_CFGR_HPRE_NODIV,
88 .ppre = RCC_CFGR_PPRE_NODIV,
89 .flash_waitstates = FLASH_ACR_LATENCY_1WS,
90 .voltage_scale = PWR_SCALE1,
91 .ahb_frequency = 32000000,
92 .apb_frequency = 32000000,
93 },
95 /* 64mhz from hsi via pll @ 128mhz / 2, scale1, 2ws */
96 .sysclock_source = RCC_PLL,
97 .pll_source = RCC_PLLCFGR_PLLSRC_HSI16,
98 .pll_div = RCC_PLLCFGR_PLLM_DIV(1),
99 .pll_mul = RCC_PLLCFGR_PLLN_MUL(8),
100 .pllp_div = RCC_PLLCFGR_PLLP_DIV(2),
101 .pllq_div = RCC_PLLCFGR_PLLQ_DIV(2),
102 .pllr_div = RCC_PLLCFGR_PLLR_DIV(2),
103 .hpre = RCC_CFGR_HPRE_NODIV,
104 .ppre = RCC_CFGR_PPRE_NODIV,
105 .flash_waitstates = FLASH_ACR_LATENCY_2WS,
106 .voltage_scale = PWR_SCALE1,
107 .ahb_frequency = 64000000,
108 .apb_frequency = 64000000,
109 },
111 /* 64mhz from hse@12mhz via pll @ 128mhz / 2, scale1, 2ws */
112 .sysclock_source = RCC_PLL,
113 .pll_source = RCC_PLLCFGR_PLLSRC_HSE,
114 .pll_div = RCC_PLLCFGR_PLLM_DIV(3),
115 .pll_mul = RCC_PLLCFGR_PLLN_MUL(32),
116 .pllp_div = RCC_PLLCFGR_PLLP_DIV(2),
117 .pllq_div = RCC_PLLCFGR_PLLQ_DIV(2),
118 .pllr_div = RCC_PLLCFGR_PLLR_DIV(2),
119 .hpre = RCC_CFGR_HPRE_NODIV,
120 .ppre = RCC_CFGR_PPRE_NODIV,
121 .flash_waitstates = FLASH_ACR_LATENCY_2WS,
122 .voltage_scale = PWR_SCALE1,
123 .ahb_frequency = 64000000,
124 .apb_frequency = 64000000,
125 },
126};
127
128void rcc_osc_on(enum rcc_osc osc)
129{
130 switch (osc) {
131 case RCC_PLL:
133 break;
134 case RCC_HSE:
136 break;
137 case RCC_HSI:
139 break;
140 case RCC_LSE:
142 break;
143 case RCC_LSI:
145 break;
146 default:
148 break;
149 }
150}
151
152void rcc_osc_off(enum rcc_osc osc)
153{
154 switch (osc) {
155 case RCC_PLL:
156 RCC_CR &= ~RCC_CR_PLLON;
157 break;
158 case RCC_HSE:
159 RCC_CR &= ~RCC_CR_HSEON;
160 break;
161 case RCC_HSI:
162 RCC_CR &= ~RCC_CR_HSION;
163 break;
164 case RCC_LSE:
165 RCC_BDCR &= ~RCC_BDCR_LSEON;
166 break;
167 case RCC_LSI:
168 RCC_CSR &= ~RCC_CSR_LSION;
169 break;
170 default:
172 break;
173 }
174}
175
177{
178 switch (osc) {
179 case RCC_PLL:
180 return RCC_CR & RCC_CR_PLLRDY;
181 case RCC_HSE:
182 return RCC_CR & RCC_CR_HSERDY;
183 case RCC_HSI:
184 return RCC_CR & RCC_CR_HSIRDY;
185 case RCC_LSE:
186 return RCC_BDCR & RCC_BDCR_LSERDY;
187 case RCC_LSI:
188 return RCC_CSR & RCC_CSR_LSIRDY;
189 default:
191 return 0;
192 }
193 return false;
194}
195
197{
198 while (!rcc_is_osc_ready(osc));
199}
200
202{
204}
205
207{
208 RCC_CR &= ~RCC_CR_CSSON;
209}
210
212{
214}
215
217{
218 return ((RCC_CIFR & RCC_CIFR_CSSF) != 0);
219}
220
221/*---------------------------------------------------------------------------*/
222/** @brief Set the Source for the System Clock.
223 * @param osc Oscillator to use.
224 */
226{
227 uint32_t reg32;
228 uint32_t sw = 0;
229
230 switch (osc) {
231 case RCC_HSI:
233 break;
234 case RCC_HSE:
235 sw = RCC_CFGR_SW_HSE;
236 break;
237 case RCC_PLL:
239 break;
240 case RCC_LSE:
241 sw = RCC_CFGR_SW_LSE;
242 break;
243 case RCC_LSI:
244 sw = RCC_CFGR_SW_LSI;
245 break;
246 default:
248 return;
249 }
250
251 reg32 = RCC_CFGR;
252 reg32 &= ~(RCC_CFGR_SW_MASK << RCC_CFGR_SW_SHIFT);
253 RCC_CFGR = (reg32 | (sw << RCC_CFGR_SW_SHIFT));
254}
255
256/*---------------------------------------------------------------------------*/
257/** @brief Return the clock source which is used as system clock.
258 * @return rcc_osc system clock source
259 */
261{
264 return RCC_HSI;
265 case RCC_CFGR_SW_HSE:
266 return RCC_HSE;
268 return RCC_PLL;
269 case RCC_CFGR_SW_LSE:
270 return RCC_LSE;
271 case RCC_CFGR_SW_LSI:
272 return RCC_LSI;
273 default:
275 return 0;
276 }
277}
278
279/*---------------------------------------------------------------------------*/
280/** @brief Wait until system clock switched to given oscillator.
281 * @param osc Oscillator.
282 */
284{
285 uint32_t sws = 0;
286
287 switch (osc) {
288 case RCC_PLL:
290 break;
291 case RCC_HSE:
292 sws = RCC_CFGR_SWS_HSE;
293 break;
294 case RCC_HSI:
296 break;
297 case RCC_LSI:
298 sws = RCC_CFGR_SWS_LSI;
299 break;
300 case RCC_LSE:
301 sws = RCC_CFGR_SWS_LSE;
302 break;
303 default:
305 break;
306 }
307
308 while (((RCC_CFGR >> RCC_CFGR_SWS_SHIFT) & RCC_CFGR_SWS_MASK) != sws);
309}
310
311/**
312 * @brief Configure pll source.
313 * @param[in] pllsrc pll clock source @ref rcc_pllcfgr_pllsrc
314 */
315void rcc_set_pll_source(uint32_t pllsrc)
316{
317 uint32_t reg32;
318
319 reg32 = RCC_PLLCFGR;
321 RCC_PLLCFGR = (reg32 | (pllsrc << RCC_PLLCFGR_PLLSRC_SHIFT));
322}
323
324/**
325 * @brief Configure pll source and output frequencies.
326 * @param[in] source pll clock source @ref rcc_pllcfgr_pllsrc
327 * @param[in] pllm pll vco division factor @ref rcc_pllcfgr_pllm
328 * @param[in] plln pll vco multiplation factor @ref rcc_pllcfgr_plln
329 * @param[in] pllp pll P clock output division factor @ref rcc_pllcfgr_pllp
330 * @param[in] pllq pll Q clock output division factor @ref rcc_pllcfgr_pllq
331 * @param[in] pllr pll R clock output (sysclock pll) division factor @ref rcc_pllcfgr_pllr
332 */
333void rcc_set_main_pll(uint32_t source, uint32_t pllm, uint32_t plln, uint32_t pllp,
334 uint32_t pllq, uint32_t pllr)
335{
337 (pllm << RCC_PLLCFGR_PLLM_SHIFT) |
338 (plln << RCC_PLLCFGR_PLLN_SHIFT) |
339 (pllp << RCC_PLLCFGR_PLLP_SHIFT) |
340 (pllq << RCC_PLLCFGR_PLLQ_SHIFT) |
341 (pllr << RCC_PLLCFGR_PLLR_SHIFT);
342}
343
344/**
345 * @brief Enable PLL P clock output.
346 * @param[in] enable or disable P clock output
347 */
348void rcc_enable_pllp(bool enable)
349{
350 if (enable) {
352 } else {
353 RCC_PLLCFGR &= ~RCC_PLLCFGR_PLLPEN;
354 }
355}
356
357/**
358 * @brief Enable PLL Q clock output.
359 * @param[in] enable or disable Q clock output
360 */
361void rcc_enable_pllq(bool enable)
362{
363 if (enable) {
365 } else {
366 RCC_PLLCFGR &= ~RCC_PLLCFGR_PLLQEN;
367 }
368}
369
370/**
371 * @brief Enable PLL R clock output.
372 * @param[in] enable or disable R clock output
373 */
374void rcc_enable_pllr(bool enable)
375{
376 if (enable) {
378 } else {
379 RCC_PLLCFGR &= ~RCC_PLLCFGR_PLLREN;
380 }
381}
382
383/**
384 * @brief Configure APB peripheral clock prescaler
385 * @param[in] ppre APB clock prescaler value @ref rcc_cfgr_ppre
386 */
387void rcc_set_ppre(uint32_t ppre)
388{
389 uint32_t reg32;
390
391 reg32 = RCC_CFGR;
393 RCC_CFGR = (reg32 | (ppre << RCC_CFGR_PPRE_SHIFT));
394}
395
396/**
397 * @brief Configure AHB peripheral clock prescaler
398 * @param[in] hpre AHB clock prescaler value @ref rcc_cfgr_hpre
399 */
400void rcc_set_hpre(uint32_t hpre)
401{
402 uint32_t reg32;
403
404 reg32 = RCC_CFGR;
406 RCC_CFGR = (reg32 | (hpre << RCC_CFGR_HPRE_SHIFT));
407}
408
409/**
410 * @brief Configure HSI16 clock division factor to feed SYSCLK
411 * @param[in] hsidiv HSYSSIS clock division factor @ref rcc_cr_hsidiv
412 */
413void rcc_set_hsisys_div(uint32_t hsidiv)
414{
415 uint32_t reg32;
416
417 reg32 = RCC_CR;
419 RCC_CR = (reg32 | (hsidiv << RCC_CR_HSIDIV_SHIFT));
420}
421
422/**
423 * @brief Configure mco prescaler.
424 * @param[in] mcopre prescaler value @ref rcc_cfgr_mcopre
425 */
426void rcc_set_mcopre(uint32_t mcopre)
427{
428 uint32_t reg32;
429
430 reg32 = RCC_CFGR;
432 RCC_CFGR = (reg32 | (mcopre << RCC_CFGR_MCOPRE_SHIFT));
433}
434
435/**
436 * @brief Setup sysclock with desired source (HSE/HSI/PLL/LSE/LSI). taking care of flash/pwr and src configuration
437 * @param clock rcc_clock_scale with desired parameters
438 */
439void rcc_clock_setup(const struct rcc_clock_scale *clock)
440{
441 if (clock->sysclock_source == RCC_PLL) {
442 enum rcc_osc pll_source;
443
446 else
448
449 /* start pll src osc. */
452
453 /* stop pll to reconfigure it. */
455 while (rcc_is_osc_ready(RCC_PLL));
456
457 rcc_set_main_pll(clock->pll_source, clock->pll_div, clock->pll_mul, clock->pllp_div, clock->pllq_div, clock->pllr_div);
458
459 rcc_enable_pllr(true);
460 } else if (clock->sysclock_source == RCC_HSI) {
462 }
463
466
468
469 /* enable flash prefetch if we have at least 1WS */
472 else
474
475 rcc_set_hpre(clock->hpre);
476 rcc_set_ppre(clock->ppre);
477
480
483
486}
487
488/**
489 * @brief Setup RNG Peripheral Clock Divider
490 * @param rng_div clock divider @ref rcc_ccipr_rngdiv
491 */
492void rcc_set_rng_clk_div(uint32_t rng_div)
493{
495 RCC_CCIPR = reg32 | (rng_div << RCC_CCIPR_RNGDIV_SHIFT);
496}
497
498/**
499 * @brief Set the peripheral clock source
500 * @param periph peripheral of choice, eg XXX_BASE
501 * @param sel periphral clock source
502 */
503void rcc_set_peripheral_clk_sel(uint32_t periph, uint32_t sel)
504{
505 uint8_t shift;
506 uint32_t mask;
507
508 switch (periph) {
509 case ADC1_BASE:
512 break;
513 case RNG_BASE:
516 break;
517 case TIM1_BASE:
520 break;
521 case LPTIM1_BASE:
524 break;
525 case LPTIM2_BASE:
528 break;
529 case CEC_BASE:
532 break;
533 case USART2_BASE:
536 break;
537 case USART1_BASE:
540 break;
541 default:
543 return;
544 }
545
546 uint32_t reg32 = RCC_CCIPR & ~(mask << shift);
547 RCC_CCIPR = reg32 | (sel << shift);
548}
549
550static uint32_t rcc_get_clksel_freq(uint8_t shift) {
551 uint8_t clksel = (RCC_CCIPR >> shift) & RCC_CCIPR_USARTxSEL_MASK;
553 switch (clksel) {
555 return rcc_apb1_frequency;
559 return 32768;
561 return 16000000U;
562 }
564}
565
566/*---------------------------------------------------------------------------*/
567/** @brief Get the peripheral clock speed for the USART at base specified.
568 * @param usart Base address of USART to get clock frequency for.
569 */
570uint32_t rcc_get_usart_clk_freq(uint32_t usart)
571{
572 if (usart == USART1_BASE) {
574 } else if (usart == USART2_BASE) {
576 } else if (usart == USART3_BASE) {
578 } else if (usart == LPUART1_BASE) {
580 } else if (usart == LPUART2_BASE) {
582 }
584}
585
586/*---------------------------------------------------------------------------*/
587/** @brief Get the peripheral clock speed for the Timer at base specified.
588 * @param timer Base address of TIM to get clock frequency for.
589 */
590uint32_t rcc_get_timer_clk_freq(uint32_t timer __attribute__((unused)))
591{
594 : 2 * rcc_apb1_frequency;
595}
596
597/*---------------------------------------------------------------------------*/
598/** @brief Get the peripheral clock speed for the I2C device at base specified.
599 * @param i2c Base address of I2C to get clock frequency for.
600 */
601uint32_t rcc_get_i2c_clk_freq(uint32_t i2c)
602{
603 if (i2c == I2C1_BASE) {
605 } else if (i2c == I2C2_BASE) {
607 }
609}
610
611/*---------------------------------------------------------------------------*/
612/** @brief Get the peripheral clock speed for the SPI device at base specified.
613 * @param spi Base address of SPI device to get clock frequency for (e.g. SPI1_BASE).
614 */
615uint32_t rcc_get_spi_clk_freq(uint32_t spi __attribute__((unused))) {
616 return rcc_apb1_frequency;
617}
618
619/**@}*/
#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_prefetch_disable(void)
Note carefully the clock restrictions under which the prefetch buffer may be set to disabled.
void flash_set_ws(uint32_t ws)
Set the Number of Wait States.
#define FLASH_ACR_LATENCY_0WS
Definition: g0/flash.h:72
#define FLASH_ACR_LATENCY_2WS
Definition: g0/flash.h:74
#define FLASH_ACR_LATENCY_1WS
Definition: g0/flash.h:73
void pwr_set_vos_scale(enum pwr_vos_scale scale)
Setup voltage scaling range.
Definition: pwr.c:37
@ PWR_SCALE1
Definition: g0/pwr.h:182
@ PWR_SCALE2
Definition: g0/pwr.h:183
#define RCC_BDCR_LSEON
Definition: g0/rcc.h:612
#define RCC_BDCR_LSERDY
Definition: g0/rcc.h:611
#define RCC_CCIPR_USARTxSEL_LSE
Definition: g0/rcc.h:578
#define RCC_CCIPR_USARTxSEL_PCLK
Definition: g0/rcc.h:575
#define RCC_CCIPR_USARTxSEL_SYSCLK
Definition: g0/rcc.h:576
#define RCC_CCIPR_USARTxSEL_HSI16
Definition: g0/rcc.h:577
#define RCC_CCIPR_USART3SEL_SHIFT
Definition: g0/rcc.h:570
#define RCC_CCIPR_USART1SEL_SHIFT
Definition: g0/rcc.h:572
#define RCC_CCIPR_TIM1SEL_SHIFT
Definition: g0/rcc.h:503
#define RCC_CCIPR_LPUART1SEL_SHIFT
Definition: g0/rcc.h:551
#define RCC_CCIPR_RNGDIV_MASK
Definition: g0/rcc.h:474
#define RCC_CCIPR_RNGSEL_MASK
Definition: g0/rcc.h:484
#define RCC_CCIPR_I2C2SEL_SHIFT
Definition: g0/rcc.h:542
#define RCC_CCIPR_USART2SEL_SHIFT
Definition: g0/rcc.h:571
#define RCC_CCIPR_CECSEL_SHIFT
Definition: g0/rcc.h:562
#define RCC_CCIPR_LPTIM1SEL_MASK
Definition: g0/rcc.h:520
#define RCC_CCIPR_I2C1SEL_SHIFT
Definition: g0/rcc.h:541
#define RCC_CCIPR_USARTxSEL_MASK
Definition: g0/rcc.h:569
#define RCC_CCIPR_LPTIM1SEL_SHIFT
Definition: g0/rcc.h:521
#define RCC_CCIPR_TIM1SEL_MASK
Definition: g0/rcc.h:502
#define RCC_CCIPR_ADCSEL_SHIFT
Definition: g0/rcc.h:466
#define RCC_CCIPR_LPUART2SEL_SHIFT
Definition: g0/rcc.h:552
#define RCC_CCIPR_LPTIM2SEL_MASK
Definition: g0/rcc.h:510
#define RCC_CCIPR_RNGDIV_SHIFT
Definition: g0/rcc.h:475
#define RCC_CCIPR_LPTIM2SEL_SHIFT
Definition: g0/rcc.h:511
#define RCC_CCIPR_ADCSEL_MASK
Definition: g0/rcc.h:465
#define RCC_CCIPR_CECSEL_MASK
Definition: g0/rcc.h:561
#define RCC_CCIPR_RNGSEL_SHIFT
Definition: g0/rcc.h:485
#define RCC_CFGR_HPRE_NODIV
Definition: g0/rcc.h:168
#define RCC_CFGR_PPRE_NODIV
Definition: g0/rcc.h:155
#define RCC_CFGR_SW_PLLRCLK
Definition: g0/rcc.h:200
#define RCC_CFGR_SW_HSISYS
Definition: g0/rcc.h:198
#define RCC_CFGR_SW_LSI
Definition: g0/rcc.h:201
#define RCC_CFGR_SW_LSE
Definition: g0/rcc.h:202
#define RCC_CFGR_SW_HSE
Definition: g0/rcc.h:199
#define RCC_CFGR_SWS_LSE
Definition: g0/rcc.h:189
#define RCC_CFGR_SWS_HSISYS
Definition: g0/rcc.h:185
#define RCC_CFGR_SWS_HSE
Definition: g0/rcc.h:186
#define RCC_CFGR_SWS_LSI
Definition: g0/rcc.h:188
#define RCC_CFGR_SWS_PLLRCLK
Definition: g0/rcc.h:187
#define RCC_CFGR_PPRE_SHIFT
Definition: g0/rcc.h:149
#define RCC_CFGR_HPRE_MASK
Definition: g0/rcc.h:162
#define RCC_CFGR_SWS_MASK
Definition: g0/rcc.h:179
#define RCC_CFGR_MCOPRE_SHIFT
Definition: g0/rcc.h:116
#define RCC_CFGR_MCOPRE_MASK
Definition: g0/rcc.h:117
#define RCC_CFGR_PPRE_MASK
Definition: g0/rcc.h:148
#define RCC_CFGR_SW_MASK
Definition: g0/rcc.h:192
#define RCC_CFGR_SWS_SHIFT
Definition: g0/rcc.h:180
#define RCC_CFGR_HPRE_SHIFT
Definition: g0/rcc.h:163
#define RCC_CFGR_SW_SHIFT
Definition: g0/rcc.h:193
#define RCC_CICR_CSSC
Definition: g0/rcc.h:294
#define RCC_CIFR_CSSF
Definition: g0/rcc.h:283
#define RCC_CR_HSIDIV_DIV4
Definition: g0/rcc.h:91
#define RCC_CR_HSIDIV_DIV1
Definition: g0/rcc.h:89
#define RCC_CR_HSIDIV_SHIFT
Definition: g0/rcc.h:83
#define RCC_CR_HSERDY
Definition: g0/rcc.h:80
#define RCC_CR_HSIRDY
Definition: g0/rcc.h:99
#define RCC_CR_HSIDIV_MASK
Definition: g0/rcc.h:84
#define RCC_CR_CSSON
Definition: g0/rcc.h:78
#define RCC_CR_PLLON
Definition: g0/rcc.h:77
#define RCC_CR_HSEON
Definition: g0/rcc.h:81
#define RCC_CR_HSION
Definition: g0/rcc.h:101
#define RCC_CR_PLLRDY
Definition: g0/rcc.h:76
#define RCC_CSR_LSION
Definition: g0/rcc.h:626
#define RCC_CSR_LSIRDY
Definition: g0/rcc.h:625
rcc_osc
Definition: g0/rcc.h:643
void rcc_periph_clock_enable(enum rcc_periph_clken clken)
Enable Peripheral Clock in running mode.
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,...
@ RCC_CLOCK_CONFIG_HSE_12MHZ_PLL_64MHZ
Definition: g0/rcc.h:849
@ RCC_CLOCK_CONFIG_HSI_PLL_32MHZ
Definition: g0/rcc.h:847
@ RCC_CLOCK_CONFIG_HSI_4MHZ
Definition: g0/rcc.h:845
@ RCC_CLOCK_CONFIG_LSI_32KHZ
Definition: g0/rcc.h:844
@ RCC_CLOCK_CONFIG_HSI_PLL_64MHZ
Definition: g0/rcc.h:848
@ RCC_CLOCK_CONFIG_HSI_16MHZ
Definition: g0/rcc.h:846
@ RCC_CLOCK_CONFIG_END
Definition: g0/rcc.h:850
@ RCC_PWR
Definition: g0/rcc.h:670
@ RCC_HSI
Definition: g0/rcc.h:644
@ RCC_LSI
Definition: g0/rcc.h:648
@ RCC_PLL
Definition: g0/rcc.h:646
@ RCC_LSE
Definition: g0/rcc.h:647
@ RCC_HSE
Definition: g0/rcc.h:645
void rcc_set_ppre(uint32_t ppre)
Configure APB peripheral clock prescaler.
Definition: rcc.c:387
void rcc_enable_pllr(bool enable)
Enable PLL R clock output.
Definition: rcc.c:374
int rcc_css_int_flag(void)
Definition: rcc.c:216
void rcc_enable_pllp(bool enable)
Enable PLL P clock output.
Definition: rcc.c:348
void rcc_wait_for_osc_ready(enum rcc_osc osc)
Wait for Oscillator Ready.
Definition: rcc.c:196
void rcc_set_main_pll(uint32_t source, uint32_t pllm, uint32_t plln, uint32_t pllp, uint32_t pllq, uint32_t pllr)
Configure pll source and output frequencies.
Definition: rcc.c:333
void rcc_css_disable(void)
Definition: rcc.c:206
enum rcc_osc rcc_system_clock_source(void)
Return the clock source which is used as system clock.
Definition: rcc.c:260
bool rcc_is_osc_ready(enum rcc_osc osc)
Is the given oscillator ready?
Definition: rcc.c:176
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:615
void rcc_set_pll_source(uint32_t pllsrc)
Configure pll source.
Definition: rcc.c:315
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
Definition: rcc.c:590
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
Definition: rcc.c:570
void rcc_set_hsisys_div(uint32_t hsidiv)
Configure HSI16 clock division factor to feed SYSCLK.
Definition: rcc.c:413
void rcc_enable_pllq(bool enable)
Enable PLL Q clock output.
Definition: rcc.c:361
void rcc_set_peripheral_clk_sel(uint32_t periph, uint32_t sel)
Set the peripheral clock source.
Definition: rcc.c:503
void rcc_osc_on(enum rcc_osc osc)
Definition: rcc.c:128
uint32_t rcc_ahb_frequency
Definition: rcc.c:42
void rcc_osc_off(enum rcc_osc osc)
Definition: rcc.c:152
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:601
void rcc_clock_setup(const struct rcc_clock_scale *clock)
Setup sysclock with desired source (HSE/HSI/PLL/LSE/LSI).
Definition: rcc.c:439
const struct rcc_clock_scale rcc_clock_config[RCC_CLOCK_CONFIG_END]
Definition: rcc.c:45
uint32_t rcc_apb1_frequency
Definition: rcc.c:43
void rcc_wait_for_sysclk_status(enum rcc_osc osc)
Wait until system clock switched to given oscillator.
Definition: rcc.c:283
void rcc_css_int_clear(void)
Definition: rcc.c:211
void rcc_set_rng_clk_div(uint32_t rng_div)
Setup RNG Peripheral Clock Divider.
Definition: rcc.c:492
static uint32_t rcc_get_clksel_freq(uint8_t shift)
Definition: rcc.c:550
void rcc_css_enable(void)
Definition: rcc.c:201
void rcc_set_hpre(uint32_t hpre)
Configure AHB peripheral clock prescaler.
Definition: rcc.c:400
void rcc_set_mcopre(uint32_t mcopre)
Configure mco prescaler.
Definition: rcc.c:426
void rcc_set_sysclk_source(enum rcc_osc osc)
Set the Source for the System Clock.
Definition: rcc.c:225
#define RCC_PLLCFGR_PLLM_DIV(x)
Definition: g0/rcc.h:256
#define RCC_PLLCFGR_PLLN_MUL(x)
Definition: g0/rcc.h:248
#define RCC_PLLCFGR_PLLP_DIV(x)
Definition: g0/rcc.h:238
#define RCC_PLLCFGR_PLLQ_DIV(x)
Definition: g0/rcc.h:227
#define RCC_PLLCFGR_PLLR_DIV(x)
Definition: g0/rcc.h:216
#define RCC_PLLCFGR_PLLSRC_HSI16
Definition: g0/rcc.h:266
#define RCC_PLLCFGR_PLLSRC_HSE
Definition: g0/rcc.h:267
#define RCC_PLLCFGR_PLLN_SHIFT
Definition: g0/rcc.h:243
#define RCC_PLLCFGR_PLLPEN
Definition: g0/rcc.h:241
#define RCC_PLLCFGR_PLLSRC_SHIFT
Definition: g0/rcc.h:259
#define RCC_PLLCFGR_PLLSRC_MASK
Definition: g0/rcc.h:260
#define RCC_PLLCFGR_PLLQEN
Definition: g0/rcc.h:230
#define RCC_PLLCFGR_PLLR_SHIFT
Definition: g0/rcc.h:210
#define RCC_PLLCFGR_PLLQ_SHIFT
Definition: g0/rcc.h:221
#define RCC_PLLCFGR_PLLM_SHIFT
Definition: g0/rcc.h:251
#define RCC_PLLCFGR_PLLREN
Definition: g0/rcc.h:219
#define RCC_PLLCFGR_PLLP_SHIFT
Definition: g0/rcc.h:232
#define RCC_CICR
Definition: g0/rcc.h:44
#define RCC_CR
Definition: g0/rcc.h:38
#define RCC_CIFR
Definition: g0/rcc.h:43
#define RCC_CCIPR
Definition: g0/rcc.h:69
#define RCC_CSR
Definition: g0/rcc.h:71
#define RCC_PLLCFGR
Definition: g0/rcc.h:41
#define RCC_CFGR
Definition: g0/rcc.h:40
#define RCC_BDCR
Definition: g0/rcc.h:70
#define LPTIM1_BASE
#define I2C2_BASE
#define LPUART1_BASE
#define ADC1_BASE
#define LPTIM2_BASE
#define USART1_BASE
#define CEC_BASE
#define RNG_BASE
#define USART3_BASE
#define LPUART2_BASE
#define I2C1_BASE
#define USART2_BASE
#define TIM1_BASE
uint8_t ppre
Definition: g0/rcc.h:836
uint8_t pll_div
Definition: g0/rcc.h:826
uint8_t flash_waitstates
Definition: g0/rcc.h:837
uint8_t pllr_div
Definition: g0/rcc.h:830
uint8_t pllq_div
Definition: g0/rcc.h:829
uint8_t pll_mul
Definition: g0/rcc.h:827
uint32_t ahb_frequency
Definition: g0/rcc.h:839
uint8_t pllp_div
Definition: g0/rcc.h:828
enum pwr_vos_scale voltage_scale
Definition: g0/rcc.h:838
enum rcc_osc sysclock_source
Definition: g0/rcc.h:822
uint8_t hpre
Definition: g0/rcc.h:835
uint32_t apb_frequency
Definition: g0/rcc.h:840
uint8_t pll_source
Definition: g0/rcc.h:825
uint8_t hsisys_div
Definition: g0/rcc.h:833