41#ifndef LIBOPENCM3_RCC_H
42#define LIBOPENCM3_RCC_H
46#define RCC_CR MMIO32(RCC_BASE + 0x00)
47#define RCC_CFGR MMIO32(RCC_BASE + 0x04)
48#define RCC_CIR MMIO32(RCC_BASE + 0x08)
49#define RCC_APB2RSTR MMIO32(RCC_BASE + 0x0c)
50#define RCC_APB1RSTR MMIO32(RCC_BASE + 0x10)
51#define RCC_AHBENR MMIO32(RCC_BASE + 0x14)
52#define RCC_APB2ENR MMIO32(RCC_BASE + 0x18)
53#define RCC_APB1ENR MMIO32(RCC_BASE + 0x1c)
54#define RCC_BDCR MMIO32(RCC_BASE + 0x20)
55#define RCC_CSR MMIO32(RCC_BASE + 0x24)
56#define RCC_AHBRSTR MMIO32(RCC_BASE + 0x28)
57#define RCC_CFGR2 MMIO32(RCC_BASE + 0x2c)
58#define RCC_CFGR3 MMIO32(RCC_BASE + 0x30)
59#define RCC_CR2 MMIO32(RCC_BASE + 0x34)
64#define RCC_CR_PLLRDY (1 << 25)
65#define RCC_CR_PLLON (1 << 24)
66#define RCC_CR_CSSON (1 << 19)
67#define RCC_CR_HSEBYP (1 << 18)
68#define RCC_CR_HSERDY (1 << 17)
69#define RCC_CR_HSEON (1 << 16)
72#define RCC_CR_HSIRDY (1 << 1)
73#define RCC_CR_HSION (1 << 0)
77#define RCC_CFGR_PLLNODIV (1 << 31)
79#define RCC_CFGR_MCOPRE_SHIFT 28
80#define RCC_CFGR_MCOPRE (7 << RCC_CFGR_MCOPRE_SHIFT)
81#define RCC_CFGR_MCOPRE_DIV1 (0 << RCC_CFGR_MCOPRE_SHIFT)
82#define RCC_CFGR_MCOPRE_DIV2 (1 << RCC_CFGR_MCOPRE_SHIFT)
83#define RCC_CFGR_MCOPRE_DIV4 (2 << RCC_CFGR_MCOPRE_SHIFT)
84#define RCC_CFGR_MCOPRE_DIV8 (3 << RCC_CFGR_MCOPRE_SHIFT)
85#define RCC_CFGR_MCOPRE_DIV16 (4 << RCC_CFGR_MCOPRE_SHIFT)
86#define RCC_CFGR_MCOPRE_DIV32 (5 << RCC_CFGR_MCOPRE_SHIFT)
87#define RCC_CFGR_MCOPRE_DIV64 (6 << RCC_CFGR_MCOPRE_SHIFT)
88#define RCC_CFGR_MCOPRE_DIV128 (7 << RCC_CFGR_MCOPRE_SHIFT)
90#define RCC_CFGR_PLLMUL_4_SHIFT 27
91#define RCC_CFGR_PLLMUL_4 (1 << RCC_CFGR_PLLMUL_4_SHIFT)
93#define RCC_CFGR_MCO_SHIFT 24
94#define RCC_CFGR_MCO_MASK 0x7
95#define RCC_CFGR_MCO_NOCLK 0
96#define RCC_CFGR_MCO_HSI14 1
97#define RCC_CFGR_MCO_LSI 2
98#define RCC_CFGR_MCO_LSE 3
99#define RCC_CFGR_MCO_SYSCLK 4
100#define RCC_CFGR_MCO_HSI 5
101#define RCC_CFGR_MCO_HSE 6
102#define RCC_CFGR_MCO_PLL 7
104#define RCC_CFGR_USBPRE_SHIFT 22
105#define RCC_CFGR_USBPRE (3 << RCC_CFGR_USBPRE_SHIFT)
107#define RCC_CFGR_PLLMUL_0_3_SHIFT 18
108#define RCC_CFGR_PLLMUL_0_3 (0xF << RCC_CFGR_PLLMUL_0_3_SHIFT)
110#define RCC_CFGR_PLLXTPRE (1 << 17)
111#define RCC_CFGR_PLLSRC (1 << 16)
113#define RCC_CFGR_ADCPRE_SHIFT 14
114#define RCC_CFGR_ADCPRE (3 << RCC_CFGR_ADCPRE_SHIFT)
116#define RCC_CFGR_PPRE2_SHIFT 11
117#define RCC_CFGR_PPRE2 (7 << RCC_CFGR_PPRE2_SHIFT)
119#define RCC_CFGR_PPRE1_SHIFT 8
120#define RCC_CFGR_PPRE1 (7 << RCC_CFGR_PPRE1_SHIFT)
122#define RCC_CFGR_HPRE_SHIFT 4
123#define RCC_CFGR_HPRE (0xF << RCC_CFGR_HPRE_SHIFT)
125#define RCC_CFGR_SWS_SHIFT 2
126#define RCC_CFGR_SWS (3 << RCC_CFGR_SWS_SHIFT)
128#define RCC_CFGR_SW_SHIFT 0
129#define RCC_CFGR_SW (3 << RCC_CFGR_SW_SHIFT)
134#define RCC_CFGR_USBPRE_PLL_CLK_DIV1_5 0x0
135#define RCC_CFGR_USBPRE_PLL_CLK_NODIV 0x1
136#define RCC_CFGR_USBPRE_PLL_CLK_DIV2_5 0x2
137#define RCC_CFGR_USBPRE_PLL_CLK_DIV2 0x3
143#define RCC_CFGR_PLLMUL_PLL_CLK_MUL2 0x0
144#define RCC_CFGR_PLLMUL_PLL_CLK_MUL3 0x1
145#define RCC_CFGR_PLLMUL_PLL_CLK_MUL4 0x2
146#define RCC_CFGR_PLLMUL_PLL_CLK_MUL5 0x3
147#define RCC_CFGR_PLLMUL_PLL_CLK_MUL6 0x4
148#define RCC_CFGR_PLLMUL_PLL_CLK_MUL7 0x5
149#define RCC_CFGR_PLLMUL_PLL_CLK_MUL8 0x6
150#define RCC_CFGR_PLLMUL_PLL_CLK_MUL9 0x7
151#define RCC_CFGR_PLLMUL_PLL_CLK_MUL10 0x8
152#define RCC_CFGR_PLLMUL_PLL_CLK_MUL11 0x9
153#define RCC_CFGR_PLLMUL_PLL_CLK_MUL12 0xa
154#define RCC_CFGR_PLLMUL_PLL_CLK_MUL13 0xb
155#define RCC_CFGR_PLLMUL_PLL_CLK_MUL14 0xc
156#define RCC_CFGR_PLLMUL_PLL_CLK_MUL15 0xd
157#define RCC_CFGR_PLLMUL_PLL_CLK_MUL16 0xe
163#define RCC_CFGR_PLLXTPRE_HSE_CLK 0x0
164#define RCC_CFGR_PLLXTPRE_HSE_CLK_DIV2 0x1
170#define RCC_CFGR_PLLSRC_HSI_CLK_DIV2 0x0
171#define RCC_CFGR_PLLSRC_HSE_CLK 0x1
177#define RCC_CFGR_ADCPRE_DIV2 0x0
178#define RCC_CFGR_ADCPRE_DIV4 0x1
179#define RCC_CFGR_ADCPRE_DIV6 0x2
180#define RCC_CFGR_ADCPRE_DIV8 0x3
183#define RCC_CFGR_PPRE2_SHIFT 11
184#define RCC_CFGR_PPRE2_MASK 0x7
185#define RCC_CFGR_PPRE1_SHIFT 8
186#define RCC_CFGR_PPRE1_MASK 0x7
191#define RCC_CFGR_PPRE_NODIV 0x0
192#define RCC_CFGR_PPRE_DIV2 0x4
193#define RCC_CFGR_PPRE_DIV4 0x5
194#define RCC_CFGR_PPRE_DIV8 0x6
195#define RCC_CFGR_PPRE_DIV16 0x7
201#define RCC_CFGR_HPRE_NODIV 0x0
202#define RCC_CFGR_HPRE_DIV2 0x8
203#define RCC_CFGR_HPRE_DIV4 0x9
204#define RCC_CFGR_HPRE_DIV8 0xa
205#define RCC_CFGR_HPRE_DIV16 0xb
206#define RCC_CFGR_HPRE_DIV64 0xc
207#define RCC_CFGR_HPRE_DIV128 0xd
208#define RCC_CFGR_HPRE_DIV256 0xe
209#define RCC_CFGR_HPRE_DIV512 0xf
213#define RCC_CFGR_SWS_SYSCLKSEL_HSICLK 0x0
214#define RCC_CFGR_SWS_SYSCLKSEL_HSECLK 0x1
215#define RCC_CFGR_SWS_SYSCLKSEL_PLLCLK 0x2
220#define RCC_CFGR_SW_SYSCLKSEL_HSICLK 0x0
221#define RCC_CFGR_SW_SYSCLKSEL_HSECLK 0x1
222#define RCC_CFGR_SW_SYSCLKSEL_PLLCLK 0x2
230#define RCC_CFGR_ADCPRE_PCLK2_DIV2 0x0
231#define RCC_CFGR_ADCPRE_PCLK2_DIV4 0x1
232#define RCC_CFGR_ADCPRE_PCLK2_DIV6 0x2
233#define RCC_CFGR_ADCPRE_PCLK2_DIV8 0x3
235#define RCC_CFGR_PPRE2_HCLK_NODIV 0x0
236#define RCC_CFGR_PPRE2_HCLK_DIV2 0x4
237#define RCC_CFGR_PPRE2_HCLK_DIV4 0x5
238#define RCC_CFGR_PPRE2_HCLK_DIV8 0x6
239#define RCC_CFGR_PPRE2_HCLK_DIV16 0x7
241#define RCC_CFGR_PPRE1_HCLK_NODIV 0x0
242#define RCC_CFGR_PPRE1_HCLK_DIV2 0x4
243#define RCC_CFGR_PPRE1_HCLK_DIV4 0x5
244#define RCC_CFGR_PPRE1_HCLK_DIV8 0x6
245#define RCC_CFGR_PPRE1_HCLK_DIV16 0x7
247#define RCC_CFGR_HPRE_SYSCLK_NODIV 0x0
248#define RCC_CFGR_HPRE_SYSCLK_DIV2 0x8
249#define RCC_CFGR_HPRE_SYSCLK_DIV4 0x9
250#define RCC_CFGR_HPRE_SYSCLK_DIV8 0xa
251#define RCC_CFGR_HPRE_SYSCLK_DIV16 0xb
252#define RCC_CFGR_HPRE_SYSCLK_DIV64 0xc
253#define RCC_CFGR_HPRE_SYSCLK_DIV128 0xd
254#define RCC_CFGR_HPRE_SYSCLK_DIV256 0xe
255#define RCC_CFGR_HPRE_SYSCLK_DIV512 0xf
261#define RCC_CIR_CSSC (1 << 23)
264#define RCC_CIR_HSI14RDYC (1 << 21)
265#define RCC_CIR_PLLRDYC (1 << 20)
266#define RCC_CIR_HSERDYC (1 << 19)
267#define RCC_CIR_HSIRDYC (1 << 18)
268#define RCC_CIR_LSERDYC (1 << 17)
269#define RCC_CIR_LSIRDYC (1 << 16)
272#define RCC_CIR_HSI14RDYIE (1 << 13)
273#define RCC_CIR_PLLRDYIE (1 << 12)
274#define RCC_CIR_HSERDYIE (1 << 11)
275#define RCC_CIR_HSIRDYIE (1 << 10)
276#define RCC_CIR_LSERDYIE (1 << 9)
277#define RCC_CIR_LSIRDYIE (1 << 8)
280#define RCC_CIR_CSSF (1 << 7)
283#define RCC_CIR_HSI14RDYF (1 << 5)
284#define RCC_CIR_PLLRDYF (1 << 4)
285#define RCC_CIR_HSERDYF (1 << 3)
286#define RCC_CIR_HSIRDYF (1 << 2)
287#define RCC_CIR_LSERDYF (1 << 1)
288#define RCC_CIR_LSIRDYF (1 << 0)
292#define RCC_APB2RSTR_TIM17RST (1 << 18)
293#define RCC_APB2RSTR_TIM16RST (1 << 17)
294#define RCC_APB2RSTR_TIM15RST (1 << 16)
295#define RCC_APB2RSTR_USART1RST (1 << 14)
296#define RCC_APB2RSTR_SPI1RST (1 << 12)
297#define RCC_APB2RSTR_TIM1RST (1 << 11)
298#define RCC_APB2RSTR_ADCRST (1 << 9)
299#define RCC_APB2RSTR_SYSCFGRST (1 << 0)
304#define RCC_APB1RSTR_CECRST (1 << 30)
305#define RCC_APB1RSTR_DACRST (1 << 29)
306#define RCC_APB1RSTR_PWRRST (1 << 28)
307#define RCC_APB1RSTR_USBRST (1 << 23)
308#define RCC_APB1RSTR_I2C2RST (1 << 22)
309#define RCC_APB1RSTR_I2C1RST (1 << 21)
310#define RCC_APB1RSTR_USART2RST (1 << 17)
311#define RCC_APB1RSTR_SPI3RST (1 << 15)
312#define RCC_APB1RSTR_SPI2RST (1 << 14)
313#define RCC_APB1RSTR_WWDGRST (1 << 11)
314#define RCC_APB1RSTR_TIM14RST (1 << 8)
315#define RCC_APB1RSTR_TIM6RST (1 << 4)
316#define RCC_APB1RSTR_TIM3RST (1 << 1)
317#define RCC_APB1RSTR_TIM2RST (1 << 0)
322#define RCC_AHBENR_TSCEN (1 << 24)
323#define RCC_AHBENR_GPIOFEN (1 << 22)
324#define RCC_AHBENR_GPIOEEN (1 << 21)
325#define RCC_AHBENR_GPIODEN (1 << 20)
326#define RCC_AHBENR_GPIOCEN (1 << 19)
327#define RCC_AHBENR_GPIOBEN (1 << 18)
328#define RCC_AHBENR_GPIOAEN (1 << 17)
329#define RCC_AHBENR_CRCEN (1 << 6)
330#define RCC_AHBENR_FLTFEN (1 << 4)
331#define RCC_AHBENR_SRAMEN (1 << 2)
332#define RCC_AHBENR_DMAEN (1 << 0)
337#define RCC_APB2ENR_TIM17EN (1 << 18)
338#define RCC_APB2ENR_TIM16EN (1 << 17)
339#define RCC_APB2ENR_TIM15EN (1 << 16)
340#define RCC_APB2ENR_USART1EN (1 << 14)
341#define RCC_APB2ENR_SPI1EN (1 << 12)
342#define RCC_APB2ENR_TIM1EN (1 << 11)
343#define RCC_APB2ENR_ADCEN (1 << 9)
344#define RCC_APB2ENR_SYSCFGCOMPEN (1 << 0)
349#define RCC_APB1ENR_CECEN (1 << 30)
350#define RCC_APB1ENR_DACEN (1 << 29)
351#define RCC_APB1ENR_PWREN (1 << 28)
352#define RCC_APB1ENR_USBEN (1 << 23)
353#define RCC_APB1ENR_I2C2EN (1 << 22)
354#define RCC_APB1ENR_I2C1EN (1 << 21)
355#define RCC_APB1ENR_USART2EN (1 << 17)
356#define RCC_APB1ENR_SPI3EN (1 << 15)
357#define RCC_APB1ENR_SPI2EN (1 << 14)
358#define RCC_APB1ENR_WWDGEN (1 << 11)
359#define RCC_APB1ENR_TIM14EN (1 << 8)
360#define RCC_APB1ENR_TIM6EN (1 << 4)
361#define RCC_APB1ENR_TIM3EN (1 << 1)
362#define RCC_APB1ENR_TIM2EN (1 << 0)
367#define RCC_BDCR_BDRST (1 << 16)
368#define RCC_BDCR_RTCEN (1 << 15)
370#define RCC_BDCR_LSEBYP (1 << 2)
371#define RCC_BDCR_LSERDY (1 << 1)
372#define RCC_BDCR_LSEON (1 << 0)
376#define RCC_CSR_LPWRRSTF (1 << 31)
377#define RCC_CSR_WWDGRSTF (1 << 30)
378#define RCC_CSR_IWDGRSTF (1 << 29)
379#define RCC_CSR_SFTRSTF (1 << 28)
380#define RCC_CSR_PORRSTF (1 << 27)
381#define RCC_CSR_PINRSTF (1 << 26)
382#define RCC_CSR_RMVF (1 << 24)
383#define RCC_CSR_LSIRDY (1 << 1)
384#define RCC_CSR_LSION (1 << 0)
388#define RCC_AHBRSTR_ETHMACRST (1 << 14)
389#define RCC_AHBRSTR_OTGFSRST (1 << 12)
394#define RCC_CFGR2_PREDIV 0xf
395#define RCC_CFGR2_PREDIV_NODIV 0x0
396#define RCC_CFGR2_PREDIV_DIV2 0x1
397#define RCC_CFGR2_PREDIV_DIV3 0x2
398#define RCC_CFGR2_PREDIV_DIV4 0x3
399#define RCC_CFGR2_PREDIV_DIV5 0x4
400#define RCC_CFGR2_PREDIV_DIV6 0x5
401#define RCC_CFGR2_PREDIV_DIV7 0x6
402#define RCC_CFGR2_PREDIV_DIV8 0x7
403#define RCC_CFGR2_PREDIV_DIV9 0x8
404#define RCC_CFGR2_PREDIV_DIV10 0x9
405#define RCC_CFGR2_PREDIV_DIV11 0xa
406#define RCC_CFGR2_PREDIV_DIV12 0xb
407#define RCC_CFGR2_PREDIV_DIV13 0xc
408#define RCC_CFGR2_PREDIV_DIV14 0xd
409#define RCC_CFGR2_PREDIV_DIV15 0xe
410#define RCC_CFGR2_PREDIV_DIV16 0xf
414#define RCC_CFGR3_USART2SW_SHIFT 16
415#define RCC_CFGR3_USART2SW (3 << RCC_CFGR3_USART2SW_SHIFT)
416#define RCC_CFGR3_USART2SW_PCLK (0 << RCC_CFGR3_USART2SW_SHIFT)
417#define RCC_CFGR3_USART2SW_SYSCLK (1 << RCC_CFGR3_USART2SW_SHIFT)
418#define RCC_CFGR3_USART2SW_LSE (2 << RCC_CFGR3_USART2SW_SHIFT)
419#define RCC_CFGR3_USART2SW_HSI (3 << RCC_CFGR3_USART2SW_SHIFT)
421#define RCC_CFGR3_ADCSW (1 << 8)
422#define RCC_CFGR3_CECSW (1 << 6)
463#define _REG_BIT(base, bit) (((base) << 5) + (bit))
int rcc_osc_ready_int_flag(enum rcc_osc osc)
RCC Read the Oscillator Ready Interrupt Flag.
int rcc_css_int_flag(void)
RCC Read the Clock Security System Interrupt Flag.
const struct rcc_clock_scale rcc_hse8_configs[RCC_CLOCK_HSE8_END]
void rcc_set_adcpre(uint32_t adcpre)
ADC Setup the A/D Clock.
void rcc_set_rtc_clock_source(enum rcc_osc clock_source)
RCC Set the Source for the RTC clock.
void rcc_osc_ready_int_clear(enum rcc_osc osc)
RCC Clear the Oscillator Ready Interrupt Flag.
void rcc_css_disable(void)
RCC Disable the Clock Security System.
void rcc_set_sysclk_source(uint32_t clk)
RCC Set the Source for the System Clock.
uint32_t rcc_apb2_frequency
void rcc_set_pll_source(uint32_t pllsrc)
RCC Set the PLL Clock Source.
uint32_t rcc_system_clock_source(void)
RCC Get the System Clock Source.
void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
Setup clocks to run from PLL.
const struct rcc_clock_scale rcc_hsi_configs[RCC_CLOCK_HSI_END]
void rcc_set_prediv(uint32_t prediv)
void rcc_osc_ready_int_enable(enum rcc_osc osc)
RCC Enable the Oscillator Ready Interrupt.
void rcc_set_ppre2(uint32_t ppre1)
RCC Set the APB2 Prescale Factor.
void rcc_osc_ready_int_disable(enum rcc_osc osc)
RCC Disable the Oscillator Ready Interrupt.
void rcc_osc_on(enum rcc_osc osc)
RCC Turn on an Oscillator.
#define _REG_BIT(base, bit)
uint32_t rcc_ahb_frequency
void rcc_osc_off(enum rcc_osc osc)
RCC Turn off an Oscillator.
void rcc_set_pll_multiplication_factor(uint32_t mul)
RCC Set the PLL Multiplication Factor.
void rcc_backupdomain_reset(void)
RCC Reset the Backup Domain.
uint32_t rcc_apb1_frequency
Set the default clock frequencies.
void rcc_set_ppre1(uint32_t ppre1)
RCC Set the APB1 Prescale Factor.
void rcc_css_int_clear(void)
RCC Clear the Clock Security System Interrupt Flag.
void rcc_enable_rtc_clock(void)
RCC Enable the RTC clock.
void rcc_set_usbpre(uint32_t usbpre)
RCC Set the USB Prescale Factor.
void rcc_css_enable(void)
RCC Enable the Clock Security System.
void rcc_set_hpre(uint32_t hpre)
RCC Set the AHB Prescale Factor.
void rcc_set_pllxtpre(uint32_t pllxtpre)
RCC Set the HSE Frequency Divider used as PLL Clock Source.
uint32_t rcc_rtc_clock_enabled_flag(void)
RCC RTC Clock Enabled Flag.