Skip to content

Commit 71a7df6

Browse files
committed
sync usb to commit hathach/tinyusb@6db24e0
1 parent 429e228 commit 71a7df6

File tree

8 files changed

+84
-43
lines changed

8 files changed

+84
-43
lines changed

src/arduino/Adafruit_TinyUSB_API.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ void TinyUSB_Device_FlushCDC(void) {
5757

5858
// Debug log with Serial1
5959
#if CFG_TUSB_DEBUG && defined(CFG_TUSB_DEBUG_PRINTF)
60-
int CFG_TUSB_DEBUG_PRINTF(const char *__restrict format, ...) {
60+
__attribute__((used)) int CFG_TUSB_DEBUG_PRINTF(const char *__restrict format,
61+
...) {
6162
static bool ser1_inited = false;
6263
if (!ser1_inited) {
6364
ser1_inited = true;

src/class/hid/hid_host.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,15 @@ static bool _hidh_set_idle(uint8_t daddr, uint8_t itf_num, uint16_t idle_rate, t
337337
// Interrupt Endpoint API
338338
//--------------------------------------------------------------------+
339339

340+
// Check if HID interface is ready to receive report
341+
bool tuh_hid_receive_ready(uint8_t dev_addr, uint8_t idx)
342+
{
343+
hidh_interface_t* p_hid = get_hid_itf(dev_addr, idx);
344+
TU_VERIFY(p_hid);
345+
346+
return !usbh_edpt_busy(dev_addr, p_hid->ep_in);
347+
}
348+
340349
bool tuh_hid_receive_report(uint8_t daddr, uint8_t idx)
341350
{
342351
hidh_interface_t* p_hid = get_hid_itf(daddr, idx);
@@ -354,13 +363,13 @@ bool tuh_hid_receive_report(uint8_t daddr, uint8_t idx)
354363
return true;
355364
}
356365

357-
//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t instance)
358-
//{
359-
// TU_VERIFY(tuh_n_hid_n_mounted(dev_addr, instance));
360-
//
361-
// hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
362-
// return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
363-
//}
366+
bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx)
367+
{
368+
hidh_interface_t* p_hid = get_hid_itf(dev_addr, idx);
369+
TU_VERIFY(p_hid);
370+
371+
return !usbh_edpt_busy(dev_addr, p_hid->ep_out);
372+
}
364373

365374
bool tuh_hid_send_report(uint8_t daddr, uint8_t idx, uint8_t report_id, const void* report, uint16_t len)
366375
{

src/class/hid/hid_host.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef struct
6262
// Interface API
6363
//--------------------------------------------------------------------+
6464

65-
// Get the number of mounted HID interfaces of a device
65+
// Get the total number of mounted HID interfaces of a device
6666
uint8_t tuh_hid_itf_get_count(uint8_t dev_addr);
6767

6868
// Get all mounted interfaces across devices
@@ -109,14 +109,17 @@ bool tuh_hid_set_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, uint8_
109109
// Interrupt Endpoint API
110110
//--------------------------------------------------------------------+
111111

112-
// Check if the interface is ready to use
113-
//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t idx);
112+
// Check if HID interface is ready to receive report
113+
bool tuh_hid_receive_ready(uint8_t dev_addr, uint8_t idx);
114114

115115
// Try to receive next report on Interrupt Endpoint. Immediately return
116116
// - true If succeeded, tuh_hid_report_received_cb() callback will be invoked when report is available
117117
// - false if failed to queue the transfer e.g endpoint is busy
118118
bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t idx);
119119

120+
// Check if HID interface is ready to send report
121+
bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx);
122+
120123
// Send report using interrupt endpoint
121124
// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
122125
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, const void* report, uint16_t len);

src/class/net/net_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void tud_network_init_cb(void);
9494

9595
// client must provide this: 48-bit MAC address
9696
// TODO removed later since it is not part of tinyusb stack
97-
extern const uint8_t tud_network_mac_address[6];
97+
extern uint8_t tud_network_mac_address[6];
9898

9999
//------------- NCM -------------//
100100

src/class/vendor/vendor_device.c

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,20 @@ static void _prep_out_transaction (vendord_interface_t* p_itf)
9191
{
9292
uint8_t const rhport = 0;
9393

94-
// skip if previous transfer not complete
95-
if ( usbd_edpt_busy(rhport, p_itf->ep_out) ) return;
94+
// claim endpoint
95+
TU_VERIFY(usbd_edpt_claim(rhport, p_itf->ep_out), );
9696

9797
// Prepare for incoming data but only allow what we can store in the ring buffer.
9898
uint16_t max_read = tu_fifo_remaining(&p_itf->rx_ff);
9999
if ( max_read >= CFG_TUD_VENDOR_EPSIZE )
100100
{
101101
usbd_edpt_xfer(rhport, p_itf->ep_out, p_itf->epout_buf, CFG_TUD_VENDOR_EPSIZE);
102102
}
103+
else
104+
{
105+
// Release endpoint since we don't make any transfer
106+
usbd_edpt_release(rhport, p_itf->ep_out);
107+
}
103108
}
104109

105110
uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize)
@@ -120,37 +125,47 @@ void tud_vendor_n_read_flush (uint8_t itf)
120125
//--------------------------------------------------------------------+
121126
// Write API
122127
//--------------------------------------------------------------------+
123-
static uint16_t maybe_transmit(vendord_interface_t* p_itf)
124-
{
125-
uint8_t const rhport = 0;
126-
127-
// skip if previous transfer not complete
128-
TU_VERIFY( !usbd_edpt_busy(rhport, p_itf->ep_in) );
129-
130-
uint16_t count = tu_fifo_read_n(&p_itf->tx_ff, p_itf->epin_buf, CFG_TUD_VENDOR_EPSIZE);
131-
if (count > 0)
132-
{
133-
TU_ASSERT( usbd_edpt_xfer(rhport, p_itf->ep_in, p_itf->epin_buf, count) );
134-
}
135-
return count;
136-
}
137-
138128
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize)
139129
{
140130
vendord_interface_t* p_itf = &_vendord_itf[itf];
141131
uint16_t ret = tu_fifo_write_n(&p_itf->tx_ff, buffer, (uint16_t) bufsize);
132+
133+
// flush if queue more than packet size
142134
if (tu_fifo_count(&p_itf->tx_ff) >= CFG_TUD_VENDOR_EPSIZE) {
143-
maybe_transmit(p_itf);
135+
tud_vendor_n_write_flush(itf);
144136
}
145137
return ret;
146138
}
147139

