[genpinmap] Use Black code formatter
Black is the uncompromising Python code formatter: https://github.com/ambv/black/ Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
This commit is contained in:
parent
aae08a915d
commit
27cea3ca8a
1 changed files with 449 additions and 292 deletions
|
|
@ -9,6 +9,7 @@ import textwrap
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
from xml.dom.minidom import parse, Node
|
from xml.dom.minidom import parse, Node
|
||||||
from argparse import RawTextHelpFormatter
|
from argparse import RawTextHelpFormatter
|
||||||
|
|
||||||
mcu_file = ""
|
mcu_file = ""
|
||||||
mcu_list = [] # 'name'
|
mcu_list = [] # 'name'
|
||||||
io_list = [] # 'PIN','name'
|
io_list = [] # 'PIN','name'
|
||||||
|
|
@ -31,21 +32,23 @@ eth_list = [] #'PIN','name','ETH'
|
||||||
qspi_list = [] # 'PIN','name','QUADSPI'
|
qspi_list = [] # 'PIN','name','QUADSPI'
|
||||||
syswkup_list = [] # 'PIN','name','SYSWKUP'
|
syswkup_list = [] # 'PIN','name','SYSWKUP'
|
||||||
|
|
||||||
|
|
||||||
def find_gpio_file():
|
def find_gpio_file():
|
||||||
res = 'ERROR'
|
res = "ERROR"
|
||||||
itemlist = xml_mcu.getElementsByTagName('IP')
|
itemlist = xml_mcu.getElementsByTagName("IP")
|
||||||
for s in itemlist:
|
for s in itemlist:
|
||||||
a = s.attributes['Name'].value
|
a = s.attributes["Name"].value
|
||||||
if "GPIO" in a:
|
if "GPIO" in a:
|
||||||
res = s.attributes['Version'].value
|
res = s.attributes["Version"].value
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def get_gpio_af_num(pintofind, iptofind):
|
def get_gpio_af_num(pintofind, iptofind):
|
||||||
if 'STM32F10' in mcu_file:
|
if "STM32F10" in mcu_file:
|
||||||
return get_gpio_af_numF1(pintofind, iptofind)
|
return get_gpio_af_numF1(pintofind, iptofind)
|
||||||
# DBG print ('pin to find ' + pintofind)
|
# DBG print ('pin to find ' + pintofind)
|
||||||
i = 0
|
i = 0
|
||||||
mygpioaf = 'NOTFOUND'
|
mygpioaf = "NOTFOUND"
|
||||||
for n in xml_gpio.documentElement.childNodes:
|
for n in xml_gpio.documentElement.childNodes:
|
||||||
i += 1
|
i += 1
|
||||||
j = 0
|
j = 0
|
||||||
|
|
@ -74,17 +77,27 @@ def get_gpio_af_num(pintofind, iptofind):
|
||||||
if myc.nodeType == Node.ELEMENT_NODE:
|
if myc.nodeType == Node.ELEMENT_NODE:
|
||||||
# myc = node of ALTERNATE
|
# myc = node of ALTERNATE
|
||||||
for mygpioaflist in myc.childNodes:
|
for mygpioaflist in myc.childNodes:
|
||||||
mygpioaf += ' ' + mygpioaflist.data
|
mygpioaf += (
|
||||||
|
" " + mygpioaflist.data
|
||||||
|
)
|
||||||
# print (mygpioaf)
|
# print (mygpioaf)
|
||||||
if mygpioaf == 'NOTFOUND':
|
if mygpioaf == "NOTFOUND":
|
||||||
print ('GPIO AF not found in ' + gpiofile + ' for ' + pintofind + ' and the IP ' + iptofind)
|
print(
|
||||||
|
"GPIO AF not found in "
|
||||||
|
+ gpiofile
|
||||||
|
+ " for "
|
||||||
|
+ pintofind
|
||||||
|
+ " and the IP "
|
||||||
|
+ iptofind
|
||||||
|
)
|
||||||
# quit()
|
# quit()
|
||||||
return mygpioaf.replace('NOTFOUND ', '')
|
return mygpioaf.replace("NOTFOUND ", "")
|
||||||
|
|
||||||
|
|
||||||
def get_gpio_af_numF1(pintofind, iptofind):
|
def get_gpio_af_numF1(pintofind, iptofind):
|
||||||
# print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
|
# print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
|
||||||
i = 0
|
i = 0
|
||||||
mygpioaf = 'NOTFOUND'
|
mygpioaf = "NOTFOUND"
|
||||||
for n in xml_gpio.documentElement.childNodes:
|
for n in xml_gpio.documentElement.childNodes:
|
||||||
i += 1
|
i += 1
|
||||||
j = 0
|
j = 0
|
||||||
|
|
@ -108,8 +121,11 @@ def get_gpio_af_numF1(pintofind, iptofind):
|
||||||
# print (i, j, m.attributes.items())
|
# print (i, j, m.attributes.items())
|
||||||
for p in m.childNodes:
|
for p in m.childNodes:
|
||||||
# p node 'RemapBlock'
|
# p node 'RemapBlock'
|
||||||
if p.nodeType == Node.ELEMENT_NODE and p.hasChildNodes() == False:
|
if (
|
||||||
mygpioaf += ' AFIO_NONE'
|
p.nodeType == Node.ELEMENT_NODE
|
||||||
|
and p.hasChildNodes() == False
|
||||||
|
):
|
||||||
|
mygpioaf += " AFIO_NONE"
|
||||||
else:
|
else:
|
||||||
for s in p.childNodes:
|
for s in p.childNodes:
|
||||||
if s.nodeType == Node.ELEMENT_NODE:
|
if s.nodeType == Node.ELEMENT_NODE:
|
||||||
|
|
@ -117,15 +133,32 @@ def get_gpio_af_numF1(pintofind, iptofind):
|
||||||
# DBG print (i,j,k,p.attributes.items())
|
# DBG print (i,j,k,p.attributes.items())
|
||||||
for myc in s.childNodes:
|
for myc in s.childNodes:
|
||||||
# DBG print (myc)
|
# DBG print (myc)
|
||||||
if myc.nodeType == Node.ELEMENT_NODE:
|
if (
|
||||||
|
myc.nodeType
|
||||||
|
== Node.ELEMENT_NODE
|
||||||
|
):
|
||||||
# myc = AF value
|
# myc = AF value
|
||||||
for mygpioaflist in myc.childNodes:
|
for (
|
||||||
mygpioaf += ' ' + mygpioaflist.data.replace("__HAL_", "").replace("_REMAP", "")
|
mygpioaflist
|
||||||
|
) in myc.childNodes:
|
||||||
|
mygpioaf += " " + mygpioaflist.data.replace(
|
||||||
|
"__HAL_", ""
|
||||||
|
).replace(
|
||||||
|
"_REMAP", ""
|
||||||
|
)
|
||||||
# print mygpioaf
|
# print mygpioaf
|
||||||
if mygpioaf == 'NOTFOUND':
|
if mygpioaf == "NOTFOUND":
|
||||||
print ('GPIO AF not found in ' + gpiofile + ' for ' + pintofind + ' and the IP ' + iptofind + ' set as AFIO_NONE')
|
print(
|
||||||
mygpioaf = 'AFIO_NONE'
|
"GPIO AF not found in "
|
||||||
return mygpioaf.replace('NOTFOUND ', '')
|
+ gpiofile
|
||||||
|
+ " for "
|
||||||
|
+ pintofind
|
||||||
|
+ " and the IP "
|
||||||
|
+ iptofind
|
||||||
|
+ " set as AFIO_NONE"
|
||||||
|
)
|
||||||
|
mygpioaf = "AFIO_NONE"
|
||||||
|
return mygpioaf.replace("NOTFOUND ", "")
|
||||||
|
|
||||||
|
|
||||||
def store_pin(pin, name):
|
def store_pin(pin, name):
|
||||||
|
|
@ -133,14 +166,17 @@ def store_pin (pin, name):
|
||||||
p = [pin, name]
|
p = [pin, name]
|
||||||
io_list.append(p)
|
io_list.append(p)
|
||||||
|
|
||||||
|
|
||||||
# function to store ADC list
|
# function to store ADC list
|
||||||
def store_adc(pin, name, signal):
|
def store_adc(pin, name, signal):
|
||||||
adclist.append([pin, name, signal])
|
adclist.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store DAC list
|
# function to store DAC list
|
||||||
def store_dac(pin, name, signal):
|
def store_dac(pin, name, signal):
|
||||||
daclist.append([pin, name, signal])
|
daclist.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store I2C list
|
# function to store I2C list
|
||||||
def store_i2c(pin, name, signal):
|
def store_i2c(pin, name, signal):
|
||||||
# is it SDA or SCL ?
|
# is it SDA or SCL ?
|
||||||
|
|
@ -149,11 +185,13 @@ def store_i2c (pin, name, signal):
|
||||||
if "_SDA" in signal:
|
if "_SDA" in signal:
|
||||||
i2csda_list.append([pin, name, signal])
|
i2csda_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store timers
|
# function to store timers
|
||||||
def store_pwm(pin, name, signal):
|
def store_pwm(pin, name, signal):
|
||||||
if "_CH" in signal:
|
if "_CH" in signal:
|
||||||
pwm_list.append([pin, name, signal])
|
pwm_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store Uart pins
|
# function to store Uart pins
|
||||||
def store_uart(pin, name, signal):
|
def store_uart(pin, name, signal):
|
||||||
if "_TX" in signal:
|
if "_TX" in signal:
|
||||||
|
|
@ -165,6 +203,7 @@ def store_uart(pin, name, signal):
|
||||||
if "_RTS" in signal:
|
if "_RTS" in signal:
|
||||||
uartrts_list.append([pin, name, signal])
|
uartrts_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store SPI pins
|
# function to store SPI pins
|
||||||
def store_spi(pin, name, signal):
|
def store_spi(pin, name, signal):
|
||||||
if "_MISO" in signal:
|
if "_MISO" in signal:
|
||||||
|
|
@ -176,6 +215,7 @@ def store_spi(pin, name, signal):
|
||||||
if "_NSS" in signal:
|
if "_NSS" in signal:
|
||||||
spissel_list.append([pin, name, signal])
|
spissel_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store CAN pins
|
# function to store CAN pins
|
||||||
def store_can(pin, name, signal):
|
def store_can(pin, name, signal):
|
||||||
if "_RX" in signal:
|
if "_RX" in signal:
|
||||||
|
|
@ -183,21 +223,25 @@ def store_can(pin, name, signal):
|
||||||
if "_TX" in signal:
|
if "_TX" in signal:
|
||||||
cantd_list.append([pin, name, signal])
|
cantd_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store ETH list
|
# function to store ETH list
|
||||||
def store_eth(pin, name, signal):
|
def store_eth(pin, name, signal):
|
||||||
eth_list.append([pin, name, signal])
|
eth_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store QSPI pins
|
# function to store QSPI pins
|
||||||
def store_qspi(pin, name, signal):
|
def store_qspi(pin, name, signal):
|
||||||
qspi_list.append([pin, name, signal])
|
qspi_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
# function to store SYS pins
|
# function to store SYS pins
|
||||||
def store_sys(pin, name, signal):
|
def store_sys(pin, name, signal):
|
||||||
if "_WKUP" in signal:
|
if "_WKUP" in signal:
|
||||||
syswkup_list.append([pin, name, signal])
|
syswkup_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
def print_header():
|
def print_header():
|
||||||
s = ("""/*
|
s = """/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* Copyright (c) %i, STMicroelectronics
|
* Copyright (c) %i, STMicroelectronics
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|
@ -235,9 +279,14 @@ def print_header():
|
||||||
* If you change them, you will have to know what you do
|
* If you change them, you will have to know what you do
|
||||||
* =====
|
* =====
|
||||||
*/
|
*/
|
||||||
""" % (datetime.datetime.now().year, os.path.basename(input_file_name), re.sub('\.c$', '', out_c_filename)))
|
""" % (
|
||||||
|
datetime.datetime.now().year,
|
||||||
|
os.path.basename(input_file_name),
|
||||||
|
re.sub("\.c$", "", out_c_filename),
|
||||||
|
)
|
||||||
out_c_file.write(s)
|
out_c_file.write(s)
|
||||||
|
|
||||||
|
|
||||||
def print_all_lists():
|
def print_all_lists():
|
||||||
if print_list_header("ADC", "ADC", adclist, "ADC"):
|
if print_list_header("ADC", "ADC", adclist, "ADC"):
|
||||||
print_adc()
|
print_adc()
|
||||||
|
|
@ -276,221 +325,288 @@ def print_all_lists():
|
||||||
# Print specific PinNames
|
# Print specific PinNames
|
||||||
print_syswkup()
|
print_syswkup()
|
||||||
|
|
||||||
|
|
||||||
def print_list_header(comment, name, l, switch):
|
def print_list_header(comment, name, l, switch):
|
||||||
if len(l) > 0:
|
if len(l) > 0:
|
||||||
if comment:
|
if comment:
|
||||||
s = ("""
|
s = (
|
||||||
|
(
|
||||||
|
"""
|
||||||
//*** %s ***
|
//*** %s ***
|
||||||
""") % comment
|
"""
|
||||||
|
)
|
||||||
|
% comment
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
s = ""
|
s = ""
|
||||||
s += ("""
|
s += (
|
||||||
|
(
|
||||||
|
"""
|
||||||
#ifdef HAL_%s_MODULE_ENABLED
|
#ifdef HAL_%s_MODULE_ENABLED
|
||||||
const PinMap PinMap_%s[] = {
|
const PinMap PinMap_%s[] = {
|
||||||
""") % (switch, name)
|
"""
|
||||||
|
)
|
||||||
|
% (switch, name)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if comment:
|
if comment:
|
||||||
s = ("""
|
s = (
|
||||||
|
(
|
||||||
|
"""
|
||||||
//*** %s ***
|
//*** %s ***
|
||||||
""") % comment
|
"""
|
||||||
|
)
|
||||||
|
% comment
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
s = ""
|
s = ""
|
||||||
s+=("""
|
s += (
|
||||||
|
(
|
||||||
|
"""
|
||||||
//*** No %s ***
|
//*** No %s ***
|
||||||
""") % name
|
"""
|
||||||
|
)
|
||||||
|
% name
|
||||||
|
)
|
||||||
out_c_file.write(s)
|
out_c_file.write(s)
|
||||||
return len(l)
|
return len(l)
|
||||||
|
|
||||||
|
|
||||||
def print_adc():
|
def print_adc():
|
||||||
# Check GPIO version (alternate or not)
|
# Check GPIO version (alternate or not)
|
||||||
s_pin_data = 'STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, '
|
s_pin_data = "STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, "
|
||||||
for p in adclist:
|
for p in adclist:
|
||||||
if "IN" in p[2]:
|
if "IN" in p[2]:
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
a = p[2].split('_')
|
a = p[2].split("_")
|
||||||
inst = a[0].replace("ADC", "")
|
inst = a[0].replace("ADC", "")
|
||||||
if len(inst) == 0:
|
if len(inst) == 0:
|
||||||
inst = '1' #single ADC for this product
|
inst = "1" # single ADC for this product
|
||||||
s1 += "%-7s" % ('ADC' + inst + ',')
|
s1 += "%-7s" % ("ADC" + inst + ",")
|
||||||
chan = re.sub('IN[N|P]?', '', a[1])
|
chan = re.sub("IN[N|P]?", "", a[1])
|
||||||
s1 += s_pin_data + chan
|
s1 += s_pin_data + chan
|
||||||
s1 += ', 0)}, // ' + p[2] + '\n'
|
s1 += ", 0)}, // " + p[2] + "\n"
|
||||||
out_c_file.write(s1)
|
out_c_file.write(s1)
|
||||||
out_c_file.write( """ {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
""" {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_dac():
|
def print_dac():
|
||||||
for p in daclist:
|
for p in daclist:
|
||||||
b = p[2]
|
b = p[2]
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
# 2nd element is the DAC signal
|
# 2nd element is the DAC signal
|
||||||
if b[3] == '_': # 1 DAC in this chip
|
if b[3] == "_": # 1 DAC in this chip
|
||||||
s1 += 'DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b[7] + ', 0)}, // ' + b + '\n'
|
s1 += (
|
||||||
|
"DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, "
|
||||||
|
+ b[7]
|
||||||
|
+ ", 0)}, // "
|
||||||
|
+ b
|
||||||
|
+ "\n"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
s1 += 'DAC' + b[3] + ', STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b[8] + ', 0)}, // ' + b + '\n'
|
s1 += (
|
||||||
|
"DAC"
|
||||||
|
+ b[3]
|
||||||
|
+ ", STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, "
|
||||||
|
+ b[8]
|
||||||
|
+ ", 0)}, // "
|
||||||
|
+ b
|
||||||
|
+ "\n"
|
||||||
|
)
|
||||||
out_c_file.write(s1)
|
out_c_file.write(s1)
|
||||||
out_c_file.write( """ {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
""" {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_i2c(l):
|
def print_i2c(l):
|
||||||
for p in l:
|
for p in l:
|
||||||
result = get_gpio_af_num(p[1], p[2])
|
result = get_gpio_af_num(p[1], p[2])
|
||||||
if result != 'NOTFOUND':
|
if result != "NOTFOUND":
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
# 2nd element is the I2C XXX signal
|
# 2nd element is the I2C XXX signal
|
||||||
b = p[2].split('_')[0]
|
b = p[2].split("_")[0]
|
||||||
s1 += b[:len(b)-1] + b[len(b)-1] + ', STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, '
|
s1 += (
|
||||||
r = result.split(' ')
|
b[: len(b) - 1]
|
||||||
|
+ b[len(b) - 1]
|
||||||
|
+ ", STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, "
|
||||||
|
)
|
||||||
|
r = result.split(" ")
|
||||||
for af in r:
|
for af in r:
|
||||||
s2 = s1 + af + ')},\n'
|
s2 = s1 + af + ")},\n"
|
||||||
out_c_file.write(s2)
|
out_c_file.write(s2)
|
||||||
out_c_file.write( """ {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
""" {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_pwm():
|
def print_pwm():
|
||||||
for p in pwm_list:
|
for p in pwm_list:
|
||||||
result = get_gpio_af_num(p[1], p[2])
|
result = get_gpio_af_num(p[1], p[2])
|
||||||
if result != 'NOTFOUND':
|
if result != "NOTFOUND":
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
# 2nd element is the PWM signal
|
# 2nd element is the PWM signal
|
||||||
a = p[2].split('_')
|
a = p[2].split("_")
|
||||||
inst = a[0]
|
inst = a[0]
|
||||||
if len(inst) == 3:
|
if len(inst) == 3:
|
||||||
inst += '1'
|
inst += "1"
|
||||||
s1 += "%-8s" % (inst + ',')
|
s1 += "%-8s" % (inst + ",")
|
||||||
chan = a[1].replace("CH", "")
|
chan = a[1].replace("CH", "")
|
||||||
if chan.endswith('N'):
|
if chan.endswith("N"):
|
||||||
neg = ', 1'
|
neg = ", 1"
|
||||||
chan = chan.strip('N')
|
chan = chan.strip("N")
|
||||||
else:
|
else:
|
||||||
neg = ', 0'
|
neg = ", 0"
|
||||||
s1 += 'STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, '
|
s1 += "STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, "
|
||||||
r = result.split(' ')
|
r = result.split(" ")
|
||||||
for af in r:
|
for af in r:
|
||||||
s2 = s1 + af + ', ' + chan + neg + ')}, // ' + p[2] + '\n'
|
s2 = s1 + af + ", " + chan + neg + ")}, // " + p[2] + "\n"
|
||||||
out_c_file.write(s2)
|
out_c_file.write(s2)
|
||||||
out_c_file.write( """ {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
""" {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_uart(l):
|
def print_uart(l):
|
||||||
for p in l:
|
for p in l:
|
||||||
result = get_gpio_af_num(p[1], p[2])
|
result = get_gpio_af_num(p[1], p[2])
|
||||||
if result != 'NOTFOUND':
|
if result != "NOTFOUND":
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
# 2nd element is the UART_XX signal
|
# 2nd element is the UART_XX signal
|
||||||
b=p[2].split('_')[0]
|
b = p[2].split("_")[0]
|
||||||
s1 += "%-9s" % (b[:len(b)-1] + b[len(b)-1:] + ',')
|
s1 += "%-9s" % (b[: len(b) - 1] + b[len(b) - 1 :] + ",")
|
||||||
if 'STM32F10' in mcu_file and l == uartrx_list:
|
if "STM32F10" in mcu_file and l == uartrx_list:
|
||||||
s1 += 'STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, '
|
s1 += "STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, "
|
||||||
else:
|
else:
|
||||||
s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
|
s1 += "STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
|
||||||
r = result.split(' ')
|
r = result.split(" ")
|
||||||
for af in r:
|
for af in r:
|
||||||
s2 = s1 + af + ')},\n'
|
s2 = s1 + af + ")},\n"
|
||||||
out_c_file.write(s2)
|
out_c_file.write(s2)
|
||||||
out_c_file.write( """ {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
""" {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_spi(l):
|
def print_spi(l):
|
||||||
for p in l:
|
for p in l:
|
||||||
result = get_gpio_af_num(p[1], p[2])
|
result = get_gpio_af_num(p[1], p[2])
|
||||||
if result != 'NOTFOUND':
|
if result != "NOTFOUND":
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
# 2nd element is the SPI_XXXX signal
|
# 2nd element is the SPI_XXXX signal
|
||||||
instance=p[2].split('_')[0].replace("SPI", "")
|
instance = p[2].split("_")[0].replace("SPI", "")
|
||||||
s1 += 'SPI' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
|
s1 += "SPI" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
|
||||||
r = result.split(' ')
|
r = result.split(" ")
|
||||||
for af in r:
|
for af in r:
|
||||||
s2 = s1 + af + ')},\n'
|
s2 = s1 + af + ")},\n"
|
||||||
out_c_file.write(s2)
|
out_c_file.write(s2)
|
||||||
out_c_file.write( """ {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
""" {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_can(l):
|
def print_can(l):
|
||||||
for p in l:
|
for p in l:
|
||||||
b = p[2]
|
b = p[2]
|
||||||
result = get_gpio_af_num(p[1], p[2])
|
result = get_gpio_af_num(p[1], p[2])
|
||||||
if result != 'NOTFOUND':
|
if result != "NOTFOUND":
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
# 2nd element is the CAN_XX signal
|
# 2nd element is the CAN_XX signal
|
||||||
instance = p[2].split('_')[0].replace("CAN", "")
|
instance = p[2].split("_")[0].replace("CAN", "")
|
||||||
if len(instance) == 0:
|
if len(instance) == 0:
|
||||||
instance = '1'
|
instance = "1"
|
||||||
if 'STM32F10' in mcu_file and l == canrd_list:
|
if "STM32F10" in mcu_file and l == canrd_list:
|
||||||
s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, '
|
s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
|
||||||
else:
|
else:
|
||||||
s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, '
|
s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, "
|
||||||
r = result.split(' ')
|
r = result.split(" ")
|
||||||
for af in r:
|
for af in r:
|
||||||
s2 = s1 + af + ')},\n'
|
s2 = s1 + af + ")},\n"
|
||||||
out_c_file.write(s2)
|
out_c_file.write(s2)
|
||||||
out_c_file.write( """ {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
""" {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_eth():
|
def print_eth():
|
||||||
prev_s = ''
|
prev_s = ""
|
||||||
for p in eth_list:
|
for p in eth_list:
|
||||||
result = get_gpio_af_num(p[1], p[2])
|
result = get_gpio_af_num(p[1], p[2])
|
||||||
if result != 'NOTFOUND':
|
if result != "NOTFOUND":
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
# 2nd element is the ETH_XXXX signal
|
# 2nd element is the ETH_XXXX signal
|
||||||
s1 += 'ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},'
|
s1 += "ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
|
||||||
# check duplicated lines, only signal differs
|
# check duplicated lines, only signal differs
|
||||||
if (prev_s == s1):
|
if prev_s == s1:
|
||||||
s1 = '|' + p[2]
|
s1 = "|" + p[2]
|
||||||
else:
|
else:
|
||||||
if len(prev_s) > 0:
|
if len(prev_s) > 0:
|
||||||
out_c_file.write('\n')
|
out_c_file.write("\n")
|
||||||
prev_s = s1
|
prev_s = s1
|
||||||
s1 += ' // ' + p[2]
|
s1 += " // " + p[2]
|
||||||
out_c_file.write(s1)
|
out_c_file.write(s1)
|
||||||
out_c_file.write( """\n {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
"""\n {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_qspi():
|
def print_qspi():
|
||||||
prev_s = ''
|
prev_s = ""
|
||||||
for p in qspi_list:
|
for p in qspi_list:
|
||||||
result = get_gpio_af_num(p[1], p[2])
|
result = get_gpio_af_num(p[1], p[2])
|
||||||
if result != 'NOTFOUND':
|
if result != "NOTFOUND":
|
||||||
s1 = "%-12s" % (" {" + p[0] + ',')
|
s1 = "%-12s" % (" {" + p[0] + ",")
|
||||||
# 2nd element is the QUADSPI_XXXX signal
|
# 2nd element is the QUADSPI_XXXX signal
|
||||||
s1 += 'QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},'
|
s1 += "QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
|
||||||
# check duplicated lines, only signal differs
|
# check duplicated lines, only signal differs
|
||||||
if (prev_s == s1):
|
if prev_s == s1:
|
||||||
s1 = '|' + p[2]
|
s1 = "|" + p[2]
|
||||||
else:
|
else:
|
||||||
if len(prev_s) > 0:
|
if len(prev_s) > 0:
|
||||||
out_c_file.write('\n')
|
out_c_file.write("\n")
|
||||||
prev_s = s1
|
prev_s = s1
|
||||||
s1 += ' // ' + p[2]
|
s1 += " // " + p[2]
|
||||||
out_c_file.write(s1)
|
out_c_file.write(s1)
|
||||||
out_c_file.write( """\n {NC, NP, 0}
|
out_c_file.write(
|
||||||
|
"""\n {NC, NP, 0}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_syswkup():
|
def print_syswkup():
|
||||||
out_h_file.write(" /* SYS_WKUP */\n")
|
out_h_file.write(" /* SYS_WKUP */\n")
|
||||||
# H7xx and F446 start from 0, inc by 1
|
# H7xx and F446 start from 0, inc by 1
|
||||||
num = syswkup_list[0][2].replace("SYS_WKUP", "")
|
num = syswkup_list[0][2].replace("SYS_WKUP", "")
|
||||||
inc = 0
|
inc = 0
|
||||||
if num == '0':
|
if num == "0":
|
||||||
inc = 1
|
inc = 1
|
||||||
# Fill list with missing SYS_WKUPx set to NC
|
# Fill list with missing SYS_WKUPx set to NC
|
||||||
i = 0
|
i = 0
|
||||||
|
|
@ -502,30 +618,35 @@ def print_syswkup():
|
||||||
num = int(n) if inc == 1 else int(n) - 1
|
num = int(n) if inc == 1 else int(n) - 1
|
||||||
x = i if inc == 1 else i + 1
|
x = i if inc == 1 else i + 1
|
||||||
if num != i:
|
if num != i:
|
||||||
syswkup_list.insert(i,['NC', 'NC_' + str(x), 'SYS_WKUP'+ str(x)])
|
syswkup_list.insert(i, ["NC", "NC_" + str(x), "SYS_WKUP" + str(x)])
|
||||||
i += 1
|
i += 1
|
||||||
# print pin name under switch
|
# print pin name under switch
|
||||||
for p in syswkup_list:
|
for p in syswkup_list:
|
||||||
num = p[2].replace("SYS_WKUP", "")
|
num = p[2].replace("SYS_WKUP", "")
|
||||||
if len(num) == 0:
|
if len(num) == 0:
|
||||||
s1 = '#ifdef PWR_WAKEUP_PIN1\n'
|
s1 = "#ifdef PWR_WAKEUP_PIN1\n"
|
||||||
s1 += ' SYS_WKUP1' #single SYS_WKUP for this product
|
s1 += " SYS_WKUP1" # single SYS_WKUP for this product
|
||||||
else:
|
else:
|
||||||
s1 = '#ifdef PWR_WAKEUP_PIN%i\n' % (int(num) + inc)
|
s1 = "#ifdef PWR_WAKEUP_PIN%i\n" % (int(num) + inc)
|
||||||
s1 += ' SYS_WKUP' + str(int(num) + inc)
|
s1 += " SYS_WKUP" + str(int(num) + inc)
|
||||||
s1 += ' = ' + p[0] + ','
|
s1 += " = " + p[0] + ","
|
||||||
if (inc == 1) and (p[0] != 'NC'):
|
if (inc == 1) and (p[0] != "NC"):
|
||||||
s1 += ' /* ' + p[2] + ' */'
|
s1 += " /* " + p[2] + " */"
|
||||||
s1 += '\n#endif\n'
|
s1 += "\n#endif\n"
|
||||||
out_h_file.write(s1)
|
out_h_file.write(s1)
|
||||||
|
|
||||||
tokenize = re.compile(r'(\d+)|(\D+)').findall
|
|
||||||
|
tokenize = re.compile(r"(\d+)|(\D+)").findall
|
||||||
|
|
||||||
|
|
||||||
def natural_sortkey(list_2_elem):
|
def natural_sortkey(list_2_elem):
|
||||||
return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[0]))
|
return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[0]))
|
||||||
|
|
||||||
|
|
||||||
def natural_sortkey2(list_2_elem):
|
def natural_sortkey2(list_2_elem):
|
||||||
return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[2]))
|
return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[2]))
|
||||||
|
|
||||||
|
|
||||||
def sort_my_lists():
|
def sort_my_lists():
|
||||||
adclist.sort(key=natural_sortkey)
|
adclist.sort(key=natural_sortkey)
|
||||||
daclist.sort(key=natural_sortkey)
|
daclist.sort(key=natural_sortkey)
|
||||||
|
|
@ -547,6 +668,7 @@ def sort_my_lists():
|
||||||
qspi_list.sort(key=natural_sortkey)
|
qspi_list.sort(key=natural_sortkey)
|
||||||
syswkup_list.sort(key=natural_sortkey2)
|
syswkup_list.sort(key=natural_sortkey2)
|
||||||
|
|
||||||
|
|
||||||
def clean_all_lists():
|
def clean_all_lists():
|
||||||
del io_list[:]
|
del io_list[:]
|
||||||
del adclist[:]
|
del adclist[:]
|
||||||
|
|
@ -568,31 +690,34 @@ def clean_all_lists():
|
||||||
del qspi_list[:]
|
del qspi_list[:]
|
||||||
del syswkup_list[:]
|
del syswkup_list[:]
|
||||||
|
|
||||||
|
|
||||||
def parse_pins():
|
def parse_pins():
|
||||||
print(" * Getting pins per Ips...")
|
print(" * Getting pins per Ips...")
|
||||||
pinregex=r'^(P[A-Z][0-9][0-5]?)'
|
pinregex = r"^(P[A-Z][0-9][0-5]?)"
|
||||||
itemlist = xml_mcu.getElementsByTagName('Pin')
|
itemlist = xml_mcu.getElementsByTagName("Pin")
|
||||||
for s in itemlist:
|
for s in itemlist:
|
||||||
m = re.match(pinregex, s.attributes['Name'].value)
|
m = re.match(pinregex, s.attributes["Name"].value)
|
||||||
if m:
|
if m:
|
||||||
pin = m.group(0)[:2] + '_' + m.group(0)[2:] # pin formatted P<port>_<number>: PF_O
|
pin = (
|
||||||
name = s.attributes['Name'].value.strip() # full name: "PF0 / OSC_IN"
|
m.group(0)[:2] + "_" + m.group(0)[2:]
|
||||||
if s.attributes['Type'].value == "I/O":
|
) # pin formatted P<port>_<number>: PF_O
|
||||||
|
name = s.attributes["Name"].value.strip() # full name: "PF0 / OSC_IN"
|
||||||
|
if s.attributes["Type"].value == "I/O":
|
||||||
store_pin(pin, name)
|
store_pin(pin, name)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
siglist = s.getElementsByTagName('Signal')
|
siglist = s.getElementsByTagName("Signal")
|
||||||
for a in siglist:
|
for a in siglist:
|
||||||
sig = a.attributes['Name'].value.strip()
|
sig = a.attributes["Name"].value.strip()
|
||||||
if "ADC" in sig:
|
if "ADC" in sig:
|
||||||
store_adc(pin, name, sig)
|
store_adc(pin, name, sig)
|
||||||
if all(["DAC" in sig, "_OUT" in sig]):
|
if all(["DAC" in sig, "_OUT" in sig]):
|
||||||
store_dac(pin, name, sig)
|
store_dac(pin, name, sig)
|
||||||
if "I2C" in sig:
|
if "I2C" in sig:
|
||||||
store_i2c(pin, name, sig)
|
store_i2c(pin, name, sig)
|
||||||
if re.match('^TIM', sig) is not None: #ignore HRTIM
|
if re.match("^TIM", sig) is not None: # ignore HRTIM
|
||||||
store_pwm(pin, name, sig)
|
store_pwm(pin, name, sig)
|
||||||
if re.match('^(LPU|US|U)ART', sig) is not None:
|
if re.match("^(LPU|US|U)ART", sig) is not None:
|
||||||
store_uart(pin, name, sig)
|
store_uart(pin, name, sig)
|
||||||
if "SPI" in sig:
|
if "SPI" in sig:
|
||||||
store_spi(pin, name, sig)
|
store_spi(pin, name, sig)
|
||||||
|
|
@ -604,29 +729,35 @@ def parse_pins():
|
||||||
store_qspi(pin, name, sig)
|
store_qspi(pin, name, sig)
|
||||||
if "SYS_" in sig:
|
if "SYS_" in sig:
|
||||||
store_sys(pin, name, sig)
|
store_sys(pin, name, sig)
|
||||||
|
|
||||||
|
|
||||||
# main
|
# main
|
||||||
cur_dir = os.getcwd()
|
cur_dir = os.getcwd()
|
||||||
out_c_filename = 'PeripheralPins.c'
|
out_c_filename = "PeripheralPins.c"
|
||||||
out_h_filename = 'PinNamesVar.h'
|
out_h_filename = "PinNamesVar.h"
|
||||||
config_filename = 'config.json'
|
config_filename = "config.json"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config_file = open(config_filename, "r")
|
config_file = open(config_filename, "r")
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Please set your configuration in '%s' file" % config_filename)
|
print("Please set your configuration in '%s' file" % config_filename)
|
||||||
config_file = open(config_filename, "w")
|
config_file = open(config_filename, "w")
|
||||||
if sys.platform.startswith('win32'):
|
if sys.platform.startswith("win32"):
|
||||||
print("Platform is Windows")
|
print("Platform is Windows")
|
||||||
cubemxdir = 'C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeMX\\db\\mcu'
|
cubemxdir = (
|
||||||
elif sys.platform.startswith('linux'):
|
"C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeMX\\db\\mcu"
|
||||||
|
)
|
||||||
|
elif sys.platform.startswith("linux"):
|
||||||
print("Platform is Linux")
|
print("Platform is Linux")
|
||||||
cubemxdir = os.getenv("HOME")+'/STM32CubeMX/db/mcu'
|
cubemxdir = os.getenv("HOME") + "/STM32CubeMX/db/mcu"
|
||||||
elif sys.platform.startswith('darwin'):
|
elif sys.platform.startswith("darwin"):
|
||||||
print("Platform is Mac OSX")
|
print("Platform is Mac OSX")
|
||||||
cubemxdir = '/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources/db/mcu'
|
cubemxdir = (
|
||||||
|
"/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources/db/mcu"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print("Platform unknown")
|
print("Platform unknown")
|
||||||
cubemxdir = '<Set CubeMX install directory>/db/mcu'
|
cubemxdir = "<Set CubeMX install directory>/db/mcu"
|
||||||
config_file.write(json.dumps({"CUBEMX_DIRECTORY": cubemxdir}))
|
config_file.write(json.dumps({"CUBEMX_DIRECTORY": cubemxdir}))
|
||||||
config_file.close()
|
config_file.close()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
@ -637,42 +768,66 @@ cubemxdir = config["CUBEMX_DIRECTORY"]
|
||||||
|
|
||||||
# by default, generate for all mcu xml files description
|
# by default, generate for all mcu xml files description
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description=textwrap.dedent('''\
|
description=textwrap.dedent(
|
||||||
|
"""\
|
||||||
By default, generate %s and %s for all xml files description available in
|
By default, generate %s and %s for all xml files description available in
|
||||||
STM32CubeMX directory defined in '%s':
|
STM32CubeMX directory defined in '%s':
|
||||||
\t%s''' % (out_c_filename, out_h_filename, config_filename, cubemxdir)),
|
\t%s"""
|
||||||
epilog=textwrap.dedent('''\
|
% (out_c_filename, out_h_filename, config_filename, cubemxdir)
|
||||||
|
),
|
||||||
|
epilog=textwrap.dedent(
|
||||||
|
"""\
|
||||||
After files generation, review them carefully and please report any issue to github:
|
After files generation, review them carefully and please report any issue to github:
|
||||||
\thttps://github.com/stm32duino/Arduino_Tools/issues\n
|
\thttps://github.com/stm32duino/Arduino_Tools/issues\n
|
||||||
Once generated, you have to comment a line if the pin is generated several times
|
Once generated, you have to comment a line if the pin is generated several times
|
||||||
for the same IP or if the pin should not be used (overlaid with some HW on the board,
|
for the same IP or if the pin should not be used (overlaid with some HW on the board,
|
||||||
for instance)'''),
|
for instance)"""
|
||||||
formatter_class=RawTextHelpFormatter)
|
),
|
||||||
|
formatter_class=RawTextHelpFormatter,
|
||||||
|
)
|
||||||
group = parser.add_mutually_exclusive_group()
|
group = parser.add_mutually_exclusive_group()
|
||||||
group.add_argument("-l", "--list", help="list available xml files description in STM32CubeMX", action="store_true")
|
group.add_argument(
|
||||||
group.add_argument("-m", "--mcu", metavar='xml', help=textwrap.dedent('''\
|
"-l",
|
||||||
|
"--list",
|
||||||
|
help="list available xml files description in STM32CubeMX",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"-m",
|
||||||
|
"--mcu",
|
||||||
|
metavar="xml",
|
||||||
|
help=textwrap.dedent(
|
||||||
|
"""\
|
||||||
Generate %s and %s for specified mcu xml file description
|
Generate %s and %s for specified mcu xml file description
|
||||||
in STM32CubeMX. This xml file contains non alpha characters in
|
in STM32CubeMX. This xml file contains non alpha characters in
|
||||||
its name, you should call it with double quotes''' % (out_c_filename, out_h_filename)))
|
its name, you should call it with double quotes"""
|
||||||
|
% (out_c_filename, out_h_filename)
|
||||||
|
),
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not (os.path.isdir(cubemxdir)):
|
if not (os.path.isdir(cubemxdir)):
|
||||||
print("\n ! ! ! Cube Mx seems not to be installed or not at the requested location")
|
print("\n ! ! ! Cube Mx seems not to be installed or not at the requested location")
|
||||||
print ("\n ! ! ! please check the value you set for 'CUBEMX_DIRECTORY' in '%s' file" % config_filename)
|
print(
|
||||||
|
"\n ! ! ! please check the value you set for 'CUBEMX_DIRECTORY' in '%s' file"
|
||||||
|
% config_filename
|
||||||
|
)
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
cubemxdirIP = os.path.join(cubemxdir, 'IP')
|
cubemxdirIP = os.path.join(cubemxdir, "IP")
|
||||||
|
|
||||||
if args.mcu:
|
if args.mcu:
|
||||||
# check input file exists
|
# check input file exists
|
||||||
if not (os.path.isfile(os.path.join(cubemxdir, args.mcu))):
|
if not (os.path.isfile(os.path.join(cubemxdir, args.mcu))):
|
||||||
print("\n ! ! ! " + args.mcu + " file not found")
|
print("\n ! ! ! " + args.mcu + " file not found")
|
||||||
print("\n ! ! ! Check in " + cubemxdir + " the correct name of this file")
|
print("\n ! ! ! Check in " + cubemxdir + " the correct name of this file")
|
||||||
print ("\n ! ! ! You may use double quotes for this file if it contains special characters")
|
print(
|
||||||
|
"\n ! ! ! You may use double quotes for this file if it contains special characters"
|
||||||
|
)
|
||||||
quit()
|
quit()
|
||||||
mcu_list.append(args.mcu)
|
mcu_list.append(args.mcu)
|
||||||
else:
|
else:
|
||||||
mcu_list=fnmatch.filter(os.listdir(cubemxdir), 'STM32*.xml')
|
mcu_list = fnmatch.filter(os.listdir(cubemxdir), "STM32*.xml")
|
||||||
|
|
||||||
if args.list:
|
if args.list:
|
||||||
print("Available xml files description: %i" % len(mcu_list))
|
print("Available xml files description: %i" % len(mcu_list))
|
||||||
|
|
@ -681,38 +836,40 @@ if args.list:
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
for mcu_file in mcu_list:
|
for mcu_file in mcu_list:
|
||||||
print("Generating %s and %s for '%s'..." % (out_c_filename, out_h_filename, mcu_file))
|
print(
|
||||||
|
"Generating %s and %s for '%s'..." % (out_c_filename, out_h_filename, mcu_file)
|
||||||
|
)
|
||||||
input_file_name = os.path.join(cubemxdir, mcu_file)
|
input_file_name = os.path.join(cubemxdir, mcu_file)
|
||||||
out_path = os.path.join(cur_dir, 'Arduino', os.path.splitext(mcu_file)[0])
|
out_path = os.path.join(cur_dir, "Arduino", os.path.splitext(mcu_file)[0])
|
||||||
output_c_filename = os.path.join(out_path, out_c_filename)
|
output_c_filename = os.path.join(out_path, out_c_filename)
|
||||||
output_h_filename = os.path.join(out_path, out_h_filename)
|
output_h_filename = os.path.join(out_path, out_h_filename)
|
||||||
if not (os.path.isdir(out_path)):
|
if not (os.path.isdir(out_path)):
|
||||||
os.makedirs(out_path)
|
os.makedirs(out_path)
|
||||||
|
|
||||||
# open output file
|
# open output file
|
||||||
if (os.path.isfile(output_c_filename)):
|
if os.path.isfile(output_c_filename):
|
||||||
# print (" * Requested %s file already exists and will be overwritten" % out_c_filename)
|
# print (" * Requested %s file already exists and will be overwritten" % out_c_filename)
|
||||||
os.remove(output_c_filename)
|
os.remove(output_c_filename)
|
||||||
out_c_file = open(output_c_filename, 'w')
|
out_c_file = open(output_c_filename, "w")
|
||||||
if (os.path.isfile(output_h_filename)):
|
if os.path.isfile(output_h_filename):
|
||||||
# print (" * Requested %s file already exists and will be overwritten" % out_h_filename)
|
# print (" * Requested %s file already exists and will be overwritten" % out_h_filename)
|
||||||
os.remove(output_h_filename)
|
os.remove(output_h_filename)
|
||||||
out_h_file = open(output_h_filename, 'w')
|
out_h_file = open(output_h_filename, "w")
|
||||||
|
|
||||||
# open input file
|
# open input file
|
||||||
xml_mcu = parse(input_file_name)
|
xml_mcu = parse(input_file_name)
|
||||||
gpiofile = find_gpio_file()
|
gpiofile = find_gpio_file()
|
||||||
if gpiofile == 'ERROR':
|
if gpiofile == "ERROR":
|
||||||
print("Could not find GPIO file")
|
print("Could not find GPIO file")
|
||||||
quit()
|
quit()
|
||||||
xml_gpio = parse(os.path.join(cubemxdirIP, 'GPIO-' + gpiofile + '_Modes.xml'))
|
xml_gpio = parse(os.path.join(cubemxdirIP, "GPIO-" + gpiofile + "_Modes.xml"))
|
||||||
|
|
||||||
parse_pins()
|
parse_pins()
|
||||||
sort_my_lists()
|
sort_my_lists()
|
||||||
print_header()
|
print_header()
|
||||||
print_all_lists()
|
print_all_lists()
|
||||||
|
|
||||||
nb_pin = (len(io_list))
|
nb_pin = len(io_list)
|
||||||
print(" * I/O pins found: %i" % nb_pin)
|
print(" * I/O pins found: %i" % nb_pin)
|
||||||
print("done\n")
|
print("done\n")
|
||||||
clean_all_lists()
|
clean_all_lists()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue