Skip to content

Commit e9da6bc

Browse files
committed
return actual length from ctrl_transfer
Previously this returned the requested transfer length argument, ignoring the actual length of transferred bytes. This changes to returning the actual length.
1 parent b076077 commit e9da6bc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

shared-module/usb/core/Device.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,11 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
355355
.complete_cb = _transfer_done_cb,
356356
};
357357

358+
// Prepare for transfer. Unless there is a timeout, these static globals will
359+
// get modified by the _transfer_done_cb() callback when tinyusb finishes the
360+
// transfer or encounters an error condition.
358361
_xfer_result = XFER_RESULT_INVALID;
362+
_actual_len = 0;
359363

360364
if (!tuh_control_xfer(&xfer)) {
361365
mp_raise_usb_core_USBError(NULL);
@@ -377,7 +381,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
377381
_xfer_result = XFER_RESULT_INVALID;
378382
switch (result) {
379383
case XFER_RESULT_SUCCESS:
380-
return len;
384+
return _actual_len;
381385
case XFER_RESULT_FAILED:
382386
break;
383387
case XFER_RESULT_STALLED:

0 commit comments

Comments
 (0)