Skip to content

Commit d4801b8

Browse files
authored
Merge pull request #3225 from hathach/improve-highspeed-usb
Improve highspeed usb
2 parents 510985f + b2ec77e commit d4801b8

File tree

8 files changed

+30
-48
lines changed

8 files changed

+30
-48
lines changed

lib/tinyusb

Submodule tinyusb updated 166 files

ports/cxd56/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ LDFLAGS = \
151151
--end-group \
152152
-L$(BUILD) \
153153

154-
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_CXD56 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=512 $(CFLAGS_MOD)
154+
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_CXD56 -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=512 -DCFG_TUD_MSC_BUFSIZE=512 $(CFLAGS_MOD)
155155

156156
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
157157
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \

ports/cxd56/mpconfigport.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
USB_SERIAL_NUMBER_LENGTH = 10
2-
USB_MSC_MAX_PACKET_SIZE = 512
2+
USB_HIGHSPEED = 1
33
USB_RENUMBER_ENDPOINTS = 0
44
USB_CDC_EP_NUM_NOTIFICATION = 3
55
USB_CDC_EP_NUM_DATA_OUT = 2

ports/mimxrt10xx/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ INC += \
7878
CFLAGS += -Os -DNDEBUG
7979

8080
# TinyUSB defines
81-
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024
81+
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=512 -DCFG_TUD_MSC_BUFSIZE=1024
8282

8383
#Debugging/Optimization
8484
ifeq ($(DEBUG), 1)

ports/mimxrt10xx/mpconfigport.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ endif
1515
INTERNAL_LIBM = 1
1616

1717
USB_SERIAL_NUMBER_LENGTH = 32
18-
USB_MSC_MAX_PACKET_SIZE = 512
18+
USB_HIGHSPEED = 1
1919

2020
INTERNAL_FLASH_FILESYSTEM = 1
2121

supervisor/shared/usb/tusb_config.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
//--------------------------------------------------------------------+
4848
// COMMON CONFIGURATION
4949
//--------------------------------------------------------------------+
50-
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
51-
5250
#ifndef CFG_TUSB_DEBUG
5351
#define CFG_TUSB_DEBUG 0
5452
#endif
@@ -58,23 +56,13 @@
5856
#define CFG_TUSB_OS OPT_OS_NONE
5957
#endif
6058
//#define CFG_TUD_TASK_QUEUE_SZ 16
61-
//#define CFG_TUD_TASK_PRIO 0
62-
//#define CFG_TUD_TASK_STACK_SZ 150
6359

6460
//--------------------------------------------------------------------+
6561
// DEVICE CONFIGURATION
6662
//--------------------------------------------------------------------+
6763

6864
#define CFG_TUD_ENDOINT0_SIZE 64
6965

70-
/*------------- Descriptors -------------*/
71-
/* Enable auto generated descriptor, tinyusb will try its best to create
72-
* descriptor ( device, configuration, hid ) that matches enabled CFG_* in this file
73-
*
74-
* Note: All CFG_TUD_DESC_* are relevant only if CFG_TUD_DESC_AUTO is enabled
75-
*/
76-
#define CFG_TUD_DESC_AUTO 0
77-
7866
//------------- CLASS -------------//
7967
#define CFG_TUD_CDC 1
8068
#define CFG_TUD_MSC 1
@@ -86,23 +74,6 @@
8674
/* CLASS DRIVER
8775
*------------------------------------------------------------------*/
8876

89-
/* TX is sent automatically on every Start of Frame event ~ 1ms.
90-
* If not enabled, application must call tud_cdc_flush() periodically
91-
* Note: Enabled this could overflow device task, if it does, define
92-
* CFG_TUD_TASK_QUEUE_SZ with large value
93-
*/
94-
#define CFG_TUD_CDC_FLUSH_ON_SOF 0
95-
96-
97-
/*------------- MSC -------------*/
98-
// Number of supported Logical Unit Number (At least 1)
99-
#define CFG_TUD_MSC_MAXLUN 1
100-
101-
// Number of Blocks
102-
#define CFG_TUD_MSC_BLOCK_NUM (256*1024)/512
103-
104-
105-
10677
// Product revision string included in Inquiry response, max 4 bytes
10778
#define CFG_TUD_MSC_PRODUCT_REV "1.0"
10879

supervisor/supervisor.mk

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ ifndef USB_HID_DEVICES
129129
USB_HID_DEVICES = "KEYBOARD,MOUSE,CONSUMER,GAMEPAD"
130130
endif
131131

132-
ifndef USB_MSC_MAX_PACKET_SIZE
133-
USB_MSC_MAX_PACKET_SIZE = 64
132+
ifndef USB_HIGHSPEED
133+
USB_HIGHSPEED = 0
134134
endif
135135

136136
ifndef USB_CDC_EP_NUM_NOTIFICATION
@@ -178,7 +178,6 @@ USB_DESCRIPTOR_ARGS = \
178178
--interface_name $(USB_INTERFACE_NAME)\
179179
--devices $(USB_DEVICES)\
180180
--hid_devices $(USB_HID_DEVICES)\
181-
--msc_max_packet_size $(USB_MSC_MAX_PACKET_SIZE)\
182181
--cdc_ep_num_notification $(USB_CDC_EP_NUM_NOTIFICATION)\
183182
--cdc_ep_num_data_out $(USB_CDC_EP_NUM_DATA_OUT)\
184183
--cdc_ep_num_data_in $(USB_CDC_EP_NUM_DATA_IN)\
@@ -195,6 +194,10 @@ ifeq ($(USB_RENUMBER_ENDPOINTS), 0)
195194
USB_DESCRIPTOR_ARGS += --no-renumber_endpoints
196195
endif
197196

