<?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>Kinetis MicrocontrollersのトピックRe: SDK: Adding a Read/Write Interface for the USB Virtual COM Device</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SDK-Adding-a-Read-Write-Interface-for-the-USB-Virtual-COM-Device/m-p/815247#M49433</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;FYI: I found a bug where "ready" was not cleared when "attached" is set to zero. In my testing if I physically disconnected the device from the bus, "attached" was cleared but "ready" remained set. When plugging the device back in both "ready" and "attached" were set which is an incorrect state. "ready" is set when the device file is opened in Linux or MacOS (likely similar in Windows).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, find where "attached" is cleared and also clear "ready".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 06 Dec 2018 00:01:45 GMT</pubDate>
    <dc:creator>razed11</dc:creator>
    <dc:date>2018-12-06T00:01:45Z</dc:date>
    <item>
      <title>SDK: Adding a Read/Write Interface for the USB Virtual COM Device</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SDK-Adding-a-Read-Write-Interface-for-the-USB-Virtual-COM-Device/m-p/815245#M49431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using a K64 with SDK 2.4.2 and FreeRTOS. I'd like to extend the example code to provide read and write functions that block with a timeout. For example:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;count = virtual_com_read(buffer, 8, timeout);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Would return after either timeout milliseconds or 8 bytes was read from the bus. It would return the actual number of bytes read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have experience using the RTOS. My questions are more about interpreting the existing code. Here are my questions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This routine looks promising:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;extern usb_status_t USB_DeviceCdcAcmSend(class_handle_t handle, uint8_t ep, uint8_t *buffer, uint32_t length);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;May I pass a buffer of any length? Will it block? Is there a way to specify a timeout?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Elsewhere in &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&lt;STRONG&gt;USB_DeviceCdcVcomCallback&lt;/STRONG&gt;&lt;/SPAN&gt; when &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&lt;STRONG&gt;kUSB_DeviceCdcEventSendResponse&lt;/STRONG&gt;&lt;/SPAN&gt; is handled there is the following (sorry the source code formatting is not working in Chrome ):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;else if ((1 == _cdcvc.attach) &amp;amp;&amp;amp; (1 == _cdcvc.startTransactions))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; if ((epCbParam-&amp;gt;buffer != NULL) ||&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ((epCbParam-&amp;gt;buffer == NULL) &amp;amp;&amp;amp; (epCbParam-&amp;gt;length == 0)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; /* User: add your own code for send complete event */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; /* Schedule buffer for next receive event */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; error = USB_DeviceCdcAcmRecv(handle,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USB_CDC_VCOM_BULK_OUT_ENDPOINT,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_receive_buffer,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;g_UsbDeviceCdcVcomDicEndpoints[0].maxPacketSize);&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I can see how I might use this in combination with &lt;SPAN style="color: #000000; font-family: 'courier new', courier, monospace;"&gt;&lt;STRONG&gt;USB_DeviceCdcAcmSend&lt;/STRONG&gt;&lt;/SPAN&gt; to create my &lt;SPAN style="color: #000000; font-family: 'courier new', courier, monospace;"&gt;&lt;STRONG&gt;virtual_com_send&lt;/STRONG&gt;&lt;/SPAN&gt; routine by adding an RTOS primitive.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why though is this code called when the callback buffer is not null? What is in this buffer?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I were to add a timeout how may I return the number of bytes actually written to the host?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What are some suggestions for implementing my read function?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, there is a macro USB_DEVICE_CONFIG_USE_TASK which ultimately allows a task to periodically call:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;void USB_DeviceTaskFunction(void *deviceHandle)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; usb_device_struct_t *handle = (usb_device_struct_t *)deviceHandle;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; static usb_device_callback_message_struct_t message;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; if (deviceHandle)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; /* Get the message from the queue */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; if (kStatus_USB_OSA_Success == USB_OsaMsgqRecv(handle-&amp;gt;notificationQueue,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (uint32_t *)&amp;amp;message, 0U))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; /* Handle the message */&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; USB_DeviceNotification(handle, &amp;amp;message);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This function is ultimately calling FreeRTOS's &lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;&lt;STRONG&gt;xQueueReceive&lt;/STRONG&gt;&lt;/SPAN&gt; with a timeout of zero. It would be nice to support a timeout as that task will return immediately whether or not a message is in the queue. So this task will starve other tasks at lower priority. I can sleep a bit in the calling task but that will always add that latency rather than only when a message is unavailable (if I understand this correctly).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for reading.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Nov 2018 01:32:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SDK-Adding-a-Read-Write-Interface-for-the-USB-Virtual-COM-Device/m-p/815245#M49431</guid>
      <dc:creator>razed11</dc:creator>
      <dc:date>2018-11-29T01:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: SDK: Adding a Read/Write Interface for the USB Virtual COM Device</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SDK-Adding-a-Read-Write-Interface-for-the-USB-Virtual-COM-Device/m-p/815246#M49432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe I've worked this out and I'm attaching a replacement virtual_com.h/.c along with a Python test script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that I'm using the helper task so&amp;nbsp;USB_DEVICE_CONFIG_USE_TASK must be defined to be nonzero. Also configSUPPORT_STATIC_ALLOCATION must be set in FreeRTOSConfig.h. I'm probably missing some other details.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Nov 2018 20:56:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SDK-Adding-a-Read-Write-Interface-for-the-USB-Virtual-COM-Device/m-p/815246#M49432</guid>
      <dc:creator>razed11</dc:creator>
      <dc:date>2018-11-30T20:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: SDK: Adding a Read/Write Interface for the USB Virtual COM Device</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SDK-Adding-a-Read-Write-Interface-for-the-USB-Virtual-COM-Device/m-p/815247#M49433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;FYI: I found a bug where "ready" was not cleared when "attached" is set to zero. In my testing if I physically disconnected the device from the bus, "attached" was cleared but "ready" remained set. When plugging the device back in both "ready" and "attached" were set which is an incorrect state. "ready" is set when the device file is opened in Linux or MacOS (likely similar in Windows).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, find where "attached" is cleared and also clear "ready".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2018 00:01:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SDK-Adding-a-Read-Write-Interface-for-the-USB-Virtual-COM-Device/m-p/815247#M49433</guid>
      <dc:creator>razed11</dc:creator>
      <dc:date>2018-12-06T00:01:45Z</dc:date>
    </item>
  </channel>
</rss>

