51#ifndef LIBOPENCM3_RCC_H
52#define LIBOPENCM3_RCC_H
58#define RCC_CR MMIO32(RCC_BASE + 0x00)
59#define RCC_CFGR MMIO32(RCC_BASE + 0x04)
60#define RCC_CIR MMIO32(RCC_BASE + 0x08)
61#define RCC_APB2RSTR MMIO32(RCC_BASE + 0x0C)
62#define RCC_APB1RSTR MMIO32(RCC_BASE + 0x10)
63#define RCC_AHBENR MMIO32(RCC_BASE + 0x14)
64#define RCC_APB2ENR MMIO32(RCC_BASE + 0x18)
65#define RCC_APB1ENR MMIO32(RCC_BASE + 0x1C)
66#define RCC_BDCR MMIO32(RCC_BASE + 0x20)
67#define RCC_CSR MMIO32(RCC_BASE + 0x24)
68#define RCC_AHBRSTR MMIO32(RCC_BASE + 0x28)
69#define RCC_CFGR2 MMIO32(RCC_BASE + 0x2C)
70#define RCC_CFGR3 MMIO32(RCC_BASE + 0x30)
74#define RCC_CR_PLLRDY (1 << 25)
75#define RCC_CR_PLLON (1 << 24)
76#define RCC_CR_CSSON (1 << 19)
77#define RCC_CR_HSEBYP (1 << 18)
78#define RCC_CR_HSERDY (1 << 17)
79#define RCC_CR_HSEON (1 << 16)
82#define RCC_CR_HSIRDY (1 << 1)
83#define RCC_CR_HSION (1 << 0)
86#define RCC_CFGR_MCOF (1 << 28)
87#define RCC_CFGR_I2SSRC (1 << 23)
88#define RCC_CFGR_USBPRES (1 << 22)
89#define RCC_CFGR_PLLXTPRE (1 << 17)
90#define RCC_CFGR_PLLSRC (1 << 16)
93#define RCC_CFGR_MCO_SHIFT 24
94#define RCC_CFGR_MCO_MASK 0x7
95#define RCC_CFGR_MCO_NOCLK 0x0
97#define RCC_CFGR_MCO_LSI 0x2
98#define RCC_CFGR_MCO_LSE 0x3
99#define RCC_CFGR_MCO_SYSCLK 0x4
100#define RCC_CFGR_MCO_HSI 0x5
101#define RCC_CFGR_MCO_HSE 0x6
102#define RCC_CFGR_MCO_PLL 0x7
105#define RCC_CFGR_PLLSRC_HSI_DIV2 0
106#define RCC_CFGR_PLLSRC_HSE_PREDIV 1
109#define RCC_CFGR_PLLMUL_SHIFT 18
110#define RCC_CFGR_PLLMUL_MASK 0xF
111#define RCC_CFGR_PLLMUL_MUL2 0x0
112#define RCC_CFGR_PLLMUL_MUL3 0x1
113#define RCC_CFGR_PLLMUL_MUL4 0x2
114#define RCC_CFGR_PLLMUL_MUL5 0x3
115#define RCC_CFGR_PLLMUL_MUL6 0x4
116#define RCC_CFGR_PLLMUL_MUL7 0x5
117#define RCC_CFGR_PLLMUL_MUL8 0x6
118#define RCC_CFGR_PLLMUL_MUL9 0x7
119#define RCC_CFGR_PLLMUL_MUL10 0x8
120#define RCC_CFGR_PLLMUL_MUL11 0x9
121#define RCC_CFGR_PLLMUL_MUL12 0xA
122#define RCC_CFGR_PLLMUL_MUL13 0xB
123#define RCC_CFGR_PLLMUL_MUL14 0xC
124#define RCC_CFGR_PLLMUL_MUL15 0xD
125#define RCC_CFGR_PLLMUL_MUL16 0xE
127#define RCC_CFGR_PPRE2_SHIFT 11
128#define RCC_CFGR_PPRE2_MASK 0x7
129#define RCC_CFGR_PPRE1_SHIFT 8
130#define RCC_CFGR_PPRE1_MASK 0x7
135#define RCC_CFGR_PPRE_NODIV 0x0
136#define RCC_CFGR_PPRE_DIV2 0x4
137#define RCC_CFGR_PPRE_DIV4 0x5
138#define RCC_CFGR_PPRE_DIV8 0x6
139#define RCC_CFGR_PPRE_DIV16 0x7
142#define RCC_CFGR_HPRE_SHIFT 4
143#define RCC_CFGR_HPRE_MASK 0xf
146#define RCC_CFGR_HPRE_NODIV 0x0
147#define RCC_CFGR_HPRE_DIV2 0x8
148#define RCC_CFGR_HPRE_DIV4 0x9
149#define RCC_CFGR_HPRE_DIV8 0xA
150#define RCC_CFGR_HPRE_DIV16 0xB
151#define RCC_CFGR_HPRE_DIV64 0xC
152#define RCC_CFGR_HPRE_DIV128 0xD
153#define RCC_CFGR_HPRE_DIV256 0xE
154#define RCC_CFGR_HPRE_DIV512 0xF
158#define RCC_CFGR_SWS_SHIFT 2
159#define RCC_CFGR_SWS_MASK 0x3
160#define RCC_CFGR_SWS_HSI 0x0
161#define RCC_CFGR_SWS_HSE 0x1
162#define RCC_CFGR_SWS_PLL 0x2
165#define RCC_CFGR_SW_SHIFT 0
166#define RCC_CFGR_SW_HSI 0x0
167#define RCC_CFGR_SW_HSE 0x1
168#define RCC_CFGR_SW_PLL 0x2
175#define RCC_CFGR_PPRE2_DIV_NONE 0x0
176#define RCC_CFGR_PPRE2_DIV_2 0x4
177#define RCC_CFGR_PPRE2_DIV_4 0x5
178#define RCC_CFGR_PPRE2_DIV_8 0x6
179#define RCC_CFGR_PPRE2_DIV_16 0x7
181#define RCC_CFGR_PPRE1_DIV_NONE 0x0
182#define RCC_CFGR_PPRE1_DIV_2 0x4
183#define RCC_CFGR_PPRE1_DIV_4 0x5
184#define RCC_CFGR_PPRE1_DIV_8 0x6
185#define RCC_CFGR_PPRE1_DIV_16 0x7
187#define RCC_CFGR_HPRE_DIV_NONE 0x0
188#define RCC_CFGR_HPRE_DIV_2 0x8
189#define RCC_CFGR_HPRE_DIV_4 0x9
190#define RCC_CFGR_HPRE_DIV_8 0xA
191#define RCC_CFGR_HPRE_DIV_16 0xB
192#define RCC_CFGR_HPRE_DIV_64 0xC
193#define RCC_CFGR_HPRE_DIV_128 0xD
194#define RCC_CFGR_HPRE_DIV_256 0xE
195#define RCC_CFGR_HPRE_DIV_512 0xF
201#define RCC_CIR_CSSC (1 << 23)
204#define RCC_CIR_PLLRDYC (1 << 20)
205#define RCC_CIR_HSERDYC (1 << 19)
206#define RCC_CIR_HSIRDYC (1 << 18)
207#define RCC_CIR_LSERDYC (1 << 17)
208#define RCC_CIR_LSIRDYC (1 << 16)
211#define RCC_CIR_PLLRDYIE (1 << 12)
212#define RCC_CIR_HSERDYIE (1 << 11)
213#define RCC_CIR_HSIRDYIE (1 << 10)
214#define RCC_CIR_LSERDYIE (1 << 9)
215#define RCC_CIR_LSIRDYIE (1 << 8)
218#define RCC_CIR_CSSF (1 << 7)
221#define RCC_CIR_PLLRDYF (1 << 4)
222#define RCC_CIR_HSERDYF (1 << 3)
223#define RCC_CIR_HSIRDYF (1 << 2)
224#define RCC_CIR_LSERDYF (1 << 1)
225#define RCC_CIR_LSIRDYF (1 << 0)
229#define RCC_APB2RSTR_TIM20RST (1 << 20)
230#define RCC_APB2RSTR_TIM17RST (1 << 18)
231#define RCC_APB2RSTR_TIM16RST (1 << 17)
232#define RCC_APB2RSTR_TIM15RST (1 << 16)
233#define RCC_APB2RSTR_SPI4RST (1 << 15)
234#define RCC_APB2RSTR_USART1RST (1 << 14)
235#define RCC_APB2RSTR_TIM8RST (1 << 13)
236#define RCC_APB2RSTR_SPI1RST (1 << 12)
237#define RCC_APB2RSTR_TIM1RST (1 << 11)
238#define RCC_APB2RSTR_SYSCFGRST (1 << 0)
243#define RCC_APB1RSTR_I2C3RST (1 << 30)
244#define RCC_APB1RSTR_DAC1RST (1 << 29)
245#define RCC_APB1RSTR_PWRRST (1 << 28)
246#define RCC_APB1RSTR_DAC2RST (1 << 26)
247#define RCC_APB1RSTR_CAN1RST (1 << 25)
248#define RCC_APB1RSTR_USBRST (1 << 23)
249#define RCC_APB1RSTR_I2C2RST (1 << 22)
250#define RCC_APB1RSTR_I2C1RST (1 << 21)
251#define RCC_APB1RSTR_UART5RST (1 << 20)
252#define RCC_APB1RSTR_UART4RST (1 << 19)
253#define RCC_APB1RSTR_USART3RST (1 << 18)
254#define RCC_APB1RSTR_USART2RST (1 << 17)
255#define RCC_APB1RSTR_SPI3RST (1 << 15)
256#define RCC_APB1RSTR_SPI2RST (1 << 14)
257#define RCC_APB1RSTR_WWDGRST (1 << 11)
258#define RCC_APB1RSTR_TIM7RST (1 << 5)
259#define RCC_APB1RSTR_TIM6RST (1 << 4)
260#define RCC_APB1RSTR_TIM4RST (1 << 2)
261#define RCC_APB1RSTR_TIM3RST (1 << 1)
262#define RCC_APB1RSTR_TIM2RST (1 << 0)
267#define RCC_AHBENR_ADC34EN (1 << 29)
268#define RCC_AHBENR_ADC12EN (1 << 28)
269#define RCC_AHBENR_TSCEN (1 << 24)
270#define RCC_AHBENR_IOPGEN (1 << 23)
271#define RCC_AHBENR_IOPFEN (1 << 22)
272#define RCC_AHBENR_IOPEEN (1 << 21)
273#define RCC_AHBENR_IOPDEN (1 << 20)
274#define RCC_AHBENR_IOPCEN (1 << 19)
275#define RCC_AHBENR_IOPBEN (1 << 18)
276#define RCC_AHBENR_IOPAEN (1 << 17)
277#define RCC_AHBENR_IOPHEN (1 << 16)
278#define RCC_AHBENR_CRCEN (1 << 6)
279#define RCC_AHBENR_FMCEN (1 << 5)
280#define RCC_AHBENR_FLITFEN (1 << 4)
281#define RCC_AHBENR_SRAMEN (1 << 2)
282#define RCC_AHBENR_DMA2EN (1 << 1)
283#define RCC_AHBENR_DMA1EN (1 << 0)
288#define RCC_APB2ENR_TIM20EN (1 << 20)
289#define RCC_APB2ENR_TIM17EN (1 << 18)
290#define RCC_APB2ENR_TIM16EN (1 << 17)
291#define RCC_APB2ENR_TIM15EN (1 << 16)
292#define RCC_APB2ENR_SPI4EN (1 << 15)
293#define RCC_APB2ENR_USART1EN (1 << 14)
294#define RCC_APB2ENR_TIM8EN (1 << 13)
295#define RCC_APB2ENR_SPI1EN (1 << 12)
296#define RCC_APB2ENR_TIM1EN (1 << 11)
297#define RCC_APB2ENR_SYSCFGEN (1 << 0)
302#define RCC_APB1ENR_I2C3EN (1 << 30)
303#define RCC_APB1ENR_DAC1EN (1 << 29)
304#define RCC_APB1ENR_PWREN (1 << 28)
305#define RCC_APB1ENR_DAC2EN (1 << 26)
306#define RCC_APB1ENR_CANEN (1 << 25)
307#define RCC_APB1ENR_USBEN (1 << 23)
308#define RCC_APB1ENR_I2C2EN (1 << 22)
309#define RCC_APB1ENR_I2C1EN (1 << 21)
310#define RCC_APB1ENR_USART5EN (1 << 20)
311#define RCC_APB1ENR_USART4EN (1 << 19)
312#define RCC_APB1ENR_USART3EN (1 << 18)
313#define RCC_APB1ENR_USART2EN (1 << 17)
314#define RCC_APB1ENR_SPI3EN (1 << 15)
315#define RCC_APB1ENR_SPI2EN (1 << 14)
316#define RCC_APB1ENR_WWDGEN (1 << 11)
317#define RCC_APB1ENR_TIM7EN (1 << 5)
318#define RCC_APB1ENR_TIM6EN (1 << 4)
319#define RCC_APB1ENR_TIM4EN (1 << 2)
320#define RCC_APB1ENR_TIM3EN (1 << 1)
321#define RCC_APB1ENR_TIM2EN (1 << 0)
326#define RCC_BDCR_BDRST (1 << 16)
327#define RCC_BDCR_RTCEN (1 << 15)
330#define RCC_BDCR_LSEBYP (1 << 2)
331#define RCC_BDCR_LSERDY (1 << 1)
332#define RCC_BDCR_LSEON (1 << 0)
336#define RCC_CSR_LPWRRSTF (1 << 31)
337#define RCC_CSR_WWDGRSTF (1 << 30)
338#define RCC_CSR_IWDGRSTF (1 << 29)
339#define RCC_CSR_SFTRSTF (1 << 28)
340#define RCC_CSR_PORRSTF (1 << 27)
341#define RCC_CSR_PINRSTF (1 << 26)
342#define RCC_CSR_OBLRSTF (1 << 25)
343#define RCC_CSR_RMVF (1 << 24)
344#define RCC_CSR_LSIRDY (1 << 1)
345#define RCC_CSR_LSION (1 << 0)
349#define RCC_AHBRSTR_ADC34RST (1 << 29)
350#define RCC_AHBRSTR_ADC12RST (1 << 28)
351#define RCC_AHBRSTR_TSCRST (1 << 24)
352#define RCC_AHBRSTR_IOPGRST (1 << 23)
353#define RCC_AHBRSTR_IOPFRST (1 << 22)
354#define RCC_AHBRSTR_IOPERST (1 << 21)
355#define RCC_AHBRSTR_IOPDRST (1 << 20)
356#define RCC_AHBRSTR_IOPCRST (1 << 19)
357#define RCC_AHBRSTR_IOPBRST (1 << 18)
358#define RCC_AHBRSTR_IOPARST (1 << 17)
359#define RCC_AHBRSTR_IOPHRST (1 << 16)
360#define RCC_AHBRSTR_FMCRST (1 << 5)
365#define RCC_CFGR2_ADC34PRES_SHIFT 9
366#define RCC_CFGR2_ADC12PRES_SHIFT 4
367#define RCC_CFGR2_ADCxPRES_MASK 0x1f
368#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_1 0x10
369#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_2 0x11
370#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_4 0x12
371#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_6 0x13
372#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_8 0x14
373#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_10 0x15
374#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_12 0x16
375#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_16 0x17
376#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_32 0x18
377#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_64 0x19
378#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_128 0x1A
379#define RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_256 0x1B
381#define RCC_CFGR2_PREDIV 0xf
385#define RCC_CFGR2_PREDIV_NODIV 0x0
386#define RCC_CFGR2_PREDIV_DIV2 0x1
387#define RCC_CFGR2_PREDIV_DIV3 0x2
388#define RCC_CFGR2_PREDIV_DIV4 0x3
389#define RCC_CFGR2_PREDIV_DIV5 0x4
390#define RCC_CFGR2_PREDIV_DIV6 0x5
391#define RCC_CFGR2_PREDIV_DIV7 0x6
392#define RCC_CFGR2_PREDIV_DIV8 0x7
393#define RCC_CFGR2_PREDIV_DIV9 0x8
394#define RCC_CFGR2_PREDIV_DIV10 0x9
395#define RCC_CFGR2_PREDIV_DIV11 0xa
396#define RCC_CFGR2_PREDIV_DIV12 0xb
397#define RCC_CFGR2_PREDIV_DIV13 0xc
398#define RCC_CFGR2_PREDIV_DIV14 0xd
399#define RCC_CFGR2_PREDIV_DIV15 0xe
400#define RCC_CFGR2_PREDIV_DIV16 0xf
404#define RCC_CFGR3_TIM8SW (1 << 9)
405#define RCC_CFGR3_TIM1SW (1 << 8)
406#define RCC_CFGR3_I2C2SW (1 << 5)
407#define RCC_CFGR3_I2C1SW (1 << 4)
411#define RCC_CFGR3_UART5SW_SHIFT 22
412#define RCC_CFGR3_UART4SW_SHIFT 20
413#define RCC_CFGR3_UART3SW_SHIFT 18
414#define RCC_CFGR3_UART2SW_SHIFT 16
415#define RCC_CFGR3_UART1SW_SHIFT 0
422#define RCC_CFGR3_UARTxSW_PCLK 0x0
423#define RCC_CFGR3_UARTxSW_SYSCLK 0x1
424#define RCC_CFGR3_UARTxSW_LSE 0x2
425#define RCC_CFGR3_UARTxSW_HSI 0x3
429#define RCC_CFGR3_UARTxSW_MASK 0x3
472#define _REG_BIT(base, bit) (((base) << 5) + (bit))
#define _REG_BIT(base, bit)
int rcc_osc_ready_int_flag(enum rcc_osc osc)
int rcc_css_int_flag(void)
void rcc_set_i2c_clock_sysclk(uint32_t i2c)
void rcc_osc_ready_int_clear(enum rcc_osc osc)
void rcc_css_disable(void)
uint32_t rcc_get_spi_clk_freq(uint32_t spi)
Get the peripheral clock speed for the SPI device at base specified.
void rcc_set_sysclk_source(uint32_t clk)
const struct rcc_clock_scale rcc_hsi_configs[RCC_CLOCK_HSI_END]
uint32_t rcc_apb2_frequency
void rcc_set_pll_source(uint32_t pllsrc)
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
const struct rcc_clock_scale rcc_hse8mhz_configs[RCC_CLOCK_HSE8_END]
void rcc_usb_prescale_1(void)
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
Setup clocks to run from PLL.
void rcc_set_prediv(uint32_t prediv)
Set PLL Source pre-divider CAUTION.
void rcc_osc_ready_int_enable(enum rcc_osc osc)
void rcc_usb_prescale_1_5(void)
void rcc_osc_ready_int_disable(enum rcc_osc osc)
void rcc_osc_on(enum rcc_osc osc)
uint32_t rcc_ahb_frequency
void rcc_osc_off(enum rcc_osc osc)
uint32_t rcc_get_system_clock_source(void)
uint32_t rcc_get_i2c_clk_freq(uint32_t i2c)
Get the peripheral clock speed for the I2C device at base specified.
void rcc_set_pll_multiplier(uint32_t pll)
void rcc_backupdomain_reset(void)
uint32_t rcc_apb1_frequency
void rcc_wait_for_sysclk_status(enum rcc_osc osc)
void rcc_adc_prescale(uint32_t prescale1, uint32_t prescale2)
uint32_t rcc_get_i2c_clocks(void)
void rcc_set_ppre1(uint32_t ppre1)
void rcc_css_int_clear(void)
void rcc_set_ppre2(uint32_t ppre2)
void rcc_set_i2c_clock_hsi(uint32_t i2c)
void rcc_css_enable(void)
void rcc_set_hpre(uint32_t hpre)
void rcc_wait_for_osc_not_ready(enum rcc_osc osc)
void rcc_clock_setup_hsi(const struct rcc_clock_scale *clock)
uint32_t flash_waitstates