Skip to content

Commit 3f21681

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

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):
@@ -675,12 +701,12 @@ def usb_pinmap(lst):
675701
nb_loop = 1
676702

677703
if lst == usb_otgfs_list:
678-
inst = "USB_OTG_FS"
704+
inst = usb_inst["otg_fs"]
679705
elif lst == usb_otghs_list:
680-
inst = "USB_OTG_HS"
706+
inst = usb_inst["otg_hs"]
681707
nb_loop = 2
682708
else:
683-
inst = "USB"
709+
inst = usb_inst["usb"]
684710
for nb in range(nb_loop):
685711
for p in lst:
686712
hsinfs = 0
@@ -1048,15 +1074,8 @@ def timer_variant():
10481074
"TIM8",
10491075
"TIM20",
10501076
]
1051-
tim_inst_list = []
1052-
tim_regex = r"^(TIM\d+)$"
1077+
10531078
tone = servo = "TIMx"
1054-
itemlist = xml_mcu.getElementsByTagName("IP")
1055-
# Collect all TIMx instance
1056-
for s in itemlist:
1057-
inst = re.match(tim_regex, s.attributes["InstanceName"].value)
1058-
if inst:
1059-
tim_inst_list.append(inst.group(1))
10601079
if tim_inst_list:
10611080
for pref in tim_inst_order:
10621081
if pref in tim_inst_list:
@@ -1676,8 +1695,8 @@ def manage_repo():
16761695

16771696
# open input file
16781697
xml_mcu = parse(str(mcu_file))
1679-
gpiofile = find_gpio_file()
1680-
if gpiofile == "ERROR":
1698+
parse_IP_file()
1699+
if not gpiofile:
16811700
print("Could not find GPIO file")
16821701
quit()
16831702
xml_gpio = parse(str(dirIP / ("GPIO-" + gpiofile + "_Modes.xml")))

0 commit comments

Comments
 (0)