66
66
#endif
67
67
"""
68
68
69
+ # Default AFIO to disable some remapping, used when:
70
+ # <RemapBlock Name="TIM2_REMAP0" DefaultRemap="true" />
71
+ # is present in xml file
72
+ default_afio_f1 = {
73
+ "PA0" : {"TIM2" : "AFIO_TIM2_DISABLE" , "USART2" : "AFIO_USART2_DISABLE" },
74
+ "PA1" : {"TIM2" : "AFIO_TIM2_DISABLE" , "USART2" : "AFIO_USART2_DISABLE" },
75
+ "PA2" : {
76
+ "TIM2" : "AFIO_TIM2_DISABLE" ,
77
+ "TIM9" : "AFIO_TIM9_DISABLE" ,
78
+ "TIM15" : "AFIO_TIM15_DISABLE" ,
79
+ "USART2" : "AFIO_USART2_DISABLE" ,
80
+ },
81
+ "PA3" : {
82
+ "TIM2" : "AFIO_TIM2_DISABLE" ,
83
+ "TIM9" : "AFIO_TIM9_DISABLE" ,
84
+ "TIM15" : "AFIO_TIM15_DISABLE" ,
85
+ "USART2" : "AFIO_USART2_DISABLE" ,
86
+ },
87
+ "PA4" : {"SPI1" : "AFIO_SPI1_DISABLE" , "USART2" : "AFIO_USART2_DISABLE" },
88
+ "PA5" : {"SPI1" : "AFIO_SPI1_DISABLE" },
89
+ "PA6" : {
90
+ "SPI1" : "AFIO_SPI1_DISABLE" ,
91
+ "TIM3" : "AFIO_TIM3_DISABLE" ,
92
+ "TIM13" : "AFIO_TIM13_DISABLE" ,
93
+ },
94
+ "PA7" : {
95
+ "ETH" : "AFIO_ETH_DISABLE" ,
96
+ "SPI1" : "AFIO_SPI1_DISABLE" ,
97
+ "TIM3" : "AFIO_TIM3_DISABLE" ,
98
+ "TIM14" : "AFIO_TIM14_DISABLE" ,
99
+ },
100
+ "PA8" : {"TIM1" : "AFIO_TIM1_DISABLE" },
101
+ "PA9" : {"TIM1" : "AFIO_TIM1_DISABLE" , "USART1" : "AFIO_USART1_DISABLE" },
102
+ "PA10" : {"TIM1" : "AFIO_TIM1_DISABLE" , "USART1" : "AFIO_USART1_DISABLE" },
103
+ "PA11" : {"CAN1" : "AFIO_CAN1_1" , "TIM1" : "AFIO_TIM1_DISABLE" },
104
+ "PA12" : {"CAN1" : "AFIO_CAN1_1" , "TIM1" : "AFIO_TIM1_DISABLE" },
105
+ "PA15" : {"SPI3" : "AFIO_SPI3_DISABLE" },
106
+ "PB0" : {"ETH" : "AFIO_ETH_DISABLE" , "TIM3" : "AFIO_TIM3_DISABLE" },
107
+ "PB1" : {"ETH" : "AFIO_ETH_DISABLE" , "TIM3" : "AFIO_TIM3_DISABLE" },
108
+ "PB3" : {"SPI3" : "AFIO_SPI3_DISABLE" },
109
+ "PB4" : {"SPI3" : "AFIO_SPI3_DISABLE" },
110
+ "PB5" : {"SPI3" : "AFIO_SPI3_DISABLE" },
111
+ "PB6" : {"I2C1" : "AFIO_I2C1_DISABLE" , "TIM4" : "AFIO_TIM4_DISABLE" },
112
+ "PB7" : {"I2C1" : "AFIO_I2C1_DISABLE" , "TIM4" : "AFIO_TIM4_DISABLE" },
113
+ "PB8" : {
114
+ "TIM4" : "AFIO_TIM4_DISABLE" ,
115
+ "TIM10" : "AFIO_TIM10_DISABLE" ,
116
+ "TIM16" : "AFIO_TIM16_DISABLE" ,
117
+ },
118
+ "PB9" : {
119
+ "TIM4" : "AFIO_TIM4_DISABLE" ,
120
+ "TIM11" : "AFIO_TIM11_DISABLE" ,
121
+ "TIM17" : "AFIO_TIM17_DISABLE" ,
122
+ },
123
+ "PB12" : {
124
+ "CAN2" : "AFIO_CAN2_DISABLE" ,
125
+ "TIM1" : "AFIO_TIM1_DISABLE" ,
126
+ "USART3" : "AFIO_USART3_DISABLE" ,
127
+ },
128
+ "PB13" : {
129
+ "CAN2" : "AFIO_CAN2_DISABLE" ,
130
+ "TIM1" : "AFIO_TIM1_DISABLE" ,
131
+ "USART3" : "AFIO_USART3_DISABLE" ,
132
+ },
133
+ "PB14" : {"TIM1" : "AFIO_TIM1_DISABLE" },
134
+ "PB15" : {"TIM1" : "AFIO_TIM1_DISABLE" },
135
+ "PC4" : {"ETH" : "AFIO_ETH_DISABLE" , "TIM12" : "AFIO_TIM12_DISABLE" },
136
+ "PC5" : {"ETH" : "AFIO_ETH_DISABLE" , "TIM12" : "AFIO_TIM12_DISABLE" },
137
+ "PC8" : {"TIM13" : "AFIO_TIM13_DISABLE" },
138
+ "PC9" : {"TIM14" : "AFIO_TIM14_DISABLE" },
139
+ "PC10" : {"USART3" : "AFIO_USART3_DISABLE" },
140
+ "PC11" : {"USART3" : "AFIO_USART3_DISABLE" },
141
+ "PC12" : {"USART3" : "AFIO_USART3_DISABLE" },
142
+ }
143
+
144
+ # Choice is based on the fact Tone and Servo do not need output nor compare
145
+ # capabilities, and thus select timer instance which have the less outputs/compare
146
+ # capabilities:
147
+ # - TIM6/TIM7/TIM18 because they have no output and no compare capabilities
148
+ # - TIM10/TIM11/TIM13/TIM14 only 1 compare channel no complementary
149
+ # - TIM16/TIM17 generally only 1 compare channel (with complementary)
150
+ # - TIM9/TIM12/TIM21/TIM22 2 compare channels (no complementary)
151
+ # - TIM15 generally 2 compare channel (with potentially complementary)
152
+ # - TIM3/TIM4/TIM19 up to 4 channels
153
+ # - TIM2/TIM5 (most of the time) the only 32bit timer. Could be reserved
154
+ # for further 32bit support
155
+ # - TIM1/TIM8/TIM20 they are the most advanced/complete timers
156
+
157
+ tim_inst_order = [
158
+ "TIM6" ,
159
+ "TIM7" ,
160
+ "TIM18" ,
161
+ "TIM10" ,
162
+ "TIM11" ,
163
+ "TIM13" ,
164
+ "TIM14" ,
165
+ "TIM16" ,
166
+ "TIM17" ,
167
+ "TIM9" ,
168
+ "TIM12" ,
169
+ "TIM21" ,
170
+ "TIM22" ,
171
+ "TIM15" ,
172
+ "TIM3" ,
173
+ "TIM4" ,
174
+ "TIM19" ,
175
+ "TIM2" ,
176
+ "TIM5" ,
177
+ "TIM1" ,
178
+ "TIM8" ,
179
+ "TIM20" ,
180
+ ]
181
+
69
182
70
183
def rm_tree (pth : Path ):
71
184
if pth .exists ():
@@ -197,8 +310,18 @@ def get_gpio_af_num(pintofind, iptofind):
197
310
return mygpioaf
198
311
199
312
313
+ def get_gpio_af_numF1_default (pintofind , iptofind ):
314
+ # return "AFIO_" + iptofind .split("_")[0] + "_DISABLE"
315
+ ip = iptofind .split ("_" )[0 ]
316
+ afio_default = "AFIO_NONE"
317
+ if pintofind in default_afio_f1 :
318
+ if ip in default_afio_f1 [pintofind ]:
319
+ afio_default = default_afio_f1 [pintofind ][ip ]
320
+ return afio_default
321
+
322
+
200
323
def get_gpio_af_numF1 (pintofind , iptofind ):
201
- # print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
324
+ # print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
202
325
i = 0
203
326
mygpioaf = ""
204
327
for n in xml_gpio .documentElement .childNodes :
@@ -232,9 +355,9 @@ def get_gpio_af_numF1(pintofind, iptofind):
232
355
p .nodeType == Node .ELEMENT_NODE
233
356
and p .hasChildNodes () is False
234
357
):
235
- if mygpioaf != "" :
236
- mygpioaf + = " "
237
- mygpioaf += "AFIO_NONE"
358
+ mygpioaf += (
359
+ " " if mygpioaf ! = "" else " "
360
+ ) + get_gpio_af_numF1_default ( pintofind , iptofind )
238
361
else :
239
362
for s in p .childNodes :
240
363
if s .nodeType != Node .ELEMENT_NODE :
@@ -254,7 +377,7 @@ def get_gpio_af_numF1(pintofind, iptofind):
254
377
).replace ("_REMAP" , "" )
255
378
# print mygpioaf
256
379
if mygpioaf == "" :
257
- mygpioaf = "AFIO_NONE"
380
+ mygpioaf = get_gpio_af_numF1_default ( pintofind , iptofind )
258
381
return mygpioaf
259
382
260
383
@@ -1089,44 +1212,6 @@ def serial_pins_variant():
1089
1212
1090
1213
1091
1214
def 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
-
1130
1215
tone = servo = "TIMx"
1131
1216
if tim_inst_list :
1132
1217
for pref in tim_inst_order :
0 commit comments