Skip to content

Commit 3b4d46b

Browse files
authored
Merge pull request #98 from adafruit/update-tinyusb
Update tinyusb to latest with various bug fix
2 parents c7387f6 + 49647bc commit 3b4d46b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2041
-286
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ assignees: ''
1212
- Your OS (mac/windows/linux) and Arduino IDE version
1313
- Your Board and BSP version
1414
- TinyUSB library version
15+
- Sketch: If is your custom sketch, please provide a minimal sketch as attached file
1516

1617
**Describe**
1718

@@ -30,4 +31,4 @@ If applicable, add screenshots to help explain your problem.
3031

3132
**Log**
3233

33-
If applicable, provide your Serial log. If the log is too long, attach it as txt file instead.
34+
If applicable, provide your Serial log as attached txt file.

.github/workflows/githubci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ jobs:
1313
- 'cpb'
1414
- 'nrf52840'
1515
# RP2040
16-
#- 'feather_rp2040_tinyusb'
17-
#- 'pico_rp2040_tinyusb'
16+
- 'feather_rp2040_tinyusb'
1817
# SAMD
1918
- 'feather_m4_can_tinyusb'
2019
- 'metro_m0_tinyusb'

examples/Composite/mouse_external_flash/.feather_rp2040_tinyusb.test.skip

Whitespace-only changes.

examples/MassStorage/msc_external_flash/.feather_rp2040_tinyusb.test.skip

Whitespace-only changes.

examples/MassStorage/msc_external_flash_sdcard/.feather_rp2040_tinyusb.test.skip

Whitespace-only changes.

examples/MassStorage/msc_sd/.feather_rp2040_tinyusb.test.skip

Whitespace-only changes.

examples/MassStorage/msc_sdfat/.feather_rp2040_tinyusb.test.skip

Whitespace-only changes.

src/arduino/Adafruit_TinyUSB_API.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void TinyUSB_Device_FlushCDC(void) {
5555
tud_cdc_n_write_flush(instance);
5656
}
5757
}
58-
}
58+
59+
} // extern C
5960

6061
#endif

src/arduino/ports/Adafruit_TinyUSB_samd.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,17 @@ void USB_Handler(void) { tud_int_handler(0); }
5454

5555
} // extern C
5656

57-
//--------------------------------------------------------------------+
58-
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
59-
//--------------------------------------------------------------------+
60-
57+
// Debug log with Serial1
6158
#if CFG_TUSB_DEBUG
6259
extern "C" int serial1_printf(const char *__restrict format, ...) {
63-
char buf[PRINTF_BUF];
60+
char buf[256];
61+
int len;
6462
va_list ap;
6563
va_start(ap, format);
66-
vsnprintf(buf, sizeof(buf), format, ap);
64+
len = vsnprintf(buf, sizeof(buf), format, ap);
6765
Serial1.write(buf);
6866
va_end(ap);
67+
return len;
6968
}
7069
#endif
7170

@@ -127,6 +126,10 @@ void TinyUSB_Port_InitDevice(uint8_t rhport) {
127126
NVIC_SetPriority((IRQn_Type)USB_IRQn, 0UL);
128127
#endif
129128

129+
#if CFG_TUSB_DEBUG
130+
Serial1.begin(115200);
131+
#endif
132+
130133
tusb_init();
131134
}
132135

src/class/audio/audio_device.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@
5555
//--------------------------------------------------------------------+
5656
// INCLUDE
5757
//--------------------------------------------------------------------+
58+
#include "device/usbd.h"
5859
#include "device/usbd_pvt.h"
60+
5961
#include "audio_device.h"
60-
//#include "common/tusb_fifo.h"
6162

6263
//--------------------------------------------------------------------+
6364
// MACRO CONSTANT TYPEDEF
@@ -548,7 +549,7 @@ static bool audiod_rx_done_cb(uint8_t rhport, audiod_function_t* audio, uint16_t
548549
TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz), false);
549550
#else
550551
// Data is already placed in EP FIFO, schedule for next receive
551-
TU_VERIFY(usbd_edpt_iso_xfer(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false);
552+
TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false);
552553
#endif
553554

554555
#endif
@@ -852,7 +853,7 @@ static bool audiod_tx_done_cb(uint8_t rhport, audiod_function_t * audio)
852853
TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_in, audio->lin_buf_in, n_bytes_tx));
853854
#else
854855
// Send everything in ISO EP FIFO
855-
TU_VERIFY(usbd_edpt_iso_xfer(rhport, audio->ep_in, &audio->ep_in_ff, n_bytes_tx));
856+
TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_in, &audio->ep_in_ff, n_bytes_tx));
856857
#endif
857858

858859
#endif
@@ -1611,7 +1612,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
16111612
#if USE_LINEAR_BUFFER_RX
16121613
TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz), false);
16131614
#else
1614-
TU_VERIFY(usbd_edpt_iso_xfer(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false);
1615+
TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false);
16151616
#endif
16161617
}
16171618

