Skip to content

Commit

Permalink
[genpinmap] Fix issue when first list is empty
Browse files Browse the repository at this point in the history
Issue added with new xSPI arrays.
For example STM32G491K(C-E)Ux.xml doesn't have DATA0 pins.
Update also the USB print if list is empty.

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Oct 27, 2020
1 parent 5271bdf commit 17f35a8
Showing 1 changed file with 72 additions and 71 deletions.
143 changes: 72 additions & 71 deletions src/genpinmap/genpinmap_arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,33 +638,34 @@ def print_eth():


def print_qspi(lst):
prev_s = ""
wpin = width_format(lst)
if "OCTOSPIM_P1" in lst[0][2]:
winst = 7
else:
winst = 6
for p in lst:
result = get_gpio_af_num(p[1], p[2])
s1 = start_elem_format.format(p[0] + ",", width=wpin)
# 2nd element is the XXXXSPI_YYYY signal
if "OCTOSPIM_P1" in p[2]:
s1 += "OCTOSPI1,"
elif "OCTOSPIM_P2" in p[2]:
s1 += "OCTOSPI2,"
else:
s1 += "QUADSPI,"
s1 += " STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
# check duplicated lines, only signal differs
if prev_s == s1:
s1 = "|" + p[2]
if lst:
prev_s = ""
wpin = width_format(lst)
if "OCTOSPIM_P1" in lst[0][2]:
winst = 7
else:
if len(prev_s) > 0:
out_c_file.write("\n")
prev_s = s1
s1 += " // " + p[2]
out_c_file.write(s1 + "\n")
out_c_file.write(end_array_format.format("", w1=wpin - 3, w2=winst))
winst = 6
for p in lst:
result = get_gpio_af_num(p[1], p[2])
s1 = start_elem_format.format(p[0] + ",", width=wpin)
# 2nd element is the XXXXSPI_YYYY signal
if "OCTOSPIM_P1" in p[2]:
s1 += "OCTOSPI1,"
elif "OCTOSPIM_P2" in p[2]:
s1 += "OCTOSPI2,"
else:
s1 += "QUADSPI,"
s1 += " STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
# check duplicated lines, only signal differs
if prev_s == s1:
s1 = "|" + p[2]
else:
if len(prev_s) > 0:
out_c_file.write("\n")
prev_s = s1
s1 += " // " + p[2]
out_c_file.write(s1 + "\n")
out_c_file.write(end_array_format.format("", w1=wpin - 3, w2=winst))


def print_sd():
Expand All @@ -686,54 +687,54 @@ def print_sd():


def print_usb(lst):
use_hs_in_fs = False
nb_loop = 1
inst = "USB"
if lst == usb_otgfs_list:
inst = "USB_OTG_FS"
elif lst == usb_otghs_list:
inst = "USB_OTG_HS"
nb_loop = 2
wpin = width_format(lst)
winst = len(inst) - 1
for nb in range(nb_loop):
for p in lst:
result = get_gpio_af_num(p[1], p[2])
s1 = start_elem_format.format(p[0] + ",", width=wpin)
if lst == usb_otghs_list:
if nb == 0:
if "ULPI" in p[2]:
continue
elif not use_hs_in_fs:
out_c_file.write("#ifdef USE_USB_HS_IN_FS\n")
use_hs_in_fs = True
if lst:
use_hs_in_fs = False
nb_loop = 1
inst = "USB"
if lst == usb_otgfs_list:
inst = "USB_OTG_FS"
elif lst == usb_otghs_list:
inst = "USB_OTG_HS"
nb_loop = 2
wpin = width_format(lst)
winst = len(inst) - 1
for nb in range(nb_loop):
for p in lst:
result = get_gpio_af_num(p[1], p[2])
s1 = start_elem_format.format(p[0] + ",", width=wpin)
if lst == usb_otghs_list:
if nb == 0:
if "ULPI" in p[2]:
continue
elif not use_hs_in_fs:
out_c_file.write("#ifdef USE_USB_HS_IN_FS\n")
use_hs_in_fs = True
else:
if "ULPI" not in p[2]:
continue
elif use_hs_in_fs:
out_c_file.write("#else\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:
if "ULPI" not in p[2]:
continue
elif use_hs_in_fs:
out_c_file.write("#else\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, "
# USB_DM/DP and VBUS: INPUT + NOPULL
s1 += inst + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
if result == "NOTFOUND":
s1 += "0)},"
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)
r = result.split(" ")
for af in r:
s1 += af + ")},"
s1 += " // " + p[2] + "\n"
out_c_file.write(s1)

if lst:
if lst == usb_otghs_list:
out_c_file.write("#endif /* USE_USB_HS_IN_FS */\n")
out_c_file.write(end_array_format.format("", w1=wpin - 3, w2=winst))
Expand Down

0 comments on commit 17f35a8

Please sign in to comment.