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 * @section rcc_l4_api_ex Reset and Clock Control API.
6 *
7 * @brief <b>libopencm3 STM32L4xx Reset and Clock Control</b>
8 *
9 * @author @htmlonly &copy; @endhtmlonly 2016 Karl Palsson <karlp@tweak.net.au>
10 *
11 * @date 12 Feb 2016
12 *
13 * This library supports the Reset and Clock Control System in the STM32 series
14 * of ARM Cortex Microcontrollers by ST Microelectronics.
15 *
16 * LGPL License Terms @ref lgpl_license
17 */
18
19/*
20 * This file is part of the libopencm3 project.
21 *
22 * Copyright (C) 2016 Karl Palsson <karlp@tweak.net.au>
23 *
24 * This library is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU Lesser General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
28 *
29 * This library is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * along with this library. If not, see <http://www.gnu.org/licenses/>.
36 */
37
38/**@{*/
43
44/* Set the default clock frequencies after reset. */
45uint32_t rcc_ahb_frequency = 4000000;
46uint32_t rcc_apb1_frequency = 4000000;
47uint32_t rcc_apb2_frequency = 4000000;
48
50 { /* 80MHz PLL from HSI16 VR1 */
51 .pllm = 4,
52 .plln = 40,
56 .pll_source = RCC_PLLCFGR_PLLSRC_HSI16,
57 .hpre = RCC_CFGR_HPRE_NODIV,
58 .ppre1 = RCC_CFGR_PPRE_NODIV,
59 .ppre2 = RCC_CFGR_PPRE_NODIV,
60 .voltage_scale = PWR_SCALE1,
61 .flash_config = FLASH_ACR_DCEN | FLASH_ACR_ICEN |
63 .ahb_frequency = 80000000,
64 .apb1_frequency = 80000000,
65 .apb2_frequency = 80000000,
66 },
67};
68
70{
71 switch (osc) {
72 case RCC_PLL:
74 break;
75 case RCC_HSE:
77 break;
78 case RCC_HSI16:
80 break;
81 case RCC_MSI:
83 break;
84 case RCC_LSE:
86 break;
87 case RCC_LSI:
89 break;
90 case RCC_HSI48:
92 break;
93 }
94}
95
97{
98 switch (osc) {
99 case RCC_PLL:
101 break;
102 case RCC_HSE:
104 break;
105 case RCC_HSI16:
107 break;
108 case RCC_MSI:
110 break;
111 case RCC_LSE:
113 break;
114 case RCC_LSI:
116 break;
117 case RCC_HSI48:
119 break;
120 }
121}
122
124{
125 switch (osc) {
126 case RCC_PLL:
127 RCC_CIER &= ~RCC_CIER_PLLRDYIE;
128 break;
129 case RCC_HSE:
130 RCC_CIER &= ~RCC_CIER_HSERDYIE;
131 break;
132 case RCC_HSI16:
133 RCC_CIER &= ~RCC_CIER_HSIRDYIE;
134 break;
135 case RCC_MSI:
136 RCC_CIER &= ~RCC_CIER_MSIRDYIE;
137 break;
138 case RCC_LSE:
139 RCC_CIER &= ~RCC_CIER_LSERDYIE;
140 break;
141 case RCC_LSI:
142 RCC_CIER &= ~RCC_CIER_LSIRDYIE;
143 break;
144 case RCC_HSI48:
145 RCC_CIER &= ~RCC_CIER_HSI48RDYIE;
146 break;
147 }
148}
149
151{
152 switch (osc) {
153 case RCC_PLL:
154 return ((RCC_CIFR & RCC_CIFR_PLLRDYF) != 0);
155 break;
156 case RCC_HSE:
157 return ((RCC_CIFR & RCC_CIFR_HSERDYF) != 0);
158 break;
159 case RCC_HSI16:
160 return ((RCC_CIFR & RCC_CIFR_HSIRDYF) != 0);
161 break;
162 case RCC_MSI:
163 return ((RCC_CIFR & RCC_CIFR_MSIRDYF) != 0);
164 break;
165 case RCC_LSE:
166 return ((RCC_CIFR & RCC_CIFR_LSERDYF) != 0);
167 break;
168 case RCC_LSI:
169 return ((RCC_CIFR & RCC_CIFR_LSIRDYF) != 0);
170 break;
171 case RCC_HSI48:
172 return ((RCC_CIFR & RCC_CIFR_HSI48RDYF) != 0);
173 break;
174 }
175 return false;
176
177}
178
180{
182}
183
185{
186 return ((RCC_CIFR & RCC_CIFR_CSSF) != 0);
187}
188
190{
191 switch (osc) {
192 case RCC_PLL:
193 return RCC_CR & RCC_CR_PLLRDY;
194 case RCC_HSE:
195 return RCC_CR & RCC_CR_HSERDY;
196 case RCC_HSI16:
197 return RCC_CR & RCC_CR_HSIRDY;
198 case RCC_MSI:
199 return RCC_CR & RCC_CR_MSIRDY;
200 case RCC_LSE:
201 return RCC_BDCR & RCC_BDCR_LSERDY;
202 case RCC_LSI:
203 return RCC_CSR & RCC_CSR_LSIRDY;
204 case RCC_HSI48:
206 }
207 return false;
208}
209
211{
212 while (!rcc_is_osc_ready(osc));
213}
214
216{
217 switch (osc) {
218 case RCC_PLL:
221 break;
222 case RCC_HSE:
225 break;
226 case RCC_HSI16:
229 break;
230 case RCC_MSI:
233 break;
234 default:
235 /* Shouldn't be reached. */
236 break;
237 }
238}
239
240void rcc_osc_on(enum rcc_osc osc)
241{
242 switch (osc) {
243 case RCC_PLL:
245 break;
246 case RCC_HSE:
248 break;
249 case RCC_HSI16:
251 break;
252 case RCC_MSI:
254 break;
255 case RCC_LSE:
257 break;
258 case RCC_LSI:
260 break;
261 case RCC_HSI48:
263 break;
264 }
265}
266
267void rcc_osc_off(enum rcc_osc osc)
268{
269 switch (osc) {
270 case RCC_PLL:
271 RCC_CR &= ~RCC_CR_PLLON;
272 break;
273 case RCC_HSE:
274 RCC_CR &= ~RCC_CR_HSEON;
275 break;
276 case RCC_HSI16:
277 RCC_CR &= ~RCC_CR_HSION;
278 break;
279 case RCC_MSI:
280 RCC_CR &= ~RCC_CR_MSION;
281 break;
282 case RCC_LSE:
283 RCC_BDCR &= ~RCC_BDCR_LSEON;
284 break;
285 case RCC_LSI:
286 RCC_CSR &= ~RCC_CSR_LSION;
287 break;
288 case RCC_HSI48:
289 RCC_CRRCR &= ~RCC_CRRCR_HSI48ON;
290 break;
291 }
292}
293
295{
297}
298
300{
301 RCC_CR &= ~RCC_CR_CSSON;
302}
303
304void rcc_set_sysclk_source(uint32_t clk)
305{
306 uint32_t reg32;
307
308 reg32 = RCC_CFGR;
309 reg32 &= ~(RCC_CFGR_SW_MASK << RCC_CFGR_SW_SHIFT);
310 RCC_CFGR = (reg32 | (clk << RCC_CFGR_SW_SHIFT));
311}
312
313void rcc_set_pll_source(uint32_t pllsrc)
314{
315 uint32_t reg32;
316
317 reg32 = RCC_PLLCFGR;
319 RCC_PLLCFGR = (reg32 | (pllsrc << RCC_PLLCFGR_PLLSRC_SHIFT));
320}
321
322void rcc_set_ppre2(uint32_t ppre2)
323{
324 uint32_t reg32;
325
326 reg32 = RCC_CFGR;
328 RCC_CFGR = (reg32 | (ppre2 << RCC_CFGR_PPRE2_SHIFT));
329}
330
331void rcc_set_ppre1(uint32_t ppre1)
332{
333 uint32_t reg32;
334
335 reg32 = RCC_CFGR;
337 RCC_CFGR = (reg32 | (ppre1 << RCC_CFGR_PPRE1_SHIFT));
338}
339
340void rcc_set_hpre(uint32_t hpre)
341{
342 uint32_t reg32;
343
344 reg32 = RCC_CFGR;
346 RCC_CFGR = (reg32 | (hpre << RCC_CFGR_HPRE_SHIFT));
347}
348
349void rcc_set_main_pll(uint32_t source, uint32_t pllm, uint32_t plln, uint32_t pllp,
350 uint32_t pllq, uint32_t pllr)
351{
354 (pllp) |
355 (source << RCC_PLLCFGR_PLLSRC_SHIFT) |
358}
359
361{
362 /* Return the clock source which is used as system clock. */
364}
365
366/**
367 * Setup clocks to run from PLL.
368 *
369 * The arguments provide the pll source, multipliers, dividers, all that's
370 * needed to establish a system clock.
371 *
372 * @param clock clock information structure.
373 */
374void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
375{
376 /* Enable internal high-speed oscillator (HSI16). */
379
380 /* Select HSI16 as SYSCLK source. */
382
383 /* Enable external high-speed oscillator (HSE). */
384 if (clock->pll_source == RCC_PLLCFGR_PLLSRC_HSE) {
387 }
388
389 /* Set the VOS scale mode */
392
393 /*
394 * Set prescalers for AHB, ADC, APB1, APB2.
395 * Do this before touching the PLL (TODO: why?).
396 */
397 rcc_set_hpre(clock->hpre);
398 rcc_set_ppre1(clock->ppre1);
399 rcc_set_ppre2(clock->ppre2);
400
401 /* Disable PLL oscillator before changing its configuration. */
403
404 /* Configure the PLL oscillator. */
405 rcc_set_main_pll(clock->pll_source, clock->pllm, clock->plln,
406 clock->pllp, clock->pllq, clock->pllr);
407
408 /* Enable PLL oscillator and wait for it to stabilize. */
411
412 /* Configure flash settings. */
413 if (clock->flash_config & FLASH_ACR_DCEN) {
415 } else {
417 }
418 if (clock->flash_config & FLASH_ACR_ICEN) {
420 } else {
422 }
424
425 /* Select PLL as SYSCLK source. */
427
428 /* Wait for PLL clock to be selected. */
430
431 /* Set the peripheral clock frequencies used. */
435
436 /* Disable internal high-speed oscillator. */
437 if (clock->pll_source == RCC_PLLCFGR_PLLSRC_HSE) {
439 }
440}
441
442/**
443 * Set the msi run time range.
444 * Can only be called when MSI is either OFF, or when MSI is on _and_
445 * ready. (RCC_CR_MSIRDY bit). @sa rcc_set_msi_range_standby
446 * @param msi_range range number @ref rcc_cr_msirange
447 */
448void rcc_set_msi_range(uint32_t msi_range)
449{
450 uint32_t reg = RCC_CR;
452 reg |= msi_range << RCC_CR_MSIRANGE_SHIFT;
453 RCC_CR = reg | RCC_CR_MSIRGSEL;
454}
455
456/**
457 * Set the msi range after reset/standby.
458 * Until MSIRGSEl bit is set, this defines the MSI range.
459 * Note that not all MSI range values are allowed here!
460 * @sa rcc_set_msi_range
461 * @param msi_range range number valid for post standby @ref rcc_csr_msirange
462 */
463void rcc_set_msi_range_standby(uint32_t msi_range)
464{
465 uint32_t reg = RCC_CSR;
467 reg |= msi_range << RCC_CSR_MSIRANGE_SHIFT;
468 RCC_CSR = reg;
469}
470
471/** Enable PLL Output
472 *
473 * - P (RCC_PLLCFGR_PLLPEN)
474 * - Q (RCC_PLLCFGR_PLLQEN)
475 * - R (RCC_PLLCFGR_PLLREN)
476 *
477 * @param pllout One or more of the definitions above
478 */
479void rcc_pll_output_enable(uint32_t pllout)
480{
481 RCC_PLLCFGR |= pllout;
482}
483
484/** Set clock source for 48MHz clock
485 *
486 * The 48 MHz clock is derived from one of the four following sources:
487 * - main PLL VCO (RCC_CCIPR_CLK48SEL_PLL)
488 * - PLLSAI1 VCO (RCC_CCIPR_CLK48SEL_PLLSAI1Q)
489 * - MSI clock (RCC_CCIPR_CLK48SEL_MSI)
490 * - HSI48 internal oscillator (RCC_CCIPR_CLK48SEL_HSI48)
491 *
492 * @param clksel One of the definitions above
493 */
494void rcc_set_clock48_source(uint32_t clksel)
495{
497 RCC_CCIPR |= (clksel << RCC_CCIPR_CLK48SEL_SHIFT);
498}
499
500
501/** Enable the RTC clock */
503{
505}
506
507/** Disable the RTC clock */
509{
510 RCC_BDCR &= ~RCC_BDCR_RTCEN;
511}
512
513/** Set the source for the RTC clock
514 * @param[in] clk ::rcc_osc. RTC clock source. Only HSE/32, LSE and LSI.
515 */
517{
519
520 switch (clk) {
521 case RCC_HSE:
523 break;
524 case RCC_LSE:
526 break;
527 case RCC_LSI:
529 break;
530 default:
531 /* none selected */
532 break;
533 }
534}
535
536/* Helper to calculate the frequency of a UART/I2C based on the apb and clksel value.
537 * For I2C, clock selection 0b11 is reserved while it specifies LSE for UARTs. */
538static uint32_t rcc_uart_i2c_clksel_freq_hz(uint32_t apb_clk, uint8_t shift, uint32_t clock_reg) {
539 uint8_t clksel = (clock_reg >> shift) & RCC_CCIPR_USARTxSEL_MASK;
541 switch (clksel) {
543 return apb_clk;
547 return 16000000U;
549 return 32768U;
550 }
552}
553
554/*---------------------------------------------------------------------------*/
555/** @brief Get the peripheral clock speed for the USART at base specified.
556 * @param usart Base address of USART to get clock frequency for.
557 */
558uint32_t rcc_get_usart_clk_freq(uint32_t usart)
559{
560 /* Handle values with selectable clocks. */
561 if (usart == LPUART1_BASE) {
563 } else if (usart == USART1_BASE) {
565 } else if (usart == USART2_BASE) {
567 } else if (usart == USART3_BASE) {
569 } else if (usart == UART4_BASE) {
571 } else { /* USART5 */
573 }
574}
575
576/*---------------------------------------------------------------------------*/
577/** @brief Get the peripheral clock speed for the Timer at base specified.
578 * @param timer Base address of TIM to get clock frequency for.
579 */
580uint32_t rcc_get_timer_clk_freq(uint32_t timer)
581{
582 /* Handle APB1 timers, and apply multiplier if necessary. */
583 if (timer == LPTIM1_BASE || timer == LPTIM2_BASE) {
585 uint8_t clksel = (RCC_CCIPR >> shift) & RCC_CCIPR_LPTIMxSEL_MASK;
586 switch (clksel) {
588 return rcc_apb1_frequency;
590 return 32000U;
592 return 16000000U;
594 return 32768U;
595 }
596 } else if (timer >= TIM2_BASE && timer <= TIM7_BASE) {
599 : 2 * rcc_apb1_frequency;
600 } else {
603 : 2 * rcc_apb2_frequency;
604 }
606}
607
608/*---------------------------------------------------------------------------*/
609/** @brief Get the peripheral clock speed for the I2C device at base specified.
610 * @param i2c Base address of I2C to get clock frequency for.
611 */
612uint32_t rcc_get_i2c_clk_freq(uint32_t i2c)
613{
614 if (i2c == I2C1_BASE) {
616 } else if (i2c == I2C2_BASE) {
618 } else if (i2c == I2C3_BASE) {
620 } else { /* I2C4 */
622 }
623}
624
625/*---------------------------------------------------------------------------*/
626/** @brief Get the peripheral clock speed for the SPI device at base specified.
627 * @param spi Base address of SPI device to get clock frequency for (e.g. SPI1_BASE).
628 */
629uint32_t rcc_get_spi_clk_freq(uint32_t spi) {
630 if (spi == SPI1_BASE) {
631 return rcc_apb2_frequency;
632 } else {
633 return rcc_apb1_frequency;
634 }
635}
636/**@}*/
#define cm3_assert_not_reached()
Check if unreachable code is reached.
Definition: assert.h:102
#define FLASH_ACR_ICEN
#define FLASH_ACR_DCEN
void flash_icache_disable(void)
Disable the Instruction Cache.
void flash_icache_enable(void)
Enable the Instruction Cache.
void flash_dcache_disable(void)
Disable the data cache.
#define FLASH_ACR_LATENCY_4WS
Definition: l4/flash.h:80
void flash_dcache_enable(void)
Enable the data cache.
void flash_set_ws(uint32_t ws)
Set the Number of Wait States.
void pwr_set_vos_scale(enum pwr_vos_scale scale)
Definition: pwr.c:39
@ PWR_SCALE1
Definition: l4/pwr.h:166
#define RCC_CFGR_HPRE_NODIV
Definition: l4/rcc.h:218
#define RCC_CFGR_PPRE_NODIV
Definition: l4/rcc.h:207
#define RCC_CR_MSIRANGE_SHIFT
Definition: l4/rcc.h:134
#define RCC_CR_MSIRANGE_MASK
Definition: l4/rcc.h:135
#define RCC_CR_HSERDY
Definition: l4/rcc.h:119
#define RCC_CR_HSIRDY
Definition: l4/rcc.h:122
#define RCC_CR_CSSON
Definition: l4/rcc.h:117
#define RCC_CR_PLLON
Definition: l4/rcc.h:116
#define RCC_CR_HSEON
Definition: l4/rcc.h:120
#define RCC_CR_HSION
Definition: l4/rcc.h:124
#define RCC_CR_PLLRDY
Definition: l4/rcc.h:115
#define RCC_CSR_MSIRANGE_SHIFT
Definition: l4/rcc.h:733
#define RCC_CSR_MSIRANGE_MASK
Definition: l4/rcc.h:732
#define RCC_BDCR_LSEON
Definition: l4/rcc.h:710
#define RCC_CIFR_HSIRDYF
Definition: l4/rcc.h:320
#define RCC_CCIPR_USARTxSEL_LSE
Definition: l4/rcc.h:670
#define RCC_BDCR_RTCSEL_MASK
Definition: l4/rcc.h:695
#define RCC_BDCR_RTCSEL_LSE
Definition: l4/rcc.h:691
#define RCC_CICR_HSIRDYC
Definition: l4/rcc.h:334
#define RCC_PLLCFGR_PLLSRC_SHIFT
Definition: l4/rcc.h:285
#define RCC_CFGR_PPRE1_MASK
Definition: l4/rcc.h:200
#define RCC_CIFR_LSERDYF
Definition: l4/rcc.h:322
#define RCC_CFGR_PPRE2_SHIFT
Definition: l4/rcc.h:201
#define RCC_CRRCR_HSI48ON
Definition: l4/rcc.h:156
#define RCC_CCIPR_USART3SEL_SHIFT
Definition: l4/rcc.h:679
#define RCC_CCIPR_UART4SEL_SHIFT
Definition: l4/rcc.h:678
#define RCC_CFGR_SWS_PLL
Definition: l4/rcc.h:233
#define RCC_CIFR_HSI48RDYF
Definition: l4/rcc.h:313
#define RCC_CIFR_PLLRDYF
Definition: l4/rcc.h:318
#define RCC_CCIPR_USART1SEL_SHIFT
Definition: l4/rcc.h:681
#define RCC_CCIPR_LPUART1SEL_SHIFT
Definition: l4/rcc.h:665
#define RCC_CICR_PLLRDYC
Definition: l4/rcc.h:332
#define RCC_CFGR_PPRE2_MASK
Definition: l4/rcc.h:202
#define RCC_CIFR_MSIRDYF
Definition: l4/rcc.h:321
#define RCC_CCIPR_LPTIMxSEL_APB
Definition: l4/rcc.h:643
#define RCC_CFGR_HPRE_MASK
Definition: l4/rcc.h:215
#define RCC_CFGR_SWS_MASK
Definition: l4/rcc.h:234
#define RCC_CR_MSIRGSEL
Definition: l4/rcc.h:149
#define RCC_CICR_LSIRDYC
Definition: l4/rcc.h:337
#define RCC_PLLCFGR_PLLP_DIV7
Definition: l4/rcc.h:264
#define RCC_CCIPR_USARTxSEL_SYSCLK
Definition: l4/rcc.h:668
#define RCC_CCIPR_I2C2SEL_SHIFT
Definition: l4/rcc.h:657
#define RCC_CICR_LSERDYC
Definition: l4/rcc.h:336
#define RCC_CFGR_SWS_HSI16
Definition: l4/rcc.h:231
#define RCC_CIFR_HSERDYF
Definition: l4/rcc.h:319
#define RCC_CICR_CSSC
Definition: l4/rcc.h:329
#define RCC_CCIPR_LPTIMxSEL_LSE
Definition: l4/rcc.h:646
#define RCC_BDCR_RTCSEL_LSI
Definition: l4/rcc.h:692
#define RCC_CCIPR_USART2SEL_SHIFT
Definition: l4/rcc.h:680
rcc_osc
Definition: l4/rcc.h:777
#define RCC_PLLCFGR_PLLSRC_MASK
Definition: l4/rcc.h:286
#define RCC_CIER_HSI48RDYIE
Definition: l4/rcc.h:299
#define RCC_CICR_HSI48RDYC
Definition: l4/rcc.h:327
#define RCC_BDCR_RTCEN
Definition: l4/rcc.h:688
#define RCC_CIER_LSERDYIE
Definition: l4/rcc.h:308
#define RCC_CCIPR_I2C1SEL_SHIFT
Definition: l4/rcc.h:658
#define RCC_PLLCFGR_PLLSRC_HSI16
Definition: l4/rcc.h:289
#define RCC_CFGR_SW_MASK
Definition: l4/rcc.h:242
#define RCC_CSR_LSION
Definition: l4/rcc.h:741
#define RCC_CCIPR_USARTxSEL_MASK
Definition: l4/rcc.h:671
#define RCC_BDCR_RTCSEL_SHIFT
Definition: l4/rcc.h:694
#define RCC_CCIPR_LPTIM1SEL_SHIFT
Definition: l4/rcc.h:649
#define RCC_CFGR_SW_PLL
Definition: l4/rcc.h:241
#define RCC_CCIPR_LPTIMxSEL_MASK
Definition: l4/rcc.h:647
#define RCC_PLLCFGR_PLLQ_DIV6
Definition: l4/rcc.h:258
#define RCC_CCIPR_I2C3SEL_SHIFT
Definition: l4/rcc.h:656
void rcc_periph_clock_enable(enum rcc_periph_clken clken)
Enable Peripheral Clock in running mode.
#define RCC_CICR_MSIRDYC
Definition: l4/rcc.h:335
#define RCC_CICR_HSERDYC
Definition: l4/rcc.h:333
#define RCC_CCIPR_I2C4SEL_SHIFT
Definition: l4/rcc.h:655
#define RCC_CFGR_SWS_SHIFT
Definition: l4/rcc.h:235
#define RCC_CIER_MSIRDYIE
Definition: l4/rcc.h:307
#define RCC_BDCR_LSERDY
Definition: l4/rcc.h:709
#define RCC_CFGR_SWS_MSI
Definition: l4/rcc.h:230
#define RCC_CSR_LSIRDY
Definition: l4/rcc.h:740
#define RCC_CCIPR_LPTIMxSEL_LSI
Definition: l4/rcc.h:644
#define RCC_CRRCR_HSI48RDY
Definition: l4/rcc.h:157
#define RCC_CCIPR_USARTxSEL_HSI16
Definition: l4/rcc.h:669
#define RCC_CCIPR_UART5SEL_SHIFT
Definition: l4/rcc.h:677
#define RCC_PLLCFGR_PLLR_SHIFT
Definition: l4/rcc.h:246
#define RCC_CCIPR_LPTIMxSEL_HSI16
Definition: l4/rcc.h:645
#define RCC_CFGR_HPRE_SHIFT
Definition: l4/rcc.h:214
#define RCC_CCIPR_USARTxSEL_APB
Definition: l4/rcc.h:667
#define RCC_CIER_HSIRDYIE
Definition: l4/rcc.h:306
#define RCC_CFGR_SW_SHIFT
Definition: l4/rcc.h:243
#define RCC_CR_MSIRDY
Definition: l4/rcc.h:151
#define RCC_PLLCFGR_PLLQ_SHIFT
Definition: l4/rcc.h:254
#define RCC_CIFR_CSSF
Definition: l4/rcc.h:315
#define RCC_CIER_LSIRDYIE
Definition: l4/rcc.h:309
#define RCC_CCIPR_CLK48SEL_MASK
Definition: l4/rcc.h:632
#define RCC_CIFR_LSIRDYF
Definition: l4/rcc.h:323
#define RCC_CIER_PLLRDYIE
Definition: l4/rcc.h:304
#define RCC_PLLCFGR_PLLR_DIV2
Definition: l4/rcc.h:248
#define RCC_BDCR_RTCSEL_HSEDIV32
Definition: l4/rcc.h:693
#define RCC_PLLCFGR_PLLREN
Definition: l4/rcc.h:252
#define RCC_CFGR_SWS_HSE
Definition: l4/rcc.h:232
#define RCC_PLLCFGR_PLLSRC_HSE
Definition: l4/rcc.h:290
#define RCC_CIER_HSERDYIE
Definition: l4/rcc.h:305
#define RCC_CR_MSION
Definition: l4/rcc.h:152
#define RCC_CCIPR_LPTIM2SEL_SHIFT
Definition: l4/rcc.h:648
#define RCC_CCIPR_CLK48SEL_SHIFT
Definition: l4/rcc.h:633
#define RCC_CFGR_PPRE1_SHIFT
Definition: l4/rcc.h:199
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_PWR
Definition: l4/rcc.h:816
@ RCC_HSI48
Definition: l4/rcc.h:778
@ RCC_LSI
Definition: l4/rcc.h:778
@ RCC_PLL
Definition: l4/rcc.h:778
@ RCC_MSI
Definition: l4/rcc.h:778
@ RCC_LSE
Definition: l4/rcc.h:778
@ RCC_HSE
Definition: l4/rcc.h:778
@ RCC_HSI16
Definition: l4/rcc.h:778
@ RCC_CLOCK_CONFIG_END
Definition: l4/rcc.h:762
int rcc_osc_ready_int_flag(enum rcc_osc osc)
Definition: rcc.c:150
void rcc_set_msi_range(uint32_t msi_range)
Set the msi run time range.
Definition: rcc.c:448
int rcc_css_int_flag(void)
Definition: rcc.c:184
void rcc_set_clock48_source(uint32_t clksel)
Set clock source for 48MHz clock.
Definition: rcc.c:494
void rcc_osc_ready_int_clear(enum rcc_osc osc)
Definition: rcc.c:69
void rcc_wait_for_osc_ready(enum rcc_osc osc)
Wait for Oscillator Ready.
Definition: rcc.c:210
void rcc_set_main_pll(uint32_t source, uint32_t pllm, uint32_t plln, uint32_t pllp, uint32_t pllq, uint32_t pllr)
Definition: rcc.c:349
void rcc_css_disable(void)
Definition: rcc.c:299
bool rcc_is_osc_ready(enum rcc_osc osc)
Is the given oscillator ready?
Definition: rcc.c:189
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:629
void rcc_set_sysclk_source(uint32_t clk)
Definition: rcc.c:304
uint32_t rcc_apb2_frequency
Definition: rcc.c:47
void rcc_set_pll_source(uint32_t pllsrc)
Definition: rcc.c:313
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
Definition: rcc.c:580
uint32_t rcc_system_clock_source(void)
Definition: rcc.c:360
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
Definition: rcc.c:558
void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
Setup clocks to run from PLL.
Definition: rcc.c:374
void rcc_osc_ready_int_enable(enum rcc_osc osc)
Definition: rcc.c:96
void rcc_set_rtc_clock_source(enum rcc_osc clk)
Set the source for the RTC clock.
Definition: rcc.c:516
void rcc_pll_output_enable(uint32_t pllout)
Enable PLL Output.
Definition: rcc.c:479
void rcc_disable_rtc_clock(void)
Disable the RTC clock.
Definition: rcc.c:508
void rcc_osc_ready_int_disable(enum rcc_osc osc)
Definition: rcc.c:123
void rcc_osc_on(enum rcc_osc osc)
Definition: rcc.c:240
uint32_t rcc_ahb_frequency
Definition: rcc.c:45
void rcc_osc_off(enum rcc_osc osc)
Definition: rcc.c:267
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:612
void rcc_set_msi_range_standby(uint32_t msi_range)
Set the msi range after reset/standby.
Definition: rcc.c:463
const struct rcc_clock_scale rcc_hsi16_configs[RCC_CLOCK_CONFIG_END]
Definition: rcc.c:49
uint32_t rcc_apb1_frequency
Definition: rcc.c:46
void rcc_wait_for_sysclk_status(enum rcc_osc osc)
Definition: rcc.c:215
void rcc_set_ppre1(uint32_t ppre1)
Definition: rcc.c:331
void rcc_css_int_clear(void)
Definition: rcc.c:179
void rcc_enable_rtc_clock(void)
Enable the RTC clock.
Definition: rcc.c:502
void rcc_set_ppre2(uint32_t ppre2)
Definition: rcc.c:322
void rcc_css_enable(void)
Definition: rcc.c:294
void rcc_set_hpre(uint32_t hpre)
Definition: rcc.c:340
static uint32_t rcc_uart_i2c_clksel_freq_hz(uint32_t apb_clk, uint8_t shift, uint32_t clock_reg)
Definition: rcc.c:538
#define RCC_PLLCFGR_PLLM(x)
Definition: l4/rcc.h:282
#define RCC_PLLCFGR_PLLM_SHIFT
Definition: l4/rcc.h:280
#define RCC_PLLCFGR_PLLN_SHIFT
Definition: l4/rcc.h:272
#define RCC_CICR
Clock interrupt clear register.
Definition: l4/rcc.h:61
#define RCC_CR
Clock control register.
Definition: l4/rcc.h:48
#define RCC_CIFR
Clock interrupt flag resiger.
Definition: l4/rcc.h:59
#define RCC_CCIPR
Definition: l4/rcc.h:98
#define RCC_CSR
Clock control and status register.
Definition: l4/rcc.h:102
#define RCC_PLLCFGR
PLL Configuration register.
Definition: l4/rcc.h:53
#define RCC_CIER
Clock interrupt enable register.
Definition: l4/rcc.h:57
#define RCC_CFGR
Clock Configuration register.
Definition: l4/rcc.h:51
#define RCC_BDCR
Backup Domain control register.
Definition: l4/rcc.h:100
#define RCC_CRRCR
Definition: l4/rcc.h:103
#define RCC_CCIPR2
Definition: l4/rcc.h:104
#define TIM2_BASE
#define LPTIM1_BASE
#define I2C2_BASE
#define TIM7_BASE
#define LPUART1_BASE
#define I2C3_BASE
#define SPI1_BASE
#define LPTIM2_BASE
#define USART1_BASE
#define UART4_BASE
#define USART3_BASE
#define I2C1_BASE
#define USART2_BASE
uint8_t ppre1
Definition: l4/rcc.h:752
uint8_t pllq
Definition: l4/rcc.h:747
uint8_t ppre2
Definition: l4/rcc.h:753
uint8_t pllp
Definition: l4/rcc.h:746
uint32_t apb1_frequency
Definition: l4/rcc.h:756
uint8_t pllm
Definition: l4/rcc.h:744
uint32_t ahb_frequency
Definition: l4/rcc.h:755
uint16_t plln
Definition: l4/rcc.h:745
enum pwr_vos_scale voltage_scale
Definition: l4/rcc.h:754
uint8_t pllr
Definition: l4/rcc.h:748
uint32_t flash_config
Definition: l4/rcc.h:750
uint8_t hpre
Definition: l4/rcc.h:751
uint32_t apb2_frequency
Definition: l4/rcc.h:757
uint8_t pll_source
Definition: l4/rcc.h:749