Skip to content

Commit ed62e65

Browse files
authoredJul 4, 2017
Merge pull request #14 from fpistm/genpinmap
Add genpinmap script
2 parents 5b2d2ef + e7bc10e commit ed62e65

File tree

4 files changed

+657
-0
lines changed

4 files changed

+657
-0
lines changed
 

‎src/genpinmap/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Arduino

‎src/genpinmap/genpinmap_arduino.bat

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
:: See xml file name in C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\db\mcu
2+
3+
:: GPIO AF function not supported:: python genpinmap_arduino.py NUCLEO_F030R8 "STM32F030R8Tx.xml"
4+
:: GPIO AF function not supported::python genpinmap_arduino.py DISCO_F051R8 "STM32F051R8Tx.xml"
5+
6+
python genpinmap_arduino.py NUCLEO_F030R8 "STM32F030R8Tx.xml"
7+
python genpinmap_arduino.py NUCLEO_F091RC "STM32F091R(B-C)Tx.xml"
8+
python genpinmap_arduino.py NUCLEO_F303RE "STM32F303R(D-E)Tx.xml"
9+
python genpinmap_arduino.py NUCLEO_F429ZI "STM32F429Z(E-G-I)Tx.xml"
10+
python genpinmap_arduino.py DISCO_F407G "STM32F407V(E-G)Tx.xml"
11+
python genpinmap_arduino.py DISCO_F746NG "STM32F746N(E-G)Hx.xml"
12+
python genpinmap_arduino.py NUCLEO_L053R8 "STM32L053R(6-8)Tx.xml"
13+
python genpinmap_arduino.py NUCLEO_L432KC "STM32L432K(B-C)Ux.xml"
14+
python genpinmap_arduino.py NUCLEO_L476RG "STM32L475R(C-E-G)Tx.xml"
15+
16+
pause
17+
::python genpinmap_arduino.py B96B_F446VE "STM32F446V(C-E)Tx.xml"
18+
::python genpinmap_arduino.py DISCO_F303VC "STM32F303V(B-C)Tx.xml"
19+
::python genpinmap_arduino.py DISCO_F334C8 "STM32F334C(4-6-8)Tx.xml"
20+
::python genpinmap_arduino.py DISCO_F429ZI "STM32F429Z(E-G-I)Tx.xml"
21+
::python genpinmap_arduino.py DISCO_F469NI "STM32F469N(E-G-I)Hx.xml"
22+
::python genpinmap_arduino.py DISCO_F746NG "STM32F746N(E-G)Hx.xml"
23+
::python genpinmap_arduino.py DISCO_L053C8 "STM32L053C(6-8)Tx.xml"
24+
::python genpinmap_arduino.py DISCO_L476VG "STM32L476V(C-E-G)Tx.xml"
25+
::pause
26+
::python genpinmap_arduino.py NUCLEO_F031K6 "STM32F031K6Tx.xml"
27+
::python genpinmap_arduino.py NUCLEO_F042K6 "STM32F042K6Tx.xml"
28+
::python genpinmap_arduino.py NUCLEO_F070RB "STM32F070RBTx.xml"
29+
::python genpinmap_arduino.py NUCLEO_F072RB "STM32F072R(8-B)Tx.xml"
30+
::python genpinmap_arduino.py NUCLEO_F091RC "STM32F091R(B-C)Tx.xml"
31+
::pause
32+
::python genpinmap_arduino.py NUCLEO_F103RB "STM32F103R(8-B)Tx.xml"
33+
::python genpinmap_arduino.py NUCLEO_F302R8 "STM32F302R(6-8)Tx.xml"
34+
::python genpinmap_arduino.py NUCLEO_F303K8 "STM32F303R(6-8)Tx.xml"
35+
::python genpinmap_arduino.py NUCLEO_F303RE "STM32F303R(D-E)Tx.xml"
36+
::python genpinmap_arduino.py NUCLEO_F334R8 "STM32F334R(6-8)Tx.xml"
37+
::pause
38+
::python genpinmap_arduino.py NUCLEO_F401RE "STM32F401R(D-E)Tx.xml"
39+
::python genpinmap_arduino.py NUCLEO_F410RB "STM32F410R(8-B)Tx.xml"
40+
::python genpinmap_arduino.py NUCLEO_F411RE "STM32F411R(C-E)Tx.xml"
41+
::python genpinmap_arduino.py NUCLEO_F446RE "STM32F446R(C-E)Tx.xml"
42+
::python genpinmap_arduino.py NUCLEO_F446ZE "STM32F446Z(C-E)Tx.xml"
43+
::pause
44+
::python genpinmap_arduino.py NUCLEO_F746ZG "STM32F746Z(E-G)Tx.xml"
45+
::python genpinmap_arduino.py NUCLEO_F767ZI "STM32F767Z(G-I)Tx.xml"
46+
::pause
47+
::python genpinmap_arduino.py NUCLEO_L011K4 "STM32L011K(3-4)Tx.xml"
48+
::python genpinmap_arduino.py NUCLEO_L031K6 "STM32L031K(4-6)Tx.xml"
49+
::python genpinmap_arduino.py NUCLEO_L053R8 "STM32L053R(6-8)Tx.xml"
50+
::python genpinmap_arduino.py NUCLEO_L073RZ "STM32L073R(B-Z)Tx.xml"
51+
::pause
52+
::python genpinmap_arduino.py NUCLEO_L152RE "STM32L152RETx.xml"
53+
::python genpinmap_arduino.py NUCLEO_L476RG "STM32L475R(C-E-G)Tx.xml"
54+
::pause

