Skip to content

Improve highspeed usb #3225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 166 files
2 changes: 1 addition & 1 deletion ports/cxd56/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ LDFLAGS = \
--end-group \
-L$(BUILD) \

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)
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)

SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
Expand Down
2 changes: 1 addition & 1 deletion ports/cxd56/mpconfigport.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
USB_SERIAL_NUMBER_LENGTH = 10
USB_MSC_MAX_PACKET_SIZE = 512
USB_HIGHSPEED = 1
USB_RENUMBER_ENDPOINTS = 0
USB_CDC_EP_NUM_NOTIFICATION = 3
USB_CDC_EP_NUM_DATA_OUT = 2
Expand Down
2 changes: 1 addition & 1 deletion ports/mimxrt10xx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ INC += \
CFLAGS += -Os -DNDEBUG

# TinyUSB defines
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
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

#Debugging/Optimization
ifeq ($(DEBUG), 1)
Expand Down
2 changes: 1 addition & 1 deletion ports/mimxrt10xx/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ endif
INTERNAL_LIBM = 1

USB_SERIAL_NUMBER_LENGTH = 32
USB_MSC_MAX_PACKET_SIZE = 512
USB_HIGHSPEED = 1

INTERNAL_FLASH_FILESYSTEM = 1

Expand Down
29 changes: 0 additions & 29 deletions supervisor/shared/usb/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
//--------------------------------------------------------------------+
// COMMON CONFIGURATION
//--------------------------------------------------------------------+
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE

#ifndef CFG_TUSB_DEBUG
#define CFG_TUSB_DEBUG 0
#endif
Expand All @@ -58,23 +56,13 @@
#define CFG_TUSB_OS OPT_OS_NONE
#endif
//#define CFG_TUD_TASK_QUEUE_SZ 16
//#define CFG_TUD_TASK_PRIO 0
//#define CFG_TUD_TASK_STACK_SZ 150

//--------------------------------------------------------------------+
// DEVICE CONFIGURATION
//--------------------------------------------------------------------+

#define CFG_TUD_ENDOINT0_SIZE 64

/*------------- Descriptors -------------*/
/* Enable auto generated descriptor, tinyusb will try its best to create
* descriptor ( device, configuration, hid ) that matches enabled CFG_* in this file
*
* Note: All CFG_TUD_DESC_* are relevant only if CFG_TUD_DESC_AUTO is enabled
*/
#define CFG_TUD_DESC_AUTO 0

//------------- CLASS -------------//
#define CFG_TUD_CDC 1
#define CFG_TUD_MSC 1
Expand All @@ -86,23 +74,6 @@
/* CLASS DRIVER
*------------------------------------------------------------------*/

/* TX is sent automatically on every Start of Frame event ~ 1ms.
* If not enabled, application must call tud_cdc_flush() periodically
* Note: Enabled this could overflow device task, if it does, define
* CFG_TUD_TASK_QUEUE_SZ with large value
*/
#define CFG_TUD_CDC_FLUSH_ON_SOF 0


/*------------- MSC -------------*/
// Number of supported Logical Unit Number (At least 1)
#define CFG_TUD_MSC_MAXLUN 1

// Number of Blocks
#define CFG_TUD_MSC_BLOCK_NUM (256*1024)/512



// Product revision string included in Inquiry response, max 4 bytes
#define CFG_TUD_MSC_PRODUCT_REV "1.0"

Expand Down
9 changes: 6 additions & 3 deletions supervisor/supervisor.mk
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ ifndef USB_HID_DEVICES
USB_HID_DEVICES = "KEYBOARD,MOUSE,CONSUMER,GAMEPAD"
endif

ifndef USB_MSC_MAX_PACKET_SIZE
USB_MSC_MAX_PACKET_SIZE = 64
ifndef USB_HIGHSPEED
USB_HIGHSPEED = 0
endif

ifndef USB_CDC_EP_NUM_NOTIFICATION
Expand Down Expand Up @@ -178,7 +178,6 @@ USB_DESCRIPTOR_ARGS = \
--interface_name $(USB_INTERFACE_NAME)\
--devices $(USB_DEVICES)\
--hid_devices $(USB_HID_DEVICES)\
--msc_max_packet_size $(USB_MSC_MAX_PACKET_SIZE)\
--cdc_ep_num_notification $(USB_CDC_EP_NUM_NOTIFICATION)\
--cdc_ep_num_data_out $(USB_CDC_EP_NUM_DATA_OUT)\
--cdc_ep_num_data_in $(USB_CDC_EP_NUM_DATA_IN)\
Expand All @@ -195,6 +194,10 @@ ifeq ($(USB_RENUMBER_ENDPOINTS), 0)
USB_DESCRIPTOR_ARGS += --no-renumber_endpoints
endif