197+
ifeq ($(USB_HIGHSPEED), 1)
198+
USB_DESCRIPTOR_ARGS += --highspeed
199+
endif
200+
198201
$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h
199202

200203
$(BUILD)/autogen_usb_descriptor.c $(BUILD)/genhdr/autogen_usb_descriptor.h: autogen_usb_descriptor.intermediate

tools/gen_usb_descriptor.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
DEFAULT_HID_DEVICES='KEYBOARD,MOUSE,CONSUMER,GAMEPAD'
2424

2525
parser = argparse.ArgumentParser(description='Generate USB descriptors.')
26+
parser.add_argument('--highspeed', default=False, action='store_true',
27+
help='descriptor for highspeed device')
2628
parser.add_argument('--manufacturer', type=str,
2729
help='manufacturer of the device')
2830
parser.add_argument('--product', type=str,
@@ -40,8 +42,6 @@
4042
parser.add_argument('--interface_name', type=str,
4143
help='The name/prefix to use in the interface descriptions',
4244
default=DEFAULT_INTERFACE_NAME)
43-
parser.add_argument('--msc_max_packet_size', type=int, default=64,
44-
help='Max packet size for MSC')
4545
parser.add_argument('--no-renumber_endpoints', dest='renumber_endpoints', action='store_false',
4646
help='use to not renumber endpoint')
4747
parser.add_argument('--cdc_ep_num_notification', type=int, default=0,
@@ -185,11 +185,15 @@ def strings_in_order(cls):
185185
standard.EndpointDescriptor(
186186
description="CDC data out",
187187
bEndpointAddress=args.cdc_ep_num_data_out | standard.EndpointDescriptor.DIRECTION_OUT,
188-
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
188+
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
189+
bInterval=0,
190+
wMaxPacketSize=512 if args.highspeed else 64),
189191
standard.EndpointDescriptor(
190192
description="CDC data in",
191193
bEndpointAddress=args.cdc_ep_num_data_in | standard.EndpointDescriptor.DIRECTION_IN,
192-
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
194+
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
195+
bInterval=0,
196+
wMaxPacketSize=512 if args.highspeed else 64),
193197
])
194198

195199
cdc_interfaces = [cdc_comm_interface, cdc_data_interface]
@@ -207,13 +211,13 @@ def strings_in_order(cls):
207211
bEndpointAddress=args.msc_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN,
208212
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
209213
bInterval=0,
210-
wMaxPacketSize=args.msc_max_packet_size),
214+
wMaxPacketSize=512 if args.highspeed else 64),
211215
standard.EndpointDescriptor(
212216
description="MSC out",
213217
bEndpointAddress=(args.msc_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT),
214218
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
215219
bInterval=0,
216-
wMaxPacketSize=args.msc_max_packet_size)
220+
wMaxPacketSize=512 if args.highspeed else 64),
217221
]
218222
)
219223
]
@@ -319,13 +323,16 @@ def strings_in_order(cls):
319323
standard.EndpointDescriptor(
320324
description="MIDI data out to {}".format(args.interface_name),
321325
bEndpointAddress=args.midi_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT,
322-
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
326+
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
327+
bInterval=0,
328+
wMaxPacketSize=512 if args.highspeed else 64),
323329
midi.DataEndpointDescriptor(baAssocJack=[midi_in_jack_emb]),
324330
standard.EndpointDescriptor(
325331
description="MIDI data in from {}".format(args.interface_name),
326332
bEndpointAddress=args.midi_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN,
327333
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
328-
bInterval = 0x0),
334+
bInterval = 0x0,
335+
wMaxPacketSize=512 if args.highspeed else 64),
329336
midi.DataEndpointDescriptor(baAssocJack=[midi_out_jack_emb]),
330337
])
331338

@@ -540,15 +547,15 @@ def strings_in_order(cls):
540547
#include <stdint.h>
541548
542549
extern const uint8_t usb_desc_dev[{device_length}];
543-
// Make sure the control buffer is big enough to fit the descriptor.
544-
#define CFG_TUD_ENUM_BUFFER_SIZE {max_configuration_length}
545550
extern const uint8_t usb_desc_cfg[{configuration_length}];
546551
extern uint16_t usb_serial_number[{serial_number_length}];
547552
extern uint16_t const * const string_desc_arr [{string_descriptor_length}];
548553
549554
extern const uint8_t hid_report_descriptor[{hid_report_descriptor_length}];
550555
551-
#define USB_HID_NUM_DEVICES {hid_num_devices}
556+
#define CFG_TUSB_RHPORT0_MODE ({rhport0_mode})
557+
558+
#define USB_HID_NUM_DEVICES {hid_num_devices}
552559
553560
// Vendor name included in Inquiry response, max 8 bytes
554561
#define CFG_TUD_MSC_VENDOR "{msc_vendor}"
@@ -563,6 +570,7 @@ def strings_in_order(cls):
563570
max_configuration_length=max(hid_descriptor_length, descriptor_length),
564571
string_descriptor_length=len(pointers_to_strings),
565572
hid_report_descriptor_length=len(bytes(combined_hid_report_descriptor)),
573+
rhport0_mode='OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED' if args.highspeed else 'OPT_MODE_DEVICE',
566574
hid_num_devices=len(args.hid_devices),
567575
msc_vendor=args.manufacturer[:8],
568576
msc_product=args.product[:16]))

0 commit comments

Comments
 (0)