<?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>i.MX ProcessorsのトピックRe: How to properly process incoming data in a USB MSC disk application?</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1677612#M208261</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/193031"&gt;@andyteufel&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can refer to this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="https://community.arm.com/support-forums/f/keil-forum/26317/usb-mass-storage-high-latency-memory" target="_blank"&gt;https://community.arm.com/support-forums/f/keil-forum/26317/usb-mass-storage-high-latency-memory&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I think if it is not to long to wait other device to ready, you can delay the response.&lt;/P&gt;
&lt;P&gt;Or you can send stall to let host delay and then unstall to let host recover. Please see the USB_DeviceStallEndpoint() and&amp;nbsp;USB_DeviceUnstallEndpoint(). Set&amp;nbsp;mscHandle-&amp;gt;needOutStallFlag=1 in&amp;nbsp;kUSB_DeviceMscEventModeSelectResponse to send stall to host.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jing&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jun 2023 07:27:37 GMT</pubDate>
    <dc:creator>jingpan</dc:creator>
    <dc:date>2023-06-28T07:27:37Z</dc:date>
    <item>
      <title>How to properly process incoming data in a USB MSC disk application?</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1671092#M207724</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm developing a USB MSC disk application for a board based on an RT1010.&lt;/P&gt;&lt;P&gt;I have the following working:&lt;BR /&gt;- I receive a `&lt;SPAN&gt;kUSB_DeviceMscEventWriteRequest` event which sets up a buffer for the USB stack to fill.&lt;BR /&gt;- I receive a `&lt;/SPAN&gt;&lt;SPAN&gt;kUSB_DeviceMscEventWriteResponse` which contains the data received via USB.&lt;BR /&gt;- In the same place while handling the MSC event in `&lt;/SPAN&gt;&lt;SPAN&gt;USB_DeviceMscCallback()`, I pass the buffer to a function that handles the received data. That data could end up being sent via UART, written to Flash memory, etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The problem I have is that all of this is executed from `&lt;SPAN&gt;USB_DeviceMscCallback()` which is called from an interrupt context. What I want to do is buffer the received data in a queue, and process it later in a thread context.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I found an&amp;nbsp;&lt;A href="https://github.com/nxp-mcuxpresso/mcux-sdk-examples/blob/main/evkmimxrt595/usb_examples/usb_device_msc_disk/freertos/disk.c" target="_self"&gt;example project&lt;/A&gt;&amp;nbsp;that seems to show what I'm looking for, but I don't understand how it works.&lt;/P&gt;&lt;P&gt;It looks like the example application changes something so that `&lt;SPAN&gt;USB_DeviceMscCallback()` is no longer called from an interrupt context, but from a thread context.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The application calls `xQueueReceive()`, not `xQueueReceiveFromISR()` when handling&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;A href="https://github.com/nxp-mcuxpresso/mcux-sdk-examples/blob/d6a984ad0c304cd19f2ca36f08e73ba2800ee21e/evkmimxrt595/usb_examples/usb_device_msc_disk/freertos/disk.c#L288" target="_self"&gt;`kUSB_DeviceMscEventWriteRequest`&lt;/A&gt;&amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How does the application make this work?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;EDIT: another question would be: is it okay to make a blocking call to `xQueueReceiveFromISR()` in the USB interrupt context? Or what is the right way to handle write requests when my application doesn't have enough resources to buffer the incoming data?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 12:02:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1671092#M207724</guid>
      <dc:creator>andyteufel</dc:creator>
      <dc:date>2023-06-16T12:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly process incoming data in a USB MSC disk application?</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1672645#M207865</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/193031"&gt;@andyteufel&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;But the RT1010&amp;nbsp;&lt;SPAN&gt;USB MSC disk application also deal data in thread.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jingpan_1-1687255766950.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/228520i6B605C87C4261A93/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jingpan_1-1687255766950.png" alt="jingpan_1-1687255766950.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The ISR routine only check what the interrupt event is and then send message to USB stack thread.&lt;/P&gt;
