Skip to content
This repository was archived by the owner on May 18, 2021. It is now read-only.

Commit c36ecda

Browse files
committed
sync tinyusb to commit 9b9ea8453d3f85db20c7c038e595949c7820173f
1 parent 238a5c0 commit c36ecda

File tree

16 files changed

+79
-33
lines changed

16 files changed

+79
-33
lines changed

Adafruit_USBD_Device.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
399399
// weak callback here to prevent linking error
400400
//--------------------------------------------------------------------+
401401

402-
#if 1
403402
// HID
404403
TU_ATTR_WEAK uint8_t const * tud_hid_descriptor_report_cb(void) { return NULL; }
405404
TU_ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { return 0; }
@@ -412,7 +411,6 @@ TU_ATTR_WEAK void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t
412411
TU_ATTR_WEAK bool tud_msc_test_unit_ready_cb(uint8_t lun) { return false; }
413412
TU_ATTR_WEAK void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size) { }
414413
TU_ATTR_WEAK int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) { return -1; }
415-
#endif
416414

417415
} // extern C
418416

tinyusb/src/class/msc/msc_device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
105105
//--------------------------------------------------------------------+
106106
#if CFG_TUSB_DEBUG >= 2
107107

108-
static lookup_entry_t const _msc_scsi_cmd_lookup[] =
108+
static tu_lookup_entry_t const _msc_scsi_cmd_lookup[] =
109109
{
110110
{ .key = SCSI_CMD_TEST_UNIT_READY , .data = "Test Unit Ready" },
111111
{ .key = SCSI_CMD_INQUIRY , .data = "Inquiry" },
@@ -120,7 +120,7 @@ static lookup_entry_t const _msc_scsi_cmd_lookup[] =
120120
{ .key = SCSI_CMD_WRITE_10 , .data = "Write10" }
121121
};
122122

