@@ -20,11 +20,12 @@ def init(module):
20
20
module .description = FileReader ("module.md" )
21
21
22
22
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" )):
28
29
return False
29
30
30
31
configs = {"device.cdc" , "device.msc" , "device.vendor" , "device.midi" , "device.dfu" }
@@ -42,12 +43,15 @@ def prepare(module, options):
42
43
dependencies = lambda vs :
43
44
[":tinyusb:{}" .format (v .replace ("." , ":" )) for v in vs ]))
44
45
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" ):
46
50
module .add_option (
47
51
EnumerationOption (name = "speed" ,
48
52
description = "USB Port Speed" ,
49
53
enumeration = {"full" : "fs" , "high" : "hs" },
50
- default = "high" if options [ ":target" ]. has_driver ( "usb_otg_hs" ) else " full" ,
54
+ default = "full" ,
51
55
dependencies = lambda s : ":platform:usb:{}s" .format (s [0 ])))
52
56
53
57
module .add_submodule (TinyUsbDeviceModule ())
@@ -121,7 +125,9 @@ def build(env):
121
125
122
126
has_device = env .has_module (":tinyusb:device" )
123
127
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" )
125
131
port = 0 if speed == "fs" else 1
126
132
127
133
mode = None
0 commit comments