[genpinmap] Add USB feature
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
This commit is contained in:
parent
d257c1c0ed
commit
4a869802e5
1 changed files with 148 additions and 58 deletions
|
|
@ -30,6 +30,9 @@ canrd_list = [] # 'PIN','name','CANRD'
|
||||||
eth_list = [] # 'PIN','name','ETH'
|
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'
|
||||||
|
usb_list = [] # 'PIN','name','USB'
|
||||||
|
usb_otgfs_list = [] # 'PIN','name','USB'
|
||||||
|
usb_otghs_list = [] # 'PIN','name','USB'
|
||||||
|
|
||||||
|
|
||||||
def find_gpio_file():
|
def find_gpio_file():
|
||||||
|
|
@ -239,6 +242,16 @@ def store_sys(pin, name, signal):
|
||||||
syswkup_list.append([pin, name, signal])
|
syswkup_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
|
# function to store USB pins
|
||||||
|
def store_usb(pin, name, signal):
|
||||||
|
if "OTG" not in signal:
|
||||||
|
usb_list.append([pin, name, signal])
|
||||||
|
if signal.startswith("USB_OTG_FS"):
|
||||||
|
usb_otgfs_list.append([pin, name, signal])
|
||||||
|
if signal.startswith("USB_OTG_HS"):
|
||||||
|
usb_otghs_list.append([pin, name, signal])
|
||||||
|
|
||||||
|
|
||||||
def print_header():
|
def print_header():
|
||||||
s = """/*
|
s = """/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
|
|
@ -287,57 +300,80 @@ def print_header():
|
||||||
|
|
||||||
|
|
||||||
def print_all_lists():
|
def print_all_lists():
|
||||||
if print_list_header("ADC", "ADC", adclist, "ADC"):
|
if print_list_header("ADC", "ADC", "ADC", adclist):
|
||||||
print_adc()
|
print_adc()
|
||||||
if print_list_header("DAC", "DAC", daclist, "DAC"):
|
if print_list_header("DAC", "DAC", "DAC", daclist):
|
||||||
print_dac()
|
print_dac()
|
||||||
if print_list_header("I2C", "I2C_SDA", i2csda_list, "I2C"):
|
if print_list_header("I2C", "I2C_SDA", "I2C", i2csda_list, i2cscl_list):
|
||||||
print_i2c(i2csda_list)
|
print_i2c(i2csda_list)
|
||||||
if print_list_header("", "I2C_SCL", i2cscl_list, "I2C"):
|
if print_list_header("", "I2C_SCL", "I2C", i2cscl_list):
|
||||||
print_i2c(i2cscl_list)
|
print_i2c(i2cscl_list)
|
||||||
if print_list_header("PWM", "PWM", pwm_list, "TIM"):
|
if print_list_header("PWM", "PWM", "TIM", pwm_list):
|
||||||
print_pwm()
|
print_pwm()
|
||||||
if print_list_header("SERIAL", "UART_TX", uarttx_list, "UART"):
|
if print_list_header(
|
||||||
|
"SERIAL",
|
||||||
|
"UART_TX",
|
||||||
|
"UART",
|
||||||
|
uarttx_list,
|
||||||
|
uartrx_list,
|
||||||
|
uartrts_list,
|
||||||
|
uartcts_list,
|
||||||
|
):
|
||||||
print_uart(uarttx_list)
|
print_uart(uarttx_list)
|
||||||
if print_list_header("", "UART_RX", uartrx_list, "UART"):
|
if print_list_header("", "UART_RX", "UART", uartrx_list):
|
||||||
print_uart(uartrx_list)
|
print_uart(uartrx_list)
|
||||||
if print_list_header("", "UART_RTS", uartrts_list, "UART"):
|
if print_list_header("", "UART_RTS", "UART", uartrts_list):
|
||||||
print_uart(uartrts_list)
|
print_uart(uartrts_list)
|
||||||
if print_list_header("", "UART_CTS", uartcts_list, "UART"):
|
if print_list_header("", "UART_CTS", "UART", uartcts_list):
|
||||||
print_uart(uartcts_list)
|
print_uart(uartcts_list)
|
||||||
if print_list_header("SPI", "SPI_MOSI", spimosi_list, "SPI"):
|
if print_list_header(
|
||||||
|
"SPI", "SPI_MOSI", "SPI", spimosi_list, spimiso_list, spisclk_list, spissel_list
|
||||||
|
):
|
||||||
print_spi(spimosi_list)
|
print_spi(spimosi_list)
|
||||||
if print_list_header("", "SPI_MISO", spimiso_list, "SPI"):
|
if print_list_header("", "SPI_MISO", "SPI", spimiso_list):
|
||||||
print_spi(spimiso_list)
|
print_spi(spimiso_list)
|
||||||
if print_list_header("", "SPI_SCLK", spisclk_list, "SPI"):
|
if print_list_header("", "SPI_SCLK", "SPI", spisclk_list):
|
||||||
print_spi(spisclk_list)
|
print_spi(spisclk_list)
|
||||||
if print_list_header("", "SPI_SSEL", spissel_list, "SPI"):
|
if print_list_header("", "SPI_SSEL", "SPI", spissel_list):
|
||||||
print_spi(spissel_list)
|
print_spi(spissel_list)
|
||||||
if print_list_header("CAN", "CAN_RD", canrd_list, "CAN"):
|
if print_list_header("CAN", "CAN_RD", "CAN", canrd_list, cantd_list):
|
||||||
print_can(canrd_list)
|
print_can(canrd_list)
|
||||||
if print_list_header("", "CAN_TD", cantd_list, "CAN"):
|
if print_list_header("", "CAN_TD", "CAN", cantd_list):
|
||||||
print_can(cantd_list)
|
print_can(cantd_list)
|
||||||
if print_list_header("ETHERNET", "Ethernet", eth_list, "ETH"):
|
if print_list_header("ETHERNET", "Ethernet", "ETH", eth_list):
|
||||||
print_eth()
|
print_eth()
|
||||||
if print_list_header("QUADSPI", "QUADSPI", qspi_list, "QSPI"):
|
if print_list_header("QUADSPI", "QUADSPI", "QSPI", qspi_list):
|
||||||
print_qspi()
|
print_qspi()
|
||||||
# Print specific PinNames
|
if print_list_header("USB", "USB", "PCD", usb_list, usb_otgfs_list, usb_otghs_list):
|
||||||
print_syswkup()
|
print_usb(usb_list)
|
||||||
|
if print_list_header("", "USB_OTG_FS", "PCD", usb_otgfs_list):
|
||||||
|
print_usb(usb_otgfs_list)
|
||||||
|
if print_list_header("", "USB_OTG_HS", "PCD", usb_otghs_list):
|
||||||
|
print_usb(usb_otghs_list)
|
||||||
|
# Print specific PinNames in header file
|
||||||
|
print_syswkup_h()
|
||||||
|
print_usb_h()
|
||||||
|
|
||||||
|
|
||||||
def print_list_header(comment, name, l, switch):
|
def print_list_header(feature, lname, switch, *argslst):
|
||||||
if len(l) > 0:
|
lenlst = 0
|
||||||
if comment:
|
for lst in argslst:
|
||||||
|
lenlst += len(lst)
|
||||||
|
if lenlst > 0:
|
||||||
|
# There is data for the feature
|
||||||
|
if feature:
|
||||||
s = (
|
s = (
|
||||||
(
|
(
|
||||||
"""
|
"""
|
||||||
//*** %s ***
|
//*** %s ***
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
% comment
|
% feature
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
s = ""
|
s = ""
|
||||||
|
# Only for the first list
|
||||||
|
if argslst[0]:
|
||||||
s += (
|
s += (
|
||||||
(
|
(
|
||||||
"""
|
"""
|
||||||
|
|
@ -345,30 +381,21 @@ def print_list_header(comment, name, l, switch):
|
||||||
const PinMap PinMap_%s[] = {
|
const PinMap PinMap_%s[] = {
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
% (switch, name)
|
% (switch, lname)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if comment:
|
# No data for the feature or the list
|
||||||
s = (
|
s = (
|
||||||
(
|
(
|
||||||
"""
|
"""
|
||||||
//*** %s ***
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
% comment
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
s = ""
|
|
||||||
s += (
|
|
||||||
(
|
|
||||||
"""
|
|
||||||
//*** No %s ***
|
//*** No %s ***
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
% name
|
% (feature if feature else lname)
|
||||||
)
|
)
|
||||||
|
|
||||||
out_c_file.write(s)
|
out_c_file.write(s)
|
||||||
return len(l)
|
return lenlst
|
||||||
|
|
||||||
|
|
||||||
def print_adc():
|
def print_adc():
|
||||||
|
|
@ -605,7 +632,7 @@ def print_qspi():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def print_syswkup():
|
def print_syswkup_h():
|
||||||
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", "")
|
||||||
|
|
@ -640,6 +667,63 @@ def print_syswkup():
|
||||||
out_h_file.write(s1)
|
out_h_file.write(s1)
|
||||||
|
|
||||||
|
|
||||||
|
def print_usb(lst):
|
||||||
|
use_hs_in_fs = False
|
||||||
|
inst = "USB"
|
||||||
|
if lst == usb_otgfs_list:
|
||||||
|
inst = "USB_OTG_FS"
|
||||||
|
elif lst == usb_otghs_list:
|
||||||
|
inst = "USB_OTG_HS"
|
||||||
|
|
||||||
|
for p in lst:
|
||||||
|
result = get_gpio_af_num(p[1], p[2])
|
||||||
|
s1 = "%-10s" % (" {" + p[0] + ",")
|
||||||
|
if lst == usb_otghs_list:
|
||||||
|
if "ULPI" not in p[2] and not use_hs_in_fs:
|
||||||
|
out_c_file.write("#ifdef USE_USB_HS_IN_FS\n")
|
||||||
|
use_hs_in_fs = True
|
||||||
|
if "ULPI" in p[2] and use_hs_in_fs:
|
||||||
|
out_c_file.write("#endif /* USE_USB_HS_IN_FS */\n")
|
||||||
|
use_hs_in_fs = False
|
||||||
|
|
||||||
|
# 2nd element is the USB_XXXX signal
|
||||||
|
if not p[2].startswith("USB_D") and "VBUS" not in p[2]:
|
||||||
|
if "ID" not in p[2]:
|
||||||
|
s1 += inst + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
|
||||||
|
else:
|
||||||
|
# ID pin: AF_PP + PULLUP
|
||||||
|
s1 += inst + ", STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, "
|
||||||
|
else:
|
||||||
|
# USB_DM/DP and VBUS: INPUT + NOPULL
|
||||||
|
s1 += inst + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
|
||||||
|
if result == "NOTFOUND":
|
||||||
|
s1 += "0)},"
|
||||||
|
else:
|
||||||
|
r = result.split(" ")
|
||||||
|
for af in r:
|
||||||
|
s1 += af + ")},"
|
||||||
|
s1 += " // " + p[2] + "\n"
|
||||||
|
out_c_file.write(s1)
|
||||||
|
if lst:
|
||||||
|
if use_hs_in_fs:
|
||||||
|
out_c_file.write("#endif /* USE_USB_HS_IN_FS */\n")
|
||||||
|
out_c_file.write(
|
||||||
|
""" {NC, NP, 0}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def print_usb_h():
|
||||||
|
if usb_list or usb_otgfs_list or usb_otghs_list:
|
||||||
|
out_h_file.write(" /* USB */\n")
|
||||||
|
out_h_file.write("#ifdef USBCON\n")
|
||||||
|
for p in usb_list + usb_otgfs_list + usb_otghs_list:
|
||||||
|
out_h_file.write(" " + p[2] + " = " + p[0] + ",\n")
|
||||||
|
out_h_file.write("#endif\n")
|
||||||
|
|
||||||
|
|
||||||
tokenize = re.compile(r"(\d+)|(\D+)").findall
|
tokenize = re.compile(r"(\d+)|(\D+)").findall
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -671,6 +755,9 @@ def sort_my_lists():
|
||||||
eth_list.sort(key=natural_sortkey)
|
eth_list.sort(key=natural_sortkey)
|
||||||
qspi_list.sort(key=natural_sortkey)
|
qspi_list.sort(key=natural_sortkey)
|
||||||
syswkup_list.sort(key=natural_sortkey2)
|
syswkup_list.sort(key=natural_sortkey2)
|
||||||
|
usb_list.sort(key=natural_sortkey)
|
||||||
|
usb_otgfs_list.sort(key=natural_sortkey)
|
||||||
|
usb_otghs_list.sort(key=natural_sortkey)
|
||||||
|
|
||||||
|
|
||||||
def clean_all_lists():
|
def clean_all_lists():
|
||||||
|
|
@ -693,6 +780,9 @@ def clean_all_lists():
|
||||||
del eth_list[:]
|
del eth_list[:]
|
||||||
del qspi_list[:]
|
del qspi_list[:]
|
||||||
del syswkup_list[:]
|
del syswkup_list[:]
|
||||||
|
del usb_list[:]
|
||||||
|
del usb_otgfs_list[:]
|
||||||
|
del usb_otghs_list[:]
|
||||||
|
|
||||||
|
|
||||||
def parse_pins():
|
def parse_pins():
|
||||||
|
|
@ -733,6 +823,8 @@ 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)
|
||||||
|
if "USB" in sig:
|
||||||
|
store_usb(pin, name, sig)
|
||||||
|
|
||||||
|
|
||||||
# main
|
# main
|
||||||
|
|
@ -825,9 +917,7 @@ if args.mcu:
|
||||||
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("\nCheck in " + cubemxdir + " the correct name of this file")
|
print("\nCheck in " + cubemxdir + " the correct name of this file")
|
||||||
print(
|
print("\nYou may use double quotes for file containing special characters")
|
||||||
"\nYou may use double quotes for file containing special characters"
|
|
||||||
)
|
|
||||||
quit()
|
quit()
|
||||||
mcu_list.append(args.mcu)
|
mcu_list.append(args.mcu)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue