libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
f0/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 STM32F0xx Reset and Clock
4Control</b>
5 *
6 * @ingroup STM32F0xx_defines
7 *
8 * @author @htmlonly &copy; @endhtmlonly 2013
9 * Frantisek Burian <BuFran@seznam.cz>
10 *
11 * @version 1.0.0
12 *
13 * @date 29 Jun 2013
14 *
15 * LGPL License Terms @ref lgpl_license
16 */
17/*
18 * This file is part of the libopencm3 project.
19 *
20 * Copyright (C) 2013 Frantisek Burian <BuFran@seznam.cz>
21 *
22 * This library is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU Lesser General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
26 *
27 * This library is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 *
32 * You should have received a copy of the GNU Lesser General Public License
33 * along with this library. If not, see <http://www.gnu.org/licenses/>.
34 */
35/**@{*/
36
37#ifndef LIBOPENCM3_RCC_H
38#define LIBOPENCM3_RCC_H
39
40/*****************************************************************************/
41/* Module definitions */
42/*****************************************************************************/
43
44/*****************************************************************************/
45/* Register definitions */
46/*****************************************************************************/
47
48#define RCC_CR MMIO32(RCC_BASE + 0x00)
49#define RCC_CFGR MMIO32(RCC_BASE + 0x04)
50#define RCC_CIR MMIO32(RCC_BASE + 0x08)
51#define RCC_APB2RSTR MMIO32(RCC_BASE + 0x0c)
52#define RCC_APB1RSTR MMIO32(RCC_BASE + 0x10)
53#define RCC_AHBENR MMIO32(RCC_BASE + 0x14)
54#define RCC_APB2ENR MMIO32(RCC_BASE + 0x18)
55#define RCC_APB1ENR MMIO32(RCC_BASE + 0x1c)
56#define RCC_BDCR MMIO32(RCC_BASE + 0x20)
57#define RCC_CSR MMIO32(RCC_BASE + 0x24)
58#define RCC_AHBRSTR MMIO32(RCC_BASE + 0x28)
59#define RCC_CFGR2 MMIO32(RCC_BASE + 0x2c)
60#define RCC_CFGR3 MMIO32(RCC_BASE + 0x30)
61#define RCC_CR2 MMIO32(RCC_BASE + 0x34)
62
63/*****************************************************************************/
64/* Register values */
65/*****************************************************************************/
66
67/* --- RCC_CR values ------------------------------------------------------- */
68
69#define RCC_CR_PLLRDY (1 << 25)
70#define RCC_CR_PLLON (1 << 24)
71#define RCC_CR_CSSON (1 << 19)
72#define RCC_CR_HSEBYP (1 << 18)
73#define RCC_CR_HSERDY (1 << 17)
74#define RCC_CR_HSEON (1 << 16)
75#define RCC_CR_HSICAL_SHIFT 8
76#define RCC_CR_HSICAL (0xFF << RCC_CR_HSICAL_SHIFT)
77#define RCC_CR_HSITRIM_SHIFT 3
78#define RCC_CR_HSITRIM (0x1F << RCC_CR_HSITRIM_SHIFT)
79#define RCC_CR_HSIRDY (1 << 1)
80#define RCC_CR_HSION (1 << 0)
81
82/* --- RCC_CFGR values ----------------------------------------------------- */
83
84#define RCC_CFGR_PLLNODIV (1 << 31)
85
86#define RCC_CFGR_MCOPRE_SHIFT 28
87#define RCC_CFGR_MCOPRE (7 << RCC_CFGR_MCOPRE_SHIFT)
88#define RCC_CFGR_MCOPRE_DIV1 (0 << RCC_CFGR_MCOPRE_SHIFT)
89#define RCC_CFGR_MCOPRE_DIV2 (1 << RCC_CFGR_MCOPRE_SHIFT)
90#define RCC_CFGR_MCOPRE_DIV4 (2 << RCC_CFGR_MCOPRE_SHIFT)
91#define RCC_CFGR_MCOPRE_DIV8 (3 << RCC_CFGR_MCOPRE_SHIFT)
92#define RCC_CFGR_MCOPRE_DIV16 (4 << RCC_CFGR_MCOPRE_SHIFT)
93#define RCC_CFGR_MCOPRE_DIV32 (5 << RCC_CFGR_MCOPRE_SHIFT)
94#define RCC_CFGR_MCOPRE_DIV64 (6 << RCC_CFGR_MCOPRE_SHIFT)
95#define RCC_CFGR_MCOPRE_DIV128 (7 << RCC_CFGR_MCOPRE_SHIFT)
96
97#define RCC_CFGR_MCO_SHIFT 24
98#define RCC_CFGR_MCO_MASK 0xf
99#define RCC_CFGR_MCO_NOCLK 0
100#define RCC_CFGR_MCO_HSI14 1
101#define RCC_CFGR_MCO_LSI 2
102#define RCC_CFGR_MCO_LSE 3
103#define RCC_CFGR_MCO_SYSCLK 4
104#define RCC_CFGR_MCO_HSI 5
105#define RCC_CFGR_MCO_HSE 6
106#define RCC_CFGR_MCO_PLL 7
107#define RCC_CFGR_MCO_HSI48 8
108
109#define RCC_CFGR_PLLMUL_SHIFT 18
110#define RCC_CFGR_PLLMUL (0x0F << RCC_CFGR_PLLMUL_SHIFT)
111/** @defgroup rcc_cfgr_pmf PLLMUL: PLL multiplication factor
112 * @{
113 */
114#define RCC_CFGR_PLLMUL_MUL2 (0x00 << RCC_CFGR_PLLMUL_SHIFT)
115#define RCC_CFGR_PLLMUL_MUL3 (0x01 << RCC_CFGR_PLLMUL_SHIFT)
116#define RCC_CFGR_PLLMUL_MUL4 (0x02 << RCC_CFGR_PLLMUL_SHIFT)
117#define RCC_CFGR_PLLMUL_MUL5 (0x03 << RCC_CFGR_PLLMUL_SHIFT)
118#define RCC_CFGR_PLLMUL_MUL6 (0x04 << RCC_CFGR_PLLMUL_SHIFT)
119#define RCC_CFGR_PLLMUL_MUL7 (0x05 << RCC_CFGR_PLLMUL_SHIFT)
120#define RCC_CFGR_PLLMUL_MUL8 (0x06 << RCC_CFGR_PLLMUL_SHIFT)
121#define RCC_CFGR_PLLMUL_MUL9 (0x07 << RCC_CFGR_PLLMUL_SHIFT)
122#define RCC_CFGR_PLLMUL_MUL10 (0x08 << RCC_CFGR_PLLMUL_SHIFT)
123#define RCC_CFGR_PLLMUL_MUL11 (0x09 << RCC_CFGR_PLLMUL_SHIFT)
124#define RCC_CFGR_PLLMUL_MUL12 (0x0A << RCC_CFGR_PLLMUL_SHIFT)
125#define RCC_CFGR_PLLMUL_MUL13 (0x0B << RCC_CFGR_PLLMUL_SHIFT)
126#define RCC_CFGR_PLLMUL_MUL14 (0x0C << RCC_CFGR_PLLMUL_SHIFT)
127#define RCC_CFGR_PLLMUL_MUL15 (0x0D << RCC_CFGR_PLLMUL_SHIFT)
128#define RCC_CFGR_PLLMUL_MUL16 (0x0E << RCC_CFGR_PLLMUL_SHIFT)
129/**@}*/
130
131#define RCC_CFGR_PLLXTPRE (1<<17)
132/** @defgroup rcc_cfgr_hsepre PLLXTPRE: HSE divider for PLL source
133 * @{
134 */
135#define RCC_CFGR_PLLXTPRE_HSE_CLK 0x0
136#define RCC_CFGR_PLLXTPRE_HSE_CLK_DIV2 0x1
137/**@}*/
138
139#define RCC_CFGR_PLLSRC (1<<16)
140/** @defgroup rcc_cfgr_pcs PLLSRC: PLL Clock source
141 * @{
142 */
143#define RCC_CFGR_PLLSRC_HSI_CLK_DIV2 0x0
144#define RCC_CFGR_PLLSRC_HSE_CLK 0x1
145/**@}*/
146
147#define RCC_CFGR_PLLSRC0 (1<<15)
148#define RCC_CFGR_ADCPRE (1<<14)
149
150#define RCC_CFGR_PPRE_SHIFT 8
151#define RCC_CFGR_PPRE (7 << RCC_CFGR_PPRE_SHIFT)
152#define RCC_CFGR_PPRE_MASK 0x7
153/** @defgroup rcc_cfgr_apb1pre RCC_CFGR APB prescale Factors
154@{*/
155#define RCC_CFGR_PPRE_NODIV (0 << RCC_CFGR_PPRE_SHIFT)
156#define RCC_CFGR_PPRE_DIV2 (4 << RCC_CFGR_PPRE_SHIFT)
157#define RCC_CFGR_PPRE_DIV4 (5 << RCC_CFGR_PPRE_SHIFT)
158#define RCC_CFGR_PPRE_DIV8 (6 << RCC_CFGR_PPRE_SHIFT)
159#define RCC_CFGR_PPRE_DIV16 (7 << RCC_CFGR_PPRE_SHIFT)
160/**@}*/
161
162#define RCC_CFGR_HPRE_SHIFT 4
163#define RCC_CFGR_HPRE (0xf << RCC_CFGR_HPRE_SHIFT)
164#define RCC_CFGR_HPRE_MASK 0xf
165/** @defgroup rcc_cfgr_ahbpre RCC_CFGR AHB prescale Factors
166@{*/
167#define RCC_CFGR_HPRE_NODIV (0x0 << RCC_CFGR_HPRE_SHIFT)
168#define RCC_CFGR_HPRE_DIV2 (0x8 << RCC_CFGR_HPRE_SHIFT)
169#define RCC_CFGR_HPRE_DIV4 (0x9 << RCC_CFGR_HPRE_SHIFT)
170#define RCC_CFGR_HPRE_DIV8 (0xa << RCC_CFGR_HPRE_SHIFT)
171#define RCC_CFGR_HPRE_DIV16 (0xb << RCC_CFGR_HPRE_SHIFT)
172#define RCC_CFGR_HPRE_DIV64 (0xc << RCC_CFGR_HPRE_SHIFT)
173#define RCC_CFGR_HPRE_DIV128 (0xd << RCC_CFGR_HPRE_SHIFT)
174#define RCC_CFGR_HPRE_DIV256 (0xe << RCC_CFGR_HPRE_SHIFT)
175#define RCC_CFGR_HPRE_DIV512 (0xf << RCC_CFGR_HPRE_SHIFT)
176/**@}*/
177
178#define RCC_CFGR_SWS_SHIFT 2
179#define RCC_CFGR_SWS (3 << RCC_CFGR_SWS_SHIFT)
180#define RCC_CFGR_SWS_HSI (0 << RCC_CFGR_SWS_SHIFT)
181#define RCC_CFGR_SWS_HSE (1 << RCC_CFGR_SWS_SHIFT)
182#define RCC_CFGR_SWS_PLL (2 << RCC_CFGR_SWS_SHIFT)
183#define RCC_CFGR_SWS_HSI48 (3 << RCC_CFGR_SWS_SHIFT)
184
185#define RCC_CFGR_SW_SHIFT 0
186#define RCC_CFGR_SW (3 << RCC_CFGR_SW_SHIFT)
187#define RCC_CFGR_SW_HSI (0 << RCC_CFGR_SW_SHIFT)
188#define RCC_CFGR_SW_HSE (1 << RCC_CFGR_SW_SHIFT)
189#define RCC_CFGR_SW_PLL (2 << RCC_CFGR_SW_SHIFT)
190#define RCC_CFGR_SW_HSI48 (3 << RCC_CFGR_SW_SHIFT)
191
192/* --- RCC_CIR values ------------------------------------------------------ */
193
194#define RCC_CIR_CSSC (1 << 23)
195#define RCC_CIR_HSI48RDYC (1 << 22)
196#define RCC_CIR_HSI14RDYC (1 << 21)
197#define RCC_CIR_PLLRDYC (1 << 20)
198#define RCC_CIR_HSERDYC (1 << 19)
199#define RCC_CIR_HSIRDYC (1 << 18)
200#define RCC_CIR_LSERDYC (1 << 17)
201#define RCC_CIR_LSIRDYC (1 << 16)
202#define RCC_CIR_HSI48RDYIE (1 << 14)
203#define RCC_CIR_HSI14RDYIE (1 << 13)
204#define RCC_CIR_PLLRDYIE (1 << 12)
205#define RCC_CIR_HSERDYIE (1 << 11)
206#define RCC_CIR_HSIRDYIE (1 << 10)
207#define RCC_CIR_LSERDYIE (1 << 9)
208#define RCC_CIR_LSIRDYIE (1 << 8)
209#define RCC_CIR_CSSF (1 << 7)
210#define RCC_CIR_HSI48RDYF (1 << 6)
211#define RCC_CIR_HSI14RDYF (1 << 5)
212#define RCC_CIR_PLLRDYF (1 << 4)
213#define RCC_CIR_HSERDYF (1 << 3)
214#define RCC_CIR_HSIRDYF (1 << 2)
215#define RCC_CIR_LSERDYF (1 << 1)
216#define RCC_CIR_LSIRDYF (1 << 0)
217
218/** @defgroup rcc_apb2rstr_rst RCC_APB2RSTR reset values
219@{*/
220#define RCC_APB2RSTR_DBGMCURST (1 << 22)
221#define RCC_APB2RSTR_TIM17RST (1 << 18)
222#define RCC_APB2RSTR_TIM16RST (1 << 17)
223#define RCC_APB2RSTR_TIM15RST (1 << 16)
224#define RCC_APB2RSTR_USART1RST (1 << 14)
225#define RCC_APB2RSTR_SPI1RST (1 << 12)
226#define RCC_APB2RSTR_TIM1RST (1 << 11)
227#define RCC_APB2RSTR_ADCRST (1 << 9)
228#define RCC_APB2RSTR_USART8RST (1 << 7)
229#define RCC_APB2RSTR_USART7RST (1 << 6)
230#define RCC_APB2RSTR_USART6RST (1 << 5)
231#define RCC_APB2RSTR_SYSCFGRST (1 << 0)
232/**@}*/
233
234
235/** @defgroup rcc_apb1rstr_rst RCC_APB1RSTR reset values
236@{*/
237#define RCC_APB1RSTR_CECRST (1 << 30)
238#define RCC_APB1RSTR_DACRST (1 << 29)
239#define RCC_APB1RSTR_PWRRST (1 << 28)
240#define RCC_APB1RSTR_CRSRST (1 << 27)
241#define RCC_APB1RSTR_CANRST (1 << 25)
242#define RCC_APB1RSTR_USBRST (1 << 23)
243#define RCC_APB1RSTR_I2C2RST (1 << 22)
244#define RCC_APB1RSTR_I2C1RST (1 << 21)
245#define RCC_APB1RSTR_USART5RST (1 << 20)
246#define RCC_APB1RSTR_USART4RST (1 << 19)
247#define RCC_APB1RSTR_USART3RST (1 << 18)
248#define RCC_APB1RSTR_USART2RST (1 << 17)
249#define RCC_APB1RSTR_SPI2RST (1 << 14)
250#define RCC_APB1RSTR_WWDGRST (1 << 11)
251#define RCC_APB1RSTR_TIM14RST (1 << 8)
252#define RCC_APB1RSTR_TIM7RST (1 << 5)
253#define RCC_APB1RSTR_TIM6RST (1 << 4)
254#define RCC_APB1RSTR_TIM3RST (1 << 1)
255#define RCC_APB1RSTR_TIM2RST (1 << 0)
256/**@}*/
257
258/** @defgroup rcc_ahbenr_en RCC_APHBENR enable values
259@{*/
260#define RCC_AHBENR_TSCEN (1 << 24)
261#define RCC_AHBENR_GPIOFEN (1 << 22)
262#define RCC_AHBENR_GPIOEEN (1 << 21)
263#define RCC_AHBENR_GPIODEN (1 << 20)
264#define RCC_AHBENR_GPIOCEN (1 << 19)
265#define RCC_AHBENR_GPIOBEN (1 << 18)
266#define RCC_AHBENR_GPIOAEN (1 << 17)
267#define RCC_AHBENR_CRCEN (1 << 6)
268#define RCC_AHBENR_FLTFEN (1 << 4)
269#define RCC_AHBENR_SRAMEN (1 << 2)
270#define RCC_AHBENR_DMA2EN (1 << 1)
271#define RCC_AHBENR_DMA1EN (1 << 0)
272#define RCC_AHBENR_DMAEN RCC_AHBENR_DMA1EN /* compatibility alias */
273/**@}*/
274
275/** @defgroup rcc_apb2enr_en RCC_APPB2ENR enable values
276@{*/
277#define RCC_APB2ENR_DBGMCUEN (1 << 22)
278#define RCC_APB2ENR_TIM17EN (1 << 18)
279#define RCC_APB2ENR_TIM16EN (1 << 17)
280#define RCC_APB2ENR_TIM15EN (1 << 16)
281#define RCC_APB2ENR_USART1EN (1 << 14)
282#define RCC_APB2ENR_SPI1EN (1 << 12)
283#define RCC_APB2ENR_TIM1EN (1 << 11)
284#define RCC_APB2ENR_ADCEN (1 << 9)
285#define RCC_APB2ENR_USART8EN (1 << 7)
286#define RCC_APB2ENR_USART7EN (1 << 6)
287#define RCC_APB2ENR_USART6EN (1 << 5)
288#define RCC_APB2ENR_SYSCFGCOMPEN (1 << 0)
289/**@}*/
290
291/** @defgroup rcc_apb1enr_en RCC_APB1ENR enable values
292@{*/
293#define RCC_APB1ENR_CECEN (1 << 30)
294#define RCC_APB1ENR_DACEN (1 << 29)
295#define RCC_APB1ENR_PWREN (1 << 28)
296#define RCC_APB1ENR_CRSEN (1 << 27)
297#define RCC_APB1ENR_CANEN (1 << 25)
298#define RCC_APB1ENR_USBEN (1 << 23)
299#define RCC_APB1ENR_I2C2EN (1 << 22)
300#define RCC_APB1ENR_I2C1EN (1 << 21)
301#define RCC_APB1ENR_USART5EN (1 << 20)
302#define RCC_APB1ENR_USART4EN (1 << 19)
303#define RCC_APB1ENR_USART3EN (1 << 18)
304#define RCC_APB1ENR_USART2EN (1 << 17)
305#define RCC_APB1ENR_SPI2EN (1 << 14)
306#define RCC_APB1ENR_WWDGEN (1 << 11)
307#define RCC_APB1ENR_TIM14EN (1 << 8)
308#define RCC_APB1ENR_TIM7EN (1 << 5)
309#define RCC_APB1ENR_TIM6EN (1 << 4)
310#define RCC_APB1ENR_TIM3EN (1 << 1)
311#define RCC_APB1ENR_TIM2EN (1 << 0)
312/**@}*/
313
314/* --- RCC_BDCR values ----------------------------------------------------- */
315
316#define RCC_BDCR_BDRST (1 << 16)
317#define RCC_BDCR_RTCEN (1 << 15)
318#define RCC_BDCR_RTCSEL_SHIFT 8
319#define RCC_BDCR_RTCSEL (3 << RCC_BDCR_RTCSEL_SHIFT)
320#define RCC_BDCR_RTCSEL_NOCLK (0 << RCC_BDCR_RTCSEL_SHIFT)
321#define RCC_BDCR_RTCSEL_LSE (1 << RCC_BDCR_RTCSEL_SHIFT)
322#define RCC_BDCR_RTCSEL_LSI (2 << RCC_BDCR_RTCSEL_SHIFT)
323#define RCC_BDCR_RTCSEL_HSE (3 << RCC_BDCR_RTCSEL_SHIFT)
324#define RCC_BDCR_LSEDRV_SHIFT 3
325#define RCC_BDCR_LSEDRV (3 << RCC_BDCR_LSEDRV_SHIFT)
326#define RCC_BDCR_LSEDRV_LOW (0 << RCC_BDCR_LSEDRV_SHIFT)
327#define RCC_BDCR_LSEDRV_MEDLO (1 << RCC_BDCR_LSEDRV_SHIFT)
328#define RCC_BDCR_LSEDRV_MEDHI (2 << RCC_BDCR_LSEDRV_SHIFT)
329#define RCC_BDCR_LSEDRV_HIGH (3 << RCC_BDCR_LSEDRV_SHIFT)
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_RESET_FLAGS (RCC_CSR_LPWRRSTF | RCC_CSR_WWDGRSTF |\
345 RCC_CSR_IWDGRSTF | RCC_CSR_SFTRSTF | RCC_CSR_PORRSTF |\
346 RCC_CSR_PINRSTF | RCC_CSR_OBLRSTF)
347#define RCC_CSR_V18PWRRSTF (1 << 23)
348#define RCC_CSR_LSIRDY (1 << 1)
349#define RCC_CSR_LSION (1 << 0)
350
351/** @defgroup rcc_ahbrstr_rst RCC_AHBRSTR reset values
352@{*/
353#define RCC_AHBRSTR_TSCRST (1 << 24)
354#define RCC_AHBRSTR_IOPFRST (1 << 22)
355#define RCC_AHBRSTR_IOPERST (1 << 21)
356#define RCC_AHBRSTR_IOPDRST (1 << 20)
357#define RCC_AHBRSTR_IOPCRST (1 << 19)
358#define RCC_AHBRSTR_IOPBRST (1 << 18)
359#define RCC_AHBRSTR_IOPARST (1 << 17)
360/**@}*/
361
362
363/* --- RCC_CFGR2 values ---------------------------------------------------- */
364
365#define RCC_CFGR2_PREDIV 0xf
366/** @defgroup rcc_cfgr2_prediv PLL source predividers
367@ingroup rcc_defines
368@{*/
369#define RCC_CFGR2_PREDIV_NODIV 0x0
370#define RCC_CFGR2_PREDIV_DIV2 0x1
371#define RCC_CFGR2_PREDIV_DIV3 0x2
372#define RCC_CFGR2_PREDIV_DIV4 0x3
373#define RCC_CFGR2_PREDIV_DIV5 0x4
374#define RCC_CFGR2_PREDIV_DIV6 0x5
375#define RCC_CFGR2_PREDIV_DIV7 0x6
376#define RCC_CFGR2_PREDIV_DIV8 0x7
377#define RCC_CFGR2_PREDIV_DIV9 0x8
378#define RCC_CFGR2_PREDIV_DIV10 0x9
379#define RCC_CFGR2_PREDIV_DIV11 0xa
380#define RCC_CFGR2_PREDIV_DIV12 0xb
381#define RCC_CFGR2_PREDIV_DIV13 0xc
382#define RCC_CFGR2_PREDIV_DIV14 0xd
383#define RCC_CFGR2_PREDIV_DIV15 0xe
384#define RCC_CFGR2_PREDIV_DIV16 0xf
385/**@}*/
386
387/* --- RCC_CFGR3 values ---------------------------------------------------- */
388/** @defgroup rcc_cfgr3_uart_choices UART for clock source selecting
389 * @note This is only used internally.
390 * @{
391 */
392#define RCC_CFGR3_USART3SW_SHIFT 18
393#define RCC_CFGR3_USART2SW_SHIFT 16
394#define RCC_CFGR3_USART1SW_SHIFT 0
395/**@}*/
396
397/** @defgroup rcc_cfgr3_uart_clksel UART Clock source selections
398 * @{
399 */
400#define RCC_CFGR3_USARTxSW_PCLK 0x0
401#define RCC_CFGR3_USARTxSW_SYSCLK 0x1
402#define RCC_CFGR3_USARTxSW_LSE 0x2
403#define RCC_CFGR3_USARTxSW_HSI 0x3
404/**@}*/
405#define RCC_CFGR3_USARTxSW_MASK 0x3
406
407#define RCC_CFGR3_ADCSW (1 << 8)
408#define RCC_CFGR3_USBSW (1 << 7)
409#define RCC_CFGR3_CECSW (1 << 6)
410#define RCC_CFGR3_I2C1SW (1 << 4)
411
412#define RCC_CR2_HSI48CAL_SHIFT 24
413#define RCC_CR2_HSI48CAL (0xFF << RCC_CR2_HSI48CAL_SHIFT)
414#define RCC_CR2_HSI48RDY (1 << 17)
415#define RCC_CR2_HSI48ON (1 << 16)
416#define RCC_CR2_HSI14CAL_SHIFT 8
417#define RCC_CR2_HSI14CAL (0xFF << RCC_CR2_HSI14CAL_SHIFT)
418#define RCC_CR2_HSI14TRIM_SHIFT 3
419#define RCC_CR2_HSI14TRIM (31 << RCC_CR2_HSI14TRIM_SHIFT)
420#define RCC_CR2_HSI14DIS (1 << 2)
421#define RCC_CR2_HSI14RDY (1 << 1)
422#define RCC_CR2_HSI14ON (1 << 0)
423
424/*****************************************************************************/
425/* API definitions */
426/*****************************************************************************/
427
428/* --- Variable definitions ------------------------------------------------ */
429extern uint32_t rcc_ahb_frequency;
430extern uint32_t rcc_apb1_frequency;
431/** F0 doens't _realllly_ have apb2, but it has a bunch of things
432 * enabled via the "APB2" enable register. Fake it out.
433 */
434#define rcc_apb2_frequency rcc_apb1_frequency
435
439
440#define _REG_BIT(base, bit) (((base) << 5) + (bit))
441
443 /* AHB peripherals */
444 RCC_DMA = _REG_BIT(0x14, 0),
445 RCC_DMA1 = _REG_BIT(0x14, 0), /* Compatibility alias */
446 RCC_DMA2 = _REG_BIT(0x14, 1),
447 RCC_SRAM = _REG_BIT(0x14, 2),
448 RCC_FLTIF = _REG_BIT(0x14, 4),
449 RCC_CRC = _REG_BIT(0x14, 6),
450 RCC_GPIOA = _REG_BIT(0x14, 17),
451 RCC_GPIOB = _REG_BIT(0x14, 18),
452 RCC_GPIOC = _REG_BIT(0x14, 19),
453 RCC_GPIOD = _REG_BIT(0x14, 20),
454 RCC_GPIOE = _REG_BIT(0x14, 21),
455 RCC_GPIOF = _REG_BIT(0x14, 22),
456 RCC_TSC = _REG_BIT(0x14, 24),
457
458 /* APB2 peripherals */
463 RCC_ADC = _REG_BIT(0x18, 9),
464 RCC_ADC1 = _REG_BIT(0x18, 9), /* Compatibility alias */
465 RCC_TIM1 = _REG_BIT(0x18, 11),
466 RCC_SPI1 = _REG_BIT(0x18, 12),
467 RCC_USART1 = _REG_BIT(0x18, 14),
468 RCC_TIM15 = _REG_BIT(0x18, 16),
469 RCC_TIM16 = _REG_BIT(0x18, 17),
470 RCC_TIM17 = _REG_BIT(0x18, 18),
471 RCC_DBGMCU = _REG_BIT(0x18, 22),
472
473 /* APB1 peripherals */
474 RCC_TIM2 = _REG_BIT(0x1C, 0),
475 RCC_TIM3 = _REG_BIT(0x1C, 1),
476 RCC_TIM6 = _REG_BIT(0x1C, 4),
477 RCC_TIM7 = _REG_BIT(0x1C, 5),
478 RCC_TIM14 = _REG_BIT(0x1C, 8),
479 RCC_WWDG = _REG_BIT(0x1C, 11),
480 RCC_SPI2 = _REG_BIT(0x1C, 14),
481 RCC_USART2 = _REG_BIT(0x1C, 17),
482 RCC_USART3 = _REG_BIT(0x1C, 18),
483 RCC_USART4 = _REG_BIT(0x1C, 19),
484 RCC_USART5 = _REG_BIT(0x1C, 20),
485 RCC_I2C1 = _REG_BIT(0x1C, 21),
486 RCC_I2C2 = _REG_BIT(0x1C, 22),
487 RCC_USB = _REG_BIT(0x1C, 23),
488 RCC_CAN = _REG_BIT(0x1C, 25),
489 RCC_CAN1 = _REG_BIT(0x1C, 25), /* Compatibility alias */
490 RCC_CRS = _REG_BIT(0x1C, 27),
491 RCC_PWR = _REG_BIT(0x1C, 28),
492 RCC_DAC = _REG_BIT(0x1C, 29),
493 RCC_DAC1 = _REG_BIT(0x1C, 29), /* Compatibility alias */
494 RCC_CEC = _REG_BIT(0x1C, 30),
495
496 /* Advanced peripherals */
497 RCC_RTC = _REG_BIT(0x20, 15),/* BDCR[15] */
498};
499
501 /* APB2 peripherals */
503 RST_ADC = _REG_BIT(0x0C, 9),
504 RST_ADC1 = _REG_BIT(0x0C, 9), /* Compatibility alias */
505 RST_TIM1 = _REG_BIT(0x0C, 11),
506 RST_SPI1 = _REG_BIT(0x0C, 12),
507 RST_USART1 = _REG_BIT(0x0C, 14),
508 RST_TIM15 = _REG_BIT(0x0C, 16),
509 RST_TIM16 = _REG_BIT(0x0C, 17),
510 RST_TIM17 = _REG_BIT(0x0C, 18),
511 RST_DBGMCU = _REG_BIT(0x0C, 22),
512
513 /* APB1 peripherals */
514 RST_TIM2 = _REG_BIT(0x10, 0),
515 RST_TIM3 = _REG_BIT(0x10, 1),
516 RST_TIM6 = _REG_BIT(0x10, 4),
517 RST_TIM7 = _REG_BIT(0x10, 5),
518 RST_TIM14 = _REG_BIT(0x10, 8),
519 RST_WWDG = _REG_BIT(0x10, 11),
520 RST_SPI2 = _REG_BIT(0x10, 14),
521 RST_USART2 = _REG_BIT(0x10, 17),
522 RST_USART3 = _REG_BIT(0x10, 18),
523 RST_USART4 = _REG_BIT(0x10, 19),
524 RST_I2C1 = _REG_BIT(0x10, 21),
525 RST_I2C2 = _REG_BIT(0x10, 22),
526 RST_USB = _REG_BIT(0x10, 23),
527 RST_CAN = _REG_BIT(0x10, 25),
528 RST_CAN1 = _REG_BIT(0x10, 25), /* Compatibility alias */
529 RST_CRS = _REG_BIT(0x10, 27),
530 RST_PWR = _REG_BIT(0x10, 28),
531 RST_DAC = _REG_BIT(0x10, 29),
532 RST_DAC1 = _REG_BIT(0x10, 29), /* Compatibility alias */
533 RST_CEC = _REG_BIT(0x10, 30),
534
535 /* Backup domain control */
536 RST_BDCR = _REG_BIT(0x20, 16),/* BDCR[16] */
537
538 /* AHB peripherals */
539 RST_GPIOA = _REG_BIT(0x28, 17),
540 RST_GPIOB = _REG_BIT(0x28, 18),
541 RST_GPIOC = _REG_BIT(0x28, 19),
542 RST_GPIOD = _REG_BIT(0x28, 20),
543 RST_GPIOE = _REG_BIT(0x28, 21),
544 RST_GPIOF = _REG_BIT(0x28, 22),
545 RST_TSC = _REG_BIT(0x28, 24),
546};
547#undef _REG_BIT
548
549/*****************************************************************************/
550/* API Functions */
551/*****************************************************************************/
552
554
556
557void rcc_osc_ready_int_clear(enum rcc_osc osc);
558void rcc_osc_ready_int_enable(enum rcc_osc osc);
560int rcc_osc_ready_int_flag(enum rcc_osc osc);
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_css_int_clear(void);
566int rcc_css_int_flag(void);
567void rcc_set_sysclk_source(enum rcc_osc clk);
568void rcc_set_usbclk_source(enum rcc_osc clk);
569void rcc_set_rtc_clock_source(enum rcc_osc clk);
570void rcc_enable_rtc_clock(void);
571void rcc_disable_rtc_clock(void);
572void rcc_set_pll_multiplication_factor(uint32_t mul);
573void rcc_set_pll_source(uint32_t pllsrc);
574void rcc_set_pllxtpre(uint32_t pllxtpre);
575void rcc_set_ppre(uint32_t ppre);
576void rcc_set_hpre(uint32_t hpre);
577void rcc_set_prediv(uint32_t prediv);
579void rcc_set_i2c_clock_hsi(uint32_t i2c);
580void rcc_set_i2c_clock_sysclk(uint32_t i2c);
581uint32_t rcc_get_i2c_clocks(void);
586uint32_t rcc_get_usart_clk_freq(uint32_t usart);
587uint32_t rcc_get_timer_clk_freq(uint32_t timer);
588uint32_t rcc_get_i2c_clk_freq(uint32_t i2c);
589uint32_t rcc_get_spi_clk_freq(uint32_t spi);
590
592
593#endif
594/**@}*/
595
#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:157
void rcc_set_ppre(uint32_t ppre)
RCC Set the APB Prescale Factor.
Definition: rcc.c:473
void rcc_set_sysclk_source(enum rcc_osc clk)
RCC Set the Source for the System Clock.
Definition: rcc.c:334
int rcc_css_int_flag(void)
RCC Read the Clock Security System Interrupt Flag.
Definition: rcc.c:201
void rcc_set_i2c_clock_sysclk(uint32_t i2c)
Definition: rcc.c:531
void rcc_osc_ready_int_clear(enum rcc_osc osc)
RCC Clear the Oscillator Ready Interrupt Flag.
Definition: rcc.c:57
void rcc_css_disable(void)
RCC Disable the Clock Security System.
Definition: rcc.c:322
enum rcc_osc rcc_system_clock_source(void)
RCC Get the System Clock Source.
Definition: rcc.c:507
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:695
void rcc_set_pll_source(uint32_t pllsrc)
RCC Set the PLL Clock Source.
Definition: rcc.c:447
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
Definition: rcc.c:666
enum rcc_osc rcc_usb_clock_source(void)
RCC Get the USB Clock Source.
Definition: rcc.c:549
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
Definition: rcc.c:649
rcc_periph_rst
Definition: f0/rcc.h:500
void rcc_set_usbclk_source(enum rcc_osc clk)
RCC Set the Source for the USB Clock.
Definition: rcc.c:363
rcc_periph_clken
Definition: f0/rcc.h:442
void rcc_set_prediv(uint32_t prediv)
Set PLL Source pre-divider CAUTION.
Definition: rcc.c:495
void rcc_osc_ready_int_enable(enum rcc_osc osc)
RCC Enable the Oscillator Ready Interrupt.
Definition: rcc.c:90
void rcc_set_rtc_clock_source(enum rcc_osc clk)
RCC Set the Source for the RTC clock.
Definition: rcc.c:408
rcc_osc
Definition: f0/rcc.h:436
void rcc_clock_setup_in_hse_8mhz_out_48mhz(void)
Set System Clock PLL at 48MHz from HSE at 8MHz.
Definition: rcc.c:557
void rcc_disable_rtc_clock(void)
RCC Disable the RTC clock.
Definition: rcc.c:397
void rcc_osc_ready_int_disable(enum rcc_osc osc)
RCC Disable the Oscillator Ready Interrupt.
Definition: rcc.c:123
void rcc_osc_on(enum rcc_osc osc)
RCC Turn on an Oscillator.
Definition: rcc.c:244
#define _REG_BIT(base, bit)
Definition: f0/rcc.h:440
uint32_t rcc_ahb_frequency
Definition: rcc.c:45
void rcc_osc_off(enum rcc_osc osc)
RCC Turn off an Oscillator.
Definition: rcc.c:282
void rcc_clock_setup_in_hsi48_out_48mhz(void)
Set System Clock HSI48 at 48MHz.
Definition: rcc.c:612
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:677
void rcc_set_pll_multiplication_factor(uint32_t mul)
RCC Set the PLL Multiplication Factor.
Definition: rcc.c:434
uint32_t rcc_apb1_frequency
Definition: rcc.c:46
uint32_t rcc_get_i2c_clocks(void)
Definition: rcc.c:538
void rcc_css_int_clear(void)
RCC Clear the Clock Security System Interrupt Flag.
Definition: rcc.c:190
void rcc_enable_rtc_clock(void)
RCC Enable the RTC clock.
Definition: rcc.c:387
void rcc_set_i2c_clock_hsi(uint32_t i2c)
Definition: rcc.c:524
void rcc_clock_setup_in_hsi_out_48mhz(void)
Set System Clock PLL at 48MHz from HSI.
Definition: rcc.c:585
void rcc_css_enable(void)
RCC Enable the Clock Security System.
Definition: rcc.c:313
void rcc_set_hpre(uint32_t hpre)
RCC Set the AHB Prescale Factor.
Definition: rcc.c:484
void rcc_set_pllxtpre(uint32_t pllxtpre)
RCC Set the HSE Frequency Divider used as PLL Clock Source.
Definition: rcc.c:461
@ RST_CRS
Definition: f0/rcc.h:529
@ RST_SPI1
Definition: f0/rcc.h:506
@ RST_CEC
Definition: f0/rcc.h:533
@ RST_ADC1
Definition: f0/rcc.h:504
@ RST_TIM16
Definition: f0/rcc.h:509
@ RST_TSC
Definition: f0/rcc.h:545
@ RST_TIM14
Definition: f0/rcc.h:518
@ RST_GPIOF
Definition: f0/rcc.h:544
@ RST_DBGMCU
Definition: f0/rcc.h:511
@ RST_BDCR
Definition: f0/rcc.h:536
@ RST_SPI2
Definition: f0/rcc.h:520
@ RST_TIM15
Definition: f0/rcc.h:508
@ RST_TIM3
Definition: f0/rcc.h:515
@ RST_TIM17
Definition: f0/rcc.h:510
@ RST_GPIOA
Definition: f0/rcc.h:539
@ RST_GPIOC
Definition: f0/rcc.h:541
@ RST_TIM6
Definition: f0/rcc.h:516
@ RST_GPIOB
Definition: f0/rcc.h:540
@ RST_TIM1
Definition: f0/rcc.h:505
@ RST_USART3
Definition: f0/rcc.h:522
@ RST_DAC
Definition: f0/rcc.h:531
@ RST_ADC
Definition: f0/rcc.h:503
@ RST_TIM7
Definition: f0/rcc.h:517
@ RST_TIM2
Definition: f0/rcc.h:514
@ RST_GPIOD
Definition: f0/rcc.h:542
@ RST_USB
Definition: f0/rcc.h:526
@ RST_CAN
Definition: f0/rcc.h:527
@ RST_USART4
Definition: f0/rcc.h:523
@ RST_SYSCFG
Definition: f0/rcc.h:502
@ RST_GPIOE
Definition: f0/rcc.h:543
@ RST_I2C2
Definition: f0/rcc.h:525
@ RST_CAN1
Definition: f0/rcc.h:528
@ RST_PWR
Definition: f0/rcc.h:530
@ RST_USART1
Definition: f0/rcc.h:507
@ RST_WWDG
Definition: f0/rcc.h:519
@ RST_I2C1
Definition: f0/rcc.h:524
@ RST_DAC1
Definition: f0/rcc.h:532
@ RST_USART2
Definition: f0/rcc.h:521
@ RCC_CRS
Definition: f0/rcc.h:490
@ RCC_CAN
Definition: f0/rcc.h:488
@ RCC_SPI2
Definition: f0/rcc.h:480
@ RCC_WWDG
Definition: f0/rcc.h:479
@ RCC_TIM3
Definition: f0/rcc.h:475
@ RCC_TIM1
Definition: f0/rcc.h:465
@ RCC_SYSCFG_COMP
Definition: f0/rcc.h:459
@ RCC_USART5
Definition: f0/rcc.h:484
@ RCC_GPIOA
Definition: f0/rcc.h:450
@ RCC_CEC
Definition: f0/rcc.h:494
@ RCC_DMA
Definition: f0/rcc.h:444
@ RCC_TIM17
Definition: f0/rcc.h:470
@ RCC_RTC
Definition: f0/rcc.h:497
@ RCC_TIM2
Definition: f0/rcc.h:474
@ RCC_CAN1
Definition: f0/rcc.h:489
@ RCC_PWR
Definition: f0/rcc.h:491
@ RCC_CRC
Definition: f0/rcc.h:449
@ RCC_TIM14
Definition: f0/rcc.h:478
@ RCC_USART1
Definition: f0/rcc.h:467
@ RCC_DAC1
Definition: f0/rcc.h:493
@ RCC_I2C1
Definition: f0/rcc.h:485
@ RCC_USART7
Definition: f0/rcc.h:461
@ RCC_USART4
Definition: f0/rcc.h:483
@ RCC_SRAM
Definition: f0/rcc.h:447
@ RCC_ADC1
Definition: f0/rcc.h:464
@ RCC_TSC
Definition: f0/rcc.h:456
@ RCC_DBGMCU
Definition: f0/rcc.h:471
@ RCC_USB
Definition: f0/rcc.h:487
@ RCC_USART2
Definition: f0/rcc.h:481
@ RCC_TIM16
Definition: f0/rcc.h:469
@ RCC_USART3
Definition: f0/rcc.h:482
@ RCC_SPI1
Definition: f0/rcc.h:466
@ RCC_USART8
Definition: f0/rcc.h:462
@ RCC_I2C2
Definition: f0/rcc.h:486
@ RCC_GPIOB
Definition: f0/rcc.h:451
@ RCC_TIM7
Definition: f0/rcc.h:477
@ RCC_FLTIF
Definition: f0/rcc.h:448
@ RCC_GPIOF
Definition: f0/rcc.h:455
@ RCC_GPIOC
Definition: f0/rcc.h:452
@ RCC_TIM6
Definition: f0/rcc.h:476
@ RCC_DMA1
Definition: f0/rcc.h:445
@ RCC_DAC
Definition: f0/rcc.h:492
@ RCC_GPIOD
Definition: f0/rcc.h:453
@ RCC_TIM15
Definition: f0/rcc.h:468
@ RCC_GPIOE
Definition: f0/rcc.h:454
@ RCC_ADC
Definition: f0/rcc.h:463
@ RCC_USART6
Definition: f0/rcc.h:460
@ RCC_DMA2
Definition: f0/rcc.h:446
@ RCC_HSI
Definition: f0/rcc.h:437
@ RCC_HSI48
Definition: f0/rcc.h:437
@ RCC_LSI
Definition: f0/rcc.h:437
@ RCC_PLL
Definition: f0/rcc.h:437
@ RCC_LSE
Definition: f0/rcc.h:437
@ RCC_HSE
Definition: f0/rcc.h:437
@ RCC_HSI14
Definition: f0/rcc.h:437