123-
static lookup_table_t const _msc_scsi_cmd_table =
123+
static tu_lookup_table_t const _msc_scsi_cmd_table =
124124
{
125125
.count = TU_ARRAY_SIZE(_msc_scsi_cmd_lookup),
126126
.items = _msc_scsi_cmd_lookup
@@ -418,7 +418,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
418418
TU_ASSERT( event == XFER_RESULT_SUCCESS &&
419419
xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE );
420420

421-
TU_LOG2(" SCSI Command: %s\r\n", lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
421+
TU_LOG2(" SCSI Command: %s\r\n", tu_lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
422422
// TU_LOG2_MEM(p_cbw, xferred_bytes, 2);
423423

424424
p_csw->signature = MSC_CSW_SIGNATURE;

tinyusb/src/class/net/net_device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request
326326
{
327327
if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
328328
{
329-
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)notify.rndis_buf;
329+
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *) ((void*) notify.rndis_buf);
330330
uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
331331
TU_ASSERT(msglen <= sizeof(notify.rndis_buf));
332332
tud_control_xfer(rhport, request, notify.rndis_buf, msglen);
@@ -356,7 +356,7 @@ static void handle_incoming_packet(uint32_t len)
356356
}
357357
else
358358
{
359-
rndis_data_packet_t *r = (rndis_data_packet_t *)pnt;
359+
rndis_data_packet_t *r = (rndis_data_packet_t *) ((void*) pnt);
360360
if (len >= sizeof(rndis_data_packet_t))
361361
if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
362362
if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
@@ -450,7 +450,7 @@ void tud_network_xmit(struct pbuf *p)
450450

451451
if (!_netd_itf.ecm_mode)
452452
{
453-
rndis_data_packet_t *hdr = (rndis_data_packet_t *)transmitted;
453+
rndis_data_packet_t *hdr = (rndis_data_packet_t *) ((void*) transmitted);
454454
memset(hdr, 0, sizeof(rndis_data_packet_t));
455455
hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
456456
hdr->MessageLength = len;

tinyusb/src/common/tusb_common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,16 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize)
251251
typedef struct
252252
{
253253
uint32_t key;
254-
char const * data;
255-
}lookup_entry_t;
254+
const char* data;
255+
} tu_lookup_entry_t;
256256

257257
typedef struct
258258
{
259259
uint16_t count;
260-
lookup_entry_t const* items;
261-
} lookup_table_t;
260+
tu_lookup_entry_t const* items;
261+
} tu_lookup_table_t;
262262

263-
static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t key)
263+
static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint32_t key)
264264
{
265265
for(uint16_t i=0; i<p_table->count; i++)
266266
{

tinyusb/src/device/usbd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ bool tud_init (void)
339339

340340
// Init device controller driver
341341
dcd_init(TUD_OPT_RHPORT);
342-
tud_connect();
343342
dcd_int_enable(TUD_OPT_RHPORT);
344343

345344
return true;

tinyusb/src/device/usbd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
//--------------------------------------------------------------------+
4343

4444
// Init device stack
45+
// Note: when using with RTOS, this should be called after scheduler/kernel is started.
46+
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
4547
bool tud_init (void);
4648

4749
// Task function should be called in main/rtos loop

tinyusb/src/portable/dialog/da146xx/dcd_da146xx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,10 @@ static void handle_ep0_nak(void)
555555
*------------------------------------------------------------------*/
556556
void dcd_init(uint8_t rhport)
557557
{
558-
(void)rhport;
559-
560558
USB->USB_MCTRL_REG = USB_USB_MCTRL_REG_USBEN_Msk;
561559
tusb_vbus_changed((CRG_TOP->ANA_STATUS_REG & CRG_TOP_ANA_STATUS_REG_VBUS_AVAILABLE_Msk) != 0);
560+
561+
dcd_connect(rhport);
562562
}
563563

564564
void dcd_int_enable(uint8_t rhport)

tinyusb/src/portable/espressif/esp32s2/dcd_esp32s2.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
// FIFO size in bytes
5555
#define EP_FIFO_SIZE 1024
5656

57+
// Max number of IN EP FIFOs
58+
#define EP_FIFO_NUM 5
59+
5760
typedef struct {
5861
uint8_t *buffer;
5962
uint16_t total_len;
@@ -71,6 +74,16 @@ static uint32_t _setup_packet[2];
7174
#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
7275
static xfer_ctl_t xfer_status[EP_MAX][2];
7376

77+
// Keep count of how many FIFOs are in use
78+
static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
79+
80+
// Will either return an unused FIFO number, or 0 if all are used.
81+
static uint8_t get_free_fifo(void)
82+
{
83+
if (_allocated_fifos < EP_FIFO_NUM) return _allocated_fifos++;
84+
return 0;
85+
}
86+
7487
// Setup the control endpoint 0.
7588
static void bus_reset(void)
7689
{
@@ -152,8 +165,6 @@ static void enum_done_processing(void)
152165
*------------------------------------------------------------------*/
153166
void dcd_init(uint8_t rhport)
154167
{
155-
(void)rhport;
156-
157168
ESP_LOGV(TAG, "DCD init - Start");
158169

159170
// A. Disconnect
@@ -191,6 +202,8 @@ void dcd_init(uint8_t rhport)
191202
USB_ENUMDONEMSK_M |
192203
USB_RESETDETMSK_M |
193204
USB_DISCONNINTMSK_M; // host most only
205+
206+
dcd_connect(rhport);
194207
}
195208

196209
void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
@@ -271,8 +284,12 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
271284
// - Offset: GRXFSIZ + 16 + Size*(epnum-1)
272285
// - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
273286

287+
uint8_t fifo_num = get_free_fifo();
288+
TU_ASSERT(fifo_num != 0);
289+
290+
in_ep[epnum].diepctl &= ~(USB_D_TXFNUM1_M | USB_D_EPTYPE1_M | USB_DI_SETD0PID1 | USB_D_MPS1_M);
274291
in_ep[epnum].diepctl |= USB_D_USBACTEP1_M |
275-
epnum << USB_D_TXFNUM1_S |
292+
fifo_num << USB_D_TXFNUM1_S |
276293
desc_edpt->bmAttributes.xfer << USB_D_EPTYPE1_S |
277294
(desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? (1 << USB_DI_SETD0PID1_S) : 0) |
278295
desc_edpt->wMaxPacketSize.size << 0;
@@ -282,8 +299,8 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
282299
// Both TXFD and TXSA are in unit of 32-bit words.
283300
// IN FIFO 0 was configured during enumeration, hence the "+ 16".
284301
uint16_t const allocated_size = (USB0.grxfsiz & 0x0000ffff) + 16;
285-
uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_MAX-1);
286-
uint32_t const fifo_offset = allocated_size + fifo_size*(epnum-1);
302+
uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_FIFO_NUM-1);
303+
uint32_t const fifo_offset = allocated_size + fifo_size*(fifo_num-1);
287304

288305
// DIEPTXF starts at FIFO #1.
289306
USB0.dieptxf[epnum - 1] = (fifo_size << USB_NPTXFDEP_S) | fifo_offset;
@@ -361,7 +378,8 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
361378
}
362379

363380
// Flush the FIFO, and wait until we have confirmed it cleared.
364-
USB0.grstctl |= ((epnum - 1) << USB_TXFNUM_S);
381+
uint8_t const fifo_num = ((in_ep[epnum].diepctl >> USB_D_TXFNUM1_S) & USB_D_TXFNUM1_V);
382+
USB0.grstctl |= (fifo_num << USB_TXFNUM_S);
365383
USB0.grstctl |= USB_TXFFLSH_M;
366384
while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
367385
} else {
@@ -660,6 +678,8 @@ static void _dcd_int_handler(void* arg)
660678
// start of reset
661679
ESP_EARLY_LOGV(TAG, "dcd_int_handler - reset");
662680
USB0.gintsts = USB_USBRST_M;
681+
// FIFOs will be reassigned when the endpoints are reopen
682+
_allocated_fifos = 1;
663683
bus_reset();
664684
}
665685

