Skip to content

Commit c4bd732

Browse files
committed
[genpinmap] Fix issue when first list is empty
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]>
1 parent 932d8bf commit c4bd732

File tree

1 file changed

+72
-71
lines changed

1 file changed

+72
-71
lines changed

Diff for: src/genpinmap/genpinmap_arduino.py

+72-71
Original file line numberDiff line numberDiff line change
@@ -639,33 +639,34 @@ def print_eth():
639639

640640

641641
def print_qspi(lst):
642-
prev_s = ""
643-
wpin = width_format(lst)
644-
if "OCTOSPIM_P1" in lst[0][2]:
645-
winst = 7
646-
else:
647-
winst = 6
648-
for p in lst:
649-
result = get_gpio_af_num(p[1], p[2])
650-
s1 = start_elem_format.format(p[0] + ",", width=wpin)
651-
# 2nd element is the XXXXSPI_YYYY signal
652-
if "OCTOSPIM_P1" in p[2]:
653-
s1 += "OCTOSPI1,"
654-
elif "OCTOSPIM_P2" in p[2]:
655-
s1 += "OCTOSPI2,"
656-
else:
657-
s1 += "QUADSPI,"
658-
s1 += " STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
659-
# check duplicated lines, only signal differs
660-
if prev_s == s1:
661-
s1 = "|" + p[2]
642+
if lst:
643+
prev_s = ""
644+
wpin = width_format(lst)
645+
if "OCTOSPIM_P1" in lst[0][2]:
646+
winst = 7
662647
else:
663-
if len(prev_s) > 0:
664-
out_c_file.write("\n")
665-
prev_s = s1
666-
s1 += " // " + p[2]
667-
out_c_file.write(s1 + "\n")
668-
out_c_file.write(end_array_format.format("", w1=wpin - 3, w2=winst))
648+
winst = 6
649+
for p in lst:
650+
result = get_gpio_af_num(p[1], p[2])
651+
s1 = start_elem_format.format(p[0] + ",", width=wpin)
652+
# 2nd element is the XXXXSPI_YYYY signal
653+
if "OCTOSPIM_P1" in p[2]:
654+
s1 += "OCTOSPI1,"
655+
elif "OCTOSPIM_P2" in p[2]:
656+
s1 += "OCTOSPI2,"
657+
else:
658+
s1 += "QUADSPI,"
659+
s1 += " STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
660+
# check duplicated lines, only signal differs
661+
if prev_s == s1:
662+
s1 = "|" + p[2]
663+
else:
664+
if len(prev_s) > 0:
665+
out_c_file.write("\n")
666+
prev_s = s1
667+
s1 += " // " + p[2]
668+
out_c_file.write(s1 + "\n")
669+
out_c_file.write(end_array_format.format("", w1=wpin - 3, w2=winst))
669670

670671

671672
def print_sd():
@@ -687,54 +688,54 @@ def print_sd():
687688

688689

689690
def print_usb(lst):
690-
use_hs_in_fs = False
691-
nb_loop = 1
692-
inst = "USB"
693-
if lst == usb_otgfs_list:
694-
inst = "USB_OTG_FS"
695-
elif lst == usb_otghs_list:
696-
inst = "USB_OTG_HS"
697-
nb_loop = 2
698-
wpin = width_format(lst)
699-
winst = len(inst) - 1
700-
for nb in range(nb_loop):
701-
for p in lst:
702-
result = get_gpio_af_num(p[1], p[2])
703-
s1 = start_elem_format.format(p[0] + ",", width=wpin)
704-
if lst == usb_otghs_list:
705-
if nb == 0:
706-
if "ULPI" in p[2]:
707-
continue
708-
elif not use_hs_in_fs:
709-
out_c_file.write("#ifdef USE_USB_HS_IN_FS\n")
710-
use_hs_in_fs = True
691+
if lst:
692+
use_hs_in_fs = False
693+
nb_loop = 1
694+
inst = "USB"
695+
if lst == usb_otgfs_list:
696+
inst = "USB_OTG_FS"
697+
elif lst == usb_otghs_list:
698+
inst = "USB_OTG_HS"
699+
nb_loop = 2
700+
wpin = width_format(lst)
701+
winst = len(inst) - 1
702+
for nb in range(nb_loop):
703+
for p in lst:
704+
result = get_gpio_af_num(p[1], p[2])
705+
s1 = start_elem_format.format(p[0] + ",", width=wpin)
706+
if lst == usb_otghs_list:
707+
if nb == 0:
708+
if "ULPI" in p[2]:
709+
continue
710+
elif not use_hs_in_fs:
711+
out_c_file.write("#ifdef USE_USB_HS_IN_FS\n")
712+
use_hs_in_fs = True
713+
else:
714+
if "ULPI" not in p[2]:
715+
continue
716+
elif use_hs_in_fs:
717+
out_c_file.write("#else\n")
718+
use_hs_in_fs = False
719+
720+
# 2nd element is the USB_XXXX signal
721+
if not p[2].startswith("USB_D") and "VBUS" not in p[2]:
722+
if "ID" not in p[2]:
723+
s1 += inst + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
724+
else:
725+
# ID pin: AF_PP + PULLUP
726+
s1 += inst + ", STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, "
711727
else:
712-
if "ULPI" not in p[2]:
713-
continue
714-
elif use_hs_in_fs:
715-
out_c_file.write("#else\n")
716-
use_hs_in_fs = False
717-
718-
# 2nd element is the USB_XXXX signal
719-
if not p[2].startswith("USB_D") and "VBUS" not in p[2]:
720-
if "ID" not in p[2]:
721-
s1 += inst + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
728+
# USB_DM/DP and VBUS: INPUT + NOPULL
729+
s1 += inst + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
730+
if result == "NOTFOUND":
731+
s1 += "0)},"
722732
else:
723-
# ID pin: AF_PP + PULLUP
724-
s1 += inst + ", STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, "
725-
else:
726-
# USB_DM/DP and VBUS: INPUT + NOPULL
727-
s1 += inst + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
728-
if result == "NOTFOUND":
729-
s1 += "0)},"
730-
else:
731-
r = result.split(" ")
732-
for af in r:
733-
s1 += af + ")},"
734-
s1 += " // " + p[2] + "\n"
735-
out_c_file.write(s1)
733+
r = result.split(" ")
734+
for af in r:
735+
s1 += af + ")},"
736+
s1 += " // " + p[2] + "\n"
737+
out_c_file.write(s1)
736738

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

0 commit comments

Comments
 (0)