&lt;P&gt;You can download RT685 SDK from MCUXpresso.nxp.com and review the&amp;nbsp;usb_device_msc_disk project.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jing&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 10:11:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1672645#M207865</guid>
      <dc:creator>jingpan</dc:creator>
      <dc:date>2023-06-20T10:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly process incoming data in a USB MSC disk application?</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1672684#M207871</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;EM&gt;The ISR routine only check what the interrupt event is and then send message to USB stack thread.&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It's the message sending I have an issue with. As you point out, on `USBDeviceMscRecv()`, the MSC class callback gets called to handle the&amp;nbsp;&lt;A href="https://github.com/nxp-mcuxpresso/mcux-sdk-examples/blob/d6a984ad0c304cd19f2ca36f08e73ba2800ee21e/evkmimxrt595/usb_examples/usb_device_msc_disk/freertos/usb_device_msc.c#L1449" target="_self"&gt;kUSB_DeviceMscEventWriteRequest&lt;/A&gt;&amp;nbsp;event.&lt;/P&gt;&lt;P&gt;Then `&lt;SPAN&gt;xQueueReceive()` is called there, from an interrupt context, blocking until the queue has a buffer available.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My questions are:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Why `xQueueReceive()` and not `xQueueReceiveFromISR()`? In the screenshot you posted you can clearly see in the call stack that the first function is `USBDeviceEhciIsrFunction()`.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How is the application affected if the queue blocks the execution of the interrupt?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I handle the case where my application is not returning the buffers to the queue fast enough so that `xQueueReceive()` returns a buffer immediately?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for your help. I hope my questions are understandable.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 11:04:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1672684#M207871</guid>
      <dc:creator>andyteufel</dc:creator>
      <dc:date>2023-06-20T11:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly process incoming data in a USB MSC disk application?</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1673185#M207908</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/193031"&gt;@andyteufel&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Yes, it's different. You can see related code in&amp;nbsp;USB_DeviceNotificationTrigger().&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jingpan_1-1687318271748.png" style="width: 500px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/228653i2FCC1ABD98B4CA59/image-dimensions/500x153?v=v2" width="500" height="153" role="button" title="jingpan_1-1687318271748.png" alt="jingpan_1-1687318271748.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;USB_DEVICE_CONFIG_USE_TASK is only enabled in FreeRTOS project.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 03:35:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1673185#M207908</guid>
      <dc:creator>jingpan</dc:creator>
      <dc:date>2023-06-21T03:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly process incoming data in a USB MSC disk application?</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1673436#M207940</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/61241"&gt;@jingpan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Sorry, but I don't understand your reply. It seems you're talking about something completely different or I'm missing the point. What's different?&lt;/P&gt;&lt;P&gt;I understand how the `&lt;SPAN&gt;USB_DEVICE_CONFIG_USE_TASK` definition works, I have no questions about that.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 08:24:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1673436#M207940</guid>
      <dc:creator>andyteufel</dc:creator>
      <dc:date>2023-06-21T08:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly process incoming data in a USB MSC disk application?</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1675534#M208098</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/193031"&gt;@andyteufel&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why `xQueueReceive()` and not `xQueueReceiveFromISR()`? In the screenshot you posted you can clearly see in the call stack that the first function is `USBDeviceEhciIsrFunction()`.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A: You can see it's up to the RTOS.&amp;nbsp;xQueueReceiveFromISR() is used in ISR routine. But here queue is received in thread.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jingpan_0-1687745220956.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/229174iA61C0EA3962D03FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jingpan_0-1687745220956.png" alt="jingpan_0-1687745220956.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How is the application affected if the queue blocks the execution of the interrupt?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A:&amp;nbsp;xQueueReceive() is blocked in thread, not interrupt.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How can I handle the case where my application is not returning the buffers to the queue fast enough so that `xQueueReceive()` returns a buffer immediately?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A:&amp;nbsp; Enlarge the buffer or give higher priority to this thread.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jing&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 02:08:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1675534#M208098</guid>
      <dc:creator>jingpan</dc:creator>
      <dc:date>2023-06-26T02:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly process incoming data in a USB MSC disk application?</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1676050#M208152</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/61241"&gt;@jingpan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I figured out the thread/interrupt issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I just have a question regarding this:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;How can I handle the case where my application is not returning the buffers to the queue fast enough so that `xQueueReceive()` returns a buffer immediately?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A:&amp;nbsp; Enlarge the buffer or give higher priority to this thread.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;In my case this is not enough. My application forwards the received data to another component and it has to be sent synchronously, i.e. I can only send more data to the other component until it tells me it can receive more data.&lt;/P&gt;&lt;P&gt;So what I need is to somehow indicate the USB host that I can't handle more data at the moment and to retry later. Is something like this possible somehow?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 12:56:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1676050#M208152</guid>
      <dc:creator>andyteufel</dc:creator>
      <dc:date>2023-06-26T12:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly process incoming data in a USB MSC disk application?</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1677612#M208261</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/193031"&gt;@andyteufel&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can refer to this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="https://community.arm.com/support-forums/f/keil-forum/26317/usb-mass-storage-high-latency-memory" target="_blank"&gt;https://community.arm.com/support-forums/f/keil-forum/26317/usb-mass-storage-high-latency-memory&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I think if it is not to long to wait other device to ready, you can delay the response.&lt;/P&gt;
&lt;P&gt;Or you can send stall to let host delay and then unstall to let host recover. Please see the USB_DeviceStallEndpoint() and&amp;nbsp;USB_DeviceUnstallEndpoint(). Set&amp;nbsp;mscHandle-&amp;gt;needOutStallFlag=1 in&amp;nbsp;kUSB_DeviceMscEventModeSelectResponse to send stall to host.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Jing&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2023 07:27:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/How-to-properly-process-incoming-data-in-a-USB-MSC-disk/m-p/1677612#M208261</guid>
      <dc:creator>jingpan</dc:creator>
      <dc:date>2023-06-28T07:27:37Z</dc:date>
    </item>
  </channel>
</rss>

