rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
mcuconf_common_f4_f7.h
Go to the documentation of this file.
1/**
2 * @file mcuconf_common_f4_f7.cpp
3 * @brief Common MCU definitions for both the STM32F4 and STM32F7
4 *
5 * @date Feb 18, 2021
6 * @author Matthew Kennedy
7 */
8
9#pragma once
10
11#include "efifeatures.h"
12
13#include "interrupt_priority.h"
14
15/*
16 * SysTick driver system settings.
17 */
18#define STM32_ST_IRQ_PRIORITY EFI_IRQ_SYSTICK_PRIORITY
19#define STM32_ST_USE_TIMER 2
20
21/*
22 * ADC driver system settings.
23 */
24#define STM32_ADC_ADCPRE ADC_CCR_ADCPRE_DIV4
25
26#ifndef STM32_ADC_USE_ADC1
27#define STM32_ADC_USE_ADC1 TRUE
28#endif /* STM32_ADC_USE_ADC1 */
29
30#ifndef STM32_ADC_USE_ADC2
31#define STM32_ADC_USE_ADC2 TRUE
32#endif /* STM32_ADC_USE_ADC2 */
33
34#ifndef STM32_ADC_USE_ADC3
35#define STM32_ADC_USE_ADC3 FALSE
36#endif /* STM32_ADC_USE_ADC3 */
37
38#define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
39#define STM32_ADC_ADC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
40#define STM32_ADC_ADC3_DMA_STREAM STM32_DMA_STREAM_ID(2, 1)
41#define STM32_ADC_ADC1_DMA_PRIORITY 3
42#define STM32_ADC_ADC2_DMA_PRIORITY 3
43#define STM32_ADC_ADC3_DMA_PRIORITY 3
44#define STM32_ADC_IRQ_PRIORITY EFI_IRQ_ADC_PRIORITY
45#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY EFI_IRQ_ADC_PRIORITY
46#define STM32_ADC_ADC2_DMA_IRQ_PRIORITY EFI_IRQ_ADC_PRIORITY
47#define STM32_ADC_ADC3_DMA_IRQ_PRIORITY EFI_IRQ_ADC_PRIORITY
48
49/*
50 * CAN driver system settings.
51 */
52#ifndef STM32_CAN_USE_CAN1
53#define STM32_CAN_USE_CAN1 TRUE
54#endif
55
56#ifndef STM32_CAN_USE_CAN2
57#define STM32_CAN_USE_CAN2 TRUE
58#endif
59
60#ifndef STM32_CAN_USE_CAN3
61#define STM32_CAN_USE_CAN3 FALSE
62#endif
63
64#define STM32_CAN_CAN1_IRQ_PRIORITY EFI_IRQ_CAN_PRIORITY
65#define STM32_CAN_CAN2_IRQ_PRIORITY EFI_IRQ_CAN_PRIORITY
66#define STM32_CAN_CAN3_IRQ_PRIORITY EFI_IRQ_CAN_PRIORITY
67
68#define STM32_IRQ_EXTI0_PRIORITY EFI_IRQ_EXTI_PRIORITY
69#define STM32_IRQ_EXTI1_PRIORITY EFI_IRQ_EXTI_PRIORITY
70#define STM32_IRQ_EXTI2_PRIORITY EFI_IRQ_EXTI_PRIORITY
71#define STM32_IRQ_EXTI3_PRIORITY EFI_IRQ_EXTI_PRIORITY
72#define STM32_IRQ_EXTI4_PRIORITY EFI_IRQ_EXTI_PRIORITY
73#define STM32_IRQ_EXTI5_9_PRIORITY EFI_IRQ_EXTI_PRIORITY
74#define STM32_IRQ_EXTI10_15_PRIORITY EFI_IRQ_EXTI_PRIORITY
75#define STM32_IRQ_EXTI16_PRIORITY 15
76#define STM32_IRQ_EXTI17_PRIORITY 15 /* why? */
77#define STM32_IRQ_EXTI18_PRIORITY 15
78#define STM32_IRQ_EXTI19_PRIORITY 15
79#define STM32_IRQ_EXTI20_PRIORITY 15
80#define STM32_IRQ_EXTI21_PRIORITY 15 /* why? */
81#define STM32_IRQ_EXTI22_PRIORITY 15 /* why? */
82#define STM32_IRQ_EXTI23_PRIORITY 15
83
84/*
85 * GPT driver system settings.
86 */
87/* This actually defines TIM IRQ priorities independently of driver used */
88#define STM32_IRQ_TIM1_BRK_TIM9_PRIORITY 7
89#define STM32_IRQ_TIM1_UP_TIM10_PRIORITY 7
90#define STM32_IRQ_TIM1_TRGCO_TIM11_PRIORITY 7
91#define STM32_IRQ_TIM1_CC_PRIORITY 7
92#define STM32_IRQ_TIM2_PRIORITY 7
93#define STM32_IRQ_TIM3_PRIORITY 7
94#define STM32_IRQ_TIM4_PRIORITY 7
95#define STM32_IRQ_TIM7_PRIORITY 7
96#define STM32_IRQ_TIM8_BRK_TIM12_PRIORITY 7
97#define STM32_IRQ_TIM8_UP_TIM13_PRIORITY 7
98#define STM32_IRQ_TIM8_TRGCO_TIM14_PRIORITY 7
99#define STM32_IRQ_TIM8_CC_PRIORITY 7
100
101/*
102 * GPT driver system settings.
103 */
104#define STM32_GPT_USE_TIM1 FALSE
105#define STM32_GPT_USE_TIM2 FALSE
106#define STM32_GPT_USE_TIM3 FALSE
107#define STM32_GPT_USE_TIM4 FALSE
108#define STM32_GPT_USE_TIM5 FALSE
109#define STM32_GPT_USE_TIM6 TRUE
110#define STM32_GPT_USE_TIM7 FALSE
111#define STM32_GPT_USE_TIM8 FALSE
112#define STM32_GPT_USE_TIM9 FALSE
113#define STM32_GPT_USE_TIM11 FALSE
114#define STM32_GPT_USE_TIM12 FALSE
115#define STM32_GPT_USE_TIM14 FALSE
116
117/*
118 * I2C driver system settings.
119 */
120#ifndef STM32_I2C_USE_I2C1
121#define STM32_I2C_USE_I2C1 FALSE
122#endif
123
124#ifndef STM32_I2C_USE_I2C2
125/* PB10/PB11 like some Hellen likes AF4 */
126#define STM32_I2C_USE_I2C2 TRUE
127#endif
128
129#ifndef STM32_I2C_USE_I2C3
130// PC9 I2C3_SDA AF4
131// PA8 I2C3_SCL AF4
132#define STM32_I2C_USE_I2C3 FALSE
133#endif
134
135#ifndef STM32_I2C_USE_I2C4
136#define STM32_I2C_USE_I2C4 FALSE
137#endif
138
139#define STM32_I2C_BUSY_TIMEOUT 50
140#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
141#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
142#define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
143#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
144#define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
145#define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
146#define STM32_I2C_I2C4_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
147#define STM32_I2C_I2C4_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
148#define STM32_I2C_I2C2_IRQ_PRIORITY 5
149#define STM32_I2C_I2C3_IRQ_PRIORITY 5
150#define STM32_I2C_I2C4_IRQ_PRIORITY 5
151#define STM32_I2C_I2C1_DMA_PRIORITY 3
152#define STM32_I2C_I2C2_DMA_PRIORITY 3
153#define STM32_I2C_I2C3_DMA_PRIORITY 3
154#define STM32_I2C_I2C4_DMA_PRIORITY 3
155#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
156
157/*
158 * ICU driver system settings.
159 */
160#ifndef STM32_ICU_USE_TIM1
161#define STM32_ICU_USE_TIM1 FALSE
162#endif
163
164#ifndef STM32_ICU_USE_TIM2
165#define STM32_ICU_USE_TIM2 TRUE
166#endif
167
168#ifndef STM32_ICU_USE_TIM3
169#define STM32_ICU_USE_TIM3 FALSE
170#endif
171
172#ifndef STM32_ICU_USE_TIM4
173#define STM32_ICU_USE_TIM4 FALSE
174#endif
175
176#ifndef STM32_ICU_USE_TIM5
177#define STM32_ICU_USE_TIM5 FALSE
178#endif
179
180#ifndef STM32_ICU_USE_TIM8
181#define STM32_ICU_USE_TIM8 FALSE
182#endif
183
184#ifndef STM32_ICU_USE_TIM9
185#define STM32_ICU_USE_TIM9 FALSE
186#endif
187
188#define STM32_ICU_TIM1_IRQ_PRIORITY ICU_PRIORITY
189#define STM32_ICU_TIM2_IRQ_PRIORITY ICU_PRIORITY
190#define STM32_ICU_TIM3_IRQ_PRIORITY ICU_PRIORITY
191#define STM32_ICU_TIM4_IRQ_PRIORITY ICU_PRIORITY
192#define STM32_ICU_TIM5_IRQ_PRIORITY ICU_PRIORITY
193#define STM32_ICU_TIM8_IRQ_PRIORITY ICU_PRIORITY
194#define STM32_ICU_TIM9_IRQ_PRIORITY ICU_PRIORITY
195
196/*
197 * MAC driver system settings.
198 */
199#define STM32_MAC_TRANSMIT_BUFFERS 2
200#define STM32_MAC_RECEIVE_BUFFERS 4
201#define STM32_MAC_BUFFERS_SIZE 1522
202#define STM32_MAC_PHY_TIMEOUT 100
203#define STM32_MAC_ETH1_CHANGE_PHY_STATE TRUE
204#define STM32_MAC_ETH1_IRQ_PRIORITY 13
205#define STM32_MAC_IP_CHECKSUM_OFFLOAD 3
206
207/*
208 * PWM driver system settings.
209 */
210#ifndef STM32_PWM_USE_TIM1
211#define STM32_PWM_USE_TIM1 TRUE
212#endif
213
214#ifndef STM32_PWM_USE_TIM2
215#define STM32_PWM_USE_TIM2 FALSE
216#endif
217
218#ifndef STM32_PWM_USE_TIM3
219// Hellen often uses TIM3 for ETB
220#define STM32_PWM_USE_TIM3 TRUE
221#endif
222
223#ifndef STM32_PWM_USE_TIM4
224#define STM32_PWM_USE_TIM4 TRUE
225#endif
226
227#ifndef STM32_PWM_USE_TIM5
228#define STM32_PWM_USE_TIM5 TRUE
229#endif
230
231#ifndef STM32_PWM_USE_TIM8
232#define STM32_PWM_USE_TIM8 TRUE
233#endif
234
235#ifndef STM32_PWM_USE_TIM9
236#define STM32_PWM_USE_TIM9 FALSE
237#endif
238
239/* NOTE: following does not set TIM IRQ priority in PWM mode
240 * F4/F7 share IRQ lines between few timers...
241 * See:
242 * - ChibiOS/os/hal/ports/STM32/STM32F4xx/stm32_isr.h
243 * - ChibiOS/os/hal/ports/STM32/STM32F7xx/stm32_isr.h
244 * STM32_TIMx_SUPPRESS_ISR is defined for all TIMs
245 * Timers IRQ priority setup is done in stm32_tim*.inc
246 * files. See also tim_irq_mapping.txt for irq collision map.
247 */
248#define STM32_PWM_TIM1_IRQ_PRIORITY 7
249#define STM32_PWM_TIM2_IRQ_PRIORITY 7
250#define STM32_PWM_TIM3_IRQ_PRIORITY 7
251#define STM32_PWM_TIM4_IRQ_PRIORITY 7
252#define STM32_PWM_TIM8_IRQ_PRIORITY 7
253#define STM32_PWM_TIM9_IRQ_PRIORITY 7
254
255// TIM5 is used for the precise scheduler queue
256#define STM32_PWM_TIM5_IRQ_PRIORITY EFI_IRQ_SCHEDULING_TIMER_PRIORITY
257#define STM32_IRQ_TIM5_PRIORITY EFI_IRQ_SCHEDULING_TIMER_PRIORITY
258
259// TIM6 is used for to start the fast ADC
260#define STM32_GPT_TIM6_IRQ_PRIORITY EFI_IRQ_ADC_PRIORITY
261#define STM32_IRQ_TIM6_PRIORITY EFI_IRQ_ADC_PRIORITY
262
263/*
264 * SERIAL driver system settings.
265 */
266#ifndef STM32_SERIAL_USE_USART1
267#define STM32_SERIAL_USE_USART1 FALSE
268#endif
269
270#ifndef STM32_SERIAL_USE_USART2
271#define STM32_SERIAL_USE_USART2 FALSE
272#endif
273
274#ifndef STM32_SERIAL_USE_USART3
275#define STM32_SERIAL_USE_USART3 FALSE
276#endif
277
278#ifndef STM32_SERIAL_USE_UART4
279#define STM32_SERIAL_USE_UART4 FALSE
280#endif
281
282#ifndef STM32_SERIAL_USE_UART5
283#define STM32_SERIAL_USE_UART5 FALSE
284#endif
285
286#ifndef STM32_SERIAL_USE_USART6
287#define STM32_SERIAL_USE_USART6 TRUE
288#endif
289
290#define STM32_SERIAL_USE_UART7 FALSE
291#define STM32_SERIAL_USE_UART8 FALSE
292#define STM32_IRQ_USART1_PRIORITY EFI_IRQ_UART_PRIORITY
293#define STM32_IRQ_USART2_PRIORITY EFI_IRQ_UART_PRIORITY
294#define STM32_IRQ_USART3_PRIORITY EFI_IRQ_UART_PRIORITY
295#define STM32_IRQ_UART4_PRIORITY EFI_IRQ_UART_PRIORITY
296#define STM32_IRQ_UART5_PRIORITY EFI_IRQ_UART_PRIORITY
297#define STM32_IRQ_USART6_PRIORITY EFI_IRQ_UART_PRIORITY
298#define STM32_IRQ_UART7_PRIORITY EFI_IRQ_UART_PRIORITY
299#define STM32_IRQ_UART8_PRIORITY EFI_IRQ_UART_PRIORITY
300
301/*
302 * SPI driver system settings.
303 */
304#ifndef STM32_SPI_USE_SPI1
305#define STM32_SPI_USE_SPI1 TRUE
306#endif
307
308#ifndef STM32_SPI_USE_SPI2
309#define STM32_SPI_USE_SPI2 TRUE
310#endif
311
312#ifndef STM32_SPI_USE_SPI3
313#define STM32_SPI_USE_SPI3 TRUE
314#endif
315
316#ifndef STM32_SPI_USE_SPI4
317#define STM32_SPI_USE_SPI4 FALSE
318#endif
319
320#ifndef STM32_SPI_USE_SPI5
321#define STM32_SPI_USE_SPI5 FALSE
322#endif
323
324#ifndef STM32_SPI_USE_SPI6
325#define STM32_SPI_USE_SPI6 FALSE
326#endif
327
328#define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 0)
329#define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 3)
330#define STM32_SPI_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
331#define STM32_SPI_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
332#define STM32_SPI_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
333#define STM32_SPI_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
334#define STM32_SPI_SPI4_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 0)
335#define STM32_SPI_SPI4_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 1)
336#define STM32_SPI_SPI5_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 3)
337/* STM32_DMA_STREAM_ID(2, 4) is used by ADC1 */
338//#define STM32_SPI_SPI5_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
339#define STM32_SPI_SPI5_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 6)
340#define STM32_SPI_SPI6_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 6)
341#define STM32_SPI_SPI6_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 5)
342#define STM32_SPI_SPI1_DMA_PRIORITY 1
343#define STM32_SPI_SPI2_DMA_PRIORITY 1
344#define STM32_SPI_SPI3_DMA_PRIORITY 1
345#define STM32_SPI_SPI4_DMA_PRIORITY 1
346#define STM32_SPI_SPI5_DMA_PRIORITY 1
347#define STM32_SPI_SPI6_DMA_PRIORITY 1
348#define STM32_SPI_SPI1_IRQ_PRIORITY EFI_IRQ_SPI_PRIORITY
349#define STM32_SPI_SPI2_IRQ_PRIORITY EFI_IRQ_SPI_PRIORITY
350#define STM32_SPI_SPI3_IRQ_PRIORITY EFI_IRQ_SPI_PRIORITY
351#define STM32_SPI_SPI4_IRQ_PRIORITY EFI_IRQ_SPI_PRIORITY
352#define STM32_SPI_SPI5_IRQ_PRIORITY EFI_IRQ_SPI_PRIORITY
353#define STM32_SPI_SPI6_IRQ_PRIORITY EFI_IRQ_SPI_PRIORITY
354#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
355
356/*
357 * UART driver system settings.
358 */
359#ifndef STM32_UART_USE_USART1
360#define STM32_UART_USE_USART1 FALSE
361#endif
362
363#ifndef STM32_UART_USE_USART2
364#define STM32_UART_USE_USART2 FALSE
365#endif
366
367#ifndef STM32_UART_USE_USART3
368#define STM32_UART_USE_USART3 TRUE
369#endif
370
371#define STM32_UART_USE_UART4 FALSE
372#define STM32_UART_USE_UART5 FALSE
373#define STM32_UART_USE_USART6 FALSE
374#define STM32_UART_USE_UART7 FALSE
375
376#ifndef STM32_UART_USE_UART8
377#define STM32_UART_USE_UART8 FALSE
378#endif
379
380#define STM32_UART_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 5)
381#define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
382#define STM32_UART_USART2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
383#define STM32_UART_USART2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
384#define STM32_UART_USART3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 1)
385#define STM32_UART_USART3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
386#define STM32_UART_UART4_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
387#define STM32_UART_UART4_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
388#define STM32_UART_UART5_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
389#define STM32_UART_UART5_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
390#define STM32_UART_USART6_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
391#define STM32_UART_USART6_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
392#define STM32_UART_UART7_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
393#define STM32_UART_UART7_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 1)
394#define STM32_UART_UART8_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
395#define STM32_UART_UART8_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
396#define STM32_UART_USART1_IRQ_PRIORITY EFI_IRQ_UART_PRIORITY
397#define STM32_UART_USART2_IRQ_PRIORITY EFI_IRQ_UART_PRIORITY
398#define STM32_UART_USART3_IRQ_PRIORITY EFI_IRQ_UART_PRIORITY
399#define STM32_UART_UART4_IRQ_PRIORITY EFI_IRQ_UART_PRIORITY
400#define STM32_UART_UART5_IRQ_PRIORITY EFI_IRQ_UART_PRIORITY
401#define STM32_UART_USART6_IRQ_PRIORITY EFI_IRQ_UART_PRIORITY
402#define STM32_UART_USART1_DMA_PRIORITY 0
403#define STM32_UART_USART2_DMA_PRIORITY 0
404#define STM32_UART_USART3_DMA_PRIORITY 0
405#define STM32_UART_UART4_DMA_PRIORITY 0
406#define STM32_UART_UART5_DMA_PRIORITY 0
407#define STM32_UART_USART6_DMA_PRIORITY 0
408#define STM32_UART_UART7_DMA_PRIORITY 0
409#define STM32_UART_UART8_DMA_PRIORITY 0
410#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
411
412/*
413 * USB driver system settings.
414 */
415#ifndef STM32_USB_USE_OTG1
416#define STM32_USB_USE_OTG1 TRUE
417#endif
418
419#ifndef STM32_USB_USE_OTG2
420#define STM32_USB_USE_OTG2 FALSE
421#endif
422
423#define STM32_USB_OTG1_IRQ_PRIORITY EFI_IRQ_USB_PRIORITY
424#define STM32_USB_OTG2_IRQ_PRIORITY EFI_IRQ_USB_PRIORITY
425#define STM32_USB_OTG1_RX_FIFO_SIZE 512
426#define STM32_USB_OTG2_RX_FIFO_SIZE 1024
427#define STM32_USB_OTG_THREAD_STACK_SIZE 1024
428#define STM32_USB_OTGFIFO_FILL_BASEPRI 0
429
430/*
431 * WDG driver system settings.
432 */
433#ifndef STM32_WDG_USE_IWDG
434#define STM32_WDG_USE_IWDG TRUE
435#endif
436
437/* Some boards need to know clock early on boot.
438 * F429-Discovery board configures clock and then SDRAM early on boot */
439#ifndef STM32_HSECLK
440 // Some boards has no HSE oscillator at all and obviously disable HSE detections
441 #ifndef ENABLE_AUTO_DETECT_HSE
442 // Pretend we have a 25MHz external crystal. This value isn't actually used since we
443 // configure the PLL to start on the HSI oscillator, then compute HSE's speed at runtime
444 // and reconfigure the PLL appropriately.
445 #define STM32_HSECLK 25000000
446
447 // After boot, we will detect the real frequency, and adjust the PLL M value to suit
448 #define ENABLE_AUTO_DETECT_HSE TRUE
449 #endif
450#endif