<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: USB device transfer freezes in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878447#M52166</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You mention 'running for hours' and setting and clearing flags.&lt;BR /&gt;This has all the classic signs of a race condition in the flag handling.&lt;BR /&gt;&lt;BR /&gt;Is the flag marked volatile?&lt;/P&gt;&lt;P&gt;Is it set in the IRQ and cleared outside of the IRQ (or other way around)?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Apr 2019 13:25:44 GMT</pubDate>
    <dc:creator>bobpaddock</dc:creator>
    <dc:date>2019-04-05T13:25:44Z</dc:date>
    <item>
      <title>USB device transfer freezes</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878443#M52162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;my USB composite device:&lt;/P&gt;&lt;P&gt;- generic HID&lt;/P&gt;&lt;P&gt;- virtual COM&lt;/P&gt;&lt;P&gt;-&amp;nbsp;custom class with interrupt IN, interrupt OUT and bulk IN endpoint&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;runs on MK22FN512VLL12. I use USB stack from SDK 2.1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The device communicates with host for several hours but then suddenly I get one of my custom class'es IN endpoints frozen in transfer state. For this frozen endpoint, endpoint state structure (in s_UsbDeviceKhciState structure) contains e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;transferLength = 0x11&lt;/P&gt;&lt;P&gt;tranferDone = 0x00&lt;/P&gt;&lt;P&gt;state = 0x4040&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It means that the endpoint is in transfer state waiting for host to read the data from the device.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My USB host (libusb library on Win 10) tries to read the data. However, the read function (libusb_interrupt_transfer or libusb_bulk_transfer) always timeouts with no data read. The&amp;nbsp;USB_DeviceKhciIsrFunction is not executed when the transfer is initiated by the host.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is no issue with data transfers from the host to the device on interrupt OUT endpoint, these always work, even when IN tranfers are frozen as described above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To send data from the device to the host using interrupt IN or bulk IN endpoint I use&amp;nbsp;USB_DeviceSendRequest() function. If this call succeeds I set my internal flag indicating that the transfer is in progress. Once callback function of the endpoint is called I clear the flag. I initiate next transfer only when the flag is cleared.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please recommend how to troubleshoot this issue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2019 20:05:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878443#M52162</guid>
      <dc:creator>dusek_martin</dc:creator>
      <dc:date>2019-04-03T20:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: USB device transfer freezes</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878444#M52163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Martin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We do not recommend you to use SDK 2.1. Could you please try using our latest SDK version (2.5.0).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can download it from the following link:&lt;/P&gt;&lt;P&gt;&lt;A href="https://mcuxpresso.nxp.com/en/welcome"&gt;https://mcuxpresso.nxp.com/en/welcome&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Felipe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Apr 2019 23:19:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878444#M52163</guid>
      <dc:creator>FelipeGarcia</dc:creator>
      <dc:date>2019-04-04T23:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: USB device transfer freezes</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878445#M52164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Felipe,&lt;/P&gt;&lt;P&gt;unfortunately, my app built with SDK2.5 has exactly same issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2019 08:46:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878445#M52164</guid>
      <dc:creator>dusek_martin</dc:creator>
      <dc:date>2019-04-05T08:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: USB device transfer freezes</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878446#M52165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is my usb&amp;nbsp;communication when the communication freezes. Host wants to read data from endpoint 4 (that is interrupt in endpoint) but the transaction ends with NAK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="endpoint.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/79081i7175C12C0884409E/image-size/large?v=v2&amp;amp;px=999" role="button" title="endpoint.png" alt="endpoint.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;At the same time, this is the state of endpoint 4:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="endpointstate.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/79119i429872BF57E58AC1/image-size/large?v=v2&amp;amp;px=999" role="button" title="endpointstate.png" alt="endpointstate.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(endpointState[0] has also always tranferring = 1, all other endpoints has transferring = 0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, no there are no USB interrupts at that time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2019 11:13:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878446#M52165</guid>
      <dc:creator>dusek_martin</dc:creator>
      <dc:date>2019-04-05T11:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: USB device transfer freezes</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878447#M52166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You mention 'running for hours' and setting and clearing flags.&lt;BR /&gt;This has all the classic signs of a race condition in the flag handling.&lt;BR /&gt;&lt;BR /&gt;Is the flag marked volatile?&lt;/P&gt;&lt;P&gt;Is it set in the IRQ and cleared outside of the IRQ (or other way around)?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2019 13:25:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878447#M52166</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2019-04-05T13:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: USB device transfer freezes</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878448#M52167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Bob,&lt;/P&gt;&lt;P&gt;thanks. Yes, the flag caused the issue. I had these two lines in my code without disabling interrupts before and enabling them after:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;USB_DeviceSendRequest(...)&lt;/P&gt;&lt;P&gt;busy = 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Quite a surprise for me that that interrupt indicating transfer completion (and clearing busy flag) can happen so quickly, that it happens inside&amp;nbsp;&lt;SPAN&gt;USB_DeviceSendRequest. (CPU runs at 120 MHz, USB is full speed - 12 MHz). I used exactly same construction also in my other project and I never had any issue with that device. But that project was sending 2x - 3x larger packets over USB....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But of course, stupid mistake.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2019 14:06:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878448#M52167</guid>
      <dc:creator>dusek_martin</dc:creator>
      <dc:date>2019-04-05T14:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: USB device transfer freezes</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878449#M52168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My solution to this flag issue is to increment a byte inside the IRQ on an event.&lt;BR /&gt;Then outside the IRQ compare that value to a previous copy to see if the event happened.&lt;/P&gt;&lt;P&gt;Gets rid of the whole set/clear race mess.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2019 17:22:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/USB-device-transfer-freezes/m-p/878449#M52168</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2019-04-05T17:22:16Z</dc:date>
    </item>
  </channel>
</rss>

