Skip to content

Commit 19b22ee

Browse files
committed
[genpinmap] Update IP parsing to get some specific instance name
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 791163d commit 19b22ee

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

src/genpinmap/genpinmap_arduino.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
usb_otghs_list = [] # 'PIN','name','USB'
4444
sd_list = [] # 'PIN','name','SD'
4545

46+
# IP information
47+
gpiofile = ""
48+
tim_inst_list = [] # TIMx instance
49+
usb_inst = {"usb": "", "otg_fs": "", "otg_hs": ""}
50+
4651
# format
4752
# Peripheral
4853
start_elem_fmt = " {{{:{width}}"
@@ -52,15 +57,36 @@
5257
"""
5358

5459

55-
# GPIO file parsing
56-
def find_gpio_file():
57-
res = "ERROR"
60+
# mcu file parsing
61+
def parse_IP_file():
62+
global gpiofile
63+
tim_regex = r"^(TIM\d+)$"
64+
usb_regex = r"^(USB(?!PD|_HOST|_DEVICE).*)$"
65+
gpiofile = ""
66+
del tim_inst_list[:]
67+
usb_inst["usb"] = ""
68+
usb_inst["otg_fs"] = ""
69+
usb_inst["otg_hs"] = ""
70+
5871
itemlist = xml_mcu.getElementsByTagName("IP")
5972
for s in itemlist:
60-
if "GPIO" in s.attributes["Name"].value:
61-
res = s.attributes["Version"].value
62-
break
63-
return res
73+
inst = re.match(tim_regex, s.attributes["InstanceName"].value)
74+
if inst:
75+
# Collect all TIMx instance
76+
tim_inst_list.append(inst.group(1))
77+
else:
78+
inst = re.match(usb_regex, s.attributes["InstanceName"].value)
79+
if inst:
80+
if "OTG" in inst.group(1):
81+
if "FS" in inst.group(1):
82+
usb_inst["otg_fs"] = inst.group(1)
83+
else:
84+
usb_inst["otg_hs"] = inst.group(1)
85+
else:
86+
usb_inst["usb"] = inst.group(1)
87+
else:
88+
if gpiofile == "" and "GPIO" in s.attributes["Name"].value:
89+
gpiofile = s.attributes["Version"].value
6490

6591

6692
def get_gpio_af_num(pintofind, iptofind):
@@ -671,12 +697,12 @@ def usb_pinmap(lst):
671697
nb_loop = 1
672698

673699
if lst == usb_otgfs_list:
674-
inst = "USB_OTG_FS"
700+
inst = usb_inst["otg_fs"]
675701
elif lst == usb_otghs_list:
676-
inst = "USB_OTG_HS"
702+
inst = usb_inst["otg_hs"]
677703
nb_loop = 2
678704
else:
679-
inst = "USB"
705+
inst = usb_inst["usb"]
680706
for nb in range(nb_loop):
681707
for p in lst:
682708
hsinfs = 0
@@ -1042,15 +1068,8 @@ def timer_variant():
10421068
"TIM8",
10431069
"TIM20",
10441070
]
1045-
tim_inst_list = []
1046-
tim_regex = r"^(TIM\d+)$"
1071+
10471072
tone = servo = "TIMx"
1048-
itemlist = xml_mcu.getElementsByTagName("IP")
1049-
# Collect all TIMx instance
1050-
for s in itemlist:
1051-
inst = re.match(tim_regex, s.attributes["InstanceName"].value)
1052-
if inst:
1053-
tim_inst_list.append(inst.group(1))
10541073
if tim_inst_list:
10551074
for pref in tim_inst_order:
10561075
if pref in tim_inst_list:
@@ -1648,8 +1667,8 @@ def manage_repo():
16481667

16491668
# open input file
16501669
xml_mcu = parse(str(mcu_file))
1651-
gpiofile = find_gpio_file()
1652-
if gpiofile == "ERROR":
1670+
parse_IP_file()
1671+
if not gpiofile:
16531672
print("Could not find GPIO file")
16541673
quit()
16551674
xml_gpio = parse(str(dirIP / ("GPIO-" + gpiofile + "_Modes.xml")))

0 commit comments

Comments
 (0)