mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-16 05:42:56 +00:00
dcd_da146xx: Drop unexpected data
USB3CV tool verifies MSC device by sending too short or too long packets. In case of too long packets (msc_device requested 31 bytes but incoming data had 32 bytes) extra byte(s) were left in FIFO resulting in some data mismatch later on. Now if more data is received in packet that expected extra bytes are just dropped.
This commit is contained in:
parent
49aa0b72a8
commit
bf4b133084
@ -368,8 +368,8 @@ static void start_rx_packet(xfer_ctl_t *xfer)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Other endpoint is using DMA in that direction, fall back to interrupts.
|
// Other endpoint is using DMA in that direction, fall back to interrupts.
|
||||||
// For endpoint size greater then FIFO size enable FIFO level warning interrupt
|
// For endpoint size greater than FIFO size enable FIFO level warning interrupt
|
||||||
// when FIFO has less then 17 bytes free.
|
// when FIFO has less than 17 bytes free.
|
||||||
regs->rxc |= USB_USB_RXC1_REG_USB_RFWL_Msk;
|
regs->rxc |= USB_USB_RXC1_REG_USB_RFWL_Msk;
|
||||||
USB->USB_FWMSK_REG |= 1 << (epnum - 1 + USB_USB_FWMSK_REG_USB_M_RXWARN31_Pos);
|
USB->USB_FWMSK_REG |= 1 << (epnum - 1 + USB_USB_FWMSK_REG_USB_M_RXWARN31_Pos);
|
||||||
}
|
}
|
||||||
@ -420,7 +420,7 @@ static void start_tx_packet(xfer_ctl_t *xfer)
|
|||||||
regs->txc |= USB_USB_TXC1_REG_USB_TX_EN_Msk;
|
regs->txc |= USB_USB_TXC1_REG_USB_TX_EN_Msk;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_rx_fifo(xfer_ctl_t *xfer, uint16_t bytes_in_fifo)
|
static uint16_t read_rx_fifo(xfer_ctl_t *xfer, uint16_t bytes_in_fifo)
|
||||||
{
|
{
|
||||||
EPx_REGS *regs = XFER_REGS(xfer);
|
EPx_REGS *regs = XFER_REGS(xfer);
|
||||||
uint16_t remaining = xfer->total_len - xfer->transferred - xfer->last_packet_size;
|
uint16_t remaining = xfer->total_len - xfer->transferred - xfer->last_packet_size;
|
||||||
@ -433,6 +433,8 @@ static void read_rx_fifo(xfer_ctl_t *xfer, uint16_t bytes_in_fifo)
|
|||||||
for (int i = 0; i < receive_this_time; ++i) buf[i] = regs->rxd;
|
for (int i = 0; i < receive_this_time; ++i) buf[i] = regs->rxd;
|
||||||
|
|
||||||
xfer->last_packet_size += receive_this_time;
|
xfer->last_packet_size += receive_this_time;
|
||||||
|
|
||||||
|
return bytes_in_fifo - receive_this_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_ep0_rx(void)
|
static void handle_ep0_rx(void)
|
||||||
@ -562,7 +564,7 @@ static void handle_epx_rx_ev(uint8_t ep)
|
|||||||
// FIFO maybe empty if DMA read it before or it's final iteration and function already read all that was to read.
|
// FIFO maybe empty if DMA read it before or it's final iteration and function already read all that was to read.
|
||||||
if (fifo_bytes > 0)
|
if (fifo_bytes > 0)
|
||||||
{
|
{
|
||||||
read_rx_fifo(xfer, fifo_bytes);
|
fifo_bytes = read_rx_fifo(xfer, fifo_bytes);
|
||||||
}
|
}
|
||||||
if (GET_BIT(rxs, USB_USB_RXS1_REG_USB_RX_LAST))
|
if (GET_BIT(rxs, USB_USB_RXS1_REG_USB_RX_LAST))
|
||||||
{
|
{
|
||||||
@ -577,6 +579,13 @@ static void handle_epx_rx_ev(uint8_t ep)
|
|||||||
xfer->transferred += xfer->last_packet_size;
|
xfer->transferred += xfer->last_packet_size;
|
||||||
if (xfer->total_len == xfer->transferred || xfer->last_packet_size < xfer->max_packet_size || xfer->iso)
|
if (xfer->total_len == xfer->transferred || xfer->last_packet_size < xfer->max_packet_size || xfer->iso)
|
||||||
{
|
{
|
||||||
|
if (fifo_bytes)
|
||||||
|
{
|
||||||
|
// There are extra bytes in the FIFO just flush them
|
||||||
|
regs->rxc |= USB_USB_RXC1_REG_USB_FLUSH_Msk;
|
||||||
|
fifo_bytes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
dcd_event_xfer_complete(0, xfer->ep_addr, xfer->transferred, XFER_RESULT_SUCCESS, true);
|
dcd_event_xfer_complete(0, xfer->ep_addr, xfer->transferred, XFER_RESULT_SUCCESS, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user