libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
gd32/f1x0/rcc.h
Go to the documentation of this file.
1/** @defgroup rcc_defines RCC Defines
2 *
3 * @brief <b>Defined Constants and Types for the GD32F1x0 Reset and Clock
4 * Control</b>
5 *
6 * @ingroup GD32F1x0_defines
7 *
8 * @version 1.0.0
9 *
10 * @author @htmlonly &copy; @endhtmlonly 2009
11 * Federico Ruiz-Ugalde <memeruiz at gmail dot com>
12 * @author @htmlonly &copy; @endhtmlonly 2009
13 * Uwe Hermann <uwe@hermann-uwe.de>
14 *
15 * @date 18 August 2012
16 *
17 * LGPL License Terms @ref lgpl_license
18 * */
19/*
20 * This file is part of the libopencm3 project.
21 *
22 * Copyright (C) 2019 Icenowy Zheng <icenowy@aosc.io>
23 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
24 * Copyright (C) 2009 Federico Ruiz-Ugalde <memeruiz at gmail dot com>
25 *
26 * This library is free software: you can redistribute it and/or modify
27 * it under the terms of the GNU Lesser General Public License as published by
28 * the Free Software Foundation, either version 3 of the License, or
29 * (at your option) any later version.
30 *
31 * This library is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU Lesser General Public License for more details.
35 *
36 * You should have received a copy of the GNU Lesser General Public License
37 * along with this library. If not, see <http://www.gnu.org/licenses/>.
38 */
39/**@{*/
40
41#ifndef LIBOPENCM3_RCC_H
42#define LIBOPENCM3_RCC_H
43
44/* --- RCC registers ------------------------------------------------------- */
45
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)
60
61
62/* --- RCC_CR values ------------------------------------------------------- */
63
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)
70/* HSICAL: [15:8] */
71/* HSITRIM: [7:3] */
72#define RCC_CR_HSIRDY (1 << 1)
73#define RCC_CR_HSION (1 << 0)
74
75/* --- RCC_CFGR values ----------------------------------------------------- */
76
77#define RCC_CFGR_PLLNODIV (1 << 31)
78
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)
89
90#define RCC_CFGR_PLLMUL_4_SHIFT 27
91#define RCC_CFGR_PLLMUL_4 (1 << RCC_CFGR_PLLMUL_4_SHIFT)
92
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
103
104#define RCC_CFGR_USBPRE_SHIFT 22
105#define RCC_CFGR_USBPRE (3 << RCC_CFGR_USBPRE_SHIFT)
106
107#define RCC_CFGR_PLLMUL_0_3_SHIFT 18
108#define RCC_CFGR_PLLMUL_0_3 (0xF << RCC_CFGR_PLLMUL_0_3_SHIFT)
109
110#define RCC_CFGR_PLLXTPRE (1 << 17)
111#define RCC_CFGR_PLLSRC (1 << 16)
112
113#define RCC_CFGR_ADCPRE_SHIFT 14
114#define RCC_CFGR_ADCPRE (3 << RCC_CFGR_ADCPRE_SHIFT)
115
116#define RCC_CFGR_PPRE2_SHIFT 11
117#define RCC_CFGR_PPRE2 (7 << RCC_CFGR_PPRE2_SHIFT)
118
119#define RCC_CFGR_PPRE1_SHIFT 8
120#define RCC_CFGR_PPRE1 (7 << RCC_CFGR_PPRE1_SHIFT)
121
122#define RCC_CFGR_HPRE_SHIFT 4
123#define RCC_CFGR_HPRE (0xF << RCC_CFGR_HPRE_SHIFT)
124
125#define RCC_CFGR_SWS_SHIFT 2
126#define RCC_CFGR_SWS (3 << RCC_CFGR_SWS_SHIFT)
127
128#define RCC_CFGR_SW_SHIFT 0
129#define RCC_CFGR_SW (3 << RCC_CFGR_SW_SHIFT)
130
131/** @defgroup rcc_cfgr_usbpre USBPRE: USB prescaler (RCC_CFGR[23:22])
132 * @{
133 */
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
138/**@}*/
139
140/** @defgroup rcc_cfgr_pmf PLLMUL: PLL multiplication factor
141 * @{
142 */
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
158/**@}*/
159
160/** @defgroup rcc_cfgr_hsepre PLLXTPRE: HSE divider for PLL entry
161 * @{
162 */
163#define RCC_CFGR_PLLXTPRE_HSE_CLK 0x0
164#define RCC_CFGR_PLLXTPRE_HSE_CLK_DIV2 0x1
165/**@}*/
166
167/** @defgroup rcc_cfgr_pcs PLLSRC: PLL entry clock source
168 * @{
169 */
170#define RCC_CFGR_PLLSRC_HSI_CLK_DIV2 0x0
171#define RCC_CFGR_PLLSRC_HSE_CLK 0x1
172/**@}*/
173
174/** @defgroup rcc_cfgr_adcpre ADCPRE: ADC prescaler
175 * @{
176 */
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
181/**@}*/
182
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
187/** @defgroup rcc_cfgr_apbxpre RCC_CFGR APBx prescale factors
188 * These can be used for both APB1 and APB2 prescaling
189 * @{
190 */
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
196/**@}*/
197
198/** @defgroup rcc_cfgr_ahbpre HPRE: AHB prescaler
199 * @{
200 */
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
210/**@}*/
211
212/* SWS: System clock switch status */
213#define RCC_CFGR_SWS_SYSCLKSEL_HSICLK 0x0
214#define RCC_CFGR_SWS_SYSCLKSEL_HSECLK 0x1
215#define RCC_CFGR_SWS_SYSCLKSEL_PLLCLK 0x2
216
217/** @defgroup rcc_cfgr_scs SW: System clock switch
218 * @{
219 */
220#define RCC_CFGR_SW_SYSCLKSEL_HSICLK 0x0
221#define RCC_CFGR_SW_SYSCLKSEL_HSECLK 0x1
222#define RCC_CFGR_SW_SYSCLKSEL_PLLCLK 0x2
223/**@}*/
224
225/** Older compatible definitions to ease migration
226 * @defgroup rcc_cfgr_deprecated RCC_CFGR Deprecated dividers
227 * @deprecated Use _CFGR_xPRE_DIVn form instead, across all families
228 * @{
229 */
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
234
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
240
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
246
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
256/**@}*/
257
258/* --- RCC_CIR values ------------------------------------------------------ */
259
260/* Clock security system interrupt clear bit */
261#define RCC_CIR_CSSC (1 << 23)
262
263/* OSC ready interrupt clear bits */
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)
270
271/* OSC ready interrupt enable bits */
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)
278
279/* Clock security system interrupt flag bit */
280#define RCC_CIR_CSSF (1 << 7)
281
282/* OSC ready interrupt flag bits */
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)
289
290/** @defgroup rcc_apb2rstr_rst RCC_APB2RSTR reset values values
291@{*/
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)
300/**@}*/
301
302/** @defgroup rcc_apb1rstr_rst RCC_APB1RSTR reset values values
303@{*/
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)
318/**@}*/
319
320/** @defgroup rcc_ahbenr_en RCC_AHBENR enable values
321@{*/
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)
333/**@}*/
334
335/** @defgroup rcc_apb2enr_en RCC_APB2ENR enable values
336@{*/
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)
345/**@}*/
346
347/** @defgroup rcc_apb1enr_en RCC_APB1ENR enable values
348@{*/
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)
363/**@}*/
364
365/* --- RCC_BDCR values ----------------------------------------------------- */
366
367#define RCC_BDCR_BDRST (1 << 16)
368#define RCC_BDCR_RTCEN (1 << 15)
369/* RCC_BDCR[9:8]: RTCSEL */
370#define RCC_BDCR_LSEBYP (1 << 2)
371#define RCC_BDCR_LSERDY (1 << 1)
372#define RCC_BDCR_LSEON (1 << 0)
373
374/* --- RCC_CSR values ------------------------------------------------------ */
375
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)
385
386/** @defgroup rcc_ahbrstr_rst RCC_AHBRSTR reset values values
387@{*/
388#define RCC_AHBRSTR_ETHMACRST (1 << 14)
389#define RCC_AHBRSTR_OTGFSRST (1 << 12)
390/**@}*/
391
392/* --- RCC_CFGR2 values ---------------------------------------------------- */
393
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
411
412/* --- RCC_CFGR3 values ---------------------------------------------------- */
413
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)
420
421#define RCC_CFGR3_ADCSW (1 << 8)
422#define RCC_CFGR3_CECSW (1 << 6)
423
424/* --- Variable definitions ------------------------------------------------ */
425extern uint32_t rcc_ahb_frequency;
426extern uint32_t rcc_apb1_frequency;
427extern uint32_t rcc_apb2_frequency;
428
429/* --- Function prototypes ------------------------------------------------- */
430
436
441
443 uint8_t pllmul;
444 uint8_t hpre;
445 uint8_t ppre1;
446 uint8_t ppre2;
447 uint8_t adcpre;
448 uint8_t usbpre; /* Only valid if HSE used */
449 bool use_hse; /* PLL source is HSE if set, HSI/2 if unset */
450 uint8_t pll_hse_prediv; /* Only valid if HSE used */
454};
455
458
462
463#define _REG_BIT(base, bit) (((base) << 5) + (bit))
464
465/* V = value line F100
466 * N = standard line F101, F102, F103
467 * C = communication line F105, F107
468 */
470
471 /* AHB peripherals */
472 RCC_DMA = _REG_BIT(0x14, 0),
473 RCC_SRAM = _REG_BIT(0x14, 2),
474 RCC_FLTF = _REG_BIT(0x14, 4),
475 RCC_CRC = _REG_BIT(0x14, 6),
476 RCC_GPIOA = _REG_BIT(0x14, 17),
477 RCC_GPIOB = _REG_BIT(0x14, 18),
478 RCC_GPIOC = _REG_BIT(0x14, 19),
479 RCC_GPIOD = _REG_BIT(0x14, 20),
480 RCC_GPIOF = _REG_BIT(0x14, 22),
481 RCC_TSC = _REG_BIT(0x14, 24),
482
483 /* APB2 peripherals */
485 RCC_ADC = _REG_BIT(0x18, 9),
486 RCC_TIM1 = _REG_BIT(0x18, 11),
487 RCC_SPI1 = _REG_BIT(0x18, 12),
488 RCC_USART1 = _REG_BIT(0x18, 14),
489 RCC_TIM15 = _REG_BIT(0x18, 16),
490 RCC_TIM16 = _REG_BIT(0x18, 17),
491 RCC_TIM17 = _REG_BIT(0x18, 18),
492
493 /* APB1 peripherals */
494 RCC_TIM2 = _REG_BIT(0x1C, 0),
495 RCC_TIM3 = _REG_BIT(0x1C, 1),
496 RCC_TIM6 = _REG_BIT(0x1C, 4),
497 RCC_TIM14 = _REG_BIT(0x1C, 8),
498 RCC_WWDG = _REG_BIT(0x1C, 11),
499 RCC_SPI2 = _REG_BIT(0x1C, 14),
500 RCC_SPI3 = _REG_BIT(0x1C, 15),
501 RCC_USART2 = _REG_BIT(0x1C, 17),
502 RCC_I2C1 = _REG_BIT(0x1C, 21),
503 RCC_I2C2 = _REG_BIT(0x1C, 22),
504 RCC_USB = _REG_BIT(0x1C, 23),
505 RCC_PWR = _REG_BIT(0x1C, 28),
506 RCC_DAC = _REG_BIT(0x1C, 29),
507 RCC_CEC = _REG_BIT(0x1C, 30),
508};
509
511
512 /* Advanced peripherals */
513 RST_BACKUPDOMAIN = _REG_BIT(0x20, 16),/* BDCR[16] */
514
515 /* AHB peripherals */
516 RST_GPIOA = _REG_BIT(0x28, 17),
517 RST_GPIOB = _REG_BIT(0x28, 18),
518 RST_GPIOC = _REG_BIT(0x28, 19),
519 RST_GPIOD = _REG_BIT(0x28, 20),
520 RST_GPIOE = _REG_BIT(0x28, 21),
521 RST_GPIOF = _REG_BIT(0x28, 22),
522 RST_TSC = _REG_BIT(0x28, 24),
523
524 /* APB2 peripherals */
526 RST_ADC = _REG_BIT(0x0C, 9),
527 RST_TIM1 = _REG_BIT(0x0C, 11),
528 RST_SPI1 = _REG_BIT(0x0C, 12),
529 RST_USART1 = _REG_BIT(0x0C, 14),
530 RST_TIM15 = _REG_BIT(0x0C, 16),
531 RST_TIM16 = _REG_BIT(0x0C, 17),
532 RST_TIM17 = _REG_BIT(0x0C, 18),
533
534 /* APB1 peripherals */
535 RST_TIM2 = _REG_BIT(0x10, 0),
536 RST_TIM3 = _REG_BIT(0x10, 1),
537 RST_TIM6 = _REG_BIT(0x10, 4),
538 RST_TIM14 = _REG_BIT(0x10, 8),
539 RST_WWDG = _REG_BIT(0x10, 11),
540 RST_SPI2 = _REG_BIT(0x10, 14),
541 RST_SPI3 = _REG_BIT(0x10, 15),
542 RST_USART2 = _REG_BIT(0x10, 17),
543 RST_I2C1 = _REG_BIT(0x10, 21),
544 RST_I2C2 = _REG_BIT(0x10, 22),
545 RST_USB = _REG_BIT(0x10, 23),
546 RST_PWR = _REG_BIT(0x10, 28),
547 RST_DAC = _REG_BIT(0x10, 29),
548 RST_CEC = _REG_BIT(0x10, 30),
549};
550
552
554
555void rcc_osc_ready_int_clear(enum rcc_osc osc);
556void rcc_osc_ready_int_enable(enum rcc_osc osc);
558int rcc_osc_ready_int_flag(enum rcc_osc osc);
559void rcc_css_int_clear(void);
560int rcc_css_int_flag(void);
561void rcc_osc_on(enum rcc_osc osc);
562void rcc_osc_off(enum rcc_osc osc);
563void rcc_css_enable(void);
564void rcc_css_disable(void);
565void rcc_set_sysclk_source(uint32_t clk);
566void rcc_set_pll_multiplication_factor(uint32_t mul);
567void rcc_set_pll_source(uint32_t pllsrc);
568void rcc_set_pllxtpre(uint32_t pllxtpre);
569uint32_t rcc_rtc_clock_enabled_flag(void);
570void rcc_enable_rtc_clock(void);
571void rcc_set_rtc_clock_source(enum rcc_osc clock_source);
572void rcc_set_adcpre(uint32_t adcpre);
573void rcc_set_ppre2(uint32_t ppre1);
574void rcc_set_ppre1(uint32_t ppre1);
575void rcc_set_hpre(uint32_t hpre);
576void rcc_set_usbpre(uint32_t usbpre);
577void rcc_set_prediv(uint32_t prediv);
578uint32_t rcc_system_clock_source(void);
579void rcc_clock_setup_pll(const struct rcc_clock_scale *clock);
580void rcc_backupdomain_reset(void);
581
583
584#endif
585/**@}*/
586
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
int rcc_osc_ready_int_flag(enum rcc_osc osc)
RCC Read the Oscillator Ready Interrupt Flag.
Definition: rcc.c:194
int rcc_css_int_flag(void)
RCC Read the Clock Security System Interrupt Flag.
Definition: rcc.c:233
const struct rcc_clock_scale rcc_hse8_configs[RCC_CLOCK_HSE8_END]
Definition: rcc.c:87
void rcc_set_adcpre(uint32_t adcpre)
ADC Setup the A/D Clock.
Definition: rcc.c:487
void rcc_set_rtc_clock_source(enum rcc_osc clock_source)
RCC Set the Source for the RTC clock.
Definition: rcc.c:438
void rcc_osc_ready_int_clear(enum rcc_osc osc)
RCC Clear the Oscillator Ready Interrupt Flag.
Definition: rcc.c:112
void rcc_css_disable(void)
RCC Disable the Clock Security System.
Definition: rcc.c:351
void rcc_set_sysclk_source(uint32_t clk)
RCC Set the Source for the System Clock.
Definition: rcc.c:362
uint32_t rcc_apb2_frequency
Definition: rcc.c:59
void rcc_set_pll_source(uint32_t pllsrc)
RCC Set the PLL Clock Source.
Definition: rcc.c:391
uint32_t rcc_system_clock_source(void)
RCC Get the System Clock Source.
Definition: rcc.c:563
void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
Setup clocks to run from PLL.
Definition: rcc.c:581
rcc_periph_rst
const struct rcc_clock_scale rcc_hsi_configs[RCC_CLOCK_HSI_END]
Definition: rcc.c:62
rcc_periph_clken
void rcc_set_prediv(uint32_t prediv)
Definition: rcc.c:549
void rcc_osc_ready_int_enable(enum rcc_osc osc)
RCC Enable the Oscillator Ready Interrupt.
Definition: rcc.c:139
rcc_osc
void rcc_set_ppre2(uint32_t ppre1)
RCC Set the APB2 Prescale Factor.
Definition: rcc.c:499
rcc_clock_hsi
void rcc_osc_ready_int_disable(enum rcc_osc osc)
RCC Disable the Oscillator Ready Interrupt.
Definition: rcc.c:166
void rcc_osc_on(enum rcc_osc osc)
RCC Turn on an Oscillator.
Definition: rcc.c:280
#define _REG_BIT(base, bit)
uint32_t rcc_ahb_frequency
Definition: rcc.c:60
void rcc_osc_off(enum rcc_osc osc)
RCC Turn off an Oscillator.
Definition: rcc.c:315
void rcc_set_pll_multiplication_factor(uint32_t mul)
RCC Set the PLL Multiplication Factor.
Definition: rcc.c:376
void rcc_backupdomain_reset(void)
RCC Reset the Backup Domain.
Definition: rcc.c:644
uint32_t rcc_apb1_frequency
Set the default clock frequencies.
Definition: rcc.c:58
void rcc_set_ppre1(uint32_t ppre1)
RCC Set the APB1 Prescale Factor.
Definition: rcc.c:513
void rcc_css_int_clear(void)
RCC Clear the Clock Security System Interrupt Flag.
Definition: rcc.c:222
void rcc_enable_rtc_clock(void)
RCC Enable the RTC clock.
Definition: rcc.c:427
rcc_clock_hse8
void rcc_set_usbpre(uint32_t usbpre)
RCC Set the USB Prescale Factor.
Definition: rcc.c:544
void rcc_css_enable(void)
RCC Enable the Clock Security System.
Definition: rcc.c:341
void rcc_set_hpre(uint32_t hpre)
RCC Set the AHB Prescale Factor.
Definition: rcc.c:526
void rcc_set_pllxtpre(uint32_t pllxtpre)
RCC Set the HSE Frequency Divider used as PLL Clock Source.
Definition: rcc.c:405
uint32_t rcc_rtc_clock_enabled_flag(void)
RCC RTC Clock Enabled Flag.
Definition: rcc.c:417
@ RST_SPI1
@ RST_CEC
@ RST_TIM16
@ RST_TSC
@ RST_TIM14
@ RST_GPIOF
@ RST_SPI2
@ RST_TIM15
@ RST_TIM3
@ RST_TIM17
@ RST_GPIOA
@ RST_GPIOC
@ RST_TIM6
@ RST_GPIOB
@ RST_TIM1
@ RST_SPI3
@ RST_DAC
@ RST_ADC
@ RST_TIM2
@ RST_GPIOD
@ RST_USB
@ RST_SYSCFG
@ RST_GPIOE
@ RST_I2C2
@ RST_PWR
@ RST_BACKUPDOMAIN
@ RST_USART1
@ RST_WWDG
@ RST_I2C1
@ RST_USART2
@ RCC_SPI2
@ RCC_WWDG
@ RCC_TIM3
@ RCC_TIM1
@ RCC_SYSCFG_COMP
@ RCC_GPIOA
@ RCC_CEC
@ RCC_DMA
@ RCC_TIM17
@ RCC_TIM2
@ RCC_PWR
@ RCC_CRC
@ RCC_TIM14
@ RCC_USART1
@ RCC_I2C1
@ RCC_SRAM
@ RCC_TSC
@ RCC_FLTF
@ RCC_USB
@ RCC_USART2
@ RCC_TIM16
@ RCC_SPI1
@ RCC_I2C2
@ RCC_GPIOB
@ RCC_GPIOF
@ RCC_GPIOC
@ RCC_TIM6
@ RCC_SPI3
@ RCC_DAC
@ RCC_GPIOD
@ RCC_TIM15
@ RCC_ADC
@ RCC_HSI
@ RCC_LSI
@ RCC_PLL
@ RCC_LSE
@ RCC_HSE
@ RCC_CLOCK_HSI_48MHZ
@ RCC_CLOCK_HSI_END
@ RCC_CLOCK_HSI_64MHZ
@ RCC_CLOCK_HSE8_72MHZ
@ RCC_CLOCK_HSE8_END
uint32_t apb1_frequency
uint32_t ahb_frequency
uint8_t pll_hse_prediv
uint32_t apb2_frequency