tinyusb/src/portable/microchip/samg/dcd_samg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@ static void bus_reset(void)
154154
// Initialize controller to device mode
155155
void dcd_init (uint8_t rhport)
156156
{
157-
(void) rhport;
158-
159157
tu_memclr(_dcd_xfer, sizeof(_dcd_xfer));
158+
dcd_connect(rhport);
160159
}
161160

162161
// Enable device interrupt

tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ void dcd_disconnect(uint8_t rhport)
271271
{
272272
(void) rhport;
273273
NRF_USBD->USBPULLUP = 0;
274+
275+
// Disable Pull-up does not trigger Power USB Removed, in fact it have no
276+
// impact on the USB Power status at all -> need to submit unplugged event to the stack.
277+
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, false);
274278
}
275279

276280
// connect by enabling internal pull-up resistor on D+/D-
@@ -693,6 +697,8 @@ void tusb_hal_nrf_power_event (uint32_t event)
693697
switch ( event )
694698
{
695699
case USB_EVT_DETECTED:
700+
TU_LOG2("Power USB Detect\r\n");
701+
696702
if ( !NRF_USBD->ENABLE )
697703
{
698704
/* Prepare for READY event receiving */
@@ -743,6 +749,12 @@ void tusb_hal_nrf_power_event (uint32_t event)
743749
break;
744750

745751
case USB_EVT_READY:
752+
TU_LOG2("Power USB Ready\r\n");
753+
754+
// Skip if pull-up is enabled and HCLK is already running.
755+
// Application probably call this more than necessary.
756+
if ( NRF_USBD->USBPULLUP && hfclk_running() ) break;
757+
746758
/* Waiting for USBD peripheral enabled */
747759
while ( !(USBD_EVENTCAUSE_READY_Msk & NRF_USBD->EVENTCAUSE) ) { }
748760

@@ -810,6 +822,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
810822
break;
811823

812824
case USB_EVT_REMOVED:
825+
TU_LOG2("Power USB Removed\r\n");
813826
if ( NRF_USBD->ENABLE )
814827
{
815828
// Abort all transfers
@@ -829,7 +842,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
829842

830843
hfclk_disable();
831844

832-
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true);
845+
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? true : false);
833846
}
834847
break;
835848

tinyusb/src/portable/nxp/lpc17_40/dcd_lpc17_40.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ void dcd_init(uint8_t rhport)
181181
LPC_USB->UDCAH = (uint32_t) _dcd.udca;
182182
LPC_USB->DMAIntEn = (DMA_INT_END_OF_XFER_MASK /*| DMA_INT_NEW_DD_REQUEST_MASK*/ | DMA_INT_ERROR_MASK);
183183

184+
dcd_connect(rhport);
185+
184186
// Clear pending IRQ
185187
NVIC_ClearPendingIRQ(USB_IRQn);
186188
}

