48#ifndef LIBOPENCM3_RCC_H
49#define LIBOPENCM3_RCC_H
55#define RCC_CR MMIO32(RCC_BASE + 0x00)
56#define RCC_ICSCR MMIO32(RCC_BASE + 0x04)
57#define RCC_CFGR MMIO32(RCC_BASE + 0x08)
58#define RCC_CIR MMIO32(RCC_BASE + 0x0c)
59#define RCC_AHBRSTR MMIO32(RCC_BASE + 0x10)
60#define RCC_APB2RSTR MMIO32(RCC_BASE + 0x14)
61#define RCC_APB1RSTR MMIO32(RCC_BASE + 0x18)
62#define RCC_AHBENR MMIO32(RCC_BASE + 0x1c)
63#define RCC_APB2ENR MMIO32(RCC_BASE + 0x20)
64#define RCC_APB1ENR MMIO32(RCC_BASE + 0x24)
65#define RCC_AHBLPENR MMIO32(RCC_BASE + 0x28)
66#define RCC_APB2LPENR MMIO32(RCC_BASE + 0x2c)
67#define RCC_APB1LPENR MMIO32(RCC_BASE + 0x30)
68#define RCC_CSR MMIO32(RCC_BASE + 0x34)
72#define RCC_CR_RTCPRE_SHIFT 29
73#define RCC_CR_RTCPRE_MASK 0x3
74#define RCC_CR_CSSON (1 << 28)
75#define RCC_CR_PLLRDY (1 << 25)
76#define RCC_CR_PLLON (1 << 24)
77#define RCC_CR_HSEBYP (1 << 18)
78#define RCC_CR_HSERDY (1 << 17)
79#define RCC_CR_HSEON (1 << 16)
80#define RCC_CR_MSIRDY (1 << 9)
81#define RCC_CR_MSION (1 << 8)
82#define RCC_CR_HSIRDY (1 << 1)
83#define RCC_CR_HSION (1 << 0)
85#define RCC_CR_RTCPRE_DIV2 0
86#define RCC_CR_RTCPRE_DIV4 1
87#define RCC_CR_RTCPRE_DIV8 2
88#define RCC_CR_RTCPRE_DIV16 3
89#define RCC_CR_RTCPRE_SHIFT 29
90#define RCC_CR_RTCPRE_MASK 0x3
96#define RCC_ICSCR_MSITRIM_SHIFT 24
97#define RCC_ICSCR_MSITRIM_MASK 0xff
98#define RCC_ICSCR_MSICAL_SHIFT 16
99#define RCC_ICSCR_MSICAL_MASK 0xff
101#define RCC_ICSCR_MSIRANGE_SHIFT 13
102#define RCC_ICSCR_MSIRANGE_MASK 0x7
106#define RCC_ICSCR_MSIRANGE_65KHZ 0x0
107#define RCC_ICSCR_MSIRANGE_131KHZ 0x1
108#define RCC_ICSCR_MSIRANGE_262KHZ 0x2
109#define RCC_ICSCR_MSIRANGE_524KHZ 0x3
110#define RCC_ICSCR_MSIRANGE_1MHZ 0x4
111#define RCC_ICSCR_MSIRANGE_2MHZ 0x5
112#define RCC_ICSCR_MSIRANGE_4MHZ 0x6
114#define RCC_ICSCR_HSITRIM_SHIFT 8
115#define RCC_ICSCR_HSITRIM_MASK 0x1f
116#define RCC_ICSCR_HSICAL_SHIFT 0
117#define RCC_ICSCR_HSICAL_MASK 0xff
123#define RCC_CFGR_MCOPRE_DIV1 0
124#define RCC_CFGR_MCOPRE_DIV2 1
125#define RCC_CFGR_MCOPRE_DIV4 2
126#define RCC_CFGR_MCOPRE_DIV8 3
127#define RCC_CFGR_MCOPRE_DIV16 4
128#define RCC_CFGR_MCOPRE_SHIFT 28
129#define RCC_CFGR_MCOPRE_MASK 0x7
132#define RCC_CFGR_MCO_NOCLK 0x0
133#define RCC_CFGR_MCO_SYSCLK 0x1
134#define RCC_CFGR_MCO_HSI 0x2
135#define RCC_CFGR_MCO_MSI 0x3
136#define RCC_CFGR_MCO_HSE 0x4
137#define RCC_CFGR_MCO_PLL 0x5
138#define RCC_CFGR_MCO_LSI 0x6
139#define RCC_CFGR_MCO_LSE 0x7
140#define RCC_CFGR_MCO_SHIFT 24
141#define RCC_CFGR_MCO_MASK 0x7
144#define RCC_CFGR_PLLDIV_DIV2 0x1
145#define RCC_CFGR_PLLDIV_DIV3 0x2
146#define RCC_CFGR_PLLDIV_DIV4 0x3
147#define RCC_CFGR_PLLDIV_SHIFT 22
148#define RCC_CFGR_PLLDIV_MASK 0x3
151#define RCC_CFGR_PLLMUL_MUL3 0x0
152#define RCC_CFGR_PLLMUL_MUL4 0x1
153#define RCC_CFGR_PLLMUL_MUL6 0x2
154#define RCC_CFGR_PLLMUL_MUL8 0x3
155#define RCC_CFGR_PLLMUL_MUL12 0x4
156#define RCC_CFGR_PLLMUL_MUL16 0x5
157#define RCC_CFGR_PLLMUL_MUL24 0x6
158#define RCC_CFGR_PLLMUL_MUL32 0x7
159#define RCC_CFGR_PLLMUL_MUL48 0x8
160#define RCC_CFGR_PLLMUL_SHIFT 18
161#define RCC_CFGR_PLLMUL_MASK 0xf
164#define RCC_CFGR_PLLSRC_HSI_CLK 0x0
165#define RCC_CFGR_PLLSRC_HSE_CLK 0x1
167#define RCC_CFGR_PPRE2_SHIFT 11
168#define RCC_CFGR_PPRE2_MASK 0x7
169#define RCC_CFGR_PPRE1_SHIFT 8
170#define RCC_CFGR_PPRE1_MASK 0x7
175#define RCC_CFGR_PPRE_NODIV 0x0
176#define RCC_CFGR_PPRE_DIV2 0x4
177#define RCC_CFGR_PPRE_DIV4 0x5
178#define RCC_CFGR_PPRE_DIV8 0x6
179#define RCC_CFGR_PPRE_DIV16 0x7
184#define RCC_CFGR_HPRE_NODIV 0x0
185#define RCC_CFGR_HPRE_DIV2 0x8
186#define RCC_CFGR_HPRE_DIV4 0x9
187#define RCC_CFGR_HPRE_DIV8 0xa
188#define RCC_CFGR_HPRE_DIV16 0xb
189#define RCC_CFGR_HPRE_DIV64 0xc
190#define RCC_CFGR_HPRE_DIV128 0xd
191#define RCC_CFGR_HPRE_DIV256 0xe
192#define RCC_CFGR_HPRE_DIV512 0xf
194#define RCC_CFGR_HPRE_MASK 0xf
195#define RCC_CFGR_HPRE_SHIFT 4
198#define RCC_CFGR_SWS_SYSCLKSEL_MSICLK 0x0
199#define RCC_CFGR_SWS_SYSCLKSEL_HSICLK 0x1
200#define RCC_CFGR_SWS_SYSCLKSEL_HSECLK 0x2
201#define RCC_CFGR_SWS_SYSCLKSEL_PLLCLK 0x3
202#define RCC_CFGR_SWS_MASK 0x3
203#define RCC_CFGR_SWS_SHIFT 2
206#define RCC_CFGR_SW_SYSCLKSEL_MSICLK 0x0
207#define RCC_CFGR_SW_SYSCLKSEL_HSICLK 0x1
208#define RCC_CFGR_SW_SYSCLKSEL_HSECLK 0x2
209#define RCC_CFGR_SW_SYSCLKSEL_PLLCLK 0x3
210#define RCC_CFGR_SW_MASK 0x3
211#define RCC_CFGR_SW_SHIFT 0
218#define RCC_CFGR_PPRE2_HCLK_NODIV 0x0
219#define RCC_CFGR_PPRE2_HCLK_DIV2 0x4
220#define RCC_CFGR_PPRE2_HCLK_DIV4 0x5
221#define RCC_CFGR_PPRE2_HCLK_DIV8 0x6
222#define RCC_CFGR_PPRE2_HCLK_DIV16 0x7
224#define RCC_CFGR_PPRE1_HCLK_NODIV 0x0
225#define RCC_CFGR_PPRE1_HCLK_DIV2 0x4
226#define RCC_CFGR_PPRE1_HCLK_DIV4 0x5
227#define RCC_CFGR_PPRE1_HCLK_DIV8 0x6
228#define RCC_CFGR_PPRE1_HCLK_DIV16 0x7
230#define RCC_CFGR_HPRE_SYSCLK_NODIV 0x0
231#define RCC_CFGR_HPRE_SYSCLK_DIV2 0x8
232#define RCC_CFGR_HPRE_SYSCLK_DIV4 0x9
233#define RCC_CFGR_HPRE_SYSCLK_DIV8 0xa
234#define RCC_CFGR_HPRE_SYSCLK_DIV16 0xb
235#define RCC_CFGR_HPRE_SYSCLK_DIV64 0xc
236#define RCC_CFGR_HPRE_SYSCLK_DIV128 0xd
237#define RCC_CFGR_HPRE_SYSCLK_DIV256 0xe
238#define RCC_CFGR_HPRE_SYSCLK_DIV512 0xf
245#define RCC_CIR_CSSC (1 << 23)
248#define RCC_CIR_MSIRDYC (1 << 21)
249#define RCC_CIR_PLLRDYC (1 << 20)
250#define RCC_CIR_HSERDYC (1 << 19)
251#define RCC_CIR_HSIRDYC (1 << 18)
252#define RCC_CIR_LSERDYC (1 << 17)
253#define RCC_CIR_LSIRDYC (1 << 16)
256#define RCC_CIR_MSIRDYIE (1 << 13)
257#define RCC_CIR_PLLRDYIE (1 << 12)
258#define RCC_CIR_HSERDYIE (1 << 11)
259#define RCC_CIR_HSIRDYIE (1 << 10)
260#define RCC_CIR_LSERDYIE (1 << 9)
261#define RCC_CIR_LSIRDYIE (1 << 8)
264#define RCC_CIR_CSSF (1 << 7)
267#define RCC_CIR_MSIRDYF (1 << 5)
268#define RCC_CIR_PLLRDYF (1 << 4)
269#define RCC_CIR_HSERDYF (1 << 3)
270#define RCC_CIR_HSIRDYF (1 << 2)
271#define RCC_CIR_LSERDYF (1 << 1)
272#define RCC_CIR_LSIRDYF (1 << 0)
276#define RCC_AHBRSTR_DMA1RST (1 << 24)
277#define RCC_AHBRSTR_FLITFRST (1 << 15)
278#define RCC_AHBRSTR_CRCRST (1 << 12)
279#define RCC_AHBRSTR_GPIOHRST (1 << 5)
280#define RCC_AHBRSTR_GPIOERST (1 << 4)
281#define RCC_AHBRSTR_GPIODRST (1 << 3)
282#define RCC_AHBRSTR_GPIOCRST (1 << 2)
283#define RCC_AHBRSTR_GPIOBRST (1 << 1)
284#define RCC_AHBRSTR_GPIOARST (1 << 0)
289#define RCC_APB2RSTR_USART1RST (1 << 14)
290#define RCC_APB2RSTR_SPI1RST (1 << 12)
291#define RCC_APB2RSTR_ADC1RST (1 << 9)
292#define RCC_APB2RSTR_TIM11RST (1 << 4)
293#define RCC_APB2RSTR_TIM10RST (1 << 3)
294#define RCC_APB2RSTR_TIM9RST (1 << 2)
295#define RCC_APB2RSTR_SYSCFGRST (1 << 0)
300#define RCC_APB1RSTR_COMPRST (1 << 31)
301#define RCC_APB1RSTR_DACRST (1 << 29)
302#define RCC_APB1RSTR_PWRRST (1 << 28)
303#define RCC_APB1RSTR_USBRST (1 << 23)
304#define RCC_APB1RSTR_I2C2RST (1 << 22)
305#define RCC_APB1RSTR_I2C1RST (1 << 21)
306#define RCC_APB1RSTR_USART3RST (1 << 18)
307#define RCC_APB1RSTR_USART2RST (1 << 17)
308#define RCC_APB1RSTR_SPI2RST (1 << 14)
309#define RCC_APB1RSTR_WWDGRST (1 << 11)
310#define RCC_APB1RSTR_LCDRST (1 << 9)
311#define RCC_APB1RSTR_TIM7RST (1 << 5)
312#define RCC_APB1RSTR_TIM6RST (1 << 4)
313#define RCC_APB1RSTR_TIM5RST (1 << 3)
314#define RCC_APB1RSTR_TIM4RST (1 << 2)
315#define RCC_APB1RSTR_TIM3RST (1 << 1)
316#define RCC_APB1RSTR_TIM2RST (1 << 0)
325#define RCC_AHBENR_DMA1EN (1 << 24)
326#define RCC_AHBENR_FLITFEN (1 << 15)
327#define RCC_AHBENR_CRCEN (1 << 12)
328#define RCC_AHBENR_GPIOHEN (1 << 5)
329#define RCC_AHBENR_GPIOEEN (1 << 4)
330#define RCC_AHBENR_GPIODEN (1 << 3)
331#define RCC_AHBENR_GPIOCEN (1 << 2)
332#define RCC_AHBENR_GPIOBEN (1 << 1)
333#define RCC_AHBENR_GPIOAEN (1 << 0)
342#define RCC_APB2ENR_USART1EN (1 << 14)
343#define RCC_APB2ENR_SPI1EN (1 << 12)
344#define RCC_APB2ENR_ADC1EN (1 << 9)
345#define RCC_APB2ENR_TIM11EN (1 << 4)
346#define RCC_APB2ENR_TIM10EN (1 << 3)
347#define RCC_APB2ENR_TIM9EN (1 << 2)
348#define RCC_APB2ENR_SYSCFGEN (1 << 0)
357#define RCC_APB1ENR_COMPEN (1 << 31)
358#define RCC_APB1ENR_DACEN (1 << 29)
359#define RCC_APB1ENR_PWREN (1 << 28)
360#define RCC_APB1ENR_USBEN (1 << 23)
361#define RCC_APB1ENR_I2C2EN (1 << 22)
362#define RCC_APB1ENR_I2C1EN (1 << 21)
363#define RCC_APB1ENR_USART3EN (1 << 18)
364#define RCC_APB1ENR_USART2EN (1 << 17)
365#define RCC_APB1ENR_SPI2EN (1 << 14)
366#define RCC_APB1ENR_WWDGEN (1 << 11)
367#define RCC_APB1ENR_LCDEN (1 << 9)
368#define RCC_APB1ENR_TIM7EN (1 << 5)
369#define RCC_APB1ENR_TIM6EN (1 << 4)
370#define RCC_APB1ENR_TIM4EN (1 << 2)
371#define RCC_APB1ENR_TIM3EN (1 << 1)
372#define RCC_APB1ENR_TIM2EN (1 << 0)
376#define RCC_AHBLPENR_DMA1LPEN (1 << 24)
377#define RCC_AHBLPENR_SRAMLPEN (1 << 16)
378#define RCC_AHBLPENR_FLITFLPEN (1 << 15)
379#define RCC_AHBLPENR_CRCLPEN (1 << 12)
380#define RCC_AHBLPENR_GPIOHLPEN (1 << 5)
381#define RCC_AHBLPENR_GPIOELPEN (1 << 4)
382#define RCC_AHBLPENR_GPIODLPEN (1 << 3)
383#define RCC_AHBLPENR_GPIOCLPEN (1 << 2)
384#define RCC_AHBLPENR_GPIOBLPEN (1 << 1)
385#define RCC_AHBLPENR_GPIOALPEN (1 << 0)
387#define RCC_APB2LPENR_USART1LPEN (1 << 14)
388#define RCC_APB2LPENR_SPI1LPEN (1 << 12)
389#define RCC_APB2LPENR_ADC1LPEN (1 << 9)
390#define RCC_APB2LPENR_TIM11LPEN (1 << 4)
391#define RCC_APB2LPENR_TIM10LPEN (1 << 3)
392#define RCC_APB2LPENR_TIM9LPEN (1 << 2)
393#define RCC_APB2LPENR_SYSCFGLPEN (1 << 0)
395#define RCC_APB1LPENR_COMPLPEN (1 << 31)
396#define RCC_APB1LPENR_DACLPEN (1 << 29)
397#define RCC_APB1LPENR_PWRLPEN (1 << 28)
398#define RCC_APB1LPENR_USBLPEN (1 << 23)
399#define RCC_APB1LPENR_I2C2LPEN (1 << 22)
400#define RCC_APB1LPENR_I2C1LPEN (1 << 21)
401#define RCC_APB1LPENR_USART3LPEN (1 << 18)
402#define RCC_APB1LPENR_USART2LPEN (1 << 17)
403#define RCC_APB1LPENR_SPI2LPEN (1 << 14)
404#define RCC_APB1LPENR_WWDGLPEN (1 << 11)
405#define RCC_APB1LPENR_LCDLPEN (1 << 9)
406#define RCC_APB1LPENR_TIM7LPEN (1 << 5)
407#define RCC_APB1LPENR_TIM6LPEN (1 << 4)
408#define RCC_APB1LPENR_TIM4LPEN (1 << 2)
409#define RCC_APB1LPENR_TIM3LPEN (1 << 1)
410#define RCC_APB1LPENR_TIM2LPEN (1 << 0)
415#define RCC_CSR_LPWRRSTF (1 << 31)
416#define RCC_CSR_WWDGRSTF (1 << 30)
417#define RCC_CSR_IWDGRSTF (1 << 29)
418#define RCC_CSR_SFTRSTF (1 << 28)
419#define RCC_CSR_PORRSTF (1 << 27)
420#define RCC_CSR_PINRSTF (1 << 26)
421#define RCC_CSR_OBLRSTF (1 << 25)
422#define RCC_CSR_RMVF (1 << 24)
423#define RCC_CSR_RESET_FLAGS (RCC_CSR_LPWRRSTF | RCC_CSR_WWDGRSTF |\
424 RCC_CSR_IWDGRSTF | RCC_CSR_SFTRSTF | RCC_CSR_PORRSTF |\
425 RCC_CSR_PINRSTF | RCC_CSR_OBLRSTF)
426#define RCC_CSR_RTCRST (1 << 23)
427#define RCC_CSR_RTCEN (1 << 22)
428#define RCC_CSR_RTCSEL_SHIFT (16)
429#define RCC_CSR_RTCSEL_MASK (0x3)
430#define RCC_CSR_RTCSEL_NONE (0x0)
431#define RCC_CSR_RTCSEL_LSE (0x1)
432#define RCC_CSR_RTCSEL_LSI (0x2)
433#define RCC_CSR_RTCSEL_HSE (0x3)
434#define RCC_CSR_LSECSSD (1 << 12)
435#define RCC_CSR_LSECSSON (1 << 11)
436#define RCC_CSR_LSEBYP (1 << 10)
437#define RCC_CSR_LSERDY (1 << 9)
438#define RCC_CSR_LSEON (1 << 8)
439#define RCC_CSR_LSIRDY (1 << 1)
440#define RCC_CSR_LSION (1 << 0)
481#define _REG_BIT(base, bit) (((base) << 5) + (bit))
int rcc_osc_ready_int_flag(enum rcc_osc osc)
int rcc_css_int_flag(void)
void rcc_set_adcpre(uint32_t adcpre)
void rcc_osc_ready_int_clear(enum rcc_osc osc)
void rcc_clock_setup_msi(const struct rcc_clock_scale *clock)
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)
uint32_t rcc_apb2_frequency
void rcc_set_pll_source(uint32_t pllsrc)
void rcc_rtc_select_clock(uint32_t clock)
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
uint32_t rcc_system_clock_source(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)
void rcc_set_msi_range(uint32_t range)
Set the range of the MSI oscillator.
void rcc_set_rtcpre(uint32_t rtcpre)
void rcc_osc_ready_int_enable(enum rcc_osc osc)
void rcc_osc_ready_int_disable(enum rcc_osc osc)
void rcc_osc_on(enum rcc_osc osc)
#define _REG_BIT(base, bit)
uint32_t rcc_ahb_frequency
void rcc_osc_off(enum rcc_osc osc)
void rcc_set_pll_configuration(uint32_t source, uint32_t multiplier, uint32_t divisor)
uint32_t rcc_get_i2c_clk_freq(uint32_t i2c)
Get the peripheral clock speed for the I2C device at base specified.
const struct rcc_clock_scale rcc_clock_config[RCC_CLOCK_CONFIG_END]
void rcc_backupdomain_reset(void)
uint32_t rcc_apb1_frequency
void rcc_wait_for_sysclk_status(enum rcc_osc osc)
void rcc_set_ppre1(uint32_t ppre1)
void rcc_css_int_clear(void)
void rcc_set_ppre2(uint32_t ppre2)
void rcc_set_usbpre(uint32_t usbpre)
void rcc_css_enable(void)
void rcc_set_hpre(uint32_t hpre)
void rcc_clock_setup_hsi(const struct rcc_clock_scale *clock)
Switch sysclock to HSI with the given parameters.
@ RCC_CLOCK_VRANGE1_MSI_RAW_4MHZ
@ RCC_CLOCK_VRANGE1_HSI_RAW_4MHZ
@ RCC_CLOCK_VRANGE1_HSI_PLL_32MHZ
@ RCC_CLOCK_VRANGE1_HSI_RAW_16MHZ
@ RCC_CLOCK_VRANGE1_MSI_RAW_2MHZ
@ RCC_CLOCK_VRANGE1_HSI_PLL_24MHZ
pwr_vos_scale
Voltage scales for internal regulator.
enum pwr_vos_scale voltage_scale