148-
uint32_t tud_vendor_n_flush (uint8_t itf)
140+
uint32_t tud_vendor_n_write_flush (uint8_t itf)
149141
{
150142
vendord_interface_t* p_itf = &_vendord_itf[itf];
151-
uint32_t ret = maybe_transmit(p_itf);
152143

153-
return ret;
144+
// Skip if usb is not ready yet
145+
TU_VERIFY( tud_ready(), 0 );
146+
147+
// No data to send
148+
if ( !tu_fifo_count(&p_itf->tx_ff) ) return 0;
149+
150+
uint8_t const rhport = 0;
151+
152+
// Claim the endpoint
153+
TU_VERIFY( usbd_edpt_claim(rhport, p_itf->ep_in), 0 );
154+
155+
// Pull data from FIFO
156+
uint16_t const count = tu_fifo_read_n(&p_itf->tx_ff, p_itf->epin_buf, sizeof(p_itf->epin_buf));
157+
158+
if ( count )
159+
{
160+
TU_ASSERT( usbd_edpt_xfer(rhport, p_itf->ep_in, p_itf->epin_buf, count), 0 );
161+
return count;
162+
}else
163+
{
164+
// Release endpoint since we don't make any transfer
165+
// Note: data is dropped if terminal is not connected
166+
usbd_edpt_release(rhport, p_itf->ep_in);
167+
return 0;
168+
}
154169
}
155170