tinyusb/src/portable/nxp/transdimension/dcd_transdimension.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ void dcd_init(uint8_t rhport)
345345
dcd_reg->USBSTS = dcd_reg->USBSTS;
346346
dcd_reg->USBINTR = INTR_USB | INTR_ERROR | INTR_PORT_CHANGE | INTR_RESET | INTR_SUSPEND /*| INTR_SOF*/;
347347

348-
dcd_reg->USBCMD &= ~0x00FF0000; // Interrupt Threshold Interval = 0
348+
dcd_reg->USBCMD &= ~0x00FF0000; // Interrupt Threshold Interval = 0
349+
dcd_reg->USBCMD |= USBCMD_RUN_STOP; // Connect
349350
}
350351

351352
void dcd_int_enable(uint8_t rhport)

tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ static inline void reg16_clear_bits(__IO uint16_t *reg, uint16_t mask) {
205205

206206
void dcd_init (uint8_t rhport)
207207
{
208-
(void)rhport;
209208
/* Clocks should already be enabled */
210209
/* Use __HAL_RCC_USB_CLK_ENABLE(); to enable the clocks before calling this function */
211210

@@ -244,7 +243,8 @@ void dcd_init (uint8_t rhport)
244243
USB->CNTR |= USB_CNTR_RESETM | (USE_SOF ? USB_CNTR_SOFM : 0) | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
245244
dcd_handle_bus_reset();
246245

247-
// Data-line pull-up is left disconnected.
246+
// Enable pull-up if supported
247+
if ( dcd_connect ) dcd_connect(rhport);
248248
}
249249

250250
// Define only on MCU with internal pull-up. BSP can define on MCU without internal PU.

tinyusb/src/portable/st/synopsys/dcd_synopsys.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static void bus_reset(uint8_t rhport)
231231
}
232232

233233
// Set turn-around timeout according to link speed
234+
extern uint32_t SystemCoreClock;
234235
static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
235236
{
236237
usb_otg->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
@@ -243,7 +244,6 @@ static void set_turnaround(USB_OTG_GlobalTypeDef * usb_otg, tusb_speed_t speed)
243244
else
244245
{
245246
// Turnaround timeout depends on the MCU clock
246-
extern uint32_t SystemCoreClock;
247247
uint32_t turnaround;
248248

249249
if ( SystemCoreClock >= 32000000U )
@@ -453,6 +453,8 @@ void dcd_init (uint8_t rhport)
453453

454454
// Enable global interrupt
455455
usb_otg->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
456+
457+
dcd_connect(rhport);
456458
}
457459

458460
void dcd_int_enable (uint8_t rhport)
@@ -514,8 +516,14 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
514516

515517
TU_ASSERT(epnum < EP_MAX);
516518

517-
// TODO ISO endpoint can be up to 1024 bytes
518-
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 512 : 64));
519+
if (desc_edpt->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS)
520+
{
521+
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 1024 : 1023));
522+
}
523+
else
524+
{
525+
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= (get_speed(rhport) == TUSB_SPEED_HIGH ? 512 : 64));
526+
}
519527

520528
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
521529
xfer->max_size = desc_edpt->wMaxPacketSize.size;

tinyusb/src/portable/ti/msp430x5xx/dcd_msp430x5xx.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ typedef enum
7070
SIZXY = 7
7171
} ep_regs_index_t;
7272

73-
#define EP_REGS(epnum, dir) &USBOEPCNF_1 + 64*dir + 8*(epnum - 1)
74-
73+
#define EP_REGS(epnum, dir) ((ep_regs_t) ((uintptr_t)&USBOEPCNF_1 + 64*dir + 8*(epnum - 1)))
7574

7675
static void bus_reset(void)
7776
{
@@ -134,6 +133,9 @@ void dcd_init (uint8_t rhport)
134133
// Enable reset and wait for it before continuing.
135134
USBIE |= RSTRIE;
136135

136+
// Enable pullup.
137+
USBCNF |= PUR_EN;
138+
137139
USBKEYPID = 0;
138140
}
139141

tinyusb/src/tusb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
* @{ */
110110

111111
// Initialize device/host stack
112+
// Note: when using with RTOS, this should be called after scheduler/kernel is started.
113+
// Otherwise it could cause kernel issue since USB IRQ handler does use RTOS queue API.
112114
bool tusb_init(void);
113115

114116
// Check if stack is initialized

0 commit comments

Comments
 (0)