6666#endif
6767"""
6868
69+ # Choice is based on the fact Tone and Servo do not need output nor compare
70+ # capabilities, and thus select timer instance which have the less outputs/compare
71+ # capabilities:
72+ # - TIM6/TIM7/TIM18 because they have no output and no compare capabilities
73+ # - TIM10/TIM11/TIM13/TIM14 only 1 compare channel no complementary
74+ # - TIM16/TIM17 generally only 1 compare channel (with complementary)
75+ # - TIM9/TIM12/TIM21/TIM22 2 compare channels (no complementary)
76+ # - TIM15 generally 2 compare channel (with potentially complementary)
77+ # - TIM3/TIM4/TIM19 up to 4 channels
78+ # - TIM2/TIM5 (most of the time) the only 32bit timer. Could be reserved
79+ # for further 32bit support
80+ # - TIM1/TIM8/TIM20 they are the most advanced/complete timers
81+
82+ tim_inst_order = [
83+ "TIM6" ,
84+ "TIM7" ,
85+ "TIM18" ,
86+ "TIM10" ,
87+ "TIM11" ,
88+ "TIM13" ,
89+ "TIM14" ,
90+ "TIM16" ,
91+ "TIM17" ,
92+ "TIM9" ,
93+ "TIM12" ,
94+ "TIM21" ,
95+ "TIM22" ,
96+ "TIM15" ,
97+ "TIM3" ,
98+ "TIM4" ,
99+ "TIM19" ,
100+ "TIM2" ,
101+ "TIM5" ,
102+ "TIM1" ,
103+ "TIM8" ,
104+ "TIM20" ,
105+ ]
106+
69107
70108def rm_tree (pth : Path ):
71109 if pth .exists ():
@@ -197,8 +235,117 @@ def get_gpio_af_num(pintofind, iptofind):
197235 return mygpioaf
198236
199237
238+ def get_gpio_af_numF1_default (pintofind , iptofind ):
239+ # Default AFIO to disable some remapping, used when:
240+ # <RemapBlock Name="TIM2_REMAP0" DefaultRemap="true" />
241+ # is present in xml file
242+ default_afio_f1 = {
243+ "PA0" : {"TIM2" : "AFIO_TIM2_DISABLE" , "USART2" : "AFIO_USART2_DISABLE" },
244+ "PA1" : {"TIM2" : "AFIO_TIM2_DISABLE" , "USART2" : "AFIO_USART2_DISABLE" },
245+ "PA2" : {
246+ "TIM2" : "AFIO_TIM2_DISABLE" ,
247+ "TIM9" : "AFIO_TIM9_DISABLE" ,
248+ "TIM15" : "AFIO_TIM15_DISABLE" ,
249+ "USART2" : "AFIO_USART2_DISABLE" ,
250+ },
251+ "PA3" : {
252+ "TIM2" : "AFIO_TIM2_DISABLE" ,
253+ "TIM9" : "AFIO_TIM9_DISABLE" ,
254+ "TIM15" : "AFIO_TIM15_DISABLE" ,
255+ "USART2" : "AFIO_USART2_DISABLE" ,
256+ },
257+ "PA4" : {"SPI1" : "AFIO_SPI1_DISABLE" , "USART2" : "AFIO_USART2_DISABLE" },
258+ "PA5" : {"SPI1" : "AFIO_SPI1_DISABLE" },
259+ "PA6" : {
260+ "SPI1" : "AFIO_SPI1_DISABLE" ,
261+ "TIM3" : "AFIO_TIM3_DISABLE" ,
262+ "TIM13" : "AFIO_TIM13_DISABLE" ,
263+ },
264+ "PA7" : {
265+ "ETH" : "AFIO_ETH_DISABLE" ,
266+ "SPI1" : "AFIO_SPI1_DISABLE" ,
267+ "TIM3" : "AFIO_TIM3_DISABLE" ,
268+ "TIM14" : "AFIO_TIM14_DISABLE" ,
269+ },
270+ "PA8" : {"TIM1" : "AFIO_TIM1_DISABLE" },
271+ "PA9" : {"TIM1" : "AFIO_TIM1_DISABLE" , "USART1" : "AFIO_USART1_DISABLE" },
272+ "PA10" : {"TIM1" : "AFIO_TIM1_DISABLE" , "USART1" : "AFIO_USART1_DISABLE" },
273+ "PA11" : {"CAN1" : "AFIO_CAN1_1" , "TIM1" : "AFIO_TIM1_DISABLE" },
274+ "PA12" : {"CAN1" : "AFIO_CAN1_1" , "TIM1" : "AFIO_TIM1_DISABLE" },
275+ "PA15" : {
276+ "SPI3" : (
277+ "AFIO_SPI3_DISABLE"
278+ if re .match ("STM32F10[57]" , mcu_refname )
279+ else "AFIO_NONE"
280+ )
281+ },
282+ "PB0" : {"ETH" : "AFIO_ETH_DISABLE" , "TIM3" : "AFIO_TIM3_DISABLE" },
283+ "PB1" : {"ETH" : "AFIO_ETH_DISABLE" , "TIM3" : "AFIO_TIM3_DISABLE" },
284+ "PB3" : {
285+ "SPI3" : (
286+ "AFIO_SPI3_DISABLE"
287+ if re .match ("STM32F10[57]" , mcu_refname )
288+ else "AFIO_NONE"
289+ )
290+ },
291+ "PB4" : {
292+ "SPI3" : (
293+ "AFIO_SPI3_DISABLE"
294+ if re .match ("STM32F10[57]" , mcu_refname )
295+ else "AFIO_NONE"
296+ )
297+ },
298+ "PB5" : {
299+ "SPI3" : (
300+ "AFIO_SPI3_DISABLE"
301+ if re .match ("STM32F10[57]" , mcu_refname )
302+ else "AFIO_NONE"
303+ )
304+ },
305+ "PB6" : {"I2C1" : "AFIO_I2C1_DISABLE" , "TIM4" : "AFIO_TIM4_DISABLE" },
306+ "PB7" : {"I2C1" : "AFIO_I2C1_DISABLE" , "TIM4" : "AFIO_TIM4_DISABLE" },
307+ "PB8" : {
308+ "TIM4" : "AFIO_TIM4_DISABLE" ,
309+ "TIM10" : "AFIO_TIM10_DISABLE" ,
310+ "TIM16" : "AFIO_TIM16_DISABLE" ,
311+ },
312+ "PB9" : {
313+ "TIM4" : "AFIO_TIM4_DISABLE" ,
314+ "TIM11" : "AFIO_TIM11_DISABLE" ,
315+ "TIM17" : "AFIO_TIM17_DISABLE" ,
316+ },
317+ "PB12" : {
318+ "CAN2" : "AFIO_CAN2_DISABLE" ,
319+ "TIM1" : "AFIO_TIM1_DISABLE" ,
320+ "USART3" : "AFIO_USART3_DISABLE" ,
321+ },
322+ "PB13" : {
323+ "CAN2" : "AFIO_CAN2_DISABLE" ,
324+ "TIM1" : "AFIO_TIM1_DISABLE" ,
325+ "USART3" : "AFIO_USART3_DISABLE" ,
326+ },
327+ "PB14" : {"TIM1" : "AFIO_TIM1_DISABLE" },
328+ "PB15" : {"TIM1" : "AFIO_TIM1_DISABLE" },
329+ "PC4" : {"ETH" : "AFIO_ETH_DISABLE" , "TIM12" : "AFIO_TIM12_DISABLE" },
330+ "PC5" : {"ETH" : "AFIO_ETH_DISABLE" , "TIM12" : "AFIO_TIM12_DISABLE" },
331+ "PC8" : {"TIM13" : "AFIO_TIM13_DISABLE" },
332+ "PC9" : {"TIM14" : "AFIO_TIM14_DISABLE" },
333+ "PC10" : {"USART3" : "AFIO_USART3_DISABLE" },
334+ "PC11" : {"USART3" : "AFIO_USART3_DISABLE" },
335+ "PC12" : {"USART3" : "AFIO_USART3_DISABLE" },
336+ }
337+
338+ # return "AFIO_" + iptofind .split("_")[0] + "_DISABLE"
339+ ip = iptofind .split ("_" )[0 ]
340+ afio_default = "AFIO_NONE"
341+ if pintofind in default_afio_f1 :
342+ if ip in default_afio_f1 [pintofind ]:
343+ afio_default = default_afio_f1 [pintofind ][ip ]
344+ return afio_default
345+
346+
200347def get_gpio_af_numF1 (pintofind , iptofind ):
201- # print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
348+ # print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
202349 i = 0
203350 mygpioaf = ""
204351 for n in xml_gpio .documentElement .childNodes :
@@ -232,9 +379,9 @@ def get_gpio_af_numF1(pintofind, iptofind):
232379 p .nodeType == Node .ELEMENT_NODE
233380 and p .hasChildNodes () is False
234381 ):
235- if mygpioaf != "" :
236- mygpioaf + = " "
237- mygpioaf += "AFIO_NONE"
382+ mygpioaf += (
383+ " " if mygpioaf ! = "" else " "
384+ ) + get_gpio_af_numF1_default ( pintofind , iptofind )
238385 else :
239386 for s in p .childNodes :
240387 if s .nodeType != Node .ELEMENT_NODE :
@@ -254,7 +401,7 @@ def get_gpio_af_numF1(pintofind, iptofind):
254401 ).replace ("_REMAP" , "" )
255402 # print mygpioaf
256403 if mygpioaf == "" :
257- mygpioaf = "AFIO_NONE"
404+ mygpioaf = get_gpio_af_numF1_default ( pintofind , iptofind )
258405 return mygpioaf
259406
260407
@@ -1089,44 +1236,6 @@ def serial_pins_variant():
10891236
10901237
10911238def timer_variant ():
1092- # Choice is based on the fact Tone and Servo do not need output nor compare
1093- # capabilities, and thus select timer instance which have the less outputs/compare
1094- # capabilities:
1095- # - TIM6/TIM7/TIM18 because they have no output and no compare capabilities
1096- # - TIM10/TIM11/TIM13/TIM14 only 1 compare channel no complementary
1097- # - TIM16/TIM17 generally only 1 compare channel (with complementary)
1098- # - TIM9/TIM12/TIM21/TIM22 2 compare channels (no complementary)
1099- # - TIM15 generally 2 compare channel (with potentially complementary)
1100- # - TIM3/TIM4/TIM19 up to 4 channels
1101- # - TIM2/TIM5 (most of the time) the only 32bit timer. Could be reserved
1102- # for further 32bit support
1103- # - TIM1/TIM8/TIM20 they are the most advanced/complete timers
1104-
1105- tim_inst_order = [
1106- "TIM6" ,
1107- "TIM7" ,
1108- "TIM18" ,
1109- "TIM10" ,
1110- "TIM11" ,
1111- "TIM13" ,
1112- "TIM14" ,
1113- "TIM16" ,
1114- "TIM17" ,
1115- "TIM9" ,
1116- "TIM12" ,
1117- "TIM21" ,
1118- "TIM22" ,
1119- "TIM15" ,
1120- "TIM3" ,
1121- "TIM4" ,
1122- "TIM19" ,
1123- "TIM2" ,
1124- "TIM5" ,
1125- "TIM1" ,
1126- "TIM8" ,
1127- "TIM20" ,
1128- ]
1129-
11301239 tone = servo = "TIMx"
11311240 if tim_inst_list :
11321241 for pref in tim_inst_order :
0 commit comments