156171
uint32_t tud_vendor_n_write_available (uint8_t itf)
@@ -230,10 +245,10 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, ui
230245
// Prepare for incoming data
231246
if ( p_vendor->ep_out )
232247
{
233-
TU_ASSERT(usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)), 0);
248+
_prep_out_transaction(p_vendor);
234249
}
235250

236-
if ( p_vendor->ep_in ) maybe_transmit(p_vendor);
251+
if ( p_vendor->ep_in ) tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
237252
}
238253

239254
return (uint16_t) ((uintptr_t) p_desc - (uintptr_t) desc_itf);
@@ -268,7 +283,7 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
268283
{
269284
if (tud_vendor_tx_cb) tud_vendor_tx_cb(itf, (uint16_t) xferred_bytes);
270285
// Send complete, try to send more if possible
271-
maybe_transmit(p_itf);
286+
tud_vendor_n_write_flush(itf);
272287
}
273288

274289
return true;

src/class/vendor/vendor_device.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ bool tud_vendor_n_peek (uint8_t itf, uint8_t* ui8);
4848
void tud_vendor_n_read_flush (uint8_t itf);
4949

5050
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
51+
uint32_t tud_vendor_n_write_flush (uint8_t itf);
5152
uint32_t tud_vendor_n_write_available (uint8_t itf);
5253

5354
static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
54-
uint32_t tud_vendor_n_flush (uint8_t itf);
55+
56+
// backward compatible
57+
#define tud_vendor_n_flush(itf) tud_vendor_n_write_flush(itf)
5558

5659
//--------------------------------------------------------------------+
5760
// Application API (Single Port)
@@ -64,7 +67,10 @@ static inline void tud_vendor_read_flush (void);
6467
static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize);
6568
static inline uint32_t tud_vendor_write_str (char const* str);
6669
static inline uint32_t tud_vendor_write_available (void);
67-
static inline uint32_t tud_vendor_flush (void);
70+
static inline uint32_t tud_vendor_write_flush (void);
71+
72+
// backward compatible
73+
#define tud_vendor_flush() tud_vendor_write_flush()
6874

6975
//--------------------------------------------------------------------+
7076
// Application Callback API (weak is optional)
@@ -114,6 +120,11 @@ static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize)
114120
return tud_vendor_n_write(0, buffer, bufsize);
115121
}
116122

123+
static inline uint32_t tud_vendor_write_flush (void)
124+
{
125+
return tud_vendor_n_write_flush(0);
126+
}
127+
117128
static inline uint32_t tud_vendor_write_str (char const* str)
118129
{
119130
return tud_vendor_n_write_str(0, str);
@@ -124,11 +135,6 @@ static inline uint32_t tud_vendor_write_available (void)
124135
return tud_vendor_n_write_available(0);
125136
}
126137

127-
static inline uint32_t tud_vendor_flush (void)
128-
{
129-
return tud_vendor_n_flush(0);
130-
}
131-
132138
//--------------------------------------------------------------------+
133139
// Internal Class Driver API
134140
//--------------------------------------------------------------------+

src/common/tusb_mcu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@
229229
#define TUP_USBIP_DWC2_STM32
230230
#define TUP_DCD_ENDPOINT_MAX 6
231231

232+
#elif TU_CHECK_MCU(OPT_MCU_STM32L5)
233+
#define TUP_USBIP_FSDEV
234+
#define TUP_USBIP_FSDEV_STM32
235+
#define TUP_DCD_ENDPOINT_MAX 8
236+
237+
232238
//--------------------------------------------------------------------+
233239
// Sony
234240
//--------------------------------------------------------------------+

src/tusb_option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#define OPT_MCU_STM32G4 311 ///< ST G4
8383
#define OPT_MCU_STM32WB 312 ///< ST WB
8484
#define OPT_MCU_STM32U5 313 ///< ST U5
85+
#define OPT_MCU_STM32L5 314 ///< ST L5
8586

8687
// Sony
8788
#define OPT_MCU_CXD56 400 ///< SONY CXD56

0 commit comments

Comments
 (0)