Skip to content

Commit 5340c00

Browse files
committed
STM32 gen PeriphPin script update for USB
1 parent 9534327 commit 5340c00

File tree

1 file changed

+95
-9
lines changed

1 file changed

+95
-9
lines changed

tools/targets/STM32_gen_PeripheralPins.py

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
* mbed Microcontroller Library
3-
* Copyright (c) 2006-2018 ARM Limited
4-
* Copyright (c) 2019 STMicroelectronics
3+
* Copyright (c) 2006-2019 ARM Limited
4+
* Copyright (c) 2006-2019 STMicroelectronics
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
from xml.dom.minidom import parse, Node
2828
from argparse import RawTextHelpFormatter
2929

30-
GENPINMAP_VERSION = "1.7"
30+
GENPINMAP_VERSION = "1.8"
3131

3232
ADD_DEVICE_IF = 0
3333
ADD_QSPI_FEATURE = 1
@@ -57,7 +57,9 @@
5757
quadspidata3_list = [] #'PIN','name','QUADSPIDATA3'
5858
quadspisclk_list = [] #'PIN','name','QUADSPISCLK'
5959
quadspissel_list = [] #'PIN','name','QUADSPISSEL'
60-
usb_list = [] #'PIN','name','USB'
60+
usb_list = [] # 'PIN','name','USB'
61+
usb_otgfs_list = [] # 'PIN','name','USB'
62+
usb_otghs_list = [] # 'PIN','name','USB'
6163
osc_list = [] #'PIN','name','OSC'
6264
sys_list = [] #'PIN','name','SYS'
6365

@@ -332,7 +334,12 @@ def store_qspi(pin, name, signal):
332334

333335
# function to store USB pins
334336
def store_usb(pin, name, signal):
335-
usb_list.append([pin, name, signal])
337+
if "OTG" not in signal:
338+
usb_list.append([pin, name, signal])
339+
elif signal.startswith("USB_OTG_FS"):
340+
usb_otgfs_list.append([pin, name, signal])
341+
elif signal.startswith("USB_OTG_HS"):
342+
usb_otghs_list.append([pin, name, signal])
336343

337344

338345
# function to store OSC pins
@@ -518,7 +525,15 @@ def print_all_lists():
518525
print_qspi(quadspisclk_list)
519526
if print_list_header("", "QSPI_SSEL", quadspissel_list, "QSPI"):
520527
print_qspi(quadspissel_list)
528+
if print_list_header("USBDEVICE", "USB_FS", usb_list, "USBDEVICE"):
529+
print_usb(usb_list)
530+
if print_list_header("USBDEVICE", "USB_FS", usb_otgfs_list, "USBDEVICE"):
531+
print_usb(usb_otgfs_list)
532+
if print_list_header("USBDEVICE", "USB_HS", usb_otghs_list, "USBDEVICE"):
533+
print_usb(usb_otghs_list)
521534
print_h_file(usb_list, "USB")
535+
print_h_file(usb_otgfs_list, "USB FS")
536+
print_h_file(usb_otghs_list, "USB HS")
522537
print_h_file(eth_list, "ETHERNET")
523538
print_h_file(osc_list, "OSCILLATOR")
524539
print_h_file(sys_list, "DEBUG")
@@ -873,8 +888,80 @@ def print_qspi(l):
873888
if ADD_DEVICE_IF:
874889
out_c_file.write( "#endif\n" )
875890

891+
def print_usb(lst):
892+
use_hs_in_fs = False
893+
nb_loop = 1
894+
inst = "USB_FS"
895+
if lst is usb_otgfs_list:
896+
inst = "USB_FS"
897+
elif lst is usb_otghs_list:
898+
inst = "USB_HS"
899+
nb_loop = 2
900+
901+
for nb in range(nb_loop):
902+
for p in lst:
903+
result = get_gpio_af_num(p[1], p[2])
904+
905+
CommentedLine = " "
906+
907+
if p[1] in PinLabel.keys():
908+
if "STDIO_UART" in PinLabel[p[1]]:
909+
CommentedLine = "//"
910+
if "RCC_OSC" in PinLabel[p[1]]:
911+
CommentedLine = "//"
912+
913+
if "_SOF" in p[2] or "_NOE" in p[2]:
914+
CommentedLine = "//"
915+
916+
if lst is usb_otghs_list:
917+
if nb == 0:
918+
if "ULPI" in p[2]:
919+
continue
920+
elif not use_hs_in_fs:
921+
out_c_file.write("#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_HS_IN_FS)\n")
922+
use_hs_in_fs = True
923+
else:
924+
if "ULPI" not in p[2]:
925+
continue
926+
elif use_hs_in_fs:
927+
out_c_file.write("#else /* MBED_CONF_TARGET_USB_SPEED */\n")
928+
use_hs_in_fs = False
929+
930+
s1 = "%-16s" % (CommentedLine + " {" + p[0] + ',')
931+
932+
# 2nd element is the USB_XXXX signal
933+
if not p[2].startswith("USB_D") and "VBUS" not in p[2]:
934+
if "ID" not in p[2]:
935+
s1 += inst + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
936+
else:
937+
# ID pin: AF_PP + PULLUP
938+
s1 += inst + ", STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, "
939+
else:
940+
# USB_DM/DP and VBUS: INPUT + NOPULL
941+
s1 += inst + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
942+
if result == "NOTFOUND":
943+
s1 += "0)},"
944+
else:
945+
r = result.split(" ")
946+
for af in r:
947+
s1 += af + ")},"
948+
s1 += " // " + p[2]
949+
if p[1] in PinLabel.keys():
950+
s1 += ' // Connected to ' + PinLabel[p[1]]
951+
s1 += "\n"
952+
out_c_file.write(s1)
953+
if lst:
954+
if lst is usb_otghs_list:
955+
out_c_file.write("#endif /* MBED_CONF_TARGET_USB_SPEED */\n")
956+
out_c_file.write(""" {NC, NC, 0}
957+
};
958+
""")
959+
if ADD_DEVICE_IF:
960+
out_c_file.write( "#endif\n" )
961+
876962

877963
def print_h_file(l, comment):
964+
l.sort(key=natural_sortkey2)
878965
if len(l) > 0:
879966
s = ("\n /**** %s pins ****/\n" % comment)
880967
out_h_file.write(s)
@@ -934,16 +1021,15 @@ def sort_my_lists():
9341021
spisclk_list.sort(key=natural_sortkey)
9351022
cantd_list.sort(key=natural_sortkey)
9361023
canrd_list.sort(key=natural_sortkey)
937-
eth_list.sort(key=natural_sortkey2)
9381024
quadspidata0_list.sort(key=natural_sortkey)
9391025
quadspidata1_list.sort(key=natural_sortkey)
9401026
quadspidata2_list.sort(key=natural_sortkey)
9411027
quadspidata3_list.sort(key=natural_sortkey)
9421028
quadspisclk_list.sort(key=natural_sortkey)
9431029
quadspissel_list.sort(key=natural_sortkey)
944-
usb_list.sort(key=natural_sortkey2)
945-
osc_list.sort(key=natural_sortkey2)
946-
sys_list.sort(key=natural_sortkey2)
1030+
usb_list.sort(key=natural_sortkey)
1031+
usb_otgfs_list.sort(key=natural_sortkey)
1032+
usb_otghs_list.sort(key=natural_sortkey)
9471033

9481034
def clean_all_lists():
9491035
del io_list[:]

0 commit comments

Comments
 (0)