diff options
Diffstat (limited to 'lib/chibios/os/hal/ports/STM32/STM32F4xx/hal_lld.h')
-rw-r--r-- | lib/chibios/os/hal/ports/STM32/STM32F4xx/hal_lld.h | 278 |
1 files changed, 278 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/ports/STM32/STM32F4xx/hal_lld.h b/lib/chibios/os/hal/ports/STM32/STM32F4xx/hal_lld.h new file mode 100644 index 000000000..68501510c --- /dev/null +++ b/lib/chibios/os/hal/ports/STM32/STM32F4xx/hal_lld.h | |||
@@ -0,0 +1,278 @@ | |||
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 STM32F4xx/hal_lld.h | ||
19 | * @brief STM32F4xx/STM32F2xx HAL subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup HAL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #ifndef HAL_LLD_H | ||
26 | #define HAL_LLD_H | ||
27 | |||
28 | #include "stm32_registry.h" | ||
29 | |||
30 | #if defined(STM32F413xx) | ||
31 | #include "hal_lld_type2.h" | ||
32 | #else | ||
33 | #include "hal_lld_type1.h" | ||
34 | #endif | ||
35 | |||
36 | /* Various helpers.*/ | ||
37 | #include "nvic.h" | ||
38 | #include "cache.h" | ||
39 | #include "mpu_v7m.h" | ||
40 | #include "stm32_isr.h" | ||
41 | #include "stm32_dma.h" | ||
42 | #include "stm32_exti.h" | ||
43 | #include "stm32_rcc.h" | ||
44 | #include "stm32_tim.h" | ||
45 | |||
46 | /*===========================================================================*/ | ||
47 | /* Driver constants. */ | ||
48 | /*===========================================================================*/ | ||
49 | |||
50 | /*===========================================================================*/ | ||
51 | /* Driver pre-compile time settings. */ | ||
52 | /*===========================================================================*/ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Derived constants and error checks. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | /** | ||
59 | * @brief MCO1 divider clock. | ||
60 | */ | ||
61 | #if (STM32_MCO1SEL == STM32_MCO1SEL_HSI) || defined(__DOXYGEN__) | ||
62 | #define STM32_MCO1DIVCLK STM32_HSICLK | ||
63 | |||
64 | #elif STM32_MCO1SEL == STM32_MCO1SEL_LSE | ||
65 | #define STM32_MCO1DIVCLK STM32_LSECLK | ||
66 | |||
67 | #elif STM32_MCO1SEL == STM32_MCO1SEL_HSE | ||
68 | #define STM32_MCO1DIVCLK STM32_HSECLK | ||
69 | |||
70 | #elif STM32_MCO1SEL == STM32_MCO1SEL_PLL | ||
71 | #define STM32_MCO1DIVCLK STM32_PLLCLKOUT | ||
72 | |||
73 | #else | ||
74 | #error "invalid STM32_MCO1SEL value specified" | ||
75 | #endif | ||
76 | |||
77 | /** | ||
78 | * @brief MCO1 output pin clock. | ||
79 | */ | ||
80 | #if (STM32_MCO1PRE == STM32_MCO1PRE_DIV1) || defined(__DOXYGEN__) | ||
81 | #define STM32_MCO1CLK STM32_MCO1DIVCLK | ||
82 | |||
83 | #elif STM32_MCO1PRE == STM32_MCO1PRE_DIV2 | ||
84 | #define STM32_MCO1CLK (STM32_MCO1DIVCLK / 2) | ||
85 | |||
86 | #elif STM32_MCO1PRE == STM32_MCO1PRE_DIV3 | ||
87 | #define STM32_MCO1CLK (STM32_MCO1DIVCLK / 3) | ||
88 | |||
89 | #elif STM32_MCO1PRE == STM32_MCO1PRE_DIV4 | ||
90 | #define STM32_MCO1CLK (STM32_MCO1DIVCLK / 4) | ||
91 | |||
92 | #elif STM32_MCO1PRE == STM32_MCO1PRE_DIV5 | ||
93 | #define STM32_MCO1CLK (STM32_MCO1DIVCLK / 5) | ||
94 | |||
95 | #else | ||
96 | #error "invalid STM32_MCO1PRE value specified" | ||
97 | #endif | ||
98 | |||
99 | /** | ||
100 | * @brief MCO2 divider clock. | ||
101 | */ | ||
102 | #if (STM32_MCO2SEL == STM32_MCO2SEL_HSE) || defined(__DOXYGEN__) | ||
103 | #define STM32_MCO2DIVCLK STM32_HSECLK | ||
104 | |||
105 | #elif STM32_MCO2SEL == STM32_MCO2SEL_PLL | ||
106 | #define STM32_MCO2DIVCLK STM32_PLLCLKOUT | ||
107 | |||
108 | #elif STM32_MCO2SEL == STM32_MCO2SEL_SYSCLK | ||
109 | #define STM32_MCO2DIVCLK STM32_SYSCLK | ||
110 | |||
111 | #elif STM32_MCO2SEL == STM32_MCO2SEL_PLLI2S | ||
112 | #define STM32_MCO2DIVCLK STM32_PLLI2S | ||
113 | |||
114 | #else | ||
115 | #error "invalid STM32_MCO2SEL value specified" | ||
116 | #endif | ||
117 | |||
118 | /** | ||
119 | * @brief MCO2 output pin clock. | ||
120 | */ | ||
121 | #if (STM32_MCO2PRE == STM32_MCO2PRE_DIV1) || defined(__DOXYGEN__) | ||
122 | #define STM32_MCO2CLK STM32_MCO2DIVCLK | ||
123 | |||
124 | #elif STM32_MCO2PRE == STM32_MCO2PRE_DIV2 | ||
125 | #define STM32_MCO2CLK (STM32_MCO2DIVCLK / 2) | ||
126 | |||
127 | #elif STM32_MCO2PRE == STM32_MCO2PRE_DIV3 | ||
128 | #define STM32_MCO2CLK (STM32_MCO2DIVCLK / 3) | ||
129 | |||
130 | #elif STM32_MCO2PRE == STM32_MCO2PRE_DIV4 | ||
131 | #define STM32_MCO2CLK (STM32_MCO2DIVCLK / 4) | ||
132 | |||
133 | #elif STM32_MCO2PRE == STM32_MCO2PRE_DIV5 | ||
134 | #define STM32_MCO2CLK (STM32_MCO2DIVCLK / 5) | ||
135 | |||
136 | #else | ||
137 | #error "invalid STM32_MCO2PRE value specified" | ||
138 | #endif | ||
139 | |||
140 | /** | ||
141 | * @brief RTC HSE divider setting. | ||
142 | */ | ||
143 | #if ((STM32_RTCPRE_VALUE >= 2) && (STM32_RTCPRE_VALUE <= 31)) || \ | ||
144 | defined(__DOXYGEN__) | ||
145 | #define STM32_RTCPRE (STM32_RTCPRE_VALUE << 16) | ||
146 | #else | ||
147 | #error "invalid STM32_RTCPRE value specified" | ||
148 | #endif | ||
149 | |||
150 | /** | ||
151 | * @brief HSE divider toward RTC clock. | ||
152 | */ | ||
153 | #if ((STM32_RTCPRE_VALUE >= 2) && (STM32_RTCPRE_VALUE <= 31)) || \ | ||
154 | defined(__DOXYGEN__) | ||
155 | #define STM32_HSEDIVCLK (STM32_HSECLK / STM32_RTCPRE_VALUE) | ||
156 | #else | ||
157 | #error "invalid STM32_RTCPRE value specified" | ||
158 | #endif | ||
159 | |||
160 | /** | ||
161 | * @brief RTC clock. | ||
162 | */ | ||
163 | #if (STM32_RTCSEL == STM32_RTCSEL_NOCLOCK) || defined(__DOXYGEN__) | ||
164 | #define STM32_RTCCLK 0 | ||
165 | |||
166 | #elif STM32_RTCSEL == STM32_RTCSEL_LSE | ||
167 | #define STM32_RTCCLK STM32_LSECLK | ||
168 | |||
169 | #elif STM32_RTCSEL == STM32_RTCSEL_LSI | ||
170 | #define STM32_RTCCLK STM32_LSICLK | ||
171 | |||
172 | #elif STM32_RTCSEL == STM32_RTCSEL_HSEDIV | ||
173 | #define STM32_RTCCLK STM32_HSEDIVCLK | ||
174 | |||
175 | #else | ||
176 | #error "invalid STM32_RTCSEL value specified" | ||
177 | #endif | ||
178 | |||
179 | /** | ||
180 | * @brief 48MHz frequency. | ||
181 | */ | ||
182 | #if STM32_CLOCK48_REQUIRED || defined(__DOXYGEN__) | ||
183 | #if STM32_HAS_RCC_CK48MSEL || defined(__DOXYGEN__) | ||
184 | #if (STM32_CK48MSEL == STM32_CK48MSEL_PLL) || defined(__DOXYGEN__) | ||
185 | #define STM32_PLL48CLK (STM32_PLLVCO / STM32_PLLQ_VALUE) | ||
186 | #elif STM32_CK48MSEL == STM32_CK48MSEL_PLLALT | ||
187 | #define STM32_PLL48CLK STM32_PLL48CLK_ALTSRC | ||
188 | #else | ||
189 | #error "invalid source selected for PLL48CLK clock" | ||
190 | #endif | ||
191 | #else /* !STM32_HAS_RCC_CK48MSEL */ | ||
192 | #define STM32_PLL48CLK (STM32_PLLVCO / STM32_PLLQ_VALUE) | ||
193 | #endif /* !STM32_HAS_RCC_CK48MSEL */ | ||
194 | #else /* !STM32_CLOCK48_REQUIRED */ | ||
195 | #define STM32_PLL48CLK 0 | ||
196 | #endif /* STM32_CLOCK48_REQUIRED */ | ||
197 | |||
198 | #if !STM32_HAS_RCC_DCKCFGR || (STM32_TIMPRE == STM32_TIMPRE_PCLK) || \ | ||
199 | defined(__DOXYGEN__) | ||
200 | /** | ||
201 | * @brief Clock of timers connected to APB1 | ||
202 | * (Timers 2, 3, 4, 5, 6, 7, 12, 13, 14). | ||
203 | */ | ||
204 | #if (STM32_PPRE1 == STM32_PPRE1_DIV1) || defined(__DOXYGEN__) | ||
205 | #define STM32_TIMCLK1 (STM32_PCLK1 * 1) | ||
206 | #else | ||
207 | #define STM32_TIMCLK1 (STM32_PCLK1 * 2) | ||
208 | #endif | ||
209 | |||
210 | /** | ||
211 | * @brief Clock of timers connected to APB2 (Timers 1, 8, 9, 10, 11). | ||
212 | */ | ||
213 | #if (STM32_PPRE2 == STM32_PPRE2_DIV1) || defined(__DOXYGEN__) | ||
214 | #define STM32_TIMCLK2 (STM32_PCLK2 * 1) | ||
215 | #else | ||
216 | #define STM32_TIMCLK2 (STM32_PCLK2 * 2) | ||
217 | #endif | ||
218 | |||
219 | #else /* STM32_HAS_RCC_DCKCFGR && (STM32_TIMPRE == STM32_TIMPRE_HCLK) */ | ||
220 | #if (STM32_PPRE1 == STM32_PPRE1_DIV1) || \ | ||
221 | (STM32_PPRE1 == STM32_PPRE1_DIV2) || \ | ||
222 | ((STM32_PPRE1 == STM32_PPRE1_DIV4) && \ | ||
223 | (STM32_TIMPRE_PRESCALE4 == TRUE)) || defined(__DOXYGEN__) | ||
224 | #define STM32_TIMCLK1 STM32_HCLK | ||
225 | #else | ||
226 | #define STM32_TIMCLK1 (STM32_PCLK1 * 4) | ||
227 | #endif | ||
228 | |||
229 | #if (STM32_PPRE2 == STM32_PPRE2_DIV1) || \ | ||
230 | (STM32_PPRE2 == STM32_PPRE2_DIV2) || \ | ||
231 | ((STM32_PPRE2 == STM32_PPRE2_DIV4) && \ | ||
232 | (STM32_TIMPRE_PRESCALE4 == TRUE)) || defined(__DOXYGEN__) | ||
233 | #define STM32_TIMCLK2 STM32_HCLK | ||
234 | #else | ||
235 | #define STM32_TIMCLK2 (STM32_PCLK2 * 4) | ||
236 | #endif | ||
237 | #endif /* STM32_HAS_RCC_DCKCFGR && (STM32_TIMPRE == STM32_TIMPRE_HCLK) */ | ||
238 | |||
239 | /** | ||
240 | * @brief Flash settings. | ||
241 | */ | ||
242 | #if (STM32_HCLK <= STM32_0WS_THRESHOLD) || defined(__DOXYGEN__) | ||
243 | #define STM32_FLASHBITS 0x00000000 | ||
244 | #elif STM32_HCLK <= STM32_1WS_THRESHOLD | ||
245 | #define STM32_FLASHBITS 0x00000001 | ||
246 | #elif STM32_HCLK <= STM32_2WS_THRESHOLD | ||
247 | #define STM32_FLASHBITS 0x00000002 | ||
248 | #elif STM32_HCLK <= STM32_3WS_THRESHOLD | ||
249 | #define STM32_FLASHBITS 0x00000003 | ||
250 | #elif STM32_HCLK <= STM32_4WS_THRESHOLD | ||
251 | #define STM32_FLASHBITS 0x00000004 | ||
252 | #elif STM32_HCLK <= STM32_5WS_THRESHOLD | ||
253 | #define STM32_FLASHBITS 0x00000005 | ||
254 | #elif STM32_HCLK <= STM32_6WS_THRESHOLD | ||
255 | #define STM32_FLASHBITS 0x00000006 | ||
256 | #elif STM32_HCLK <= STM32_7WS_THRESHOLD | ||
257 | #define STM32_FLASHBITS 0x00000007 | ||
258 | #elif STM32_HCLK <= STM32_8WS_THRESHOLD | ||
259 | #define STM32_FLASHBITS 0x00000008 | ||
260 | #else | ||
261 | #error "invalid frequency at specified VDD level" | ||
262 | #endif | ||
263 | |||
264 | /*===========================================================================*/ | ||
265 | /* Driver data structures and types. */ | ||
266 | /*===========================================================================*/ | ||
267 | |||
268 | /*===========================================================================*/ | ||
269 | /* Driver macros. */ | ||
270 | /*===========================================================================*/ | ||
271 | |||
272 | /*===========================================================================*/ | ||
273 | /* External declarations. */ | ||
274 | /*===========================================================================*/ | ||
275 | |||
276 | #endif /* HAL_LLD_H */ | ||
277 | |||
278 | /** @} */ | ||