libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
f3/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 STM32F3xx Reset and Clock
4 * Control</b>
5 *
6 * @ingroup STM32F3xx_defines
7 *
8 * @author @htmlonly &copy; @endhtmlonly 2009
9 * Federico Ruiz-Ugalde <memeruiz at gmail dot com>
10 * @author @htmlonly &copy; @endhtmlonly 2009
11 * Uwe Hermann <uwe@hermann-uwe.de>
12 * @author @htmlonly &copy; @endhtmlonly 2011
13 * Fergus Noble <fergusnoble@gmail.com>
14 * @author @htmlonly &copy; @endhtmlonly 2011
15 * Stephen Caudle <scaudle@doceme.com>
16 * @author @htmlonly &copy; @endhtmlonly 2013
17 * Fernando Cortes <fernando.corcam@gmail.com>
18 * @author @htmlonly &copy; @endhtmlonly 2013
19 * Guillermo Rivera <memogrg@gmail.com>
20 *
21 * @version 1.0.0
22 *
23 * @date 11 July 2013
24 *
25 * LGPL License Terms @ref lgpl_license
26 */
27/*
28 * This file is part of the libopencm3 project.
29 *
30 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
31 * Copyright (C) 2009 Federico Ruiz-Ugalde <memeruiz at gmail dot com>
32 * Copyright (C) 2011 Fergus Noble <fergusnoble@gmail.com>
33 * Copyright (C) 2011 Stephen Caudle <scaudle@doceme.com>
34 * Modified by 2013 Fernando Cortes <fernando.corcam@gmail.com> (stm32f3)
35 * Modified by 2013 Guillermo Rivera <memogrg@gmail.com> (stm32f3)
36 *
37 * This library is free software: you can redistribute it and/or modify
38 * it under the terms of the GNU Lesser General Public License as published by
39 * the Free Software Foundation, either version 3 of the License, or
40 * (at your option) any later version.
41 *
42 * This library is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU Lesser General Public License for more details.
46 *
47 * You should have received a copy of the GNU Lesser General Public License
48 * along with this library. If not, see <http://www.gnu.org/licenses/>.
49 */
50
51#ifndef LIBOPENCM3_RCC_H
52#define LIBOPENCM3_RCC_H
53
54#include <stdbool.h>
55
56/* --- RCC registers ------------------------------------------------------- */
57
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)
71
72/* --- RCC_CR values ------------------------------------------------------- */
73
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)
80/* HSICAL: [15:8] */
81/* HSITRIM: [7:3] */
82#define RCC_CR_HSIRDY (1 << 1)
83#define RCC_CR_HSION (1 << 0)
84
85/* --- RCC_CFGR values ----------------------------------------------------- */
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)
91
92/* MCO: Microcontroller clock output */
93#define RCC_CFGR_MCO_SHIFT 24
94#define RCC_CFGR_MCO_MASK 0x7
95#define RCC_CFGR_MCO_NOCLK 0x0
96/*Reserve RCC_CFGR_MCO 0x1*/
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
103
104/* PLLSRC: PLL source values */
105#define RCC_CFGR_PLLSRC_HSI_DIV2 0
106#define RCC_CFGR_PLLSRC_HSE_PREDIV 1
107
108/* PLLMUL: PLL multiplication factor */
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
126
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
131/** @defgroup rcc_cfgr_apbxpre RCC_CFGR APBx prescale factors
132 * These can be used for both APB1 and APB2 prescaling
133 * @{
134 */
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
140/**@}*/
141
142#define RCC_CFGR_HPRE_SHIFT 4
143#define RCC_CFGR_HPRE_MASK 0xf
144/** @defgroup rcc_cfgr_ahbpre RCC_CFGR AHB prescale factors
145@{*/
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
155/**@}*/
156
157/* SWS: System clock switch status */
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
163
164/* SW: System clock switch */
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
169
170/** Older compatible definitions to ease migration
171 * @defgroup rcc_cfgr_deprecated RCC_CFGR Deprecated dividers
172 * @deprecated Use _CFGR_xPRE_DIVn form instead, across all families
173 * @{
174 */
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
180
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
186
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
196/**@}*/
197
198/* --- RCC_CIR values ------------------------------------------------------ */
199
200/* Clock security system interrupt clear bit */
201#define RCC_CIR_CSSC (1 << 23)
202
203/* OSC ready interrupt clear bits */
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)
209
210/* OSC ready interrupt enable bits */
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)
216
217/* Clock security system interrupt flag bit */
218#define RCC_CIR_CSSF (1 << 7)
219
220/* OSC ready interrupt flag bits */
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)
226
227/** @defgroup rcc_apb2rstr_rst RCC_APB2RSTR reset values
228@{*/
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)
239/**@}*/
240
241/** @defgroup rcc_apb1rstr_rst RCC_APB1RSTR reset values
242@{*/
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)
263/**@}*/
264
265/** @defgroup rcc_ahbenr_en RCC_AHBENR enable values
266 *@{*/
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)
284/**@}*/
285
286/** @defgroup rcc_apb2enr_en RCC_APB2ENR enable values
287@{*/
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)
298/**@}*/
299
300/** @defgroup rcc_apb1enr_en RCC_APB1ENR enable values
301@{*/
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)
322/**@}*/
323
324/* --- RCC_BDCR values ----------------------------------------------------- */
325
326#define RCC_BDCR_BDRST (1 << 16)
327#define RCC_BDCR_RTCEN (1 << 15)
328/* RCC_BDCR[9:8]: RTCSEL */
329/* RCC_BDCR[4:3]: LSEDRV */
330#define RCC_BDCR_LSEBYP (1 << 2)
331#define RCC_BDCR_LSERDY (1 << 1)
332#define RCC_BDCR_LSEON (1 << 0)
333
334/* --- RCC_CSR values ------------------------------------------------------ */
335
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)
346
347/** @defgroup rcc_ahbrstr_rst RCC_AHBxRSTR reset values (full set)
348@{*/
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)
361/**@}*/
362
363/* --- RCC_CFGR2 values ---------------------------------------------------- */
364/* ADCxxPRES: ADCxx prescaler */
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
380
381#define RCC_CFGR2_PREDIV 0xf
382/** @defgroup rcc_cfgr2_prediv PLL source predividers
383@ingroup rcc_defines
384@{*/
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
401/**@}*/
402
403/* --- RCC_CFGR3 values ---------------------------------------------------- */
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)
408/** @defgroup rcc_cfgr3_uart_choices UART for clock sour selecting
409 * @{
410 */
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
416/**@}*/
417
418/** @defgroup rcc_cfgr3_uart_clksel UART Clock source selections
419 * @note This is only used internally.
420 * @{
421 */
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
426/**@}*/
427
428/* Shared mask for UART clock source. */
429#define RCC_CFGR3_UARTxSW_MASK 0x3
430
431
432/* --- Variable definitions ------------------------------------------------ */
433extern uint32_t rcc_ahb_frequency;
434extern uint32_t rcc_apb1_frequency;
435extern uint32_t rcc_apb2_frequency;
436
437/* --- Function prototypes ------------------------------------------------- */
438
441 RCC_CLOCK_HSI_64MHZ, /* Max from HSI */
448
449
451 uint8_t pllsrc;
452 uint8_t pllmul;
453 uint8_t plldiv;
456 uint8_t hpre;
457 uint8_t ppre1;
458 uint8_t ppre2;
459 uint8_t power_save;
463};
464
467
471
472#define _REG_BIT(base, bit) (((base) << 5) + (bit))
473
474/* Availability in comment:
475 * 0: F30x
476 * 1: F31x
477 * 7: F37x
478 * 8: F38x
479 */
481 /* AHB peripherals*/
482 RCC_DMA1 = _REG_BIT(0x14, 0),/*0178*/
483 RCC_DMA2 = _REG_BIT(0x14, 1),/*0178*/
484 RCC_SRAM = _REG_BIT(0x14, 2),/*0178*/
485 RCC_FLTIF = _REG_BIT(0x14, 4),/*0178*/
486 RCC_FMC = _REG_BIT(0x14, 5),/*0178*/
487 RCC_CRC = _REG_BIT(0x14, 6),/*0178*/
488 RCC_GPIOH = _REG_BIT(0x14, 16),/*0178*/
489 RCC_GPIOA = _REG_BIT(0x14, 17),/*0178*/
490 RCC_GPIOB = _REG_BIT(0x14, 18),/*0178*/
491 RCC_GPIOC = _REG_BIT(0x14, 19),/*0178*/
492 RCC_GPIOD = _REG_BIT(0x14, 20),/*0178*/
493 RCC_GPIOE = _REG_BIT(0x14, 21),/*0178*/
494 RCC_GPIOF = _REG_BIT(0x14, 22),/*0178*/
495 RCC_GPIOG = _REG_BIT(0x14, 23),/*0178*/
496 RCC_TSC = _REG_BIT(0x14, 24),/*0178*/
497 RCC_ADC12 = _REG_BIT(0x14, 28),/*01--*/
498 RCC_ADC34 = _REG_BIT(0x14, 29),/*01--*/
499
500 /* APB2 peripherals */
501 RCC_SYSCFG = _REG_BIT(0x18, 0),/*0178*/
502 RCC_ADC = _REG_BIT(0x18, 9),/*--78*/
503 RCC_TIM1 = _REG_BIT(0x18, 11),/*01--*/
504 RCC_SPI1 = _REG_BIT(0x18, 12),/*0178*/
505 RCC_TIM8 = _REG_BIT(0x18, 13),/*01--*/
506 RCC_USART1 = _REG_BIT(0x18, 14),/*0178*/
507 RCC_SPI4 = _REG_BIT(0x18, 15),
508 RCC_TIM15 = _REG_BIT(0x18, 16),/*0178*/
509 RCC_TIM16 = _REG_BIT(0x18, 17),/*0178*/
510 RCC_TIM17 = _REG_BIT(0x18, 18),/*0178*/
511 RCC_TIM19 = _REG_BIT(0x18, 19),/*--78*/
512 RCC_TIM20 = _REG_BIT(0x18, 20),
513 RCC_DBGMCU = _REG_BIT(0x18, 22),/*--78*/
514 RCC_SDADC1 = _REG_BIT(0x18, 24),/*--78*/
515 RCC_SDADC2 = _REG_BIT(0x18, 25),/*--78*/
516 RCC_SDADC3 = _REG_BIT(0x18, 26),/*--78*/
517 RCC_HRTIM = _REG_BIT(0x18, 29),
518
519 /* APB1 peripherals */
520 RCC_TIM2 = _REG_BIT(0x1C, 0),/*0178*/
521 RCC_TIM3 = _REG_BIT(0x1C, 1),/*0178*/
522 RCC_TIM4 = _REG_BIT(0x1C, 2),/*0178*/
523 RCC_TIM5 = _REG_BIT(0x1C, 3),/*--78*/
524 RCC_TIM6 = _REG_BIT(0x1C, 4),/*0178*/
525 RCC_TIM7 = _REG_BIT(0x1C, 5),/*0178*/
526 RCC_TIM12 = _REG_BIT(0x1C, 6),/*--78*/
527 RCC_TIM13 = _REG_BIT(0x1C, 7),/*--78*/
528 RCC_TIM14 = _REG_BIT(0x1C, 8),/*--78*/
529 RCC_TIM18 = _REG_BIT(0x1C, 9),/*--78*/
530 RCC_WWDG = _REG_BIT(0x1C, 11),/*0178*/
531 RCC_SPI2 = _REG_BIT(0x1C, 14),/*0178*/
532 RCC_SPI3 = _REG_BIT(0x1C, 15),/*0178*/
533 RCC_USART2 = _REG_BIT(0x1C, 17),/*0178*/
534 RCC_USART3 = _REG_BIT(0x1C, 18),/*0178*/
535 RCC_UART4 = _REG_BIT(0x1C, 19),/*01--*/
536 RCC_UART5 = _REG_BIT(0x1C, 20),/*01--*/
537 RCC_I2C1 = _REG_BIT(0x1C, 21),/*0178*/
538 RCC_I2C2 = _REG_BIT(0x1C, 22),/*0178*/
539 RCC_USB = _REG_BIT(0x1C, 23),/*0178*/
540 RCC_CAN = _REG_BIT(0x1C, 25),/*0178*/
541 RCC_CAN1 = _REG_BIT(0x1C, 25),/*0178*/
542 RCC_DAC2 = _REG_BIT(0x1C, 26),
543 RCC_PWR = _REG_BIT(0x1C, 28),/*0178*/
544 RCC_DAC1 = _REG_BIT(0x1C, 29),
545 RCC_CEC = _REG_BIT(0x1C, 30),/*--78*/
546 RCC_I2C3 = _REG_BIT(0x1C, 30),
547};
548
550 /* APB2 peripherals*/
551 RST_SYSCFG = _REG_BIT(0x0C, 0),/*0178*/
552 RST_ADC = _REG_BIT(0x0C, 9),/*--78*/
553 RST_TIM1 = _REG_BIT(0x0C, 11),/*01--*/
554 RST_SPI1 = _REG_BIT(0x0C, 12),/*0178*/
555 RST_TIM8 = _REG_BIT(0x0C, 13),/*01--*/
556 RST_USART1 = _REG_BIT(0x0C, 14),/*0178*/
557 RST_SPI4 = _REG_BIT(0x0C, 15),
558 RST_TIM15 = _REG_BIT(0x0C, 16),/*0178*/
559 RST_TIM16 = _REG_BIT(0x0C, 17),/*0178*/
560 RST_TIM17 = _REG_BIT(0x0C, 18),/*0178*/
561 RST_TIM19 = _REG_BIT(0x0C, 19),/*--78*/
562 RST_TIM20 = _REG_BIT(0x0C, 20),
563 RST_SDADC1 = _REG_BIT(0x0C, 24),/*--78*/
564 RST_SDADC2 = _REG_BIT(0x0C, 25),/*--78*/
565 RST_SDADC3 = _REG_BIT(0x0C, 26),/*--78*/
566 RST_HRTIM = _REG_BIT(0x0C, 29),
567
568 /* APB1 peripherals */
569 RST_TIM2 = _REG_BIT(0x10, 0),/*0178*/
570 RST_TIM3 = _REG_BIT(0x10, 1),/*0178*/
571 RST_TIM4 = _REG_BIT(0x10, 2),/*0178*/
572 RST_TIM5 = _REG_BIT(0x10, 3),/*--78*/
573 RST_TIM6 = _REG_BIT(0x10, 4),/*0178*/
574 RST_TIM7 = _REG_BIT(0x10, 5),/*0178*/
575 RST_TIM12 = _REG_BIT(0x10, 6),/*--78*/
576 RST_TIM13 = _REG_BIT(0x10, 7),/*--78*/
577 RST_TIM14 = _REG_BIT(0x10, 8),/*--78*/
578 RST_TIM18 = _REG_BIT(0x10, 9),/*--78*/
579 RST_WWDG = _REG_BIT(0x10, 11),/*0178*/
580 RST_SPI2 = _REG_BIT(0x10, 14),/*0178*/
581 RST_SPI3 = _REG_BIT(0x10, 15),/*0178*/
582 RST_USART2 = _REG_BIT(0x10, 17),/*0178*/
583 RST_USART3 = _REG_BIT(0x10, 18),/*0178*/
584 RST_UART4 = _REG_BIT(0x10, 19),/*01--*/
585 RST_UART5 = _REG_BIT(0x10, 20),/*01--*/
586 RST_I2C1 = _REG_BIT(0x10, 21),/*0178*/
587 RST_I2C2 = _REG_BIT(0x10, 22),/*0178*/
588 RST_USB = _REG_BIT(0x10, 23),/*0178*/
589 RST_CAN = _REG_BIT(0x10, 25),/*0178*/
590 RST_CAN1 = _REG_BIT(0x10, 25),/*0178*/
591 RST_DAC2 = _REG_BIT(0x10, 26),
592 RST_PWR = _REG_BIT(0x10, 28),/*0178*/
593 RST_DAC1 = _REG_BIT(0x10, 29),
594 RST_CEC = _REG_BIT(0x10, 30),/*--78*/
595 RST_I2C3 = _REG_BIT(0x10, 30),
596
597 /* AHB peripherals */
598 RST_FMC = _REG_BIT(0x28, 5),
599 RST_GPIOH = _REG_BIT(0x28, 16),
600 RST_GPIOA = _REG_BIT(0x28, 17),/*0178*/
601 RST_GPIOB = _REG_BIT(0x28, 18),/*0178*/
602 RST_GPIOC = _REG_BIT(0x28, 19),/*0178*/
603 RST_GPIOD = _REG_BIT(0x28, 20),/*0178*/
604 RST_GPIOE = _REG_BIT(0x28, 21),/*0178*/
605 RST_GPIOF = _REG_BIT(0x28, 22),/*0178*/
606 RST_GPIOG = _REG_BIT(0x28, 23),
607 RST_TSC = _REG_BIT(0x28, 24),/*0178*/
608 RST_ADC12 = _REG_BIT(0x28, 28),/*01--*/
609 RST_ADC34 = _REG_BIT(0x28, 29),/*01--*/
610
611 /* BDCR[16] */
612 RST_BD = _REG_BIT(0x20, 16),
613};
614
615#undef _REG_BIT
616
618
620
621void rcc_osc_ready_int_clear(enum rcc_osc osc);
622void rcc_osc_ready_int_enable(enum rcc_osc osc);
624int rcc_osc_ready_int_flag(enum rcc_osc osc);
625void rcc_css_int_clear(void);
626int rcc_css_int_flag(void);
629void rcc_osc_on(enum rcc_osc osc);
630void rcc_osc_off(enum rcc_osc osc);
631void rcc_css_enable(void);
632void rcc_css_disable(void);
633void rcc_set_sysclk_source(uint32_t clk);
634void rcc_set_pll_source(uint32_t pllsrc);
635void rcc_set_ppre2(uint32_t ppre2);
636void rcc_set_ppre1(uint32_t ppre1);
637void rcc_set_hpre(uint32_t hpre);
638void rcc_set_prediv(uint32_t prediv);
639void rcc_set_pll_multiplier(uint32_t pll);
640uint32_t rcc_get_system_clock_source(void);
641void rcc_backupdomain_reset(void);
642void rcc_clock_setup_pll(const struct rcc_clock_scale *clock);
643void rcc_clock_setup_hsi(const struct rcc_clock_scale *clock);
644void rcc_set_i2c_clock_hsi(uint32_t i2c);
645void rcc_set_i2c_clock_sysclk(uint32_t i2c);
646uint32_t rcc_get_i2c_clocks(void);
647void rcc_usb_prescale_1_5(void);
648void rcc_usb_prescale_1(void);
649void rcc_adc_prescale(uint32_t prescale1, uint32_t prescale2);
650uint32_t rcc_get_usart_clk_freq(uint32_t usart);
651uint32_t rcc_get_timer_clk_freq(uint32_t timer);
652uint32_t rcc_get_i2c_clk_freq(uint32_t i2c);
653uint32_t rcc_get_spi_clk_freq(uint32_t spi);
654
656
657#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
rcc_periph_rst
Definition: f3/rcc.h:549
@ RST_TIM18
Definition: f3/rcc.h:578
@ RST_SPI4
Definition: f3/rcc.h:557
@ RST_SPI1
Definition: f3/rcc.h:554
@ RST_I2C3
Definition: f3/rcc.h:595
@ RST_TIM19
Definition: f3/rcc.h:561
@ RST_CEC
Definition: f3/rcc.h:594
@ RST_ADC12
Definition: f3/rcc.h:608
@ RST_GPIOG
Definition: f3/rcc.h:606
@ RST_SDADC1
Definition: f3/rcc.h:563
@ RST_TIM16
Definition: f3/rcc.h:559
@ RST_TSC
Definition: f3/rcc.h:607
@ RST_BD
Definition: f3/rcc.h:612
@ RST_TIM14
Definition: f3/rcc.h:577
@ RST_GPIOF
Definition: f3/rcc.h:605
@ RST_SPI2
Definition: f3/rcc.h:580
@ RST_GPIOH
Definition: f3/rcc.h:599
@ RST_UART4
Definition: f3/rcc.h:584
@ RST_TIM8
Definition: f3/rcc.h:555
@ RST_TIM15
Definition: f3/rcc.h:558
@ RST_TIM3
Definition: f3/rcc.h:570
@ RST_TIM17
Definition: f3/rcc.h:560
@ RST_TIM12
Definition: f3/rcc.h:575
@ RST_GPIOA
Definition: f3/rcc.h:600
@ RST_GPIOC
Definition: f3/rcc.h:602
@ RST_TIM6
Definition: f3/rcc.h:573
@ RST_GPIOB
Definition: f3/rcc.h:601
@ RST_TIM1
Definition: f3/rcc.h:553
@ RST_SPI3
Definition: f3/rcc.h:581
@ RST_USART3
Definition: f3/rcc.h:583
@ RST_ADC
Definition: f3/rcc.h:552
@ RST_TIM20
Definition: f3/rcc.h:562
@ RST_TIM13
Definition: f3/rcc.h:576
@ RST_TIM7
Definition: f3/rcc.h:574
@ RST_HRTIM
Definition: f3/rcc.h:566
@ RST_TIM2
Definition: f3/rcc.h:569
@ RST_SDADC2
Definition: f3/rcc.h:564
@ RST_GPIOD
Definition: f3/rcc.h:603
@ RST_USB
Definition: f3/rcc.h:588
@ RST_CAN
Definition: f3/rcc.h:589
@ RST_SDADC3
Definition: f3/rcc.h:565
@ RST_ADC34
Definition: f3/rcc.h:609
@ RST_TIM4
Definition: f3/rcc.h:571
@ RST_TIM5
Definition: f3/rcc.h:572
@ RST_SYSCFG
Definition: f3/rcc.h:551
@ RST_UART5
Definition: f3/rcc.h:585
@ RST_GPIOE
Definition: f3/rcc.h:604
@ RST_I2C2
Definition: f3/rcc.h:587
@ RST_CAN1
Definition: f3/rcc.h:590
@ RST_PWR
Definition: f3/rcc.h:592
@ RST_USART1
Definition: f3/rcc.h:556
@ RST_WWDG
Definition: f3/rcc.h:579
@ RST_DAC2
Definition: f3/rcc.h:591
@ RST_I2C1
Definition: f3/rcc.h:586
@ RST_DAC1
Definition: f3/rcc.h:593
@ RST_FMC
Definition: f3/rcc.h:598
@ RST_USART2
Definition: f3/rcc.h:582
rcc_periph_clken
Definition: f3/rcc.h:480
@ RCC_TIM8
Definition: f3/rcc.h:505
@ RCC_UART5
Definition: f3/rcc.h:536
@ RCC_TIM19
Definition: f3/rcc.h:511
@ RCC_CAN
Definition: f3/rcc.h:540
@ RCC_FMC
Definition: f3/rcc.h:486
@ RCC_SPI2
Definition: f3/rcc.h:531
@ RCC_WWDG
Definition: f3/rcc.h:530
@ RCC_TIM3
Definition: f3/rcc.h:521
@ RCC_TIM1
Definition: f3/rcc.h:503
@ RCC_GPIOA
Definition: f3/rcc.h:489
@ RCC_CEC
Definition: f3/rcc.h:545
@ RCC_TIM17
Definition: f3/rcc.h:510
@ RCC_ADC34
Definition: f3/rcc.h:498
@ RCC_TIM20
Definition: f3/rcc.h:512
@ RCC_TIM2
Definition: f3/rcc.h:520
@ RCC_GPIOG
Definition: f3/rcc.h:495
@ RCC_SDADC2
Definition: f3/rcc.h:515
@ RCC_GPIOH
Definition: f3/rcc.h:488
@ RCC_CAN1
Definition: f3/rcc.h:541
@ RCC_PWR
Definition: f3/rcc.h:543
@ RCC_CRC
Definition: f3/rcc.h:487
@ RCC_HRTIM
Definition: f3/rcc.h:517
@ RCC_TIM14
Definition: f3/rcc.h:528
@ RCC_USART1
Definition: f3/rcc.h:506
@ RCC_DAC1
Definition: f3/rcc.h:544
@ RCC_TIM4
Definition: f3/rcc.h:522
@ RCC_I2C1
Definition: f3/rcc.h:537
@ RCC_SRAM
Definition: f3/rcc.h:484
@ RCC_TIM13
Definition: f3/rcc.h:527
@ RCC_ADC12
Definition: f3/rcc.h:497
@ RCC_TIM18
Definition: f3/rcc.h:529
@ RCC_TSC
Definition: f3/rcc.h:496
@ RCC_DBGMCU
Definition: f3/rcc.h:513
@ RCC_SDADC3
Definition: f3/rcc.h:516
@ RCC_USB
Definition: f3/rcc.h:539
@ RCC_DAC2
Definition: f3/rcc.h:542
@ RCC_USART2
Definition: f3/rcc.h:533
@ RCC_TIM16
Definition: f3/rcc.h:509
@ RCC_TIM12
Definition: f3/rcc.h:526
@ RCC_USART3
Definition: f3/rcc.h:534
@ RCC_TIM5
Definition: f3/rcc.h:523
@ RCC_SPI1
Definition: f3/rcc.h:504
@ RCC_SYSCFG
Definition: f3/rcc.h:501
@ RCC_I2C2
Definition: f3/rcc.h:538
@ RCC_GPIOB
Definition: f3/rcc.h:490
@ RCC_TIM7
Definition: f3/rcc.h:525
@ RCC_SDADC1
Definition: f3/rcc.h:514
@ RCC_FLTIF
Definition: f3/rcc.h:485
@ RCC_GPIOF
Definition: f3/rcc.h:494
@ RCC_GPIOC
Definition: f3/rcc.h:491
@ RCC_TIM6
Definition: f3/rcc.h:524
@ RCC_UART4
Definition: f3/rcc.h:535
@ RCC_DMA1
Definition: f3/rcc.h:482
@ RCC_SPI3
Definition: f3/rcc.h:532
@ RCC_GPIOD
Definition: f3/rcc.h:492
@ RCC_TIM15
Definition: f3/rcc.h:508
@ RCC_I2C3
Definition: f3/rcc.h:546
@ RCC_GPIOE
Definition: f3/rcc.h:493
@ RCC_ADC
Definition: f3/rcc.h:502
@ RCC_DMA2
Definition: f3/rcc.h:483
@ RCC_SPI4
Definition: f3/rcc.h:507
rcc_osc
Definition: f3/rcc.h:468
@ RCC_HSI
Definition: f3/rcc.h:469
@ RCC_LSI
Definition: f3/rcc.h:469
@ RCC_PLL
Definition: f3/rcc.h:469
@ RCC_LSE
Definition: f3/rcc.h:469
@ RCC_HSE
Definition: f3/rcc.h:469
rcc_clock_hsi
Definition: f3/rcc.h:439
@ RCC_CLOCK_HSI_48MHZ
Definition: f3/rcc.h:440
@ RCC_CLOCK_HSI_END
Definition: f3/rcc.h:442
@ RCC_CLOCK_HSI_64MHZ
Definition: f3/rcc.h:441
#define _REG_BIT(base, bit)
Definition: f3/rcc.h:472
rcc_clock_hse8
Definition: f3/rcc.h:444
@ RCC_CLOCK_HSE8_72MHZ
Definition: f3/rcc.h:445
@ RCC_CLOCK_HSE8_END
Definition: f3/rcc.h:446
int rcc_osc_ready_int_flag(enum rcc_osc osc)
Definition: rcc.c:151
int rcc_css_int_flag(void)
Definition: rcc.c:179
void rcc_set_i2c_clock_sysclk(uint32_t i2c)
Definition: rcc.c:460
void rcc_osc_ready_int_clear(enum rcc_osc osc)
Definition: rcc.c:88
void rcc_css_disable(void)
Definition: rcc.c:280
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:573
void rcc_set_sysclk_source(uint32_t clk)
Definition: rcc.c:285
const struct rcc_clock_scale rcc_hsi_configs[RCC_CLOCK_HSI_END]
Definition: rcc.c:47
uint32_t rcc_apb2_frequency
Definition: rcc.c:45
void rcc_set_pll_source(uint32_t pllsrc)
Definition: rcc.c:294
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
Definition: rcc.c:537
const struct rcc_clock_scale rcc_hse8mhz_configs[RCC_CLOCK_HSE8_END]
Definition: rcc.c:72
void rcc_usb_prescale_1(void)
Definition: rcc.c:480
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
Definition: rcc.c:517
void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
Setup clocks to run from PLL.
Definition: rcc.c:363
void rcc_set_prediv(uint32_t prediv)
Set PLL Source pre-divider CAUTION.
Definition: rcc.c:336
void rcc_osc_ready_int_enable(enum rcc_osc osc)
Definition: rcc.c:109
void rcc_usb_prescale_1_5(void)
Definition: rcc.c:475
void rcc_osc_ready_int_disable(enum rcc_osc osc)
Definition: rcc.c:130
void rcc_osc_on(enum rcc_osc osc)
Definition: rcc.c:233
uint32_t rcc_ahb_frequency
Definition: rcc.c:43
void rcc_osc_off(enum rcc_osc osc)
Definition: rcc.c:254
uint32_t rcc_get_system_clock_source(void)
Definition: rcc.c:351
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:555
void rcc_set_pll_multiplier(uint32_t pll)
Definition: rcc.c:341
void rcc_backupdomain_reset(void)
Definition: rcc.c:441
uint32_t rcc_apb1_frequency
Definition: rcc.c:44
void rcc_wait_for_sysclk_status(enum rcc_osc osc)
Definition: rcc.c:212
void rcc_adc_prescale(uint32_t prescale1, uint32_t prescale2)
Definition: rcc.c:485
uint32_t rcc_get_i2c_clocks(void)
Definition: rcc.c:470
void rcc_set_ppre1(uint32_t ppre1)
Definition: rcc.c:312
void rcc_css_int_clear(void)
Definition: rcc.c:174
void rcc_set_ppre2(uint32_t ppre2)
Definition: rcc.c:303
void rcc_set_i2c_clock_hsi(uint32_t i2c)
Definition: rcc.c:450
void rcc_css_enable(void)
Definition: rcc.c:275
void rcc_set_hpre(uint32_t hpre)
Definition: rcc.c:321
void rcc_wait_for_osc_not_ready(enum rcc_osc osc)
Definition: rcc.c:207
void rcc_clock_setup_hsi(const struct rcc_clock_scale *clock)
Definition: rcc.c:404
uint8_t ppre1
Definition: f3/rcc.h:457
uint8_t ppre2
Definition: f3/rcc.h:458
uint32_t apb1_frequency
Definition: f3/rcc.h:461
uint8_t pllsrc
Definition: f3/rcc.h:451
uint8_t power_save
Definition: f3/rcc.h:459
uint32_t ahb_frequency
Definition: f3/rcc.h:460
uint8_t pllmul
Definition: f3/rcc.h:452
bool usbdiv1
Definition: f3/rcc.h:454
uint8_t hpre
Definition: f3/rcc.h:456
uint32_t apb2_frequency
Definition: f3/rcc.h:462
uint32_t flash_waitstates
Definition: f3/rcc.h:455
uint8_t plldiv
Definition: f3/rcc.h:453