diff options
Diffstat (limited to 'lib/chibios/os/hal/ports/STM32/STM32F3xx/hal_lld.h')
-rw-r--r-- | lib/chibios/os/hal/ports/STM32/STM32F3xx/hal_lld.h | 1205 |
1 files changed, 1205 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/ports/STM32/STM32F3xx/hal_lld.h b/lib/chibios/os/hal/ports/STM32/STM32F3xx/hal_lld.h new file mode 100644 index 000000000..f5e123547 --- /dev/null +++ b/lib/chibios/os/hal/ports/STM32/STM32F3xx/hal_lld.h | |||
@@ -0,0 +1,1205 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file STM32F3xx/hal_lld.h | ||
19 | * @brief STM32F3xx HAL subsystem low level driver header. | ||
20 | * @pre This module requires the following macros to be defined in the | ||
21 | * @p board.h file: | ||
22 | * - STM32_LSECLK. | ||
23 | * - STM32_LSEDRV. | ||
24 | * - STM32_LSE_BYPASS (optionally). | ||
25 | * - STM32_HSECLK. | ||
26 | * - STM32_HSE_BYPASS (optionally). | ||
27 | * . | ||
28 | * One of the following macros must also be defined: | ||
29 | * - STM32F301x8 for Analog & DSP devices. | ||
30 | * - STM32F302x8 for Analog & DSP devices. | ||
31 | * - STM32F302xC for Analog & DSP devices. | ||
32 | * - STM32F302xE for Analog & DSP devices. | ||
33 | * - STM32F303x8 for Analog & DSP devices. | ||
34 | * - STM32F303xC for Analog & DSP devices. | ||
35 | * - STM32F303xE for Analog & DSP devices. | ||
36 | * - STM32F318xx for Analog & DSP devices. | ||
37 | * - STM32F328xx for Analog & DSP devices. | ||
38 | * - STM32F334x8 for Analog & DSP devices. | ||
39 | * - STM32F358xx for Analog & DSP devices. | ||
40 | * - STM32F398xx for Analog & DSP devices. | ||
41 | * . | ||
42 | * | ||
43 | * @addtogroup HAL | ||
44 | * @{ | ||
45 | */ | ||
46 | |||
47 | #ifndef HAL_LLD_H | ||
48 | #define HAL_LLD_H | ||
49 | |||
50 | #include "stm32_registry.h" | ||
51 | |||
52 | /*===========================================================================*/ | ||
53 | /* Driver constants. */ | ||
54 | /*===========================================================================*/ | ||
55 | |||
56 | /** | ||
57 | * @name Platform identification macros | ||
58 | * @{ | ||
59 | */ | ||
60 | #if defined(STM32F301x8) || defined(__DOXYGEN__) | ||
61 | #define PLATFORM_NAME "STM32F301x8 Analog & DSP" | ||
62 | |||
63 | #elif defined(STM32F302x8) | ||
64 | #define PLATFORM_NAME "STM32F302x8 Analog & DSP" | ||
65 | |||
66 | #elif defined(STM32F302xC) | ||
67 | #define PLATFORM_NAME "STM32F302xC Analog & DSP" | ||
68 | |||
69 | #elif defined(STM32F302xE) | ||
70 | #define PLATFORM_NAME "STM32F302xE Analog & DSP" | ||
71 | |||
72 | #elif defined(STM32F303x8) | ||
73 | #define PLATFORM_NAME "STM32F303x8 Analog & DSP" | ||
74 | |||
75 | #elif defined(STM32F303xC) | ||
76 | #define PLATFORM_NAME "STM32F303xC Analog & DSP" | ||
77 | |||
78 | #elif defined(STM32F303xE) | ||
79 | #define PLATFORM_NAME "STM32F303xE Analog & DSP" | ||
80 | |||
81 | #elif defined(STM32F318xx) | ||
82 | #define PLATFORM_NAME "STM32F318xx Analog & DSP" | ||
83 | |||
84 | #elif defined(STM32F328xx) | ||
85 | #define PLATFORM_NAME "STM32F328xx Analog & DSP" | ||
86 | |||
87 | #elif defined(STM32F334x8) | ||
88 | #define PLATFORM_NAME "STM32F334x8 Analog & DSP" | ||
89 | |||
90 | #elif defined(STM32F358xx) | ||
91 | #define PLATFORM_NAME "STM32F358xx Analog & DSP" | ||
92 | |||
93 | #elif defined(STM32F398xx) | ||
94 | #define PLATFORM_NAME "STM32F398xx Analog & DSP" | ||
95 | |||
96 | #else | ||
97 | #error "STM32F3xx device not specified" | ||
98 | #endif | ||
99 | /** @} */ | ||
100 | |||
101 | /** | ||
102 | * @name Absolute Maximum Ratings | ||
103 | * @{ | ||
104 | */ | ||
105 | /** | ||
106 | * @brief Maximum system clock frequency. | ||
107 | */ | ||
108 | #define STM32_SYSCLK_MAX 72000000 | ||
109 | |||
110 | /** | ||
111 | * @brief Maximum HSE clock frequency. | ||
112 | */ | ||
113 | #define STM32_HSECLK_MAX 32000000 | ||
114 | |||
115 | /** | ||
116 | * @brief Minimum HSE clock frequency. | ||
117 | */ | ||
118 | #define STM32_HSECLK_MIN 1000000 | ||
119 | |||
120 | /** | ||
121 | * @brief Maximum LSE clock frequency. | ||
122 | */ | ||
123 | #define STM32_LSECLK_MAX 1000000 | ||
124 | |||
125 | /** | ||
126 | * @brief Minimum LSE clock frequency. | ||
127 | */ | ||
128 | #define STM32_LSECLK_MIN 32768 | ||
129 | |||
130 | /** | ||
131 | * @brief Maximum PLLs input clock frequency. | ||
132 | */ | ||
133 | #define STM32_PLLIN_MAX 24000000 | ||
134 | |||
135 | /** | ||
136 | * @brief Minimum PLLs input clock frequency. | ||
137 | */ | ||
138 | #define STM32_PLLIN_MIN 1000000 | ||
139 | |||
140 | /** | ||
141 | * @brief Maximum PLL output clock frequency. | ||
142 | */ | ||
143 | #define STM32_PLLOUT_MAX 72000000 | ||
144 | |||
145 | /** | ||
146 | * @brief Minimum PLL output clock frequency. | ||
147 | */ | ||
148 | #define STM32_PLLOUT_MIN 16000000 | ||
149 | |||
150 | /** | ||
151 | * @brief Maximum APB1 clock frequency. | ||
152 | */ | ||
153 | #define STM32_PCLK1_MAX 36000000 | ||
154 | |||
155 | /** | ||
156 | * @brief Maximum APB2 clock frequency. | ||
157 | */ | ||
158 | #define STM32_PCLK2_MAX 72000000 | ||
159 | |||
160 | /** | ||
161 | * @brief Maximum ADC clock frequency. | ||
162 | */ | ||
163 | #define STM32_ADCCLK_MAX 72000000 | ||
164 | /** @} */ | ||
165 | |||
166 | /** | ||
167 | * @name Internal clock sources | ||
168 | * @{ | ||
169 | */ | ||
170 | #define STM32_HSICLK 8000000 /**< High speed internal clock. */ | ||
171 | #define STM32_LSICLK 40000 /**< Low speed internal clock. */ | ||
172 | /** @} */ | ||
173 | |||
174 | /** | ||
175 | * @name PWR_CR register bits definitions | ||
176 | * @{ | ||
177 | */ | ||
178 | #define STM32_PLS_MASK (7 << 5) /**< PLS bits mask. */ | ||
179 | #define STM32_PLS_LEV0 (0 << 5) /**< PVD level 0. */ | ||
180 | #define STM32_PLS_LEV1 (1 << 5) /**< PVD level 1. */ | ||
181 | #define STM32_PLS_LEV2 (2 << 5) /**< PVD level 2. */ | ||
182 | #define STM32_PLS_LEV3 (3 << 5) /**< PVD level 3. */ | ||
183 | #define STM32_PLS_LEV4 (4 << 5) /**< PVD level 4. */ | ||
184 | #define STM32_PLS_LEV5 (5 << 5) /**< PVD level 5. */ | ||
185 | #define STM32_PLS_LEV6 (6 << 5) /**< PVD level 6. */ | ||
186 | #define STM32_PLS_LEV7 (7 << 5) /**< PVD level 7. */ | ||
187 | /** @} */ | ||
188 | |||
189 | /** | ||
190 | * @name RCC_CFGR register bits definitions | ||
191 | * @{ | ||
192 | */ | ||
193 | #define STM32_SW_HSI (0 << 0) /**< SYSCLK source is HSI. */ | ||
194 | #define STM32_SW_HSE (1 << 0) /**< SYSCLK source is HSE. */ | ||
195 | #define STM32_SW_PLL (2 << 0) /**< SYSCLK source is PLL. */ | ||
196 | |||
197 | #define STM32_HPRE_DIV1 (0 << 4) /**< SYSCLK divided by 1. */ | ||
198 | #define STM32_HPRE_DIV2 (8 << 4) /**< SYSCLK divided by 2. */ | ||
199 | #define STM32_HPRE_DIV4 (9 << 4) /**< SYSCLK divided by 4. */ | ||
200 | #define STM32_HPRE_DIV8 (10 << 4) /**< SYSCLK divided by 8. */ | ||
201 | #define STM32_HPRE_DIV16 (11 << 4) /**< SYSCLK divided by 16. */ | ||
202 | #define STM32_HPRE_DIV64 (12 << 4) /**< SYSCLK divided by 64. */ | ||
203 | #define STM32_HPRE_DIV128 (13 << 4) /**< SYSCLK divided by 128. */ | ||
204 | #define STM32_HPRE_DIV256 (14 << 4) /**< SYSCLK divided by 256. */ | ||
205 | #define STM32_HPRE_DIV512 (15 << 4) /**< SYSCLK divided by 512. */ | ||
206 | |||
207 | #define STM32_PPRE1_DIV1 (0 << 8) /**< HCLK divided by 1. */ | ||
208 | #define STM32_PPRE1_DIV2 (4 << 8) /**< HCLK divided by 2. */ | ||
209 | #define STM32_PPRE1_DIV4 (5 << 8) /**< HCLK divided by 4. */ | ||
210 | #define STM32_PPRE1_DIV8 (6 << 8) /**< HCLK divided by 8. */ | ||
211 | #define STM32_PPRE1_DIV16 (7 << 8) /**< HCLK divided by 16. */ | ||
212 | |||
213 | #define STM32_PPRE2_DIV1 (0 << 11) /**< HCLK divided by 1. */ | ||
214 | #define STM32_PPRE2_DIV2 (4 << 11) /**< HCLK divided by 2. */ | ||
215 | #define STM32_PPRE2_DIV4 (5 << 11) /**< HCLK divided by 4. */ | ||
216 | #define STM32_PPRE2_DIV8 (6 << 11) /**< HCLK divided by 8. */ | ||
217 | #define STM32_PPRE2_DIV16 (7 << 11) /**< HCLK divided by 16. */ | ||
218 | |||
219 | #define STM32_PLLSRC_HSI (0 << 16) /**< PLL clock source is HSI/2. */ | ||
220 | #define STM32_PLLSRC_HSE (1 << 16) /**< PLL clock source is | ||
221 | HSE/PREDIV. */ | ||
222 | |||
223 | #define STM32_USBPRE_DIV1P5 (0 << 22) /**< USB clock is PLLCLK/1.5. */ | ||
224 | #define STM32_USBPRE_DIV1 (1 << 22) /**< USB clock is PLLCLK/1. */ | ||
225 | |||
226 | #define STM32_MCOSEL_NOCLOCK (0 << 24) /**< No clock on MCO pin. */ | ||
227 | #define STM32_MCOSEL_LSI (2 << 24) /**< LSI clock on MCO pin. */ | ||
228 | #define STM32_MCOSEL_LSE (3 << 24) /**< LSE clock on MCO pin. */ | ||
229 | #define STM32_MCOSEL_SYSCLK (4 << 24) /**< SYSCLK on MCO pin. */ | ||
230 | #define STM32_MCOSEL_HSI (5 << 24) /**< HSI clock on MCO pin. */ | ||
231 | #define STM32_MCOSEL_HSE (6 << 24) /**< HSE clock on MCO pin. */ | ||
232 | #define STM32_MCOSEL_PLLDIV2 (7 << 24) /**< PLL/2 clock on MCO pin. */ | ||
233 | /** @} */ | ||
234 | |||
235 | /** | ||
236 | * @name RCC_BDCR register bits definitions | ||
237 | * @{ | ||
238 | */ | ||
239 | #define STM32_RTCSEL_MASK (3 << 8) /**< RTC clock source mask. */ | ||
240 | #define STM32_RTCSEL_NOCLOCK (0 << 8) /**< No clock. */ | ||
241 | #define STM32_RTCSEL_LSE (1 << 8) /**< LSE used as RTC clock. */ | ||
242 | #define STM32_RTCSEL_LSI (2 << 8) /**< LSI used as RTC clock. */ | ||
243 | #define STM32_RTCSEL_HSEDIV (3 << 8) /**< HSE divided by 32 used as | ||
244 | RTC clock. */ | ||
245 | /** @} */ | ||
246 | |||
247 | /** | ||
248 | * @name RCC_CFGR2 register bits definitions | ||
249 | * @{ | ||
250 | */ | ||
251 | #define STM32_PREDIV_MASK (15 << 0) /**< PREDIV divisor mask. */ | ||
252 | #define STM32_ADC12PRES_MASK (31 << 4) /**< ADC12 clock source mask. */ | ||
253 | #define STM32_ADC12PRES_NOCLOCK (0 << 4) /**< ADC12 clock is disabled. */ | ||
254 | #define STM32_ADC12PRES_DIV1 (16 << 4) /**< ADC12 clock is PLL/1. */ | ||
255 | #define STM32_ADC12PRES_DIV2 (17 << 4) /**< ADC12 clock is PLL/2. */ | ||
256 | #define STM32_ADC12PRES_DIV4 (18 << 4) /**< ADC12 clock is PLL/4. */ | ||
257 | #define STM32_ADC12PRES_DIV6 (19 << 4) /**< ADC12 clock is PLL/6. */ | ||
258 | #define STM32_ADC12PRES_DIV8 (20 << 4) /**< ADC12 clock is PLL/8. */ | ||
259 | #define STM32_ADC12PRES_DIV10 (21 << 4) /**< ADC12 clock is PLL/10. */ | ||
260 | #define STM32_ADC12PRES_DIV12 (22 << 4) /**< ADC12 clock is PLL/12. */ | ||
261 | #define STM32_ADC12PRES_DIV16 (23 << 4) /**< ADC12 clock is PLL/16. */ | ||
262 | #define STM32_ADC12PRES_DIV32 (24 << 4) /**< ADC12 clock is PLL/32. */ | ||
263 | #define STM32_ADC12PRES_DIV64 (25 << 4) /**< ADC12 clock is PLL/64. */ | ||
264 | #define STM32_ADC12PRES_DIV128 (26 << 4) /**< ADC12 clock is PLL/128. */ | ||
265 | #define STM32_ADC12PRES_DIV256 (27 << 4) /**< ADC12 clock is PLL/256. */ | ||
266 | #define STM32_ADC34PRES_MASK (31 << 9) /**< ADC34 clock source mask. */ | ||
267 | #define STM32_ADC34PRES_NOCLOCK (0 << 9) /**< ADC34 clock is disabled. */ | ||
268 | #define STM32_ADC34PRES_DIV1 (16 << 9) /**< ADC34 clock is PLL/1. */ | ||
269 | #define STM32_ADC34PRES_DIV2 (17 << 9) /**< ADC34 clock is PLL/2. */ | ||
270 | #define STM32_ADC34PRES_DIV4 (18 << 9) /**< ADC34 clock is PLL/4. */ | ||
271 | #define STM32_ADC34PRES_DIV6 (19 << 9) /**< ADC34 clock is PLL/6. */ | ||
272 | #define STM32_ADC34PRES_DIV8 (20 << 9) /**< ADC34 clock is PLL/8. */ | ||
273 | #define STM32_ADC34PRES_DIV10 (21 << 9) /**< ADC34 clock is PLL/10. */ | ||
274 | #define STM32_ADC34PRES_DIV12 (22 << 9) /**< ADC34 clock is PLL/12. */ | ||
275 | #define STM32_ADC34PRES_DIV16 (23 << 9) /**< ADC34 clock is PLL/16. */ | ||
276 | #define STM32_ADC34PRES_DIV32 (24 << 9) /**< ADC34 clock is PLL/32. */ | ||
277 | #define STM32_ADC34PRES_DIV64 (25 << 9) /**< ADC34 clock is PLL/64. */ | ||
278 | #define STM32_ADC34PRES_DIV128 (26 << 9) /**< ADC34 clock is PLL/128. */ | ||
279 | #define STM32_ADC34PRES_DIV256 (27 << 9) /**< ADC34 clock is PLL/256. */ | ||
280 | /** @} */ | ||
281 | |||
282 | /** | ||
283 | * @name RCC_CFGR3 register bits definitions | ||
284 | * @{ | ||
285 | */ | ||
286 | #define STM32_USART1SW_MASK (3 << 0) /**< USART1 clock source mask. */ | ||
287 | #define STM32_USART1SW_PCLK (0 << 0) /**< USART1 clock is PCLK. */ | ||
288 | #define STM32_USART1SW_SYSCLK (1 << 0) /**< USART1 clock is SYSCLK. */ | ||
289 | #define STM32_USART1SW_LSE (2 << 0) /**< USART1 clock is LSE. */ | ||
290 | #define STM32_USART1SW_HSI (3 << 0) /**< USART1 clock is HSI. */ | ||
291 | #define STM32_I2C1SW_MASK (1 << 4) /**< I2C1 clock source mask. */ | ||
292 | #define STM32_I2C1SW_HSI (0 << 4) /**< I2C1 clock is HSI. */ | ||
293 | #define STM32_I2C1SW_SYSCLK (1 << 4) /**< I2C1 clock is SYSCLK. */ | ||
294 | #define STM32_I2C2SW_MASK (1 << 5) /**< I2C2 clock source mask. */ | ||
295 | #define STM32_I2C2SW_HSI (0 << 5) /**< I2C2 clock is HSI. */ | ||
296 | #define STM32_I2C2SW_SYSCLK (1 << 5) /**< I2C2 clock is SYSCLK. */ | ||
297 | #define STM32_TIM1SW_MASK (1 << 8) /**< TIM1 clock source mask. */ | ||
298 | #define STM32_TIM1SW_PCLK2 (0 << 8) /**< TIM1 clock is PCLK2. */ | ||
299 | #define STM32_TIM1SW_PLLX2 (1 << 8) /**< TIM1 clock is PLL*2. */ | ||
300 | #define STM32_TIM8SW_MASK (1 << 9) /**< TIM8 clock source mask. */ | ||
301 | #define STM32_TIM8SW_PCLK2 (0 << 9) /**< TIM8 clock is PCLK2. */ | ||
302 | #define STM32_TIM8SW_PLLX2 (1 << 9) /**< TIM8 clock is PLL*2. */ | ||
303 | #define STM32_HRTIM1SW_MASK (1 << 12) /**< HRTIM1 clock source mask. */ | ||
304 | #define STM32_HRTIM1SW_PCLK2 (0 << 12) /**< HRTIM1 clock is PCLK2. */ | ||
305 | #define STM32_HRTIM1SW_PLLX2 (1 << 12) /**< HRTIM1 clock is PLL*2. */ | ||
306 | #define STM32_USART2SW_MASK (3 << 16) /**< USART2 clock source mask. */ | ||
307 | #define STM32_USART2SW_PCLK (0 << 16) /**< USART2 clock is PCLK. */ | ||
308 | #define STM32_USART2SW_SYSCLK (1 << 16) /**< USART2 clock is SYSCLK. */ | ||
309 | #define STM32_USART2SW_LSE (2 << 16) /**< USART2 clock is LSE. */ | ||
310 | #define STM32_USART2SW_HSI (3 << 16) /**< USART2 clock is HSI. */ | ||
311 | #define STM32_USART3SW_MASK (3 << 18) /**< USART3 clock source mask. */ | ||
312 | #define STM32_USART3SW_PCLK (0 << 18) /**< USART3 clock is PCLK. */ | ||
313 | #define STM32_USART3SW_SYSCLK (1 << 18) /**< USART3 clock is SYSCLK. */ | ||
314 | #define STM32_USART3SW_LSE (2 << 18) /**< USART3 clock is LSE. */ | ||
315 | #define STM32_USART3SW_HSI (3 << 18) /**< USART3 clock is HSI. */ | ||
316 | #define STM32_UART4SW_MASK (3 << 20) /**< USART4 clock source mask. */ | ||
317 | #define STM32_UART4SW_PCLK (0 << 20) /**< USART4 clock is PCLK. */ | ||
318 | #define STM32_UART4SW_SYSCLK (1 << 20) /**< USART4 clock is SYSCLK. */ | ||
319 | #define STM32_UART4SW_LSE (2 << 20) /**< USART4 clock is LSE. */ | ||
320 | #define STM32_UART4SW_HSI (3 << 20) /**< USART4 clock is HSI. */ | ||
321 | #define STM32_UART5SW_MASK (3 << 22) /**< USART5 clock source mask. */ | ||
322 | #define STM32_UART5SW_PCLK (0 << 22) /**< USART5 clock is PCLK. */ | ||
323 | #define STM32_UART5SW_SYSCLK (1 << 22) /**< USART5 clock is SYSCLK. */ | ||
324 | #define STM32_UART5SW_LSE (2 << 22) /**< USART5 clock is LSE. */ | ||
325 | #define STM32_UART5SW_HSI (3 << 22) /**< USART5 clock is HSI. */ | ||
326 | /** @} */ | ||
327 | |||
328 | /*===========================================================================*/ | ||
329 | /* Driver pre-compile time settings. */ | ||
330 | /*===========================================================================*/ | ||
331 | |||
332 | /** | ||
333 | * @name Configuration options | ||
334 | * @{ | ||
335 | */ | ||
336 | /** | ||
337 | * @brief Disables the PWR/RCC initialization in the HAL. | ||
338 | */ | ||
339 | #if !defined(STM32_NO_INIT) || defined(__DOXYGEN__) | ||
340 | #define STM32_NO_INIT FALSE | ||
341 | #endif | ||
342 | |||
343 | /** | ||
344 | * @brief Enables or disables the programmable voltage detector. | ||
345 | */ | ||
346 | #if !defined(STM32_PVD_ENABLE) || defined(__DOXYGEN__) | ||
347 | #define STM32_PVD_ENABLE FALSE | ||
348 | #endif | ||
349 | |||
350 | /** | ||
351 | * @brief Sets voltage level for programmable voltage detector. | ||
352 | */ | ||
353 | #if !defined(STM32_PLS) || defined(__DOXYGEN__) | ||
354 | #define STM32_PLS STM32_PLS_LEV0 | ||
355 | #endif | ||
356 | |||
357 | /** | ||
358 | * @brief Enables or disables the HSI clock source. | ||
359 | */ | ||
360 | #if !defined(STM32_HSI_ENABLED) || defined(__DOXYGEN__) | ||
361 | #define STM32_HSI_ENABLED TRUE | ||
362 | #endif | ||
363 | |||
364 | /** | ||
365 | * @brief Enables or disables the LSI clock source. | ||
366 | */ | ||
367 | #if !defined(STM32_LSI_ENABLED) || defined(__DOXYGEN__) | ||
368 | #define STM32_LSI_ENABLED TRUE | ||
369 | #endif | ||
370 | |||
371 | /** | ||
372 | * @brief Enables or disables the HSE clock source. | ||
373 | */ | ||
374 | #if !defined(STM32_HSE_ENABLED) || defined(__DOXYGEN__) | ||
375 | #define STM32_HSE_ENABLED TRUE | ||
376 | #endif | ||
377 | |||
378 | /** | ||
379 | * @brief Enables or disables the LSE clock source. | ||
380 | */ | ||
381 | #if !defined(STM32_LSE_ENABLED) || defined(__DOXYGEN__) | ||
382 | #define STM32_LSE_ENABLED FALSE | ||
383 | #endif | ||
384 | |||
385 | /** | ||
386 | * @brief Main clock source selection. | ||
387 | * @note If the selected clock source is not the PLL then the PLL is not | ||
388 | * initialized and started. | ||
389 | * @note The default value is calculated for a 72MHz system clock from | ||
390 | * a 8MHz crystal using the PLL. | ||
391 | */ | ||
392 | #if !defined(STM32_SW) || defined(__DOXYGEN__) | ||
393 | #define STM32_SW STM32_SW_PLL | ||
394 | #endif | ||
395 | |||
396 | /** | ||
397 | * @brief Clock source for the PLL. | ||
398 | * @note This setting has only effect if the PLL is selected as the | ||
399 | * system clock source. | ||
400 | * @note The default value is calculated for a 72MHz system clock from | ||
401 | * a 8MHz crystal using the PLL. | ||
402 | */ | ||
403 | #if !defined(STM32_PLLSRC) || defined(__DOXYGEN__) | ||
404 | #define STM32_PLLSRC STM32_PLLSRC_HSE | ||
405 | #endif | ||
406 | |||
407 | /** | ||
408 | * @brief Crystal PLL pre-divider. | ||
409 | * @note This setting has only effect if the PLL is selected as the | ||
410 | * system clock source. | ||
411 | * @note The default value is calculated for a 72MHz system clock from | ||
412 | * a 8MHz crystal using the PLL. | ||
413 | */ | ||
414 | #if !defined(STM32_PREDIV_VALUE) || defined(__DOXYGEN__) | ||
415 | #define STM32_PREDIV_VALUE 1 | ||
416 | #endif | ||
417 | |||
418 | /** | ||
419 | * @brief PLL multiplier value. | ||
420 | * @note The allowed range is 2...16. | ||
421 | * @note The default value is calculated for a 72MHz system clock from | ||
422 | * a 8MHz crystal using the PLL. | ||
423 | */ | ||
424 | #if !defined(STM32_PLLMUL_VALUE) || defined(__DOXYGEN__) | ||
425 | #define STM32_PLLMUL_VALUE 9 | ||
426 | #endif | ||
427 | |||
428 | /** | ||
429 | * @brief AHB prescaler value. | ||
430 | * @note The default value is calculated for a 72MHz system clock from | ||
431 | * a 8MHz crystal using the PLL. | ||
432 | */ | ||
433 | #if !defined(STM32_HPRE) || defined(__DOXYGEN__) | ||
434 | #define STM32_HPRE STM32_HPRE_DIV1 | ||
435 | #endif | ||
436 | |||
437 | /** | ||
438 | * @brief APB1 prescaler value. | ||
439 | */ | ||
440 | #if !defined(STM32_PPRE1) || defined(__DOXYGEN__) | ||
441 | #define STM32_PPRE1 STM32_PPRE1_DIV2 | ||
442 | #endif | ||
443 | |||
444 | /** | ||
445 | * @brief APB2 prescaler value. | ||
446 | */ | ||
447 | #if !defined(STM32_PPRE2) || defined(__DOXYGEN__) | ||
448 | #define STM32_PPRE2 STM32_PPRE2_DIV2 | ||
449 | #endif | ||
450 | |||
451 | /** | ||
452 | * @brief MCO pin setting. | ||
453 | */ | ||
454 | #if !defined(STM32_MCOSEL) || defined(__DOXYGEN__) | ||
455 | #define STM32_MCOSEL STM32_MCOSEL_NOCLOCK | ||
456 | #endif | ||
457 | |||
458 | /** | ||
459 | * @brief ADC12 prescaler value. | ||
460 | */ | ||
461 | #if !defined(STM32_ADC12PRES) || defined(__DOXYGEN__) | ||
462 | #define STM32_ADC12PRES STM32_ADC12PRES_DIV1 | ||
463 | #endif | ||
464 | |||
465 | /** | ||
466 | * @brief ADC34 prescaler value. | ||
467 | */ | ||
468 | #if !defined(STM32_ADC34PRES) || defined(__DOXYGEN__) | ||
469 | #define STM32_ADC34PRES STM32_ADC34PRES_DIV1 | ||
470 | #endif | ||
471 | |||
472 | /** | ||
473 | * @brief USART1 clock source. | ||
474 | */ | ||
475 | #if !defined(STM32_USART1SW) || defined(__DOXYGEN__) | ||
476 | #define STM32_USART1SW STM32_USART1SW_PCLK | ||
477 | #endif | ||
478 | |||
479 | /** | ||
480 | * @brief USART2 clock source. | ||
481 | */ | ||
482 | #if !defined(STM32_USART2SW) || defined(__DOXYGEN__) | ||
483 | #define STM32_USART2SW STM32_USART2SW_PCLK | ||
484 | #endif | ||
485 | |||
486 | /** | ||
487 | * @brief USART3 clock source. | ||
488 | */ | ||
489 | #if !defined(STM32_USART3SW) || defined(__DOXYGEN__) | ||
490 | #define STM32_USART3SW STM32_USART3SW_PCLK | ||
491 | #endif | ||
492 | |||
493 | /** | ||
494 | * @brief UART4 clock source. | ||
495 | */ | ||
496 | #if !defined(STM32_UART4SW) || defined(__DOXYGEN__) | ||
497 | #define STM32_UART4SW STM32_UART4SW_PCLK | ||
498 | #endif | ||
499 | |||
500 | /** | ||
501 | * @brief UART5 clock source. | ||
502 | */ | ||
503 | #if !defined(STM32_UART5SW) || defined(__DOXYGEN__) | ||
504 | #define STM32_UART5SW STM32_UART5SW_PCLK | ||
505 | #endif | ||
506 | |||
507 | /** | ||
508 | * @brief I2C1 clock source. | ||
509 | */ | ||
510 | #if !defined(STM32_I2C1SW) || defined(__DOXYGEN__) | ||
511 | #define STM32_I2C1SW STM32_I2C1SW_SYSCLK | ||
512 | #endif | ||
513 | |||
514 | /** | ||
515 | * @brief I2C2 clock source. | ||
516 | */ | ||
517 | #if !defined(STM32_I2C2SW) || defined(__DOXYGEN__) | ||
518 | #define STM32_I2C2SW STM32_I2C2SW_SYSCLK | ||
519 | #endif | ||
520 | |||
521 | /** | ||
522 | * @brief TIM1 clock source. | ||
523 | */ | ||
524 | #if !defined(STM32_TIM1SW) || defined(__DOXYGEN__) | ||
525 | #define STM32_TIM1SW STM32_TIM1SW_PCLK2 | ||
526 | #endif | ||
527 | |||
528 | /** | ||
529 | * @brief TIM8 clock source. | ||
530 | */ | ||
531 | #if !defined(STM32_TIM8SW) || defined(__DOXYGEN__) | ||
532 | #define STM32_TIM8SW STM32_TIM8SW_PCLK2 | ||
533 | #endif | ||
534 | |||
535 | /** | ||
536 | * @brief HRTIM1 clock source. | ||
537 | */ | ||
538 | #if !defined(STM32_HRTIM1SW) || defined(__DOXYGEN__) | ||
539 | #define STM32_HRTIM1SW STM32_HRTIM1SW_PCLK2 | ||
540 | #endif | ||
541 | |||
542 | /** | ||
543 | * @brief RTC clock source. | ||
544 | */ | ||
545 | #if !defined(STM32_RTCSEL) || defined(__DOXYGEN__) | ||
546 | #define STM32_RTCSEL STM32_RTCSEL_LSI | ||
547 | #endif | ||
548 | |||
549 | /** | ||
550 | * @brief USB clock setting. | ||
551 | */ | ||
552 | #if !defined(STM32_USB_CLOCK_REQUIRED) || defined(__DOXYGEN__) | ||
553 | #define STM32_USB_CLOCK_REQUIRED TRUE | ||
554 | #endif | ||
555 | |||
556 | /** | ||
557 | * @brief USB prescaler initialization. | ||
558 | */ | ||
559 | #if !defined(STM32_USBPRE) || defined(__DOXYGEN__) | ||
560 | #define STM32_USBPRE STM32_USBPRE_DIV1P5 | ||
561 | #endif | ||
562 | /** @} */ | ||
563 | |||
564 | /*===========================================================================*/ | ||
565 | /* Derived constants and error checks. */ | ||
566 | /*===========================================================================*/ | ||
567 | |||
568 | /* | ||
569 | * Configuration-related checks. | ||
570 | */ | ||
571 | #if !defined(STM32F3xx_MCUCONF) | ||
572 | #error "Using a wrong mcuconf.h file, STM32F3xx_MCUCONF not defined" | ||
573 | #endif | ||
574 | |||
575 | /* Only some devices have strongly checked mcuconf.h files. Others will be | ||
576 | added gradually.*/ | ||
577 | #if (defined(STM32F303xC) || defined(STM32F303xE)) && \ | ||
578 | !defined(STM32F303_MCUCONF) | ||
579 | #error "Using a wrong mcuconf.h file, STM32F303_MCUCONF not defined" | ||
580 | #endif | ||
581 | |||
582 | /* | ||
583 | * HSI related checks. | ||
584 | */ | ||
585 | #if STM32_HSI_ENABLED | ||
586 | #else /* !STM32_HSI_ENABLED */ | ||
587 | |||
588 | #if STM32_SW == STM32_SW_HSI | ||
589 | #error "HSI not enabled, required by STM32_SW" | ||
590 | #endif | ||
591 | |||
592 | #if STM32_USART1SW == STM32_USART1SW_HSI | ||
593 | #error "HSI not enabled, required by STM32_USART1SW" | ||
594 | #endif | ||
595 | |||
596 | #if STM32_USART2SW == STM32_USART2SW_HSI | ||
597 | #error "HSI not enabled, required by STM32_USART2SW" | ||
598 | #endif | ||
599 | |||
600 | #if STM32_USART3SW == STM32_USART3SW_HSI | ||
601 | #error "HSI not enabled, required by STM32_USART3SW" | ||
602 | #endif | ||
603 | |||
604 | #if STM32_UART4SW == STM32_UART4SW_HSI | ||
605 | #error "HSI not enabled, required by STM32_UART4SW" | ||
606 | #endif | ||
607 | |||
608 | #if STM32_UART5SW == STM32_UART5SW_HSI | ||
609 | #error "HSI not enabled, required by STM32_UART5SW" | ||
610 | #endif | ||
611 | |||
612 | #if STM32_I2C1SW == STM32_I2C1SW_HSI | ||
613 | #error "HSI not enabled, required by STM32_I2C1SW" | ||
614 | #endif | ||
615 | |||
616 | #if STM32_I2C2SW == STM32_I2C2SW_HSI | ||
617 | #error "HSI not enabled, required by STM32_I2C2SW" | ||
618 | #endif | ||
619 | |||
620 | #if (STM32_SW == STM32_SW_PLL) && (STM32_PLLSRC == STM32_PLLSRC_HSI) | ||
621 | #error "HSI not enabled, required by STM32_SW and STM32_PLLSRC" | ||
622 | #endif | ||
623 | |||
624 | #if (STM32_MCOSEL == STM32_MCOSEL_HSI) || \ | ||
625 | ((STM32_MCOSEL == STM32_MCOSEL_PLLDIV2) && \ | ||
626 | (STM32_PLLSRC == STM32_PLLSRC_HSI)) | ||
627 | #error "HSI not enabled, required by STM32_MCOSEL" | ||
628 | #endif | ||
629 | |||
630 | #endif /* !STM32_HSI_ENABLED */ | ||
631 | |||
632 | /* | ||
633 | * HSE related checks. | ||
634 | */ | ||
635 | #if STM32_HSE_ENABLED | ||
636 | |||
637 | #if STM32_HSECLK == 0 | ||
638 | #error "HSE frequency not defined" | ||
639 | #elif (STM32_HSECLK < STM32_HSECLK_MIN) || (STM32_HSECLK > STM32_HSECLK_MAX) | ||
640 | #error "STM32_HSECLK outside acceptable range (STM32_HSECLK_MIN...STM32_HSECLK_MAX)" | ||
641 | #endif | ||
642 | |||
643 | #else /* !STM32_HSE_ENABLED */ | ||
644 | |||
645 | #if STM32_SW == STM32_SW_HSE | ||
646 | #error "HSE not enabled, required by STM32_SW" | ||
647 | #endif | ||
648 | |||
649 | #if (STM32_SW == STM32_SW_PLL) && (STM32_PLLSRC == STM32_PLLSRC_HSE) | ||
650 | #error "HSE not enabled, required by STM32_SW and STM32_PLLSRC" | ||
651 | #endif | ||
652 | |||
653 | #if (STM32_MCOSEL == STM32_MCOSEL_HSE) || \ | ||
654 | ((STM32_MCOSEL == STM32_MCOSEL_PLLDIV2) && \ | ||
655 | (STM32_PLLSRC == STM32_PLLSRC_HSE)) | ||
656 | #error "HSE not enabled, required by STM32_MCOSEL" | ||
657 | #endif | ||
658 | |||
659 | #if STM32_RTCSEL == STM32_RTCSEL_HSEDIV | ||
660 | #error "HSE not enabled, required by STM32_RTCSEL" | ||
661 | #endif | ||
662 | |||
663 | #endif /* !STM32_HSE_ENABLED */ | ||
664 | |||
665 | /* | ||
666 | * LSI related checks. | ||
667 | */ | ||
668 | #if STM32_LSI_ENABLED | ||
669 | #else /* !STM32_LSI_ENABLED */ | ||
670 | |||
671 | #if HAL_USE_RTC && (STM32_RTCSEL == STM32_RTCSEL_LSI) | ||
672 | #error "LSI not enabled, required by STM32_RTCSEL" | ||
673 | #endif | ||
674 | |||
675 | #endif /* !STM32_LSI_ENABLED */ | ||
676 | |||
677 | /* | ||
678 | * LSE related checks. | ||
679 | */ | ||
680 | #if STM32_LSE_ENABLED | ||
681 | |||
682 | #if !defined(STM32_LSECLK) || (STM32_LSECLK == 0) | ||
683 | #error "STM32_LSECLK not defined" | ||
684 | #endif | ||
685 | |||
686 | #if (STM32_LSECLK < STM32_LSECLK_MIN) || (STM32_LSECLK > STM32_LSECLK_MAX) | ||
687 | #error "STM32_LSECLK outside acceptable range (STM32_LSECLK_MIN...STM32_LSECLK_MAX)" | ||
688 | #endif | ||
689 | |||
690 | #if !defined(STM32_LSEDRV) | ||
691 | #error "STM32_LSEDRV not defined" | ||
692 | #endif | ||
693 | |||
694 | #if (STM32_LSEDRV >> 3) > 3 | ||
695 | #error "STM32_LSEDRV outside acceptable range ((0<<3)...(3<<3))" | ||
696 | #endif | ||
697 | |||
698 | #if STM32_USART1SW == STM32_USART1SW_LSE | ||
699 | #error "LSE not enabled, required by STM32_USART1SW" | ||
700 | #endif | ||
701 | |||
702 | #if STM32_USART2SW == STM32_USART2SW_LSE | ||
703 | #error "LSE not enabled, required by STM32_USART2SW" | ||
704 | #endif | ||
705 | |||
706 | #if STM32_USART3SW == STM32_USART3SW_LSE | ||
707 | #error "LSE not enabled, required by STM32_USART3SW" | ||
708 | #endif | ||
709 | |||
710 | #if STM32_UART4SW == STM32_UART4SW_LSE | ||
711 | #error "LSE not enabled, required by STM32_UART4SW" | ||
712 | #endif | ||
713 | |||
714 | #if STM32_UART5SW == STM32_UART5SW_LSE | ||
715 | #error "LSE not enabled, required by STM32_UART5SW" | ||
716 | #endif | ||
717 | |||
718 | #else /* !STM32_LSE_ENABLED */ | ||
719 | |||
720 | #if STM32_RTCSEL == STM32_RTCSEL_LSE | ||
721 | #error "LSE not enabled, required by STM32_RTCSEL" | ||
722 | #endif | ||
723 | |||
724 | #endif /* !STM32_LSE_ENABLED */ | ||
725 | |||
726 | /* PLL activation conditions.*/ | ||
727 | #if (STM32_SW == STM32_SW_PLL) || \ | ||
728 | (STM32_MCOSEL == STM32_MCOSEL_PLLDIV2) || \ | ||
729 | (STM32_TIM1SW == STM32_TIM1SW_PLLX2) || \ | ||
730 | (STM32_TIM8SW == STM32_TIM8SW_PLLX2) || \ | ||
731 | (STM32_ADC12PRES != STM32_ADC12PRES_NOCLOCK) || \ | ||
732 | (STM32_ADC34PRES != STM32_ADC34PRES_NOCLOCK) || \ | ||
733 | STM32_USB_CLOCK_REQUIRED || \ | ||
734 | defined(__DOXYGEN__) | ||
735 | /** | ||
736 | * @brief PLL activation flag. | ||
737 | */ | ||
738 | #define STM32_ACTIVATE_PLL TRUE | ||
739 | #else | ||
740 | #define STM32_ACTIVATE_PLL FALSE | ||
741 | #endif | ||
742 | |||
743 | /* HSE prescaler setting check.*/ | ||
744 | #if ((STM32_PREDIV_VALUE >= 1) || (STM32_PREDIV_VALUE <= 16)) | ||
745 | #define STM32_PREDIV ((STM32_PREDIV_VALUE - 1) << 0) | ||
746 | #else | ||
747 | #error "invalid STM32_PREDIV value specified" | ||
748 | #endif | ||
749 | |||
750 | /** | ||
751 | * @brief PLLMUL field. | ||
752 | */ | ||
753 | #if ((STM32_PLLMUL_VALUE >= 2) && (STM32_PLLMUL_VALUE <= 16)) || \ | ||
754 | defined(__DOXYGEN__) | ||
755 | #define STM32_PLLMUL ((STM32_PLLMUL_VALUE - 2) << 18) | ||
756 | #else | ||
757 | #error "invalid STM32_PLLMUL_VALUE value specified" | ||
758 | #endif | ||
759 | |||
760 | /** | ||
761 | * @brief PLL input clock frequency. | ||
762 | */ | ||
763 | #if (STM32_PLLSRC == STM32_PLLSRC_HSE) || defined(__DOXYGEN__) | ||
764 | #define STM32_PLLCLKIN (STM32_HSECLK / STM32_PREDIV_VALUE) | ||
765 | #elif STM32_PLLSRC == STM32_PLLSRC_HSI | ||
766 | #define STM32_PLLCLKIN (STM32_HSICLK / 2) | ||
767 | #else | ||
768 | #error "invalid STM32_PLLSRC value specified" | ||
769 | #endif | ||
770 | |||
771 | /* PLL input frequency range check.*/ | ||
772 | #if (STM32_PLLCLKIN < STM32_PLLIN_MIN) || (STM32_PLLCLKIN > STM32_PLLIN_MAX) | ||
773 | #error "STM32_PLLCLKIN outside acceptable range (STM32_PLLIN_MIN...STM32_PLLIN_MAX)" | ||
774 | #endif | ||
775 | |||
776 | /** | ||
777 | * @brief PLL output clock frequency. | ||
778 | */ | ||
779 | #define STM32_PLLCLKOUT (STM32_PLLCLKIN * STM32_PLLMUL_VALUE) | ||
780 | |||
781 | /* PLL output frequency range check.*/ | ||
782 | #if (STM32_PLLCLKOUT < STM32_PLLOUT_MIN) || (STM32_PLLCLKOUT > STM32_PLLOUT_MAX) | ||
783 | #error "STM32_PLLCLKOUT outside acceptable range (STM32_PLLOUT_MIN...STM32_PLLOUT_MAX)" | ||
784 | #endif | ||
785 | |||
786 | /** | ||
787 | * @brief System clock source. | ||
788 | */ | ||
789 | #if (STM32_SW == STM32_SW_PLL) || defined(__DOXYGEN__) | ||
790 | #define STM32_SYSCLK STM32_PLLCLKOUT | ||
791 | #elif (STM32_SW == STM32_SW_HSI) | ||
792 | #define STM32_SYSCLK STM32_HSICLK | ||
793 | #elif (STM32_SW == STM32_SW_HSE) | ||
794 | #define STM32_SYSCLK STM32_HSECLK | ||
795 | #else | ||
796 | #error "invalid STM32_SW value specified" | ||
797 | #endif | ||
798 | |||
799 | /* Check on the system clock.*/ | ||
800 | #if STM32_SYSCLK > STM32_SYSCLK_MAX | ||
801 | #error "STM32_SYSCLK above maximum rated frequency (STM32_SYSCLK_MAX)" | ||
802 | #endif | ||
803 | |||
804 | /** | ||
805 | * @brief AHB frequency. | ||
806 | */ | ||
807 | #if (STM32_HPRE == STM32_HPRE_DIV1) || defined(__DOXYGEN__) | ||
808 | #define STM32_HCLK (STM32_SYSCLK / 1) | ||
809 | #elif STM32_HPRE == STM32_HPRE_DIV2 | ||
810 | #define STM32_HCLK (STM32_SYSCLK / 2) | ||
811 | #elif STM32_HPRE == STM32_HPRE_DIV4 | ||
812 | #define STM32_HCLK (STM32_SYSCLK / 4) | ||
813 | #elif STM32_HPRE == STM32_HPRE_DIV8 | ||
814 | #define STM32_HCLK (STM32_SYSCLK / 8) | ||
815 | #elif STM32_HPRE == STM32_HPRE_DIV16 | ||
816 | #define STM32_HCLK (STM32_SYSCLK / 16) | ||
817 | #elif STM32_HPRE == STM32_HPRE_DIV64 | ||
818 | #define STM32_HCLK (STM32_SYSCLK / 64) | ||
819 | #elif STM32_HPRE == STM32_HPRE_DIV128 | ||
820 | #define STM32_HCLK (STM32_SYSCLK / 128) | ||
821 | #elif STM32_HPRE == STM32_HPRE_DIV256 | ||
822 | #define STM32_HCLK (STM32_SYSCLK / 256) | ||
823 | #elif STM32_HPRE == STM32_HPRE_DIV512 | ||
824 | #define STM32_HCLK (STM32_SYSCLK / 512) | ||
825 | #else | ||
826 | #error "invalid STM32_HPRE value specified" | ||
827 | #endif | ||
828 | |||
829 | /* AHB frequency check.*/ | ||
830 | #if STM32_HCLK > STM32_SYSCLK_MAX | ||
831 | #error "STM32_HCLK exceeding maximum frequency (STM32_SYSCLK_MAX)" | ||
832 | #endif | ||
833 | |||
834 | /** | ||
835 | * @brief APB1 frequency. | ||
836 | */ | ||
837 | #if (STM32_PPRE1 == STM32_PPRE1_DIV1) || defined(__DOXYGEN__) | ||
838 | #define STM32_PCLK1 (STM32_HCLK / 1) | ||
839 | #elif STM32_PPRE1 == STM32_PPRE1_DIV2 | ||
840 | #define STM32_PCLK1 (STM32_HCLK / 2) | ||
841 | #elif STM32_PPRE1 == STM32_PPRE1_DIV4 | ||
842 | #define STM32_PCLK1 (STM32_HCLK / 4) | ||
843 | #elif STM32_PPRE1 == STM32_PPRE1_DIV8 | ||
844 | #define STM32_PCLK1 (STM32_HCLK / 8) | ||
845 | #elif STM32_PPRE1 == STM32_PPRE1_DIV16 | ||
846 | #define STM32_PCLK1 (STM32_HCLK / 16) | ||
847 | #else | ||
848 | #error "invalid STM32_PPRE1 value specified" | ||
849 | #endif | ||
850 | |||
851 | /* APB1 frequency check.*/ | ||
852 | #if STM32_PCLK1 > STM32_PCLK1_MAX | ||
853 | #error "STM32_PCLK1 exceeding maximum frequency (STM32_PCLK1_MAX)" | ||
854 | #endif | ||
855 | |||
856 | /** | ||
857 | * @brief APB2 frequency. | ||
858 | */ | ||
859 | #if (STM32_PPRE2 == STM32_PPRE2_DIV1) || defined(__DOXYGEN__) | ||
860 | #define STM32_PCLK2 (STM32_HCLK / 1) | ||
861 | #elif STM32_PPRE2 == STM32_PPRE2_DIV2 | ||
862 | #define STM32_PCLK2 (STM32_HCLK / 2) | ||
863 | #elif STM32_PPRE2 == STM32_PPRE2_DIV4 | ||
864 | #define STM32_PCLK2 (STM32_HCLK / 4) | ||
865 | #elif STM32_PPRE2 == STM32_PPRE2_DIV8 | ||
866 | #define STM32_PCLK2 (STM32_HCLK / 8) | ||
867 | #elif STM32_PPRE2 == STM32_PPRE2_DIV16 | ||
868 | #define STM32_PCLK2 (STM32_HCLK / 16) | ||
869 | #else | ||
870 | #error "invalid STM32_PPRE2 value specified" | ||
871 | #endif | ||
872 | |||
873 | /* APB2 frequency check.*/ | ||
874 | #if STM32_PCLK2 > STM32_PCLK2_MAX | ||
875 | #error "STM32_PCLK2 exceeding maximum frequency (STM32_PCLK2_MAX)" | ||
876 | #endif | ||
877 | |||
878 | /** | ||
879 | * @brief RTC clock. | ||
880 | */ | ||
881 | #if (STM32_RTCSEL == STM32_RTCSEL_LSE) || defined(__DOXYGEN__) | ||
882 | #define STM32_RTCCLK STM32_LSECLK | ||
883 | #elif STM32_RTCSEL == STM32_RTCSEL_LSI | ||
884 | #define STM32_RTCCLK STM32_LSICLK | ||
885 | #elif STM32_RTCSEL == STM32_RTCSEL_HSEDIV | ||
886 | #define STM32_RTCCLK (STM32_HSECLK / 32) | ||
887 | #elif STM32_RTCSEL == STM32_RTCSEL_NOCLOCK | ||
888 | #define STM32_RTCCLK 0 | ||
889 | #else | ||
890 | #error "invalid source selected for RTC clock" | ||
891 | #endif | ||
892 | |||
893 | /** | ||
894 | * @brief ADC12 frequency. | ||
895 | */ | ||
896 | #if (STM32_ADC12PRES == STM32_ADC12PRES_NOCLOCK) || defined(__DOXYGEN__) | ||
897 | #define STM32_ADC12CLK 0 | ||
898 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV1 | ||
899 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 1) | ||
900 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV2 | ||
901 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 2) | ||
902 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV4 | ||
903 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 4) | ||
904 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV6 | ||
905 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 6) | ||
906 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV8 | ||
907 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 8) | ||
908 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV10 | ||
909 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 10) | ||
910 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV12 | ||
911 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 12) | ||
912 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV16 | ||
913 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 16) | ||
914 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV32 | ||
915 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 32) | ||
916 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV64 | ||
917 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 64) | ||
918 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV128 | ||
919 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 128) | ||
920 | #elif STM32_ADC12PRES == STM32_ADC12PRES_DIV256 | ||
921 | #define STM32_ADC12CLK (STM32_PLLCLKOUT / 256) | ||
922 | #else | ||
923 | #error "invalid STM32_ADC12PRES value specified" | ||
924 | #endif | ||
925 | |||
926 | /** | ||
927 | * @brief ADC34 frequency. | ||
928 | */ | ||
929 | #if (STM32_ADC34PRES == STM32_ADC34PRES_NOCLOCK) || defined(__DOXYGEN__) | ||
930 | #define STM32_ADC34CLK 0 | ||
931 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV1 | ||
932 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 1) | ||
933 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV2 | ||
934 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 2) | ||
935 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV4 | ||
936 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 4) | ||
937 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV6 | ||
938 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 6) | ||
939 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV8 | ||
940 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 8) | ||
941 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV10 | ||
942 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 10) | ||
943 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV12 | ||
944 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 12) | ||
945 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV16 | ||
946 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 16) | ||
947 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV32 | ||
948 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 32) | ||
949 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV64 | ||
950 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 64) | ||
951 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV128 | ||
952 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 128) | ||
953 | #elif STM32_ADC34PRES == STM32_ADC34PRES_DIV256 | ||
954 | #define STM32_ADC34CLK (STM32_PLLCLKOUT / 256) | ||
955 | #else | ||
956 | #error "invalid STM32_ADC34PRES value specified" | ||
957 | #endif | ||
958 | |||
959 | /* ADC12 frequency check.*/ | ||
960 | #if STM32_ADC12CLK > STM32_ADCCLK_MAX | ||
961 | #error "STM32_ADC12CLK exceeding maximum frequency (STM32_ADCCLK_MAX)" | ||
962 | #endif | ||
963 | |||
964 | /* ADC34 frequency check.*/ | ||
965 | #if STM32_ADC34CLK > STM32_ADCCLK_MAX | ||
966 | #error "STM32_ADC34CLK exceeding maximum frequency (STM32_ADCCLK_MAX)" | ||
967 | #endif | ||
968 | |||
969 | /** | ||
970 | * @brief I2C1 frequency. | ||
971 | */ | ||
972 | #if STM32_I2C1SW == STM32_I2C1SW_HSI | ||
973 | #define STM32_I2C1CLK STM32_HSICLK | ||
974 | #elif STM32_I2C1SW == STM32_I2C1SW_SYSCLK | ||
975 | #define STM32_I2C1CLK STM32_SYSCLK | ||
976 | #else | ||
977 | #error "invalid source selected for I2C1 clock" | ||
978 | #endif | ||
979 | |||
980 | /** | ||
981 | * @brief I2C2 frequency. | ||
982 | */ | ||
983 | #if STM32_I2C2SW == STM32_I2C2SW_HSI | ||
984 | #define STM32_I2C2CLK STM32_HSICLK | ||
985 | #elif STM32_I2C2SW == STM32_I2C2SW_SYSCLK | ||
986 | #define STM32_I2C2CLK STM32_SYSCLK | ||
987 | #else | ||
988 | #error "invalid source selected for I2C2 clock" | ||
989 | #endif | ||
990 | |||
991 | /** | ||
992 | * @brief USART1 frequency. | ||
993 | */ | ||
994 | #if STM32_USART1SW == STM32_USART1SW_PCLK | ||
995 | #define STM32_USART1CLK STM32_PCLK2 | ||
996 | #elif STM32_USART1SW == STM32_USART1SW_SYSCLK | ||
997 | #define STM32_USART1CLK STM32_SYSCLK | ||
998 | #elif STM32_USART1SW == STM32_USART1SW_LSE | ||
999 | #define STM32_USART1CLK STM32_LSECLK | ||
1000 | #elif STM32_USART1SW == STM32_USART1SW_HSI | ||
1001 | #define STM32_USART1CLK STM32_HSICLK | ||
1002 | #else | ||
1003 | #error "invalid source selected for USART1 clock" | ||
1004 | #endif | ||
1005 | |||
1006 | /** | ||
1007 | * @brief USART2 frequency. | ||
1008 | */ | ||
1009 | #if STM32_USART2SW == STM32_USART2SW_PCLK | ||
1010 | #define STM32_USART2CLK STM32_PCLK1 | ||
1011 | #elif STM32_USART2SW == STM32_USART2SW_SYSCLK | ||
1012 | #define STM32_USART2CLK STM32_SYSCLK | ||
1013 | #elif STM32_USART2SW == STM32_USART2SW_LSE | ||
1014 | #define STM32_USART2CLK STM32_LSECLK | ||
1015 | #elif STM32_USART2SW == STM32_USART2SW_HSI | ||
1016 | #define STM32_USART2CLK STM32_HSICLK | ||
1017 | #else | ||
1018 | #error "invalid source selected for USART2 clock" | ||
1019 | #endif | ||
1020 | |||
1021 | /** | ||
1022 | * @brief USART3 frequency. | ||
1023 | */ | ||
1024 | #if STM32_USART3SW == STM32_USART3SW_PCLK | ||
1025 | #define STM32_USART3CLK STM32_PCLK1 | ||
1026 | #elif STM32_USART3SW == STM32_USART3SW_SYSCLK | ||
1027 | #define STM32_USART3CLK STM32_SYSCLK | ||
1028 | #elif STM32_USART3SW == STM32_USART3SW_LSE | ||
1029 | #define STM32_USART3CLK STM32_LSECLK | ||
1030 | #elif STM32_USART3SW == STM32_USART3SW_HSI | ||
1031 | #define STM32_USART3CLK STM32_HSICLK | ||
1032 | #else | ||
1033 | #error "invalid source selected for USART3 clock" | ||
1034 | #endif | ||
1035 | |||
1036 | /** | ||
1037 | * @brief UART4 frequency. | ||
1038 | */ | ||
1039 | #if STM32_UART4SW == STM32_UART4SW_PCLK | ||
1040 | #define STM32_UART4CLK STM32_PCLK1 | ||
1041 | #elif STM32_UART4SW == STM32_UART4SW_SYSCLK | ||
1042 | #define STM32_UART4CLK STM32_SYSCLK | ||
1043 | #elif STM32_UART4SW == STM32_UART4SW_LSE | ||
1044 | #define STM32_UART4CLK STM32_LSECLK | ||
1045 | #elif STM32_UART4SW == STM32_UART4SW_HSI | ||
1046 | #define STM32_UART4CLK STM32_HSICLK | ||
1047 | #else | ||
1048 | #error "invalid source selected for UART4 clock" | ||
1049 | #endif | ||
1050 | |||
1051 | /** | ||
1052 | * @brief UART5 frequency. | ||
1053 | */ | ||
1054 | #if STM32_UART5SW == STM32_UART5SW_PCLK | ||
1055 | #define STM32_UART5CLK STM32_PCLK1 | ||
1056 | #elif STM32_UART5SW == STM32_UART5SW_SYSCLK | ||
1057 | #define STM32_UART5CLK STM32_SYSCLK | ||
1058 | #elif STM32_UART5SW == STM32_UART5SW_LSE | ||
1059 | #define STM32_UART5CLK STM32_LSECLK | ||
1060 | #elif STM32_UART5SW == STM32_UART5SW_HSI | ||
1061 | #define STM32_UART5CLK STM32_HSICLK | ||
1062 | #else | ||
1063 | #error "invalid source selected for UART5 clock" | ||
1064 | #endif | ||
1065 | |||
1066 | /** | ||
1067 | * @brief TIM1 frequency. | ||
1068 | */ | ||
1069 | #if STM32_TIM1SW == STM32_TIM1SW_PCLK2 | ||
1070 | #if STM32_PPRE2 == STM32_PPRE2_DIV1 | ||
1071 | #define STM32_TIM1CLK STM32_PCLK2 | ||
1072 | #else | ||
1073 | #define STM32_TIM1CLK (STM32_PCLK2 * 2) | ||
1074 | #endif | ||
1075 | |||
1076 | #elif STM32_TIM1SW == STM32_TIM1SW_PLLX2 | ||
1077 | #if (STM32_SW != STM32_SW_PLL) || \ | ||
1078 | (STM32_HPRE != STM32_HPRE_DIV1) || \ | ||
1079 | (STM32_PPRE2 != STM32_PPRE2_DIV1) | ||
1080 | #error "double clock mode cannot be activated for TIM1 under the current settings" | ||
1081 | #endif | ||
1082 | #define STM32_TIM1CLK (STM32_PLLCLKOUT * 2) | ||
1083 | |||
1084 | #else | ||
1085 | #error "invalid source selected for TIM1 clock" | ||
1086 | #endif | ||
1087 | |||
1088 | /** | ||
1089 | * @brief TIM8 frequency. | ||
1090 | */ | ||
1091 | #if STM32_TIM8SW == STM32_TIM8SW_PCLK2 | ||
1092 | #if STM32_PPRE2 == STM32_PPRE2_DIV1 | ||
1093 | #define STM32_TIM8CLK STM32_PCLK2 | ||
1094 | #else | ||
1095 | #define STM32_TIM8CLK (STM32_PCLK2 * 2) | ||
1096 | #endif | ||
1097 | |||
1098 | #elif STM32_TIM8SW == STM32_TIM8SW_PLLX2 | ||
1099 | #if (STM32_SW != STM32_SW_PLL) || \ | ||
1100 | (STM32_HPRE != STM32_HPRE_DIV1) || \ | ||
1101 | (STM32_PPRE2 != STM32_PPRE2_DIV1) | ||
1102 | #error "double clock mode cannot be activated for TIM8 under the current settings" | ||
1103 | #endif | ||
1104 | #define STM32_TIM8CLK (STM32_PLLCLKOUT * 2) | ||
1105 | |||
1106 | #else | ||
1107 | #error "invalid source selected for TIM8 clock" | ||
1108 | #endif | ||
1109 | |||
1110 | /** | ||
1111 | * @brief HRTIM1 frequency. | ||
1112 | */ | ||
1113 | #if STM32_HRTIM1SW == STM32_HRTIM1SW_PCLK2 | ||
1114 | #if STM32_PPRE2 == STM32_PPRE2_DIV1 | ||
1115 | #define STM32_HRTIM1CLK STM32_PCLK2 | ||
1116 | #else | ||
1117 | #define STM32_HRTIM1CLK (STM32_PCLK2 * 2) | ||
1118 | #endif | ||
1119 | |||
1120 | #elif STM32_HRTIM1SW == STM32_HRTIM1SW_PLLX2 | ||
1121 | #if (STM32_SW != STM32_SW_PLL) || \ | ||
1122 | (STM32_HPRE != STM32_HPRE_DIV1) || \ | ||
1123 | (STM32_PPRE2 != STM32_PPRE2_DIV1) | ||
1124 | #error "double clock mode cannot be activated for HRTIM1 under the current settings" | ||
1125 | #endif | ||
1126 | #define STM32_HRTIM1CLK (STM32_PLLCLKOUT * 2) | ||
1127 | |||
1128 | #else | ||
1129 | #error "invalid source selected for HRTIM1 clock" | ||
1130 | #endif | ||
1131 | |||
1132 | /** | ||
1133 | * @brief Timers 2, 3, 4, 6, 7 frequency. | ||
1134 | */ | ||
1135 | #if (STM32_PPRE1 == STM32_PPRE1_DIV1) || defined(__DOXYGEN__) | ||
1136 | #define STM32_TIMCLK1 (STM32_PCLK1 * 1) | ||
1137 | #else | ||
1138 | #define STM32_TIMCLK1 (STM32_PCLK1 * 2) | ||
1139 | #endif | ||
1140 | |||
1141 | /** | ||
1142 | * @brief Timers 1, 8, 15, 16, 17 frequency. | ||
1143 | */ | ||
1144 | #if (STM32_PPRE2 == STM32_PPRE2_DIV1) || defined(__DOXYGEN__) | ||
1145 | #define STM32_TIMCLK2 (STM32_PCLK2 * 1) | ||
1146 | #else | ||
1147 | #define STM32_TIMCLK2 (STM32_PCLK2 * 2) | ||
1148 | #endif | ||
1149 | |||
1150 | /** | ||
1151 | * @brief USB frequency. | ||
1152 | */ | ||
1153 | #if (STM32_USBPRE == STM32_USBPRE_DIV1P5) || defined(__DOXYGEN__) | ||
1154 | #define STM32_USBCLK ((STM32_PLLCLKOUT * 2) / 3) | ||
1155 | #elif (STM32_USBPRE == STM32_USBPRE_DIV1) | ||
1156 | #define STM32_USBCLK STM32_PLLCLKOUT | ||
1157 | #else | ||
1158 | #error "invalid STM32_USBPRE value specified" | ||
1159 | #endif | ||
1160 | |||
1161 | /** | ||
1162 | * @brief Flash settings. | ||
1163 | */ | ||
1164 | #if (STM32_HCLK <= 24000000) || defined(__DOXYGEN__) | ||
1165 | #define STM32_FLASHBITS 0x00000010 | ||
1166 | #elif STM32_HCLK <= 48000000 | ||
1167 | #define STM32_FLASHBITS 0x00000011 | ||
1168 | #else | ||
1169 | #define STM32_FLASHBITS 0x00000012 | ||
1170 | #endif | ||
1171 | |||
1172 | /*===========================================================================*/ | ||
1173 | /* Driver data structures and types. */ | ||
1174 | /*===========================================================================*/ | ||
1175 | |||
1176 | /*===========================================================================*/ | ||
1177 | /* Driver macros. */ | ||
1178 | /*===========================================================================*/ | ||
1179 | |||
1180 | /*===========================================================================*/ | ||
1181 | /* External declarations. */ | ||
1182 | /*===========================================================================*/ | ||
1183 | |||
1184 | /* Various helpers.*/ | ||
1185 | #include "nvic.h" | ||
1186 | #include "cache.h" | ||
1187 | #include "mpu_v7m.h" | ||
1188 | #include "stm32_isr.h" | ||
1189 | #include "stm32_dma.h" | ||
1190 | #include "stm32_exti.h" | ||
1191 | #include "stm32_rcc.h" | ||
1192 | #include "stm32_tim.h" | ||
1193 | |||
1194 | #ifdef __cplusplus | ||
1195 | extern "C" { | ||
1196 | #endif | ||
1197 | void hal_lld_init(void); | ||
1198 | void stm32_clock_init(void); | ||
1199 | #ifdef __cplusplus | ||
1200 | } | ||
1201 | #endif | ||
1202 | |||
1203 | #endif /* HAL_LLD_H */ | ||
1204 | |||
1205 | /** @} */ | ||