‎src/genpinmap/genpinmap_arduino.py

Lines changed: 568 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,568 @@
1+
import sys
2+
import re
3+
import os
4+
from xml.dom import minidom
5+
from xml.dom.minidom import parse, Node
6+
io_list = [] #'PIN','name'
7+
adclist = [] #'PIN','name','ADCSignal'
8+
daclist = [] #'PIN','name','DACSignal'
9+
i2cscl_list = [] #'PIN','name','I2CSCLSignal'
10+
i2csda_list = [] #'PIN','name','I2CSDASignal'
11+
pwm_list = [] #'PIN','name','PWM'
12+
uarttx_list = [] #'PIN','name','UARTtx'
13+
uartrx_list = [] #'PIN','name','UARTrx'
14+
uartcts_list = [] #'PIN','name','UARTcts'
15+
uartrts_list = [] #'PIN','name','UARTrts'
16+
spimosi_list = [] #'PIN','name','SPIMOSI'
17+
spimiso_list = [] #'PIN','name','SPIMISO'
18+
spissel_list = [] #'PIN','name','SPISSEL'
19+
spisclk_list = [] #'PIN','name','SPISCLK'
20+
cantd_list = [] #'PIN','name','CANTD'
21+
canrd_list = [] #'PIN','name','CANRD'
22+
eth_list = [] #'PIN','name','ETH'
23+
24+
25+
def find_gpio_file(xmldoc):
26+
res = 'ERROR'
27+
itemlist = xmldoc.getElementsByTagName('IP')
28+
for s in itemlist:
29+
a = s.attributes['Name'].value
30+
if "GPIO" in a:
31+
res = s.attributes['Version'].value
32+
return res
33+
34+
def get_gpio_af_num(xml, pintofind, iptofind):
35+
# xml = parse('GPIO-STM32L051_gpio_v1_0_Modes.xml')
36+
#xml = parse(gpiofile)
37+
#DBG print ('pin to find ' + pintofind)
38+
i=0
39+
mygpioaf = 'NOTFOUND'
40+
for n in xml.documentElement.childNodes:
41+
i += 1
42+
j = 0
43+
if n.nodeType == Node.ELEMENT_NODE:
44+
for premlevel in n.attributes.items():
45+
# if 'PB7' in premlevel:
46+
if pintofind == premlevel[1]:
47+
#DBG print (i , premlevel)
48+
#n = noeud de la pin recherchee
49+
for m in n.childNodes:
50+
j += 1
51+
k = 0
52+
if m.nodeType == Node.ELEMENT_NODE:
53+
for deuzlevel in m.attributes.items():
54+
k += 1
55+
# if 'I2C1_SDA' in deuzlevel:
56+
if iptofind in deuzlevel:
57+
#DBG print (i, j, m.attributes.items())
58+
# m = noeud de l'IP recherchee
59+
for p in m.childNodes:
60+
if p.nodeType == Node.ELEMENT_NODE:
61+
#p noeud du 'Specific parameter'
62+
#DBG print (i,j,k,p.attributes.items())
63+
for myc in p.childNodes:
64+
#DBG print (myc)
65+
if myc.nodeType == Node.ELEMENT_NODE:
66+
#myc = noeud du ALTERNATE !!! ENFIN !!!
67+
for mygpioaflist in myc.childNodes:
68+
mygpioaf = mygpioaflist.data
69+
#print (mygpioaf)
70+
if mygpioaf == 'NOTFOUND':
71+
print ('GPIO AF not found in ' + gpiofile + ' for ' + pintofind + ' and the IP ' + iptofind)
72+
#quit()
73+
return mygpioaf
74+
75+
def store_pin (pin, name):
76+
#store pin I/O
77+
p = [pin, name]
78+
io_list.append(p)
79+
80+
#function to store ADC list
81+
def store_adc (pin, name, signal):
82+
adclist.append([pin,name,signal])
83+
84+
#function to store DAC list
85+
def store_dac (pin, name, signal):
86+
daclist.append([pin,name,signal])
87+
88+
#function to store I2C list
89+
def store_i2c (pin, name, signal):
90+
#is it SDA or SCL ?
91+
if "_SCL" in signal:
92+
i2cscl_list.append([pin,name,signal])
93+
if "_SDA" in signal:
94+
i2csda_list.append([pin,name,signal])
95+
96+
#function to store timers
97+
def store_pwm(pin, name, signal):
98+
if "_CH" in signal:
99+
pwm_list.append([pin,name,signal])
100+
101+
#function to store Uart pins
102+
def store_uart(pin, name, signal):
103+
if "_TX" in signal:
104+
uarttx_list.append([pin,name,signal])
105+
if "_RX" in signal:
106+
uartrx_list.append([pin,name,signal])
107+
if "_CTS" in signal:
108+
uartcts_list.append([pin,name,signal])
109+
if "_RTS" in signal:
110+
uartrts_list.append([pin,name,signal])
111+
112+
#function to store SPI pins
113+
def store_spi(pin, name, signal):
114+
if "_MISO" in signal:
115+
spimiso_list.append([pin,name,signal])
116+
if "_MOSI" in signal:
117+
spimosi_list.append([pin,name,signal])
118+
if "_SCK" in signal:
119+
spisclk_list.append([pin,name,signal])
120+
if "_NSS" in signal:
121+
spissel_list.append([pin,name,signal])
122+
123+
#function to store CAN pins
124+
def store_can(pin, name, signal):
125+
if "_RX" in signal:
126+
canrd_list.append([pin,name,signal])
127+
if "_TX" in signal:
128+
cantd_list.append([pin,name,signal])
129+
130+
#function to store ETH list
131+
def store_eth (pin, name, signal):
132+
eth_list.append([pin,name,signal])
133+
134+
def print_header():
135+
s = ("""/*
136+
*******************************************************************************
137+
* Copyright (c) 2016, STMicroelectronics
138+
* All rights reserved.
139+
*
140+
* Redistribution and use in source and binary forms, with or without
141+
* modification, are permitted provided that the following conditions are met:
142+
*
143+
* 1. Redistributions of source code must retain the above copyright notice,
144+
* this list of conditions and the following disclaimer.
145+
* 2. Redistributions in binary form must reproduce the above copyright notice,
146+
* this list of conditions and the following disclaimer in the documentation
147+
* and/or other materials provided with the distribution.
148+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
149+
* may be used to endorse or promote products derived from this software
150+
* without specific prior written permission.
151+
*
152+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
153+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
154+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
155+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
156+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
157+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
158+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
159+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
160+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
161+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
162+
*******************************************************************************
163+
*/
164+
#include "Arduino.h"
165+
#include "%s.h"
166+
167+
// =====
168+
// Note: Commented lines are alternative possibilities which are not used per default.
169+
// If you change them, you will have to know what you do
170+
// =====
171+
172+
""" % re.sub('\.c$', '', out_filename))
173+
out_file.write( s)
174+
175+
def print_all_lists():
176+
if print_list_header("ADC", "ADC", adclist, "ADC"):
177+
print_adc()
178+
if print_list_header("DAC", "DAC", daclist, "DAC"):
179+
print_dac()
180+
if print_list_header("I2C", "I2C_SDA", i2csda_list, "I2C"):
181+
print_i2c(xml, i2csda_list)
182+
if print_list_header("", "I2C_SCL", i2cscl_list, "I2C"):
183+
print_i2c(xml, i2cscl_list)
184+
if print_list_header("PWM", "PWM", pwm_list, "TIM"):
185+
print_pwm(xml)
186+
if print_list_header("SERIAL", "UART_TX", uarttx_list, "UART"):
187+
print_uart(xml, uarttx_list)
188+
if print_list_header("", "UART_RX", uartrx_list, "UART"):
189+
print_uart(xml, uartrx_list)
190+
if print_list_header("", "UART_RTS", uartrts_list, "UART"):
191+
print_uart(xml, uartrts_list)
192+
if print_list_header("", "UART_CTS", uartcts_list, "UART"):
193+
print_uart(xml, uartcts_list)
194+
if print_list_header("SPI", "SPI_MOSI", spimosi_list, "SPI"):
195+
print_spi(xml, spimosi_list)
196+
if print_list_header("", "SPI_MISO", spimiso_list, "SPI"):
197+
print_spi(xml, spimiso_list)
198+
if print_list_header("", "SPI_SCLK", spisclk_list, "SPI"):
199+
print_spi(xml, spisclk_list)
200+
if print_list_header("", "SPI_SSEL", spissel_list, "SPI"):
201+
print_spi(xml, spissel_list)
202+
if print_list_header("CAN", "CAN_RD", canrd_list, "CAN"):
203+
print_can(xml, canrd_list)
204+
if print_list_header("", "CAN_TD", cantd_list, "CAN"):
205+
print_can(xml, cantd_list)
206+
if print_list_header("ETHERNET", "Ethernet", eth_list, "ETH"):
207+
print_eth(xml, eth_list)
208+
209+
def print_list_header(comment, name, l, switch):
210+
if len(l)>0:
211+
if comment:
212+
s = ("""
213+
//*** %s ***
214+
""") % comment
215+
else:
216+
s = ""
217+
s += ("""
218+
#ifdef HAL_%s_MODULE_ENABLED
219+
const PinMap PinMap_%s[] = {
220+
""") % (switch, name)
221+
else:
222+
if comment:
223+
s = ("""
224+
//*** %s ***
225+
""") % comment
226+
else:
227+
s = ""
228+
s+=("""
229+
//*** No %s ***
230+
""") % name
231+
out_file.write(s)
232+
return len(l)
233+
234+
def print_adc():
235+
i = 0
236+
if len(adclist)>0:
237+
# Check GPIO version (alternate or not)
238+
s_pin_data = 'STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, '
239+
while i < len(adclist):
240+
p=adclist[i]
241+
if "IN" in p[2]:
242+
s1 = "%-12s" % (" {" + p[0] + ',')
243+
a = p[2].split('_')
244+
inst = a[0].replace("ADC", "")
245+
if len(inst) == 0:
246+
inst = '1' #single ADC for this product
247+
s1 += "%-7s" % ('ADC' + inst + ',')
248+
chan = a[1].replace("IN", "")
249+
s1 += s_pin_data + chan
250+
s1 += ', 0)}, // ' + p[2] + '\n'
251+
out_file.write(s1)
252+
i += 1
253+
254+
out_file.write( """ {NC, NP, 0}
255+
};
256+
#endif
257+
""")
258+
259+
def print_dac():
260+
i = 0
261+
if len(daclist)>0:
262+
while i < len(daclist):
263+
p=daclist[i]
264+
b=p[2]
265+
s1 = "%-12s" % (" {" + p[0] + ',')
266+
#2nd element is the DAC signal
267+
if b[3] == '_': # 1 DAC in this chip
268+
s1 += 'DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b[7] + ', 0)}, // ' + b + '\n'
269+
else:
270+
s1 += 'DAC' + b[3] + ', STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b[8] + ', 0)}, // ' + b + '\n'
271+
out_file.write(s1)
272+
i += 1
273+
out_file.write( """ {NC, NP, 0}
274+
};
275+
#endif
276+
""")
277+
278+
def print_i2c(xml, l):
279+
i = 0
280+
if len(l)>0:
281+
while i < len(l):
282+
p=l[i]
283+
result = get_gpio_af_num(xml, p[1], p[2])
284+
if result != 'NOTFOUND':
285+
s1 = "%-12s" % (" {" + p[0] + ',')
286+
#2nd element is the I2C XXX signal
287+
b = p[2].split('_')[0]
288+
s1 += b[:len(b)-1] + b[len(b)-1] + ', STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, '
289+
s1 += result + ')},\n'
290+
out_file.write(s1)
291+
i += 1
292+
out_file.write( """ {NC, NP, 0}
293+
};
294+
#endif
295+
""")
296+
297+
def print_pwm(xml):
298+
i=0
299+
if len(pwm_list)>0:
300+
while i < len(pwm_list):
301+
p=pwm_list[i]
302+
result = get_gpio_af_num(xml, p[1], p[2])
303+
if result != 'NOTFOUND':
304+
s1 = "%-12s" % (" {" + p[0] + ',')
305+
#2nd element is the PWM signal
306+
a = p[2].split('_')
307+
inst = a[0]
308+
if len(inst) == 3:
309+
inst += '1'
310+
s1 += "%-8s" % (inst + ',')
311+
chan = a[1].replace("CH", "")
312+
if chan.endswith('N'):
313+
neg = ', 1'
314+
chan = chan.strip('N')
315+
else:
316+
neg = ', 0'
317+
s1 += 'STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, ' + result + ', ' + chan + neg
318+
s1 += ')}, // ' + p[2] + '\n'
319+
out_file.write(s1)
320+
i += 1
321+
out_file.write( """ {NC, NP, 0}
322+
};
323+
#endif
324+
""")
325+
326+
def print_uart(xml, l):
327+
i=0
328+
if len(l)>0:
329+
while i < len(l):
330+
p=l[i]
331+
result = get_gpio_af_num(xml, p[1], p[2])
332+
if result != 'NOTFOUND':
333+
s1 = "%-12s" % (" {" + p[0] + ',')
334+
#2nd element is the UART_XX signal
335+
b=p[2].split('_')[0]
336+
s1 += "%-9s" % (b[:len(b)-1] + b[len(b)-1:] + ',')
337+
s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},\n'
338+
out_file.write(s1)
339+
i += 1
340+
341+
out_file.write( """ {NC, NP, 0}
342+
};
343+
#endif
344+
""")
345+
346+
def print_spi(xml, l):
347+
i=0
348+
if len(l)>0:
349+
while i < len(l):
350+
p=l[i]
351+
result = get_gpio_af_num(xml, p[1], p[2])
352+
if result != 'NOTFOUND':
353+
s1 = "%-12s" % (" {" + p[0] + ',')
354+
#2nd element is the SPI_XXXX signal
355+
instance=p[2].split('_')[0].replace("SPI", "")
356+
s1 += 'SPI' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
357+
s1 += result +')},\n'
358+
out_file.write(s1)
359+
i += 1
360+
361+
out_file.write( """ {NC, NP, 0}
362+
};
363+
#endif
364+
""")
365+
366+
def print_can(xml, l):
367+
i=0
368+
if len(l)>0:
369+
while i < len(l):
370+
p=l[i]
371+
b=p[2]
372+
result = get_gpio_af_num(xml, p[1], p[2])
373+
if result != 'NOTFOUND':
374+
s1 = "%-12s" % (" {" + p[0] + ',')
375+
#2nd element is the CAN_XX signal
376+
instance = p[2].split('_')[0].replace("CAN", "")
377+
#if len(instance) == 0:
378+
# instance = '1'
379+
s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, '
380+
s1 += result +')},\n'
381+
out_file.write( s1)
382+
i += 1
383+
out_file.write( """ {NC, NP, 0}
384+
};
385+
#endif
386+
""")
387+
388+
def print_eth(xml, l):
389+
i=0
390+
if len(l)>0:
391+
prev_s = ''
392+
while i < len(l):
393+
p=l[i]
394+
result = get_gpio_af_num(xml, p[1], p[2])
395+
if result != 'NOTFOUND':
396+
s1 = "%-12s" % (" {" + p[0] + ',')
397+
#2nd element is the ETH_XXXX signal
398+
s1 += 'ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},'
399+
#check duplicated lines, only signal differs
400+
if (prev_s == s1):
401+
s1 = '|' + p[2]
402+
else:
403+
if len(prev_s)>0:
404+
out_file.write('\n')
405+
prev_s = s1
406+
s1 += ' // ' + p[2]
407+
out_file.write(s1)
408+
i += 1
409+
410+
out_file.write( """\n {NC, NP, 0}
411+
};
412+
#endif
413+
""")
414+
415+
tokenize = re.compile(r'(\d+)|(\D+)').findall
416+
def natural_sortkey(list_2_elem):
417+
418+
return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[0]))
419+
420+
def sort_my_lists():
421+
adclist.sort(key=natural_sortkey)
422+
daclist.sort(key=natural_sortkey)
423+
i2cscl_list.sort(key=natural_sortkey)
424+
i2csda_list.sort(key=natural_sortkey)
425+
pwm_list.sort(key=natural_sortkey)
426+
uarttx_list.sort(key=natural_sortkey)
427+
uartrx_list.sort(key=natural_sortkey)
428+
uartcts_list.sort(key=natural_sortkey)
429+
uartrts_list.sort(key=natural_sortkey)
430+
spimosi_list.sort(key=natural_sortkey)
431+
spimiso_list.sort(key=natural_sortkey)
432+
spissel_list.sort(key=natural_sortkey)
433+
spisclk_list.sort(key=natural_sortkey)
434+
cantd_list.sort(key=natural_sortkey)
435+
canrd_list.sort(key=natural_sortkey)
436+
eth_list.sort(key=natural_sortkey)
437+
438+
return
439+
440+
# START MAIN PROGRAM
441+
#xmldoc = minidom.parse('STM32L051K(6-8)Tx.xml')
442+
cur_dir = os.getcwd()
443+
out_filename = 'PeripheralPins.c'
444+
445+
if len(sys.argv) < 3:
446+
print("Usage: " + sys.argv[0] + " <BOARD_NAME> <product xml file name>")
447+
print(" - <BOARD_NAME> is the name of the board as it will be named in mbed")
448+
print(" - <product xml file name> is the STM32 file description in Cube MX")
449+
print(" !!This xml file contains non alpha characters in its name, you should call it with quotes")
450+
print("")
451+
print(" This script is able to generate the %s for a specific board" % out_filename )
452+
print(" After file generation, review it carefully and ")
453+
print(" please report any issue to github:")
454+
print(" https://github.com/fpistm/stm32_tools/issues")
455+
print("")
456+
print(" Once generated, you should comment a line if the pin is generated ")
457+
print(" several times for the same IP")
458+
print(" or if the pin should not be used (overlaid with some HW on the board, ")
459+
print(" for instance)")
460+
quit()
461+
462+
if sys.platform.startswith('win32'):
463+
#print ("Windows env")
464+
cubemxdir = 'C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\db\mcu'
465+
cubemxdirIP = cubemxdir+"\\IP\\"
466+
input_file_name = cubemxdir+"\\" + sys.argv[2]
467+
out_path = cur_dir+'\\Arduino\\_'+sys.argv[1]
468+
output_filename = out_path+"\\"+out_filename
469+
else:
470+
#print ("Linux env")
471+
if sys.platform.startswith('linux'):
472+
cubemxdir = os.getenv("HOME")+'/STM32CubeMX/db/mcu'
473+
cubemxdirIP = cubemxdir+"/IP/"
474+
input_file_name = cubemxdir+'/'+ sys.argv[2]
475+
out_path = cur_dir+'/Arduino/'+sys.argv[1]
476+
output_filename = out_path+'/'+out_filename
477+
else:
478+
#print ("Darwin env")
479+
if sys.platform.startswith('darwin'):
480+
print("Platform is Mac OSX")
481+
cubemxdir = '/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources/db/mcu'
482+
cubemxdirIP = cubemxdir+"/IP/"
483+
input_file_name = cubemxdir+'/'+ sys.argv[2]
484+
out_path = cur_dir+'/Arduino/'+sys.argv[1]
485+
output_filename = out_path+'/'+out_filename
486+
else:
487+
print ("Unsupported OS")
488+
quit()
489+
490+
#open input file
491+
#check input file exists
492+
if not(os.path.isdir(cubemxdir)):
493+
print ("\n ! ! ! Cube Mx seems not to be installed or not at the requested location")
494+
print ("\n ! ! ! please check the value you set for cubemxdir variable at the top of " + sys.argv[0] + " file")
495+
quit()
496+
if not(os.path.isfile(input_file_name)):
497+
print ('\n ! ! ! '+sys.argv[2] + ' file not found')
498+
print ("\n ! ! ! Check in " + cubemxdir + " the correct name of this file")
499+
print ("\n ! ! ! You may use double quotes for this file if it contains special characters")
500+
quit()
501+
502+
503+
print (" * * * Opening input file...")
504+
if not(os.path.isdir(out_path)):
505+
os.makedirs(out_path)
506+
xmldoc = minidom.parse(input_file_name)
507+
itemlist = xmldoc.getElementsByTagName('Pin')
508+
#open output file
509+
if (os.path.isfile(output_filename)):
510+
print (" * * * * Requested %s file already exists and will be overwritten" % out_filename)
511+
os.remove(output_filename)
512+
513+
out_file = open(output_filename, 'w')
514+
515+
# Check if Alternate functions in GPIO or old GPIO (no alternate)
516+
if 'STM32F10' in sys.argv[2]:
517+
print ("STM32F10xx MCU not supported due to older GPIO IP version\n")
518+
quit()
519+
520+
gpiofile = find_gpio_file(xmldoc)
521+
if gpiofile == 'ERROR':
522+
quit()
523+
xml = parse(cubemxdirIP + 'GPIO-' + gpiofile + '_Modes.xml')
524+
print (" * * * Getting pins and Ips for the xml file...")
525+
pinregex=r'^(P[A-Z][0-9][0-5]?)'
526+
for s in itemlist:
527+
m = re.match(pinregex, s.attributes['Name'].value)
528+
if m:
529+
pin = m.group(0) # pin formatted P<port><number>: PFO
530+
name = s.attributes['Name'].value.strip() # full name: "PF0 / OSC_IN"
531+
if s.attributes['Type'].value == "I/O":
532+
store_pin(pin, name)
533+
else:
534+
continue
535+
siglist = s.getElementsByTagName('Signal')
536+
for a in siglist:
537+
sig = a.attributes['Name'].value.strip()
538+
if "ADC" in sig:
539+
#store ADC pin
540+
store_adc( pin, name, sig)
541+
if all(["DAC" in sig, "_OUT" in sig]):
542+
#store DAC
543+
store_dac( pin, name, sig)
544+
if "I2C" in sig:
545+
#store DAC
546+
store_i2c( pin, name, sig)
547+
if re.match('^TIM', sig) is not None: #ignore HRTIM
548+
#store PWM
549+
store_pwm( pin, name, sig)
550+
if re.match('^(LPU|US|U)ART', sig) is not None:
551+
store_uart( pin, name, sig)
552+
if "SPI" in sig:
553+
store_spi( pin, name, sig)
554+
if "CAN" in sig:
555+
store_can( pin, name, sig)
556+
if "ETH" in sig:
557+
store_eth( pin, name, sig)
558+
559+
print (" * * * Sorting lists...")
560+
sort_my_lists()
561+
562+
print (" * * * Printing lists...")
563+
print_header()
564+
print_all_lists()
565+
566+
nb_pin = (len(io_list))
567+
print ("nb of I/O pins: %i" % nb_pin)
568+
print ('\n * * * ' + sys.argv[1]+' OK')

