From 664d2c32c5d6a2833357efe0b2ca37e49aa1d141 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Tue, 20 Mar 2018 16:39:12 -0500 Subject: [PATCH] Disable endpoints when disconnecting on Kinetis Even thought the USB phy is disabled during disconnect, endpoints still nack packets sent. This patch disables all endpoints so after disconnect no USB traffic will be sent. This allows brief disconnects of ~200us (or more) to be reliably detected by the host PC. --- targets/TARGET_Freescale/usb/USBPhy_Kinetis.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/targets/TARGET_Freescale/usb/USBPhy_Kinetis.cpp b/targets/TARGET_Freescale/usb/USBPhy_Kinetis.cpp index 60ad7d7f1f..84c50d94b6 100644 --- a/targets/TARGET_Freescale/usb/USBPhy_Kinetis.cpp +++ b/targets/TARGET_Freescale/usb/USBPhy_Kinetis.cpp @@ -195,6 +195,10 @@ void USBPhyHw::connect() void USBPhyHw::disconnect() { + // disable all endpoints to prevent them from nacking when disconnected + for(int i = 0; i < 16; i++) { + USB0->ENDPOINT[i].ENDPT = 0x00; + } // disable USB USB0->CTL &= ~USB_CTL_USBENSOFEN_MASK; // Pull up disable