src/class/audio/audio_device.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
#ifndef _TUSB_AUDIO_DEVICE_H_
2929
#define _TUSB_AUDIO_DEVICE_H_
3030

31-
#include "assert.h"
32-
#include "common/tusb_common.h"
33-
#include "device/usbd.h"
34-
3531
#include "audio.h"
3632

3733
//--------------------------------------------------------------------+

src/class/bth/bth_device.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
// INCLUDE
3333
//--------------------------------------------------------------------+
3434
#include "bth_device.h"
35-
#include <common/tusb_types.h>
3635
#include <device/usbd_pvt.h>
3736

3837
//--------------------------------------------------------------------+

src/class/cdc/cdc_device.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828

2929
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_CDC)
3030

31-
#include "cdc_device.h"
31+
#include "device/usbd.h"
3232
#include "device/usbd_pvt.h"
3333

34+
#include "cdc_device.h"
35+
3436
//--------------------------------------------------------------------+
3537
// MACRO CONSTANT TYPEDEF
3638
//--------------------------------------------------------------------+

src/class/cdc/cdc_device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#define _TUSB_CDC_DEVICE_H_
2929

3030
#include "common/tusb_common.h"
31-
#include "device/usbd.h"
3231
#include "cdc.h"
3332

3433
//--------------------------------------------------------------------+

src/class/dfu/dfu.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2021 XMOS LIMITED
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#ifndef _TUSB_DFU_H_
28+
#define _TUSB_DFU_H_
29+
30+
#include "common/tusb_common.h"
31+
32+
#ifdef __cplusplus
33+
extern "C" {
34+
#endif
35+
36+
//--------------------------------------------------------------------+
37+
// Common Definitions
38+
//--------------------------------------------------------------------+
39+
// DFU Protocol
40+
typedef enum
41+
{
42+
DFU_PROTOCOL_RT = 0x01,
43+
DFU_PROTOCOL_DFU = 0x02,
44+
} dfu_protocol_type_t;
45+
46+
// DFU Descriptor Type
47+
typedef enum
48+
{
49+
DFU_DESC_FUNCTIONAL = 0x21,
50+
} dfu_descriptor_type_t;
51+
52+
// DFU Requests
53+
typedef enum {
54+
DFU_REQUEST_DETACH = 0,
55+
DFU_REQUEST_DNLOAD = 1,
56+
DFU_REQUEST_UPLOAD = 2,
57+
DFU_REQUEST_GETSTATUS = 3,
58+
DFU_REQUEST_CLRSTATUS = 4,
59+
DFU_REQUEST_GETSTATE = 5,
60+
DFU_REQUEST_ABORT = 6,
61+
} dfu_requests_t;
62+
63+
// DFU States
64+
typedef enum {
65+
APP_IDLE = 0,
66+
APP_DETACH = 1,
67+
DFU_IDLE = 2,
68+
DFU_DNLOAD_SYNC = 3,
69+
DFU_DNBUSY = 4,
70+
DFU_DNLOAD_IDLE = 5,
71+
DFU_MANIFEST_SYNC = 6,
72+
DFU_MANIFEST = 7,
73+
DFU_MANIFEST_WAIT_RESET = 8,
74+
DFU_UPLOAD_IDLE = 9,
75+
DFU_ERROR = 10,
76+
} dfu_state_t;
77+
78+
// DFU Status
79+
typedef enum {
80+
DFU_STATUS_OK = 0x00,
81+
DFU_STATUS_ERRTARGET = 0x01,
82+
DFU_STATUS_ERRFILE = 0x02,
83+
DFU_STATUS_ERRWRITE = 0x03,
84+
DFU_STATUS_ERRERASE = 0x04,
85+
DFU_STATUS_ERRCHECK_ERASED = 0x05,
86+
DFU_STATUS_ERRPROG = 0x06,
87+
DFU_STATUS_ERRVERIFY = 0x07,
88+
DFU_STATUS_ERRADDRESS = 0x08,
89+
DFU_STATUS_ERRNOTDONE = 0x09,
90+
DFU_STATUS_ERRFIRMWARE = 0x0A,
91+
DFU_STATUS_ERRVENDOR = 0x0B,
92+
DFU_STATUS_ERRUSBR = 0x0C,
93+
DFU_STATUS_ERRPOR = 0x0D,
94+
DFU_STATUS_ERRUNKNOWN = 0x0E,
95+
DFU_STATUS_ERRSTALLEDPKT = 0x0F,
96+
} dfu_device_status_t;
97+
98+
#define DFU_FUNC_ATTR_CAN_DOWNLOAD_BITMASK (1 << 0)
99+
#define DFU_FUNC_ATTR_CAN_UPLOAD_BITMASK (1 << 1)
100+
#define DFU_FUNC_ATTR_MANIFESTATION_TOLERANT_BITMASK (1 << 2)
101+
#define DFU_FUNC_ATTR_WILL_DETACH_BITMASK (1 << 3)
102+
103+
// DFU Status Request Payload
104+
typedef struct TU_ATTR_PACKED
105+
{
106+
uint8_t bStatus;
107+
uint8_t bwPollTimeout[3];
108+
uint8_t bState;
109+
uint8_t iString;
110+
} dfu_status_req_payload_t;
111+
112+
TU_VERIFY_STATIC( sizeof(dfu_status_req_payload_t) == 6, "size is not correct");
113+
114+
#ifdef __cplusplus
115+
}
116+
#endif
117+
118+
#endif /* _TUSB_DFU_H_ */

