libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
l1/rcc.h
Go to the documentation of this file.
1/** @defgroup rcc_defines RCC Defines
2 *
3 * @ingroup STM32L1xx_defines
4 *
5 * @brief <b>Defined Constants and Types for the STM32L1xx Reset and Clock
6 * Control</b>
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 * @author @htmlonly &copy; @endhtmlonly 2012
15 * Karl Palsson <karlp@tweak.net.au>
16 *
17 * @date 11 November 2012
18 *
19 * LGPL License Terms @ref lgpl_license
20 * */
21
22/*
23 * This file is part of the libopencm3 project.
24 *
25 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
26 * Copyright (C) 2009 Federico Ruiz-Ugalde <memeruiz at gmail dot com>
27 * Copyright (C) 2012 Karl Palsson <karlp@tweak.net.au>
28 *
29 * This library is free software: you can redistribute it and/or modify
30 * it under the terms of the GNU Lesser General Public License as published by
31 * the Free Software Foundation, either version 3 of the License, or
32 * (at your option) any later version.
33 *
34 * This library is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU Lesser General Public License for more details.
38 *
39 * You should have received a copy of the GNU Lesser General Public License
40 * along with this library. If not, see <http://www.gnu.org/licenses/>.
41 *
42 * Originally based on the F1 code, as it seemed most similar to the L1
43 * TODO: very incomplete still!
44 */
45
46/**@{*/
47
48#ifndef LIBOPENCM3_RCC_H
49#define LIBOPENCM3_RCC_H
50
52
53/* --- RCC registers ------------------------------------------------------- */
54
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)
69
70/* --- RCC_CR values ------------------------------------------------------- */
71
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)
84
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
91
92/** @defgroup rcc_icscr_defines RCC_ICSCR definitions
93 * @brief Internal clock sources calibration register
94 * @ingroup rcc_defines
95 *@{*/
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
100
101#define RCC_ICSCR_MSIRANGE_SHIFT 13
102#define RCC_ICSCR_MSIRANGE_MASK 0x7
103/** @defgroup rcc_icscr_msirange MSI Ranges
104 * @ingroup rcc_icscr_defines
105 *@{*/
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
113/**@}*/
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
118/**@}*/
119
120/* --- RCC_CFGR values ----------------------------------------------------- */
121
122/* MCOPRE */
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
130
131/* MCO: Microcontroller clock output */
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
142
143/* PLL Output division selection */
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
149
150/* PLLMUL: PLL multiplication factor */
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
162
163/* PLLSRC: PLL entry clock source */
164#define RCC_CFGR_PLLSRC_HSI_CLK 0x0
165#define RCC_CFGR_PLLSRC_HSE_CLK 0x1
166
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
171/** @defgroup rcc_cfgr_apbxpre RCC_CFGR APBx prescale factors
172 * These can be used for both APB1 and APB2 prescaling
173 * @{
174 */
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
180/**@}*/
181
182/** @defgroup rcc_cfgr_ahbpre RCC_CFGR AHB prescale factors
183@{*/
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
193/**@}*/
194#define RCC_CFGR_HPRE_MASK 0xf
195#define RCC_CFGR_HPRE_SHIFT 4
196
197/* SWS: System clock switch status */
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
204
205/* SW: System clock switch */
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
212
213/** Older compatible definitions to ease migration
214 * @defgroup rcc_cfgr_deprecated RCC_CFGR Deprecated dividers
215 * @deprecated Use _CFGR_xPRE_DIVn form instead, across all families
216 * @{
217 */
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
223
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
229
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
239
240/**@}*/
241
242/* --- RCC_CIR values ------------------------------------------------------ */
243
244/* Clock security system interrupt clear bit */
245#define RCC_CIR_CSSC (1 << 23)
246
247/* OSC ready interrupt clear bits */
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)
254
255/* OSC ready interrupt enable bits */
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)
262
263/* Clock security system interrupt flag bit */
264#define RCC_CIR_CSSF (1 << 7)
265
266/* OSC ready interrupt flag bits */
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)
273
274/** @defgroup rcc_ahbrstr_rst RCC_AHBRSTR reset values values
275@{*/
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)
285/**@}*/
286
287/** @defgroup rcc_apb2rstr_rst RCC_APB2RSTR reset values values
288@{*/
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)
296/**@}*/
297
298/** @defgroup rcc_apb1rstr_rst RCC_APB1RSTR reset values values
299@{*/
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)
317/**@}*/
318
319/* --- RCC_AHBENR values --------------------------------------------------- */
320
321/** @defgroup rcc_ahbenr_en RCC_AHBENR enable values
322@ingroup STM32L1xx_rcc_defines
323
324@{*/
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)
334/**@}*/
335
336/* --- RCC_APB2ENR values -------------------------------------------------- */
337
338/** @defgroup rcc_apb2enr_en RCC_APB2ENR enable values
339@ingroup STM32L1xx_rcc_defines
340
341@{*/
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)
349/**@}*/
350
351/* --- RCC_APB1ENR values -------------------------------------------------- */
352
353/** @defgroup rcc_apb1enr_en RCC_APB1ENR enable values
354@ingroup STM32L1xx_rcc_defines
355
356@{*/
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)
373/**@}*/
374
375/* --- RCC_AHBLPENR -------------------------------------------------------- */
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)
386
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)
394
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)
411
412
413/* --- RCC_CSR values ------------------------------------------------------ */
414
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)
441
443 uint8_t pll_mul;
444 uint16_t pll_div;
445 uint8_t pll_source;
447 uint8_t hpre;
448 uint8_t ppre1;
449 uint8_t ppre2;
454 uint8_t msi_range;
455};
456
466
468
469
470/* --- Variable definitions ------------------------------------------------ */
471extern uint32_t rcc_ahb_frequency;
472extern uint32_t rcc_apb1_frequency;
473extern uint32_t rcc_apb2_frequency;
474
475/* --- Function prototypes ------------------------------------------------- */
476
480
481#define _REG_BIT(base, bit) (((base) << 5) + (bit))
482
484 /* AHB peripherals */
485 RCC_GPIOA = _REG_BIT(0x1c, 0),
486 RCC_GPIOB = _REG_BIT(0x1c, 1),
487 RCC_GPIOC = _REG_BIT(0x1c, 2),
488 RCC_GPIOD = _REG_BIT(0x1c, 3),
489 RCC_GPIOE = _REG_BIT(0x1c, 4),
490 RCC_GPIOH = _REG_BIT(0x1c, 5),
491 RCC_GPIOF = _REG_BIT(0x1c, 6),
492 RCC_GPIOG = _REG_BIT(0x1c, 7),
493 RCC_CRC = _REG_BIT(0x1c, 12),
494 RCC_FLITF = _REG_BIT(0x1c, 15),
495 RCC_DMA1 = _REG_BIT(0x1c, 24),
496 RCC_DMA2 = _REG_BIT(0x1c, 25),
497 RCC_AES = _REG_BIT(0x1c, 27),
498 RCC_FSMC = _REG_BIT(0x1c, 30),
499
500 /* APB2 peripherals */
502 RCC_TIM9 = _REG_BIT(0x20, 2),
503 RCC_TIM10 = _REG_BIT(0x20, 3),
504 RCC_TIM11 = _REG_BIT(0x20, 4),
505 RCC_ADC1 = _REG_BIT(0x20, 9),
506 RCC_SDIO = _REG_BIT(0x20, 11),
507 RCC_SPI1 = _REG_BIT(0x20, 12),
508 RCC_USART1 = _REG_BIT(0x20, 14),
509
510 /* APB1 peripherals*/
511 RCC_TIM2 = _REG_BIT(0x24, 0),
512 RCC_TIM3 = _REG_BIT(0x24, 1),
513 RCC_TIM4 = _REG_BIT(0x24, 2),
514 RCC_TIM5 = _REG_BIT(0x24, 3),
515 RCC_TIM6 = _REG_BIT(0x24, 4),
516 RCC_TIM7 = _REG_BIT(0x24, 5),
517 RCC_LCD = _REG_BIT(0x24, 9),
518 RCC_WWDG = _REG_BIT(0x24, 11),
519 RCC_SPI2 = _REG_BIT(0x24, 14),
520 RCC_SPI3 = _REG_BIT(0x24, 15),
521 RCC_USART2 = _REG_BIT(0x24, 17),
522 RCC_USART3 = _REG_BIT(0x24, 18),
523 RCC_UART4 = _REG_BIT(0x24, 19),
524 RCC_UART5 = _REG_BIT(0x24, 20),
525 RCC_I2C1 = _REG_BIT(0x24, 21),
526 RCC_I2C2 = _REG_BIT(0x24, 22),
527 RCC_USB = _REG_BIT(0x24, 23),
528 RCC_PWR = _REG_BIT(0x24, 28),
529 RCC_DAC = _REG_BIT(0x24, 29),
530 RCC_COMP = _REG_BIT(0x24, 31),
531
532 /* AHB peripherals */
533 SCC_GPIOA = _REG_BIT(0x28, 0),
534 SCC_GPIOB = _REG_BIT(0x28, 1),
535 SCC_GPIOC = _REG_BIT(0x28, 2),
536 SCC_GPIOD = _REG_BIT(0x28, 3),
537 SCC_GPIOE = _REG_BIT(0x28, 4),
538 SCC_GPIOH = _REG_BIT(0x28, 5),
539 SCC_GPIOF = _REG_BIT(0x28, 6),
540 SCC_GPIOG = _REG_BIT(0x28, 7),
541 SCC_CRC = _REG_BIT(0x28, 12),
542 SCC_FLITF = _REG_BIT(0x28, 15),
543 SCC_SRAM = _REG_BIT(0x28, 16),
544 SCC_DMA1 = _REG_BIT(0x28, 24),
545 SCC_DMA2 = _REG_BIT(0x28, 25),
546 SCC_AES = _REG_BIT(0x28, 27),
547 SCC_FSMC = _REG_BIT(0x28, 30),
548
549 /* APB2 peripherals */
551 SCC_TIM9 = _REG_BIT(0x2c, 2),
552 SCC_TIM10 = _REG_BIT(0x2c, 3),
553 SCC_TIM11 = _REG_BIT(0x2c, 4),
554 SCC_ADC1 = _REG_BIT(0x2c, 9),
555 SCC_SDIO = _REG_BIT(0x2c, 11),
556 SCC_SPI1 = _REG_BIT(0x2c, 12),
557 SCC_USART1 = _REG_BIT(0x2c, 14),
558
559 /* APB1 peripherals*/
560 SCC_TIM2 = _REG_BIT(0x24, 0),
561 SCC_TIM3 = _REG_BIT(0x24, 1),
562 SCC_TIM4 = _REG_BIT(0x24, 2),
563 SCC_TIM5 = _REG_BIT(0x24, 3),
564 SCC_TIM6 = _REG_BIT(0x24, 4),
565 SCC_TIM7 = _REG_BIT(0x24, 5),
566 SCC_LCD = _REG_BIT(0x24, 9),
567 SCC_WWDG = _REG_BIT(0x24, 11),
568 SCC_SPI2 = _REG_BIT(0x24, 14),
569 SCC_SPI3 = _REG_BIT(0x24, 15),
570 SCC_USART2 = _REG_BIT(0x24, 17),
571 SCC_USART3 = _REG_BIT(0x24, 18),
572 SCC_UART4 = _REG_BIT(0x24, 19),
573 SCC_UART5 = _REG_BIT(0x24, 20),
574 SCC_I2C1 = _REG_BIT(0x24, 21),
575 SCC_I2C2 = _REG_BIT(0x24, 22),
576 SCC_USB = _REG_BIT(0x24, 23),
577 SCC_PWR = _REG_BIT(0x24, 28),
578 SCC_DAC = _REG_BIT(0x24, 29),
579 SCC_COMP = _REG_BIT(0x24, 31),
580};
581
583 /* AHB peripherals */
584 RST_GPIOA = _REG_BIT(0x10, 0),
585 RST_GPIOB = _REG_BIT(0x10, 1),
586 RST_GPIOC = _REG_BIT(0x10, 2),
587 RST_GPIOD = _REG_BIT(0x10, 3),
588 RST_GPIOE = _REG_BIT(0x10, 4),
589 RST_GPIOH = _REG_BIT(0x10, 5),
590 RST_GPIOF = _REG_BIT(0x10, 6),
591 RST_GPIOG = _REG_BIT(0x10, 7),
592 RST_CRC = _REG_BIT(0x10, 12),
593 RST_FLITF = _REG_BIT(0x10, 15),
594 RST_DMA1 = _REG_BIT(0x10, 24),
595 RST_DMA2 = _REG_BIT(0x10, 25),
596 RST_AES = _REG_BIT(0x10, 27),
597 RST_FSMC = _REG_BIT(0x10, 30),
598
599 /* APB2 peripherals */
601 RST_TIM9 = _REG_BIT(0x14, 2),
602 RST_TIM10 = _REG_BIT(0x14, 3),
603 RST_TIM11 = _REG_BIT(0x14, 4),
604 RST_ADC1 = _REG_BIT(0x14, 9),
605 RST_SDIO = _REG_BIT(0x14, 11),
606 RST_SPI1 = _REG_BIT(0x14, 12),
607 RST_USART1 = _REG_BIT(0x14, 14),
608
609 /* APB1 peripherals*/
610 RST_TIM2 = _REG_BIT(0x18, 0),
611 RST_TIM3 = _REG_BIT(0x18, 1),
612 RST_TIM4 = _REG_BIT(0x18, 2),
613 RST_TIM5 = _REG_BIT(0x18, 3),
614 RST_TIM6 = _REG_BIT(0x18, 4),
615 RST_TIM7 = _REG_BIT(0x18, 5),
616 RST_LCD = _REG_BIT(0x18, 9),
617 RST_WWDG = _REG_BIT(0x18, 11),
618 RST_SPI2 = _REG_BIT(0x18, 14),
619 RST_SPI3 = _REG_BIT(0x18, 15),
620 RST_USART2 = _REG_BIT(0x18, 17),
621 RST_USART3 = _REG_BIT(0x18, 18),
622 RST_UART4 = _REG_BIT(0x18, 19),
623 RST_UART5 = _REG_BIT(0x18, 20),
624 RST_I2C1 = _REG_BIT(0x18, 21),
625 RST_I2C2 = _REG_BIT(0x18, 22),
626 RST_USB = _REG_BIT(0x18, 23),
627 RST_PWR = _REG_BIT(0x18, 28),
628 RST_DAC = _REG_BIT(0x18, 29),
629 RST_COMP = _REG_BIT(0x18, 31),
630};
632
634
635void rcc_osc_ready_int_clear(enum rcc_osc osc);
636void rcc_osc_ready_int_enable(enum rcc_osc osc);
638int rcc_osc_ready_int_flag(enum rcc_osc osc);
639void rcc_css_int_clear(void);
640int rcc_css_int_flag(void);
642void rcc_osc_on(enum rcc_osc osc);
643void rcc_osc_off(enum rcc_osc osc);
644void rcc_css_enable(void);
645void rcc_css_disable(void);
646void rcc_set_msi_range(uint32_t range);
647void rcc_set_sysclk_source(uint32_t clk);
648void rcc_set_pll_configuration(uint32_t source, uint32_t multiplier,
649 uint32_t divisor);
650void rcc_set_pll_source(uint32_t pllsrc);
651void rcc_set_adcpre(uint32_t adcpre);
652void rcc_set_ppre2(uint32_t ppre2);
653void rcc_set_ppre1(uint32_t ppre1);
654void rcc_set_hpre(uint32_t hpre);
655void rcc_set_usbpre(uint32_t usbpre);
656void rcc_set_rtcpre(uint32_t rtcpre);
657uint32_t rcc_system_clock_source(void);
658void rcc_rtc_select_clock(uint32_t clock);
659void rcc_clock_setup_msi(const struct rcc_clock_scale *clock);
660void rcc_clock_setup_hsi(const struct rcc_clock_scale *clock);
661void rcc_clock_setup_pll(const struct rcc_clock_scale *clock);
663uint32_t rcc_get_usart_clk_freq(uint32_t usart);
664uint32_t rcc_get_timer_clk_freq(uint32_t timer);
665uint32_t rcc_get_i2c_clk_freq(uint32_t i2c);
666uint32_t rcc_get_spi_clk_freq(uint32_t spi);
667
669
670/**@}*/
671
672#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
int rcc_osc_ready_int_flag(enum rcc_osc osc)
Definition: rcc.c:195
int rcc_css_int_flag(void)
Definition: rcc.c:227
void rcc_set_adcpre(uint32_t adcpre)
void rcc_osc_ready_int_clear(enum rcc_osc osc)
Definition: rcc.c:123
void rcc_clock_setup_msi(const struct rcc_clock_scale *clock)
Definition: rcc.c:432
void rcc_css_disable(void)
Definition: rcc.c:334
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:603
void rcc_set_sysclk_source(uint32_t clk)
Definition: rcc.c:351
uint32_t rcc_apb2_frequency
Definition: rcc.c:50
void rcc_set_pll_source(uint32_t pllsrc)
Definition: rcc.c:375
void rcc_rtc_select_clock(uint32_t clock)
Definition: rcc.c:426
uint32_t rcc_get_timer_clk_freq(uint32_t timer)
Get the peripheral clock speed for the Timer at base specified.
Definition: rcc.c:576
uint32_t rcc_system_clock_source(void)
Definition: rcc.c:420
uint32_t rcc_get_usart_clk_freq(uint32_t usart)
Get the peripheral clock speed for the USART at base specified.
Definition: rcc.c:563
void rcc_clock_setup_pll(const struct rcc_clock_scale *clock)
Definition: rcc.c:512
rcc_periph_rst
Definition: l1/rcc.h:582
void rcc_set_msi_range(uint32_t range)
Set the range of the MSI oscillator.
Definition: rcc.c:343
rcc_periph_clken
Definition: l1/rcc.h:483
void rcc_set_rtcpre(uint32_t rtcpre)
Definition: rcc.c:411
void rcc_osc_ready_int_enable(enum rcc_osc osc)
Definition: rcc.c:147
rcc_osc
Definition: l1/rcc.h:477
void rcc_osc_ready_int_disable(enum rcc_osc osc)
Definition: rcc.c:171
void rcc_osc_on(enum rcc_osc osc)
Definition: rcc.c:281
#define _REG_BIT(base, bit)
Definition: l1/rcc.h:481
uint32_t rcc_ahb_frequency
Definition: rcc.c:48
void rcc_osc_off(enum rcc_osc osc)
Definition: rcc.c:305
void rcc_set_pll_configuration(uint32_t source, uint32_t multiplier, uint32_t divisor)
Definition: rcc.c:360
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:594
const struct rcc_clock_scale rcc_clock_config[RCC_CLOCK_CONFIG_END]
Definition: rcc.c:52
void rcc_backupdomain_reset(void)
uint32_t rcc_apb1_frequency
Definition: rcc.c:49
void rcc_wait_for_sysclk_status(enum rcc_osc osc)
Definition: rcc.c:256
void rcc_set_ppre1(uint32_t ppre1)
Definition: rcc.c:393
void rcc_css_int_clear(void)
Definition: rcc.c:222
void rcc_set_ppre2(uint32_t ppre2)
Definition: rcc.c:384
void rcc_set_usbpre(uint32_t usbpre)
void rcc_css_enable(void)
Definition: rcc.c:329
void rcc_set_hpre(uint32_t hpre)
Definition: rcc.c:402
rcc_clock_config_entry
Definition: l1/rcc.h:457
void rcc_clock_setup_hsi(const struct rcc_clock_scale *clock)
Switch sysclock to HSI with the given parameters.
Definition: rcc.c:473
@ RST_FLITF
Definition: l1/rcc.h:593
@ RST_DMA2
Definition: l1/rcc.h:595
@ RST_FSMC
Definition: l1/rcc.h:597
@ RST_DMA1
Definition: l1/rcc.h:594
@ RST_SPI1
Definition: l1/rcc.h:606
@ RST_GPIOG
Definition: l1/rcc.h:591
@ RST_ADC1
Definition: l1/rcc.h:604
@ RST_GPIOF
Definition: l1/rcc.h:590
@ RST_AES
Definition: l1/rcc.h:596
@ RST_SPI2
Definition: l1/rcc.h:618
@ RST_GPIOH
Definition: l1/rcc.h:589
@ RST_TIM9
Definition: l1/rcc.h:601
@ RST_COMP
Definition: l1/rcc.h:629
@ RST_UART4
Definition: l1/rcc.h:622
@ RST_TIM3
Definition: l1/rcc.h:611
@ RST_TIM10
Definition: l1/rcc.h:602
@ RST_GPIOA
Definition: l1/rcc.h:584
@ RST_GPIOC
Definition: l1/rcc.h:586
@ RST_TIM6
Definition: l1/rcc.h:614
@ RST_GPIOB
Definition: l1/rcc.h:585
@ RST_SPI3
Definition: l1/rcc.h:619
@ RST_USART3
Definition: l1/rcc.h:621
@ RST_DAC
Definition: l1/rcc.h:628
@ RST_TIM7
Definition: l1/rcc.h:615
@ RST_TIM2
Definition: l1/rcc.h:610
@ RST_CRC
Definition: l1/rcc.h:592
@ RST_GPIOD
Definition: l1/rcc.h:587
@ RST_USB
Definition: l1/rcc.h:626
@ RST_TIM4
Definition: l1/rcc.h:612
@ RST_TIM5
Definition: l1/rcc.h:613
@ RST_SYSCFG
Definition: l1/rcc.h:600
@ RST_UART5
Definition: l1/rcc.h:623
@ RST_GPIOE
Definition: l1/rcc.h:588
@ RST_I2C2
Definition: l1/rcc.h:625
@ RST_PWR
Definition: l1/rcc.h:627
@ RST_USART1
Definition: l1/rcc.h:607
@ RST_SDIO
Definition: l1/rcc.h:605
@ RST_WWDG
Definition: l1/rcc.h:617
@ RST_I2C1
Definition: l1/rcc.h:624
@ RST_LCD
Definition: l1/rcc.h:616
@ RST_USART2
Definition: l1/rcc.h:620
@ RST_TIM11
Definition: l1/rcc.h:603
@ SCC_CRC
Definition: l1/rcc.h:541
@ SCC_SPI3
Definition: l1/rcc.h:569
@ RCC_UART5
Definition: l1/rcc.h:524
@ SCC_TIM11
Definition: l1/rcc.h:553
@ RCC_TIM9
Definition: l1/rcc.h:502
@ RCC_FSMC
Definition: l1/rcc.h:498
@ SCC_GPIOD
Definition: l1/rcc.h:536
@ RCC_SPI2
Definition: l1/rcc.h:519
@ RCC_WWDG
Definition: l1/rcc.h:518
@ RCC_TIM3
Definition: l1/rcc.h:512
@ SCC_SPI2
Definition: l1/rcc.h:568
@ RCC_SDIO
Definition: l1/rcc.h:506
@ RCC_LCD
Definition: l1/rcc.h:517
@ RCC_FLITF
Definition: l1/rcc.h:494
@ SCC_UART4
Definition: l1/rcc.h:572
@ RCC_GPIOA
Definition: l1/rcc.h:485
@ SCC_GPIOH
Definition: l1/rcc.h:538
@ SCC_GPIOA
Definition: l1/rcc.h:533
@ SCC_DMA2
Definition: l1/rcc.h:545
@ RCC_TIM2
Definition: l1/rcc.h:511
@ SCC_TIM6
Definition: l1/rcc.h:564
@ SCC_ADC1
Definition: l1/rcc.h:554
@ SCC_TIM2
Definition: l1/rcc.h:560
@ SCC_TIM3
Definition: l1/rcc.h:561
@ SCC_TIM9
Definition: l1/rcc.h:551
@ RCC_GPIOG
Definition: l1/rcc.h:492
@ RCC_GPIOH
Definition: l1/rcc.h:490
@ RCC_TIM10
Definition: l1/rcc.h:503
@ RCC_COMP
Definition: l1/rcc.h:530
@ SCC_FSMC
Definition: l1/rcc.h:547
@ RCC_PWR
Definition: l1/rcc.h:528
@ RCC_CRC
Definition: l1/rcc.h:493
@ SCC_USART2
Definition: l1/rcc.h:570
@ SCC_USART3
Definition: l1/rcc.h:571
@ SCC_I2C2
Definition: l1/rcc.h:575
@ SCC_USB
Definition: l1/rcc.h:576
@ RCC_USART1
Definition: l1/rcc.h:508
@ SCC_WWDG
Definition: l1/rcc.h:567
@ SCC_PWR
Definition: l1/rcc.h:577
@ SCC_SYSCFG
Definition: l1/rcc.h:550
@ SCC_FLITF
Definition: l1/rcc.h:542
@ RCC_TIM4
Definition: l1/rcc.h:513
@ RCC_I2C1
Definition: l1/rcc.h:525
@ SCC_DAC
Definition: l1/rcc.h:578
@ SCC_LCD
Definition: l1/rcc.h:566
@ RCC_ADC1
Definition: l1/rcc.h:505
@ SCC_SPI1
Definition: l1/rcc.h:556
@ SCC_DMA1
Definition: l1/rcc.h:544
@ RCC_USB
Definition: l1/rcc.h:527
@ SCC_SRAM
Definition: l1/rcc.h:543
@ RCC_USART2
Definition: l1/rcc.h:521
@ SCC_GPIOE
Definition: l1/rcc.h:537
@ SCC_USART1
Definition: l1/rcc.h:557
@ SCC_COMP
Definition: l1/rcc.h:579
@ RCC_USART3
Definition: l1/rcc.h:522
@ SCC_I2C1
Definition: l1/rcc.h:574
@ RCC_TIM5
Definition: l1/rcc.h:514
@ RCC_SPI1
Definition: l1/rcc.h:507
@ RCC_SYSCFG
Definition: l1/rcc.h:501
@ SCC_GPIOC
Definition: l1/rcc.h:535
@ RCC_I2C2
Definition: l1/rcc.h:526
@ RCC_AES
Definition: l1/rcc.h:497
@ RCC_GPIOB
Definition: l1/rcc.h:486
@ RCC_TIM7
Definition: l1/rcc.h:516
@ RCC_GPIOF
Definition: l1/rcc.h:491
@ SCC_GPIOF
Definition: l1/rcc.h:539
@ RCC_GPIOC
Definition: l1/rcc.h:487
@ RCC_TIM6
Definition: l1/rcc.h:515
@ RCC_UART4
Definition: l1/rcc.h:523
@ SCC_TIM5
Definition: l1/rcc.h:563
@ SCC_GPIOB
Definition: l1/rcc.h:534
@ RCC_DMA1
Definition: l1/rcc.h:495
@ RCC_SPI3
Definition: l1/rcc.h:520
@ SCC_GPIOG
Definition: l1/rcc.h:540
@ RCC_DAC
Definition: l1/rcc.h:529
@ RCC_GPIOD
Definition: l1/rcc.h:488
@ SCC_SDIO
Definition: l1/rcc.h:555
@ RCC_GPIOE
Definition: l1/rcc.h:489
@ SCC_UART5
Definition: l1/rcc.h:573
@ SCC_TIM7
Definition: l1/rcc.h:565
@ RCC_DMA2
Definition: l1/rcc.h:496
@ SCC_AES
Definition: l1/rcc.h:546
@ RCC_TIM11
Definition: l1/rcc.h:504
@ SCC_TIM4
Definition: l1/rcc.h:562
@ SCC_TIM10
Definition: l1/rcc.h:552
@ RCC_HSI
Definition: l1/rcc.h:478
@ RCC_LSI
Definition: l1/rcc.h:478
@ RCC_PLL
Definition: l1/rcc.h:478
@ RCC_MSI
Definition: l1/rcc.h:478
@ RCC_LSE
Definition: l1/rcc.h:478
@ RCC_HSE
Definition: l1/rcc.h:478
@ RCC_CLOCK_VRANGE1_MSI_RAW_4MHZ
Definition: l1/rcc.h:462
@ RCC_CLOCK_VRANGE1_HSI_RAW_4MHZ
Definition: l1/rcc.h:461
@ RCC_CLOCK_VRANGE1_HSI_PLL_32MHZ
Definition: l1/rcc.h:459
@ RCC_CLOCK_VRANGE1_HSI_RAW_16MHZ
Definition: l1/rcc.h:460
@ RCC_CLOCK_VRANGE1_MSI_RAW_2MHZ
Definition: l1/rcc.h:463
@ RCC_CLOCK_VRANGE1_HSI_PLL_24MHZ
Definition: l1/rcc.h:458
@ RCC_CLOCK_CONFIG_END
Definition: l1/rcc.h:464
pwr_vos_scale
Voltage scales for internal regulator.
Definition: pwr_common_v2.h:82
uint8_t ppre1
Definition: l1/rcc.h:448
uint8_t flash_waitstates
Definition: l1/rcc.h:446
uint8_t ppre2
Definition: l1/rcc.h:449
uint32_t apb1_frequency
Definition: l1/rcc.h:452
uint8_t pll_mul
Definition: l1/rcc.h:443
uint32_t ahb_frequency
Definition: l1/rcc.h:451
enum pwr_vos_scale voltage_scale
Definition: l1/rcc.h:450
uint16_t pll_div
Definition: l1/rcc.h:444
uint8_t msi_range
Definition: l1/rcc.h:454
uint8_t hpre
Definition: l1/rcc.h:447
uint32_t apb2_frequency
Definition: l1/rcc.h:453
uint8_t pll_source
Definition: l1/rcc.h:445