Skip to content

Commit 239b5d5

Browse files
committed
USBTMC: Manually stall and unstall EP when clear(ENDPOINT_HALT) is received.
1 parent 3d4d373 commit 239b5d5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/class/usbtmc/usbtmc_device.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,18 +597,31 @@ bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
597597
{
598598
uint32_t ep_addr = (request->wIndex);
599599

600+
// At this point, a transfer MAY be in progress. Based on USB spec, when clearing bulk EP HALT,
601+
// the EP transfer buffer needs to be cleared and DTOG needs to be reset, even if
602+
// the EP is not halted. The only USBD API interface to do this is to stall and then unstall the EP.
600603
if(ep_addr == usbtmc_state.ep_bulk_out)
601604
{
602605
criticalEnter();
606+
usbd_edpt_stall(rhport, ep_addr);
607+
usbd_edpt_clear_stall(rhport, ep_addr);
603608
usbtmc_state.state = STATE_NAK; // USBD core has placed EP in NAK state for us
604609
criticalLeave();
605610
tud_usbtmc_bulkOut_clearFeature_cb();
606611
}
607612
else if (ep_addr == usbtmc_state.ep_bulk_in)
608613
{
614+
usbd_edpt_stall(rhport, ep_addr);
615+
usbd_edpt_clear_stall(rhport, ep_addr);
609616
tud_usbtmc_bulkIn_clearFeature_cb();
610617
}
611-
else
618+
else if ((usbtmc_state.ep_int_in != 0) && (ep_addr == usbtmc_state.ep_int_in))
619+
{
620+
// Clearing interrupt in EP
621+
usbd_edpt_stall(rhport, ep_addr);
622+
usbd_edpt_clear_stall(rhport, ep_addr);
623+
}
624+
else
612625
{
613626
return false;
614627
}
@@ -836,6 +849,7 @@ bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
836849
},
837850
.StatusByte = tud_usbtmc_get_stb_cb(&(rsp.USBTMC_status))
838851
};
852+
// USB488 spec states that transfer must be queued before control request response sent.
839853
usbd_edpt_xfer(rhport, usbtmc_state.ep_int_in, (void*)&intMsg, sizeof(intMsg));
840854
}
841855
else

0 commit comments

Comments
 (0)