‎src/genpinmap/genpinmap_arduino.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash -
2+
#===============================================================================
3+
#
4+
# FILE: genpinmap_arduino.sh
5+
#
6+
# USAGE: ./genpinmap_arduino.sh
7+
#
8+
# DESCRIPTION:
9+
#
10+
# OPTIONS: None
11+
# BUGS: ---
12+
# NOTES: ---
13+
# AUTHOR: fpistm
14+
# ORGANIZATION: STMicroelectronics
15+
# CREATED: 03/07/17 08:42
16+
# REVISION: 1.0
17+
#===============================================================================
18+
19+
set -o nounset # Treat unset variables as an error
20+
21+
# See xml file name in <STM32CubeMX install dir>\db\mcu
22+
23+
# GPIO AF function not supported:: python genpinmap_arduino.py NUCLEO_F030R8 "STM32F030R8Tx.xml"
24+
# GPIO AF function not supported::python genpinmap_arduino.py DISCO_F051R8 "STM32F051R8Tx.xml"
25+
#
26+
python genpinmap_arduino.py NUCLEO_F030R8 "STM32F030R8Tx.xml"
27+
python genpinmap_arduino.py NUCLEO_F091RC "STM32F091R(B-C)Tx.xml"
28+
python genpinmap_arduino.py NUCLEO_F303RE "STM32F303R(D-E)Tx.xml"
29+
python genpinmap_arduino.py NUCLEO_F429ZI "STM32F429Z(E-G-I)Tx.xml"
30+
python genpinmap_arduino.py DISCO_F407G "STM32F407V(E-G)Tx.xml"
31+
python genpinmap_arduino.py DISCO_F746NG "STM32F746N(E-G)Hx.xml"
32+
python genpinmap_arduino.py NUCLEO_L053R8 "STM32L053R(6-8)Tx.xml"
33+
python genpinmap_arduino.py NUCLEO_L432KC "STM32L432K(B-C)Ux.xml"
34+
python genpinmap_arduino.py NUCLEO_L476RG "STM32L475R(C-E-G)Tx.xml"

0 commit comments

Comments
 (0)
Please sign in to comment.