Skip to content

Commit 9602775

Browse files
chris-durandrleh
authored andcommitted
[tinyusb] Use STM32 full-speed by default
1 parent 7d839cf commit 9602775

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

ext/hathach/module.lb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ def init(module):
2020
module.description = FileReader("module.md")
2121

2222
def prepare(module, options):
23-
if not (options[":target"].has_driver("usb") or
24-
options[":target"].has_driver("usb_otg_fs") or
25-
options[":target"].has_driver("usb_otg_hs") or
26-
options[":target"].has_driver("udp") or
27-
options[":target"].has_driver("uhp")):
23+
device = options[":target"]
24+
if not (device.has_driver("usb") or
25+
device.has_driver("usb_otg_fs") or
26+
device.has_driver("usb_otg_hs") or
27+
device.has_driver("udp") or
28+
device.has_driver("uhp")):
2829
return False
2930

3031
configs = {"device.cdc", "device.msc", "device.vendor", "device.midi", "device.dfu"}
@@ -42,12 +43,15 @@ def prepare(module, options):
4243
dependencies=lambda vs:
4344
[":tinyusb:{}".format(v.replace(".", ":")) for v in vs]))
4445

45-
if options[":target"].has_driver("usb_otg_hs"):
46+
# Most devices only have FS=usb, some STM32 have FS/HS=usb_otg_fs/usb_otg_hs
47+
# and some STM32 only have HS=usb_otg_hs, so we only define this option if
48+
# there is a choice and default this to FS by default.
49+
if device.has_driver("usb_otg_hs") and device.has_driver("usb_otg_fs"):
4650
module.add_option(
4751
EnumerationOption(name="speed",
4852
description="USB Port Speed",
4953
enumeration={"full": "fs", "high": "hs"},
50-
default="high" if options[":target"].has_driver("usb_otg_hs") else "full",
54+
default="full",
5155
dependencies=lambda s: ":platform:usb:{}s".format(s[0])))
5256

5357
module.add_submodule(TinyUsbDeviceModule())
@@ -121,7 +125,9 @@ def build(env):
121125

122126
has_device = env.has_module(":tinyusb:device")
123127
has_host = env.has_module(":tinyusb:host")
124-
speed = env.get("speed", "fs")
128+
# On STM32 with both speeds, the option decides, otherwise we must default
129+
# to HS for the few STM32 with *only* usb_otg_hs, all other devices are FS.
130+
speed = env.get("speed", "hs" if env[":target"].has_driver("usb_otg_hs") else "fs")
125131
port = 0 if speed == "fs" else 1
126132

127133
mode = None

0 commit comments

Comments
 (0)