diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index af33edb0eb..dfc8d3abb7 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -19,6 +19,9 @@ ifeq ($(CHIP_FAMILY),samd21) # frequencyio not yet verified as working on SAMD21. CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_TOUCHIO_USE_NATIVE = 1 + +# SAMD21 needs separate endpoint pairs for MSC BULK IN and BULK OUT, otherwise it's erratic. +USB_MSC_NUM_ENDPOINT_PAIRS = 2 endif # Put samd51-only choices here. diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 016188dfd9..e758ea2165 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -89,6 +89,11 @@ ifndef USB_HID_DEVICES USB_HID_DEVICES = "KEYBOARD,MOUSE,CONSUMER,GAMEPAD" endif +# SAMD21 needs separate endpoint pairs for MSC BULK IN and BULK OUT, otherwise it's erratic. +ifndef USB_MSC_NUM_ENDPOINT_PAIRS +USB_MSC_NUM_ENDPOINT_PAIRS = 1 +endif + SUPERVISOR_O = $(addprefix $(BUILD)/, $(SRC_SUPERVISOR:.c=.o)) $(BUILD)/autogen_display_resources.o $(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h @@ -106,8 +111,9 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile --vid $(USB_VID)\ --pid $(USB_PID)\ --serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\ - --devices $(USB_DEVICES) \ - --hid_devices $(USB_HID_DEVICES) \ + --devices $(USB_DEVICES)\ + --hid_devices $(USB_HID_DEVICES)\ + --msc_num_endpoint_pairs $(USB_MSC_NUM_ENDPOINT_PAIRS)\ --output_c_file $(BUILD)/autogen_usb_descriptor.c\ --output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index 82d2daf0f7..87219194bc 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -32,6 +32,8 @@ parser.add_argument('--devices', type=lambda l: tuple(l.split(',')), default=DEF help='devices to include in descriptor (AUDIO includes MIDI support)') parser.add_argument('--hid_devices', type=lambda l: tuple(l.split(',')), default=DEFAULT_HID_DEVICES, help='HID devices to include in HID report descriptor') +parser.add_argument('--msc_num_endpoint_pairs', type=int, default=1, + help='Use 1 or 2 endpoint pairs for MSC (1 bidirectional, or 1 input + 1 output (required by SAMD21))') parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True) parser.add_argument('--output_h_file', type=argparse.FileType('w'), required=True) @@ -45,6 +47,9 @@ unknown_hid_devices = list(frozenset(args.hid_devices) - ALL_HID_DEVICES_SET) if unknown_hid_devices: raise ValueError("Unknown HID devices(s)", unknown_hid_devices) +if args.msc_num_endpoint_pairs not in (1, 2): + raise ValueError("--msc_num_endpoint_pairs must be 1 or 2") + class StringIndex: """Assign a monotonically increasing index to each unique string. Start with 0.""" @@ -153,7 +158,9 @@ msc_interfaces = [ bInterval=0), standard.EndpointDescriptor( description="MSC out", - bEndpointAddress=0x1 | standard.EndpointDescriptor.DIRECTION_OUT, + # SAMD21 needs to use a separate pair of endpoints for MSC. + bEndpointAddress=((0x1 if args.msc_num_endpoint_pairs == 2 else 0x0) | + standard.EndpointDescriptor.DIRECTION_OUT), bmAttributes=standard.EndpointDescriptor.TYPE_BULK, bInterval=0) ]