ifeq ($(USB_HIGHSPEED), 1)
USB_DESCRIPTOR_ARGS += --highspeed
endif

$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h

$(BUILD)/autogen_usb_descriptor.c $(BUILD)/genhdr/autogen_usb_descriptor.h: autogen_usb_descriptor.intermediate
Expand Down
30 changes: 19 additions & 11 deletions tools/gen_usb_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
DEFAULT_HID_DEVICES='KEYBOARD,MOUSE,CONSUMER,GAMEPAD'

parser = argparse.ArgumentParser(description='Generate USB descriptors.')
parser.add_argument('--highspeed', default=False, action='store_true',
help='descriptor for highspeed device')
parser.add_argument('--manufacturer', type=str,
help='manufacturer of the device')
parser.add_argument('--product', type=str,
Expand All @@ -40,8 +42,6 @@
parser.add_argument('--interface_name', type=str,
help='The name/prefix to use in the interface descriptions',
default=DEFAULT_INTERFACE_NAME)
parser.add_argument('--msc_max_packet_size', type=int, default=64,
help='Max packet size for MSC')
parser.add_argument('--no-renumber_endpoints', dest='renumber_endpoints', action='store_false',
help='use to not renumber endpoint')
parser.add_argument('--cdc_ep_num_notification', type=int, default=0,
Expand Down Expand Up @@ -185,11 +185,15 @@ def strings_in_order(cls):
standard.EndpointDescriptor(
description="CDC data out",
bEndpointAddress=args.cdc_ep_num_data_out | standard.EndpointDescriptor.DIRECTION_OUT,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval=0,
wMaxPacketSize=512 if args.highspeed else 64),
standard.EndpointDescriptor(
description="CDC data in",
bEndpointAddress=args.cdc_ep_num_data_in | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval=0,
wMaxPacketSize=512 if args.highspeed else 64),
])

cdc_interfaces = [cdc_comm_interface, cdc_data_interface]
Expand All @@ -207,13 +211,13 @@ def strings_in_order(cls):
bEndpointAddress=args.msc_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval=0,
wMaxPacketSize=args.msc_max_packet_size),
wMaxPacketSize=512 if args.highspeed else 64),
standard.EndpointDescriptor(
description="MSC out",
bEndpointAddress=(args.msc_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT),
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval=0,
wMaxPacketSize=args.msc_max_packet_size)
wMaxPacketSize=512 if args.highspeed else 64),
]
)
]
Expand Down Expand Up @@ -319,13 +323,16 @@ def strings_in_order(cls):
standard.EndpointDescriptor(
description="MIDI data out to {}".format(args.interface_name),
bEndpointAddress=args.midi_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval=0,
wMaxPacketSize=512 if args.highspeed else 64),
midi.DataEndpointDescriptor(baAssocJack=[midi_in_jack_emb]),
standard.EndpointDescriptor(
description="MIDI data in from {}".format(args.interface_name),
bEndpointAddress=args.midi_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval = 0x0),
bInterval = 0x0,
wMaxPacketSize=512 if args.highspeed else 64),
midi.DataEndpointDescriptor(baAssocJack=[midi_out_jack_emb]),
])

Expand Down Expand Up @@ -540,15 +547,15 @@ def strings_in_order(cls):
#include <stdint.h>

extern const uint8_t usb_desc_dev[{device_length}];
// Make sure the control buffer is big enough to fit the descriptor.
#define CFG_TUD_ENUM_BUFFER_SIZE {max_configuration_length}
extern const uint8_t usb_desc_cfg[{configuration_length}];
extern uint16_t usb_serial_number[{serial_number_length}];
extern uint16_t const * const string_desc_arr [{string_descriptor_length}];

extern const uint8_t hid_report_descriptor[{hid_report_descriptor_length}];

#define USB_HID_NUM_DEVICES {hid_num_devices}
#define CFG_TUSB_RHPORT0_MODE ({rhport0_mode})

#define USB_HID_NUM_DEVICES {hid_num_devices}

// Vendor name included in Inquiry response, max 8 bytes
#define CFG_TUD_MSC_VENDOR "{msc_vendor}"
Expand All @@ -563,6 +570,7 @@ def strings_in_order(cls):
max_configuration_length=max(hid_descriptor_length, descriptor_length),
string_descriptor_length=len(pointers_to_strings),
hid_report_descriptor_length=len(bytes(combined_hid_report_descriptor)),
rhport0_mode='OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED' if args.highspeed else 'OPT_MODE_DEVICE',
hid_num_devices=len(args.hid_devices),
msc_vendor=args.manufacturer[:8],
msc_product=args.product[:16]))
Expand Down