Skip to content

Commit 23aefe9

Browse files
committed
Add usb-endpoint-count checking
.. however, the number of endpoints is only set for SAMD (8). Other ports need to set the value. Otherwise, the build will show the message ``` Unable to check whether maximum number of endpoints is respected ```
1 parent 837abd6 commit 23aefe9

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

ports/atmel-samd/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,5 @@ endif # samd51
9191
INTERNAL_LIBM = 1
9292

9393
USB_SERIAL_NUMBER_LENGTH = 32
94+
95+
USB_NUM_EP = 8

supervisor/supervisor.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ ifndef USB_MIDI_EP_NUM_IN
171171
USB_MIDI_EP_NUM_IN = 0
172172
endif
173173

174+
ifndef USB_NUM_EP
175+
USB_NUM_EP = 0
176+
endif
177+
174178
USB_DESCRIPTOR_ARGS = \
175179
--manufacturer $(USB_MANUFACTURER)\
176180
--product $(USB_PRODUCT)\
@@ -180,6 +184,7 @@ USB_DESCRIPTOR_ARGS = \
180184
--interface_name $(USB_INTERFACE_NAME)\
181185
--devices $(USB_DEVICES)\
182186
--hid_devices $(USB_HID_DEVICES)\
187+
--max_ep $(USB_NUM_EP) \
183188
--cdc_ep_num_notification $(USB_CDC_EP_NUM_NOTIFICATION)\
184189
--cdc_ep_num_data_out $(USB_CDC_EP_NUM_DATA_OUT)\
185190
--cdc_ep_num_data_in $(USB_CDC_EP_NUM_DATA_IN)\

tools/gen_usb_descriptor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
help='endpoint number of MIDI OUT')
6363
parser.add_argument('--midi_ep_num_in', type=int, default=0,
6464
help='endpoint number of MIDI IN')
65+
parser.add_argument('--max_ep', type=int, default=0,
66+
help='total number of endpoints available')
6567
parser.add_argument('--output_c_file', type=argparse.FileType('w', encoding='UTF-8'), required=True)
6668
parser.add_argument('--output_h_file', type=argparse.FileType('w', encoding='UTF-8'), required=True)
6769

@@ -376,6 +378,15 @@ def strings_in_order(cls):
376378
# interface cross-references.
377379
interfaces = util.join_interfaces(interfaces_to_join, renumber_endpoints=args.renumber_endpoints)
378380

381+
if args.max_ep != 0:
382+
for interface in interfaces:
383+
for subdescriptor in interface.subdescriptors:
384+
endpoint_address = getattr(subdescriptor, 'bEndpointAddress', 0) & 0x7f
385+
if endpoint_address > args.max_ep:
386+
raise ValueError("Endpoint address %d of %s may not exceed %d" % (endpoint_address & 0x7f, interface.description, args.max_ep))
387+
else:
388+
print("Unable to check whether maximum number of endpoints is respected", file=sys.stderr)
389+
379390
# Now adjust the CDC interface cross-references.
380391

381392
cdc_union.bMasterInterface = cdc_comm_interface.bInterfaceNumber

0 commit comments

Comments
 (0)