summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2020-02-07 22:13:38 +0700
committerhathach <[email protected]>2020-02-07 22:13:38 +0700
commit46f22860fb6eaf0b65469b47b099e20f489b2e47 (patch)
tree2e55bddae8cbb945d57c271c205951755837ca0b /src
parent02b2c602319a55226429582dfd8002c95cc3ff87 (diff)
correct waklaround with only status IN
correct usb descriptor msc dual example to work with samg
Diffstat (limited to 'src')
-rw-r--r--src/portable/microchip/samg/dcd_samg.c67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c
index 53ccba961..882072521 100644
--- a/src/portable/microchip/samg/dcd_samg.c
+++ b/src/portable/microchip/samg/dcd_samg.c
@@ -54,6 +54,7 @@ xfer_desc_t _dcd_xfer[EP_COUNT];
// Indicate that DATA Toggle for Control Status is incorrect, which must always be DATA1 by USB Specs.
// However SAMG DToggle is read-only, therefore we must duplicate the status phase ( D0 then D1 )
// as walk-around to resolve this. The D0 status packet is likely to be discarded by USB Host safely.
+// Note: Only needed for IN Status e.g CDC_SET_LINE_CODING, since out data is sent by host
volatile bool _walkaround_incorrect_dtoggle_control_status;
void xfer_epsize_set(xfer_desc_t* xfer, uint16_t epsize)
@@ -255,46 +256,43 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
xfer_desc_t* xfer = &_dcd_xfer[epnum];
xfer_begin(xfer, buffer, total_bytes);
- // Control Endpoint direction and data toggle
- if (epnum == 0)
+ if (dir == TUSB_DIR_OUT)
{
- // Transfer direction is opposite to one previously set on EP0
- // This transfer is Control Status Stage
- if ( dir != tu_bit_test(UDP->UDP_CSR[epnum], UDP_CSR_DIR_Pos) )
+ // Clear EP0 direction bit
+ if (epnum == 0) UDP->UDP_CSR[epnum] &= ~UDP_CSR_DIR_Msk;
+
+ // Enable interrupt when starting OUT transfer
+ if (epnum != 0) UDP->UDP_IER |= (1 << epnum);
+ }
+ else
+ {
+ if (epnum == 0)
{
- // Set/Clear DIR bit accordingly
- if (dir)
+ // Previous EP0 direction is OUT --> This transfer is ZLP control status.
+ if ( !(UDP->UDP_CSR[epnum] & UDP_CSR_DIR_Msk) )
{
+ // Set EP0 dir bit
UDP->UDP_CSR[epnum] |= UDP_CSR_DIR_Msk;
- }else
- {
- UDP->UDP_CSR[epnum] &= ~UDP_CSR_DIR_Msk;
- }
- // DATA Toggle is 0, USB Specs requires Status Stage must be DATA1
- // Since SAMG DToggle is read-only, we mark this and implement a walk-around
- if ( !(UDP->UDP_CSR[epnum] & UDP_CSR_DTGLE_Msk) )
- {
- TU_LOG2("Incorrect DATA TOGGLE, Control Status must be DATA1\n");
+ // DATA Toggle is 0, USB Specs requires Status Stage must be DATA1
+ // Since SAMG DToggle is read-only, we mark this and implement the walk-around
+ if ( !(UDP->UDP_CSR[epnum] & UDP_CSR_DTGLE_Msk) )
+ {
+ TU_LOG2("Incorrect DATA TOGGLE, Control Status must be DATA1\n");
- // DTGLE is read-only on SAMG, this statement has no effect
- UDP->UDP_CSR[epnum] |= UDP_CSR_DTGLE_Msk;
-
- _walkaround_incorrect_dtoggle_control_status = true;
- }
- }
- }
+ // DTGLE is read-only on SAMG, this statement has no effect
+ UDP->UDP_CSR[epnum] |= UDP_CSR_DTGLE_Msk;
+ // WALKROUND: duplicate IN transfer to send DATA1 status packet
+ // set flag for irq to skip reporting first incorrect packet
+ _walkaround_incorrect_dtoggle_control_status = true;
- if (dir == TUSB_DIR_IN)
- {
- // WALKROUND: duplicate IN transfer to send DATA1 status packet
- if (_walkaround_incorrect_dtoggle_control_status)
- {
- UDP->UDP_CSR[epnum] |= UDP_CSR_TXPKTRDY_Msk;
- while ( UDP->UDP_CSR[epnum] & UDP_CSR_TXPKTRDY_Msk ) {}
+ UDP->UDP_CSR[epnum] |= UDP_CSR_TXPKTRDY_Msk;
+ while ( UDP->UDP_CSR[epnum] & UDP_CSR_TXPKTRDY_Msk ) {}
- _walkaround_incorrect_dtoggle_control_status = false;
+ _walkaround_incorrect_dtoggle_control_status = false;
+ }
+ }
}
xact_ep_write(epnum, xfer->buffer, xfer_packet_len(xfer));
@@ -302,11 +300,6 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
// TX ready for transfer
UDP->UDP_CSR[epnum] |= UDP_CSR_TXPKTRDY_Msk;
}
- else
- {
- // Enable interrupt when starting OUT transfer
- if (epnum != 0) UDP->UDP_IER |= (1 << epnum);
- }
return true;
}
@@ -422,7 +415,7 @@ void dcd_isr(uint8_t rhport)
UDP->UDP_CSR[epnum] |= UDP_CSR_TXPKTRDY_Msk;
}else
{
- // WALKAROUND: Skip reporting this incorrect DATA Toggle status transfer
+ // WALKAROUND: Skip reporting this incorrect DATA Toggle status IN transfer
if ( !(_walkaround_incorrect_dtoggle_control_status && (epnum == 0) && (xfer->actual_len == 0)) )
{
// xfer is complete