annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_rcc.c @ 112:fdf0272e9213 FlipDisplay

Added new nvm parameter"FlipDisplay" indicating the screen orientation
author Ideenmodellierer
date Tue, 01 Jan 2019 21:03:33 +0100
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_rcc.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief RCC HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the Reset and Clock Control (RCC) peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ##### RCC specific features #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 After reset the device is running from Internal High Speed oscillator
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 (HSI 16MHz) with Flash 0 wait state, Flash prefetch buffer, D-Cache
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 and I-Cache are disabled, and all peripherals are off except internal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 SRAM, Flash and JTAG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 (+) There is no prescaler on High speed (AHB) and Low speed (APB) busses;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 all peripherals mapped on these busses are running at HSI speed.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 (+) The clock for all peripherals is switched off, except the SRAM and FLASH.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (+) All GPIOs are in input floating state, except the JTAG pins which
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 are assigned to be used for debug purpose.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 Once the device started from reset, the user application has to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 (+) Configure the clock source to be used to drive the System clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (if the application needs higher frequency/performance)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 (+) Configure the System clock frequency and Flash settings
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 (+) Configure the AHB and APB busses prescalers
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (+) Enable the clock for the peripheral(s) to be used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 (+) Configure the clock source(s) for peripherals which clocks are not
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 derived from the System clock (I2S, RTC, ADC, USB OTG FS/SDIO/RNG)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 ##### RCC Limitations #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 A delay between an RCC peripheral clock enable and the effective peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 enabling should be taken into account in order to manage the peripheral read/write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 from/to registers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 (+) This delay depends on the peripheral mapping.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 (+) If peripheral is mapped on AHB: the delay is 2 AHB clock cycle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 after the clock enable bit is set on the hardware register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 (+) If peripheral is mapped on APB: the delay is 2 APB clock cycle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 after the clock enable bit is set on the hardware register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 Possible Workarounds:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 (#) Enable the peripheral clock sometimes before the peripheral read/write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 register is required.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 (#) For AHB peripheral, insert two dummy read to the peripheral register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 (#) For APB peripheral, insert a dummy read to the peripheral register.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 /** @defgroup RCC RCC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 * @brief RCC HAL module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 #ifdef HAL_RCC_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 /** @addtogroup RCC_Private_Constants
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 #define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 #define HSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 #define LSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 #define PLL_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 #define CLOCKSWITCH_TIMEOUT_VALUE ((uint32_t)5000) /* 5 s */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 #define __MCO1_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 #define MCO1_GPIO_PORT GPIOA
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 #define MCO1_PIN GPIO_PIN_8
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 #define __MCO2_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 #define MCO2_GPIO_PORT GPIOC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 #define MCO2_PIN GPIO_PIN_9
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 /** @defgroup RCC_Private_Variables RCC Private Variables
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 const uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 /** @defgroup RCC_Exported_Functions RCC Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 /** @defgroup RCC_Exported_Functions_Group1 Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 ##### Initialization and de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 This section provides functions allowing to configure the internal/external oscillators
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 (HSE, HSI, LSE, LSI, PLL, CSS and MCO) and the System busses clocks (SYSCLK, AHB, APB1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 and APB2).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 [..] Internal/external clock and PLL configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 (#) HSI (high-speed internal), 16 MHz factory-trimmed RC used directly or through
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 the PLL as System clock source.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 (#) LSI (low-speed internal), 32 KHz low consumption RC used as IWDG and/or RTC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 clock source.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 (#) HSE (high-speed external), 4 to 26 MHz crystal oscillator used directly or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 through the PLL as System clock source. Can be used also as RTC clock source.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 (#) LSE (low-speed external), 32 KHz oscillator used as RTC clock source.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 (#) PLL (clocked by HSI or HSE), featuring two different output clocks:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 (++) The first output is used to generate the high speed system clock (up to 168 MHz)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 (++) The second output is used to generate the clock for the USB OTG FS (48 MHz),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 the random analog generator (<=48 MHz) and the SDIO (<= 48 MHz).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 (#) CSS (Clock security system), once enable using the macro __HAL_RCC_CSS_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 and if a HSE clock failure occurs(HSE used directly or through PLL as System
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 clock source), the System clocks automatically switched to HSI and an interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 is generated if enabled. The interrupt is linked to the Cortex-M4 NMI
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 (Non-Maskable Interrupt) exception vector.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 (#) MCO1 (microcontroller clock output), used to output HSI, LSE, HSE or PLL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 clock (through a configurable prescaler) on PA8 pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 (#) MCO2 (microcontroller clock output), used to output HSE, PLL, SYSCLK or PLLI2S
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 clock (through a configurable prescaler) on PC9 pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 [..] System, AHB and APB busses clocks configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 (#) Several clock sources can be used to drive the System clock (SYSCLK): HSI,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 HSE and PLL.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 The AHB clock (HCLK) is derived from System clock through configurable
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 prescaler and used to clock the CPU, memory and peripherals mapped
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 on AHB bus (DMA, GPIO...). APB1 (PCLK1) and APB2 (PCLK2) clocks are derived
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 from AHB clock through configurable prescalers and used to clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 the peripherals mapped on these busses. You can use
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 "HAL_RCC_GetSysClockFreq()" function to retrieve the frequencies of these clocks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 -@- All the peripheral clocks are derived from the System clock (SYSCLK) except:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 (+@) I2S: the I2S clock can be derived either from a specific PLL (PLLI2S) or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 from an external clock mapped on the I2S_CKIN pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 You have to use __HAL_RCC_PLLI2S_CONFIG() macro to configure this clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 (+@) SAI: the SAI clock can be derived either from a specific PLL (PLLI2S) or (PLLSAI) or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 from an external clock mapped on the I2S_CKIN pin.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 You have to use __HAL_RCC_PLLI2S_CONFIG() macro to configure this clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 (+@) RTC: the RTC clock can be derived either from the LSI, LSE or HSE clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 divided by 2 to 31. You have to use __HAL_RCC_RTC_CONFIG() and __HAL_RCC_RTC_ENABLE()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 macros to configure this clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 (+@) USB OTG FS, SDIO and RTC: USB OTG FS require a frequency equal to 48 MHz
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 to work correctly, while the SDIO require a frequency equal or lower than
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 to 48. This clock is derived of the main PLL through PLLQ divider.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 (+@) IWDG clock which is always the LSI clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 (#) For the STM32F405xx/07xx and STM32F415xx/17xx devices, the maximum
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 frequency of the SYSCLK and HCLK is 168 MHz, PCLK2 84 MHz and PCLK1 42 MHz.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 Depending on the device voltage range, the maximum frequency should
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 be adapted accordingly (refer to the product datasheets for more details).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 (#) For the STM32F42xxx and STM32F43xxx devices, the maximum frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 of the SYSCLK and HCLK is 180 MHz, PCLK2 90 MHz and PCLK1 45 MHz.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 Depending on the device voltage range, the maximum frequency should
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 be adapted accordingly (refer to the product datasheets for more details).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 (#) For the STM32F401xx, the maximum frequency of the SYSCLK and HCLK is 84 MHz,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 PCLK2 84 MHz and PCLK1 42 MHz.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 Depending on the device voltage range, the maximum frequency should
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 be adapted accordingly (refer to the product datasheets for more details).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 * @brief Resets the RCC clock configuration to the default reset state.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 * @note The default reset state of the clock configuration is given below:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 * - HSI ON and used as system clock source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 * - HSE, PLL and PLLI2S OFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 * - AHB, APB1 and APB2 prescaler set to 1.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 * - CSS, MCO1 and MCO2 OFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 * - All interrupts disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 * @note This function doesn't modify the configuration of the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 * - Peripheral clocks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 * - LSI, LSE and RTC clocks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 void HAL_RCC_DeInit(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 /* Set HSION bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 SET_BIT(RCC->CR, RCC_CR_HSION | RCC_CR_HSITRIM_4);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 /* Reset CFGR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 CLEAR_REG(RCC->CFGR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 /* Reset HSEON, CSSON, PLLON, PLLI2S */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 CLEAR_BIT(RCC->CR, RCC_CR_HSEON | RCC_CR_CSSON | RCC_CR_PLLON| RCC_CR_PLLI2SON);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 /* Reset PLLCFGR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 CLEAR_REG(RCC->PLLCFGR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 SET_BIT(RCC->PLLCFGR, RCC_PLLCFGR_PLLM_4 | RCC_PLLCFGR_PLLN_6 | RCC_PLLCFGR_PLLN_7 | RCC_PLLCFGR_PLLQ_2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 /* Reset PLLI2SCFGR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 CLEAR_REG(RCC->PLLI2SCFGR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 SET_BIT(RCC->PLLI2SCFGR, RCC_PLLI2SCFGR_PLLI2SN_6 | RCC_PLLI2SCFGR_PLLI2SN_7 | RCC_PLLI2SCFGR_PLLI2SR_1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 /* Reset HSEBYP bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 CLEAR_BIT(RCC->CR, RCC_CR_HSEBYP);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 /* Disable all interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 CLEAR_REG(RCC->CIR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 * @brief Initializes the RCC Oscillators according to the specified parameters in the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 * RCC_OscInitTypeDef.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 * @param RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 * contains the configuration information for the RCC Oscillators.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 * @note The PLL is not disabled when used as system clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 assert_param(IS_RCC_OSCILLATORTYPE(RCC_OscInitStruct->OscillatorType));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 /*------------------------------- HSE Configuration ------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSE) == RCC_OSCILLATORTYPE_HSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 assert_param(IS_RCC_HSE(RCC_OscInitStruct->HSEState));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 /* When the HSE is used as system clock or clock source for PLL in these cases HSE will not disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSE) || ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSE)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET) && (RCC_OscInitStruct->HSEState == RCC_HSE_OFF))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 /* Reset HSEON and HSEBYP bits before configuring the HSE --------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 __HAL_RCC_HSE_CONFIG(RCC_HSE_OFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 /* Wait till HSE is disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 /* Set the new HSE configuration ---------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 __HAL_RCC_HSE_CONFIG(RCC_OscInitStruct->HSEState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 /* Check the HSE State */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 if((RCC_OscInitStruct->HSEState) != RCC_HSE_OFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 /* Wait till HSE is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 /* Wait till HSE is bypassed or disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 if((HAL_GetTick() - tickstart ) > HSE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 /*----------------------------- HSI Configuration --------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 /* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 if((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_HSI) || ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_CFGR_SWS_PLL) && ((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLCFGR_PLLSRC_HSI)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 /* When HSI is used as system clock it will not disabled */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 /* Otherwise, just the calibration is allowed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 /* Check the HSI State */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 if((RCC_OscInitStruct->HSIState)!= RCC_HSI_OFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 /* Enable the Internal High Speed oscillator (HSI). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 __HAL_RCC_HSI_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 /* Wait till HSI is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 /* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /* Disable the Internal High Speed oscillator (HSI). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 __HAL_RCC_HSI_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 /* Wait till HSI is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 /*------------------------------ LSI Configuration -------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 assert_param(IS_RCC_LSI(RCC_OscInitStruct->LSIState));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 /* Check the LSI State */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 if((RCC_OscInitStruct->LSIState)!= RCC_LSI_OFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 /* Enable the Internal Low Speed oscillator (LSI). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 __HAL_RCC_LSI_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 /* Wait till LSI is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 /* Disable the Internal Low Speed oscillator (LSI). */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 __HAL_RCC_LSI_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 /* Wait till LSI is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 if((HAL_GetTick() - tickstart ) > LSI_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 /*------------------------------ LSE Configuration -------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSE) == RCC_OSCILLATORTYPE_LSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 assert_param(IS_RCC_LSE(RCC_OscInitStruct->LSEState));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 /* Enable Power Clock*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 __HAL_RCC_PWR_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 /* Enable write access to Backup domain */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 PWR->CR |= PWR_CR_DBP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 /* Wait for Backup domain Write protection disable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 while((PWR->CR & PWR_CR_DBP) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 if((HAL_GetTick() - tickstart ) > RCC_DBP_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 /* Reset LSEON and LSEBYP bits before configuring the LSE ----------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 __HAL_RCC_LSE_CONFIG(RCC_LSE_OFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 /* Wait till LSE is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 /* Set the new LSE configuration -----------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 __HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 /* Check the LSE State */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 if((RCC_OscInitStruct->LSEState) == RCC_LSE_ON)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 /* Wait till LSE is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 /* Wait till LSE is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 /*-------------------------------- PLL Configuration -----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 /* Check if the PLL is used as system clock or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 assert_param(IS_RCC_PLLM_VALUE(RCC_OscInitStruct->PLL.PLLM));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 assert_param(IS_RCC_PLLN_VALUE(RCC_OscInitStruct->PLL.PLLN));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 assert_param(IS_RCC_PLLP_VALUE(RCC_OscInitStruct->PLL.PLLP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 assert_param(IS_RCC_PLLQ_VALUE(RCC_OscInitStruct->PLL.PLLQ));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 /* Disable the main PLL. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 __HAL_RCC_PLL_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 /* Wait till PLL is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 /* Configure the main PLL clock source, multiplication and division factors. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 RCC_OscInitStruct->PLL.PLLM,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 RCC_OscInitStruct->PLL.PLLN,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 RCC_OscInitStruct->PLL.PLLP,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 RCC_OscInitStruct->PLL.PLLQ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 /* Enable the main PLL. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 __HAL_RCC_PLL_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 /* Wait till PLL is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 /* Disable the main PLL. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 __HAL_RCC_PLL_DISABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 /* Wait till PLL is ready */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 * @brief Initializes the CPU, AHB and APB busses clocks according to the specified
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 * parameters in the RCC_ClkInitStruct.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 * @param RCC_ClkInitStruct: pointer to an RCC_OscInitTypeDef structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 * contains the configuration information for the RCC peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 * @param FLatency: FLASH Latency, this parameter depend on device selected
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 * @note The SystemCoreClock CMSIS variable is used to store System Clock Frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 * and updated by HAL_RCC_GetHCLKFreq() function called within this function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 * @note The HSI is used (enabled by hardware) as system clock source after
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 * startup from Reset, wake-up from STOP and STANDBY mode, or in case
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 * of failure of the HSE used directly or indirectly as system clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 * (if the Clock Security System CSS is enabled).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 * @note A switch from one clock source to another occurs only if the target
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 * clock source is ready (clock stable after startup delay or PLL locked).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 * If a clock source which is not yet ready is selected, the switch will
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 * occur when the clock source will be ready.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 * @note Depending on the device voltage range, the software has to set correctly
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 * HPRE[3:0] bits to ensure that HCLK not exceed the maximum allowed frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 * (for more details refer to section above "Initialization/de-initialization functions")
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 assert_param(IS_RCC_CLOCKTYPE(RCC_ClkInitStruct->ClockType));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 assert_param(IS_FLASH_LATENCY(FLatency));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 /* To correctly read data from FLASH memory, the number of wait states (LATENCY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 must be correctly programmed according to the frequency of the CPU clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 (HCLK) and the supply voltage of the device. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 /* Increasing the CPU frequency */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 if(FLatency > (FLASH->ACR & FLASH_ACR_LATENCY))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 __HAL_FLASH_SET_LATENCY(FLatency);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 /* Check that the new number of wait states is taken into account to access the Flash
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 memory by reading the FLASH_ACR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 /*-------------------------- HCLK Configuration --------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 /*------------------------- SYSCLK Configuration ---------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 /* HSE is selected as System Clock Source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 /* Check the HSE ready flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 /* PLL is selected as System Clock Source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 /* Check the PLL ready flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 if(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 /* HSI is selected as System Clock Source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 /* Check the HSI ready flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_ClkInitStruct->SYSCLKSource);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_HSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 while(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_HSI)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 /* Decreasing the CPU frequency */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 /*-------------------------- HCLK Configuration --------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 assert_param(IS_RCC_HCLK(RCC_ClkInitStruct->AHBCLKDivider));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 MODIFY_REG(RCC->CFGR, RCC_CFGR_HPRE, RCC_ClkInitStruct->AHBCLKDivider);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 /*------------------------- SYSCLK Configuration -------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 /* HSE is selected as System Clock Source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 /* Check the HSE ready flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 /* PLL is selected as System Clock Source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 /* Check the PLL ready flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 if(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 /* HSI is selected as System Clock Source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 /* Check the HSI ready flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_ClkInitStruct->SYSCLKSource);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 /* Get Start Tick*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_HSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 while(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_HSI)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 /* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 __HAL_FLASH_SET_LATENCY(FLatency);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 /* Check that the new number of wait states is taken into account to access the Flash
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 memory by reading the FLASH_ACR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 /*-------------------------- PCLK1 Configuration ---------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB1CLKDivider));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_ClkInitStruct->APB1CLKDivider);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 /*-------------------------- PCLK2 Configuration ---------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB2CLKDivider));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, ((RCC_ClkInitStruct->APB2CLKDivider) << 3));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 /* Configure the source of time base considering new system clocks settings*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 HAL_InitTick (TICK_INT_PRIORITY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 /** @defgroup RCC_Exported_Functions_Group2 Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 * @brief RCC clocks control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 ##### Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 This subsection provides a set of functions allowing to control the RCC Clocks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 frequencies.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 * @brief Selects the clock source to output on MCO1 pin(PA8) or on MCO2 pin(PC9).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 * @note PA8/PC9 should be configured in alternate function mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 * @param RCC_MCOx: specifies the output direction for the clock source.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 * @arg RCC_MCO1: Clock source to output on MCO1 pin(PA8).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 * @arg RCC_MCO2: Clock source to output on MCO2 pin(PC9).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 * @param RCC_MCOSource: specifies the clock source to output.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 * @arg RCC_MCO1SOURCE_HSI: HSI clock selected as MCO1 source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 * @arg RCC_MCO1SOURCE_LSE: LSE clock selected as MCO1 source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 * @arg RCC_MCO1SOURCE_HSE: HSE clock selected as MCO1 source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 * @arg RCC_MCO1SOURCE_PLLCLK: main PLL clock selected as MCO1 source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 * @arg RCC_MCO2SOURCE_SYSCLK: System clock (SYSCLK) selected as MCO2 source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 * @arg RCC_MCO2SOURCE_PLLI2SCLK: PLLI2S clock selected as MCO2 source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 * @arg RCC_MCO2SOURCE_HSE: HSE clock selected as MCO2 source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 * @arg RCC_MCO2SOURCE_PLLCLK: main PLL clock selected as MCO2 source
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 * @param RCC_MCODiv: specifies the MCOx prescaler.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 * @arg RCC_MCODIV_1: no division applied to MCOx clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 * @arg RCC_MCODIV_2: division by 2 applied to MCOx clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 * @arg RCC_MCODIV_3: division by 3 applied to MCOx clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 * @arg RCC_MCODIV_4: division by 4 applied to MCOx clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 * @arg RCC_MCODIV_5: division by 5 applied to MCOx clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 GPIO_InitTypeDef GPIO_InitStruct;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 assert_param(IS_RCC_MCO(RCC_MCOx));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 assert_param(IS_RCC_MCODIV(RCC_MCODiv));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 /* RCC_MCO1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 if(RCC_MCOx == RCC_MCO1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 assert_param(IS_RCC_MCO1SOURCE(RCC_MCOSource));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 /* MCO1 Clock Enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 __MCO1_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 /* Configure the MCO1 pin in alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 GPIO_InitStruct.Pin = MCO1_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 GPIO_InitStruct.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 HAL_GPIO_Init(MCO1_GPIO_PORT, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 /* Mask MCO1 and MCO1PRE[2:0] bits then Select MCO1 clock source and prescaler */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO1 | RCC_CFGR_MCO1PRE), (RCC_MCOSource | RCC_MCODiv));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 assert_param(IS_RCC_MCO2SOURCE(RCC_MCOSource));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 /* MCO2 Clock Enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 __MCO2_CLK_ENABLE();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 /* Configure the MCO2 pin in alternate function mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 GPIO_InitStruct.Pin = MCO2_PIN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 GPIO_InitStruct.Pull = GPIO_NOPULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 HAL_GPIO_Init(MCO2_GPIO_PORT, &GPIO_InitStruct);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 /* Mask MCO2 and MCO2PRE[2:0] bits then Select MCO2 clock source and prescaler */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 MODIFY_REG(RCC->CFGR, (RCC_CFGR_MCO2 | RCC_CFGR_MCO2PRE), (RCC_MCOSource | (RCC_MCODiv << 3)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 * @brief Enables the Clock Security System.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 * @note If a failure is detected on the HSE oscillator clock, this oscillator
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 * is automatically disabled and an interrupt is generated to inform the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 * software about the failure (Clock Security System Interrupt, CSSI),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 * allowing the MCU to perform rescue operations. The CSSI is linked to
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 * the Cortex-M4 NMI (Non-Maskable Interrupt) exception vector.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 void HAL_RCC_EnableCSS(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 *(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)ENABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 * @brief Disables the Clock Security System.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 void HAL_RCC_DisableCSS(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 *(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)DISABLE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 * @brief Returns the SYSCLK frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 * @note The system frequency computed by this function is not the real
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 * frequency in the chip. It is calculated based on the predefined
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 * constant and the selected clock source:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(*)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(**)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE(**)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 * or HSI_VALUE(*) multiplied/divided by the PLL factors.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 * @note (*) HSI_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 * 16 MHz) but the real value may vary depending on the variations
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 * in voltage and temperature.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 * @note (**) HSE_VALUE is a constant defined in stm32f4xx_hal_conf.h file (default value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 * 25 MHz), user has to ensure that HSE_VALUE is same as the real
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 * frequency of the crystal used. Otherwise, this function may
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 * have wrong result.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 * @note The result of this function could be not correct when using fractional
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 * value for HSE crystal.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 * @note This function can be used by the user application to compute the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 * baudrate for the communication peripherals or configure other parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 * @note Each time SYSCLK changes, this function must be called to update the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 * right SYSCLK value. Otherwise, any configuration based on this function will be incorrect.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 * @retval SYSCLK frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 uint32_t HAL_RCC_GetSysClockFreq(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 uint32_t pllm = 0, pllvco = 0, pllp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 uint32_t sysclockfreq = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 /* Get SYSCLK source -------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 switch (RCC->CFGR & RCC_CFGR_SWS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 case RCC_CFGR_SWS_HSI: /* HSI used as system clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 sysclockfreq = HSI_VALUE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 case RCC_CFGR_SWS_HSE: /* HSE used as system clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 sysclockfreq = HSE_VALUE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 case RCC_CFGR_SWS_PLL: /* PLL used as system clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 SYSCLK = PLL_VCO / PLLP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 if(__HAL_RCC_GET_PLL_OSCSOURCE() != RCC_PLLSOURCE_HSI)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 /* HSE used as PLL clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 pllvco = ((HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 /* HSI used as PLL clock source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 pllvco = ((HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 pllp = ((((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >> POSITION_VAL(RCC_PLLCFGR_PLLP)) + 1 ) *2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 sysclockfreq = pllvco/pllp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 sysclockfreq = HSI_VALUE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 return sysclockfreq;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 * @brief Returns the HCLK frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 * @note Each time HCLK changes, this function must be called to update the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 * right HCLK value. Otherwise, any configuration based on this function will be incorrect.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 * @note The SystemCoreClock CMSIS variable is used to store System Clock Frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 * and updated within this function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 * @retval HCLK frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 uint32_t HAL_RCC_GetHCLKFreq(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 SystemCoreClock = HAL_RCC_GetSysClockFreq() >> APBAHBPrescTable[(RCC->CFGR & RCC_CFGR_HPRE)>> POSITION_VAL(RCC_CFGR_HPRE)];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 return SystemCoreClock;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 * @brief Returns the PCLK1 frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 * @note Each time PCLK1 changes, this function must be called to update the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 * right PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 * @retval PCLK1 frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 uint32_t HAL_RCC_GetPCLK1Freq(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 return (HAL_RCC_GetHCLKFreq() >> APBAHBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE1)>> POSITION_VAL(RCC_CFGR_PPRE1)]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 * @brief Returns the PCLK2 frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 * @note Each time PCLK2 changes, this function must be called to update the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 * right PCLK2 value. Otherwise, any configuration based on this function will be incorrect.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 * @retval PCLK2 frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 uint32_t HAL_RCC_GetPCLK2Freq(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 /* Get HCLK source and Compute PCLK2 frequency ---------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 return (HAL_RCC_GetHCLKFreq()>> APBAHBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE2)>> POSITION_VAL(RCC_CFGR_PPRE2)]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 * @brief Configures the RCC_OscInitStruct according to the internal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 * RCC configuration registers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 * @param RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 * will be configured.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 /* Set all possible values for the Oscillator type parameter ---------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 /* Get the HSE configuration -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 if((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 else if((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 RCC_OscInitStruct->HSEState = RCC_HSE_ON;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 /* Get the HSI configuration -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 if((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 RCC_OscInitStruct->HSIState = RCC_HSI_ON;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR &RCC_CR_HSITRIM) >> POSITION_VAL(RCC_CR_HSITRIM));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 /* Get the LSE configuration -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 if((RCC->BDCR &RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 else if((RCC->BDCR &RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 RCC_OscInitStruct->LSEState = RCC_LSE_ON;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 /* Get the LSI configuration -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 if((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 RCC_OscInitStruct->LSIState = RCC_LSI_ON;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 /* Get the PLL configuration -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 if((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 RCC_OscInitStruct->PLL.PLLM = (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 RCC_OscInitStruct->PLL.PLLN = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> POSITION_VAL(RCC_PLLCFGR_PLLN));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 RCC_OscInitStruct->PLL.PLLP = (uint32_t)((((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) + RCC_PLLCFGR_PLLP_0) << 1) >> POSITION_VAL(RCC_PLLCFGR_PLLP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 RCC_OscInitStruct->PLL.PLLQ = (uint32_t)((RCC->PLLCFGR & RCC_PLLCFGR_PLLQ) >> POSITION_VAL(RCC_PLLCFGR_PLLQ));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 * @brief Configures the RCC_ClkInitStruct according to the internal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 * RCC configuration registers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 * @param RCC_ClkInitStruct: pointer to an RCC_ClkInitTypeDef structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 * will be configured.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 * @param pFLatency: Pointer on the Flash Latency.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 /* Set all possible values for the Clock type parameter --------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 RCC_ClkInitStruct->ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 /* Get the SYSCLK configuration --------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 RCC_ClkInitStruct->SYSCLKSource = (uint32_t)(RCC->CFGR & RCC_CFGR_SW);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 /* Get the HCLK configuration ----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 RCC_ClkInitStruct->AHBCLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_HPRE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 /* Get the APB1 configuration ----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 RCC_ClkInitStruct->APB1CLKDivider = (uint32_t)(RCC->CFGR & RCC_CFGR_PPRE1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 /* Get the APB2 configuration ----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 RCC_ClkInitStruct->APB2CLKDivider = (uint32_t)((RCC->CFGR & RCC_CFGR_PPRE2) >> 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 /* Get the Flash Wait State (Latency) configuration ------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 *pFLatency = (uint32_t)(FLASH->ACR & FLASH_ACR_LATENCY);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 * @brief This function handles the RCC CSS interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 * @note This API should be called under the NMI_Handler().
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 void HAL_RCC_NMI_IRQHandler(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 /* Check RCC CSSF flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 if(__HAL_RCC_GET_IT(RCC_IT_CSS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 /* RCC Clock Security System interrupt user callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 HAL_RCC_CSSCallback();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 /* Clear RCC CSS pending bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 __HAL_RCC_CLEAR_IT(RCC_IT_CSS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 * @brief RCC Clock Security System interrupt callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 __weak void HAL_RCC_CSSCallback(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 /* NOTE : This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 the HAL_RCC_CSSCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 #endif /* HAL_RCC_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/