src/class/dfu/dfu_rt_device.c

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,18 @@
2828

2929
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_DFU_RUNTIME)
3030

31-
#include "dfu_rt_device.h"
31+
#include "device/usbd.h"
3232
#include "device/usbd_pvt.h"
3333

34+
#include "dfu_rt_device.h"
35+
3436
//--------------------------------------------------------------------+
3537
// MACRO CONSTANT TYPEDEF
3638
//--------------------------------------------------------------------+
37-
typedef enum {
38-
DFU_REQUEST_DETACH = 0,
39-
DFU_REQUEST_DNLOAD = 1,
40-
DFU_REQUEST_UPLOAD = 2,
41-
DFU_REQUEST_GETSTATUS = 3,
42-
DFU_REQUEST_CLRSTATUS = 4,
43-
DFU_REQUEST_GETSTATE = 5,
44-
DFU_REQUEST_ABORT = 6,
45-
} dfu_requests_t;
46-
47-
typedef struct TU_ATTR_PACKED
48-
{
49-
uint8_t status;
50-
uint8_t poll_timeout[3];
51-
uint8_t state;
52-
uint8_t istring;
53-
} dfu_status_t;
39+
40+
//--------------------------------------------------------------------+
41+
// INTERNAL OBJECT & FUNCTION DECLARATION
42+
//--------------------------------------------------------------------+
5443

5544
//--------------------------------------------------------------------+
5645
// USBD Driver API
@@ -61,7 +50,7 @@ void dfu_rtd_init(void)
6150

6251
void dfu_rtd_reset(uint8_t rhport)
6352
{
64-
(void) rhport;
53+
(void) rhport;
6554
}
6655

6756
uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
@@ -70,8 +59,8 @@ uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, ui
7059
(void) max_len;
7160

7261
// Ensure this is DFU Runtime
73-
TU_VERIFY(itf_desc->bInterfaceSubClass == TUD_DFU_APP_SUBCLASS &&
74-
itf_desc->bInterfaceProtocol == DFU_PROTOCOL_RT, 0);
62+
TU_VERIFY((itf_desc->bInterfaceSubClass == TUD_DFU_APP_SUBCLASS) &&
63+
(itf_desc->bInterfaceProtocol == DFU_PROTOCOL_RT), 0);
7564

7665
uint8_t const * p_desc = tu_desc_next( itf_desc );
7766
uint16_t drv_len = sizeof(tusb_desc_interface_t);
@@ -90,7 +79,7 @@ uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, ui
9079
// return false to stall control endpoint (e.g unsupported request)
9180
bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
9281
{
93-
// nothing to do with DATA and ACK stage
82+
// nothing to do with DATA or ACK stage
9483
if ( stage != CONTROL_STAGE_SETUP ) return true;
9584

9685
TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
@@ -106,34 +95,34 @@ bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
10695
// Handle class request only from here
10796
TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
10897

109-
switch ( request->bRequest )
98+
switch (request->bRequest)
11099
{
111100
case DFU_REQUEST_DETACH:
101+
{
102+
TU_LOG2(" DFU RT Request: DETACH\r\n");
112103
tud_control_status(rhport, request);
113104
tud_dfu_runtime_reboot_to_dfu_cb();
105+
}
114106
break;
115107

116108
case DFU_REQUEST_GETSTATUS:
117109
{
118-
// status = OK, poll timeout = 0, state = app idle, istring = 0
119-
uint8_t status_response[6] = { 0, 0, 0, 0, 0, 0 };
120-
tud_control_xfer(rhport, request, status_response, sizeof(status_response));
110+
TU_LOG2(" DFU RT Request: GETSTATUS\r\n");
111+
dfu_status_req_payload_t resp;
112+
// Status = OK, Poll timeout is ignored during RT, State = APP_IDLE, IString = 0
113+
memset(&resp, 0x00, sizeof(dfu_status_req_payload_t));
114+
tud_control_xfer(rhport, request, &resp, sizeof(dfu_status_req_payload_t));
121115
}
122116
break;
123117

124-
default: return false; // stall unsupported request
118+
default:
119+
{
120+
TU_LOG2(" DFU RT Unexpected Request: %d\r\n", request->bRequest);
121+
return false; // stall unsupported request
122+
}
125123
}
126124

127125
return true;
128126
}
129127

130-
bool dfu_rtd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
131-
{
132-
(void) rhport;
133-
(void) ep_addr;
134-
(void) result;
135-
(void) xferred_bytes;
136-
return true;
137-
}
138-
139128
#endif

0 commit comments

Comments
 (0)