<?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: MKL27Z64VLH4 detect USB disconnect</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087664#M57643</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;&lt;/P&gt;&lt;P&gt;Sorry, when you said "device", I assumed CDC and not HID - it's not specified in your original post.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't looked at the HID device code, but I would suggest that you look for similar events in the code as I found in the CDC device and see if you can determine&amp;nbsp;when&amp;nbsp;the device is connected/enumerated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck, let me know if you have any other questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 14 Jun 2020 20:34:46 GMT</pubDate>
    <dc:creator>myke_predko</dc:creator>
    <dc:date>2020-06-14T20:34:46Z</dc:date>
    <item>
      <title>MKL27Z64VLH4 detect USB disconnect</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087661#M57640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;how can I detect USB cable disconnect event on&amp;nbsp;MKL27Z64VLH4?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I use&amp;nbsp;&lt;SPAN&gt;MKL27Z64VLH4 as USB device. It is connceted to a smartphone and at the same time it is powered by external power supply and it also powers USB bus so the smartphone can charge (USB Accessory charging adaptor).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This means It is not possible to detect USB disconnect event using USB bus voltage.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jun 2020 17:16:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087661#M57640</guid>
      <dc:creator>dusek_martin</dc:creator>
      <dc:date>2020-06-11T17:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: MKL27Z64VLH4 detect USB disconnect</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087662#M57641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Martin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I noted elsewhere, I'm using a modified form of the USB device demo code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To detect a connection/disconnection I have added code to notify my (FreeRTOS) command task that there has been a USB "disconnect" by the modifications to the "virtual_USB" code segements (int &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;red&lt;/STRONG&gt;&lt;/SPAN&gt;).&amp;nbsp; I've put in the whole "case" code so you can find where the locations are more easily.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;case kUSB_DeviceCdcEventRecvResponse:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;uint32_t i;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;if ((1 == s_cdcVcom.attach) &amp;amp;&amp;amp; (1 == s_cdcVcom.startTransactions)) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; s_recvSize = epCbParam-&amp;gt;length;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; if ((0 != s_recvSize) &amp;amp;&amp;amp; (0xFFFFFFFF != s_recvSize)) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; for (i = 0; (s_recvSize + 0) &amp;gt; i; ++i) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; if (0 != usbBlockCountDown) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; usbCMDMsg.msg[usbCMDMsgSize++] = s_currRecvBuf[i];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; --usbBlockCountDown;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; else if (usbBlockFlag) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; usbBlockCountDown = (uint32_t)(usbCMDMsg.msg[usbCMDMsgSize++] = s_currRecvBuf[i]);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; usbBlockFlag = FALSE;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; else {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&lt;STRONG&gt;// myke packet receive code here/Modified from the original&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&lt;STRONG&gt;mykeUSBBuffer[usbBufferSize++] = s_currRecvBuf[i];&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; s_recvSize = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; error = USB_DeviceCdcAcmRecv(handle&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; , USB_CDC_VCOM_BULK_OUT_ENDPOINT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; , s_currRecvBuf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; , g_UsbDeviceCdcVcomDicEndpoints[0].maxPacketSize);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; else {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000; font-family: 'andale mono', monospace;"&gt;&lt;STRONG&gt;usbCMDMsg.header = CMD_REQUEST_DISCONNECT;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000; font-family: 'andale mono', monospace;"&gt;&lt;STRONG&gt; CMDMSGISR(usbCMDMsg)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; break;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and here (I marked where I detect the "connection" in &lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;blue&lt;/STRONG&gt;&lt;/SPAN&gt;):&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;case kUSB_DeviceCdcEventSetControlLineState:&lt;BR /&gt; {&lt;BR /&gt; s_usbCdcAcmInfo.dteStatus = acmReqParam-&amp;gt;setupValue;&lt;BR /&gt; /* activate/deactivate Tx carrier */&lt;BR /&gt; if (acmInfo-&amp;gt;dteStatus &amp;amp; USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION)&lt;BR /&gt; {&lt;BR /&gt; acmInfo-&amp;gt;uartState |= USB_DEVICE_CDC_UART_STATE_TX_CARRIER;&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; acmInfo-&amp;gt;uartState &amp;amp;= (uint16_t)~USB_DEVICE_CDC_UART_STATE_TX_CARRIER;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;/* activate carrier and DTE */&lt;BR /&gt; if (acmInfo-&amp;gt;dteStatus &amp;amp; USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE)&lt;BR /&gt; {&lt;BR /&gt; acmInfo-&amp;gt;uartState |= USB_DEVICE_CDC_UART_STATE_RX_CARRIER;&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; acmInfo-&amp;gt;uartState &amp;amp;= (uint16_t)~USB_DEVICE_CDC_UART_STATE_RX_CARRIER;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;/* Indicates to DCE if DTE is present or not */&lt;BR /&gt; acmInfo-&amp;gt;dtePresent = (acmInfo-&amp;gt;dteStatus &amp;amp; USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE) ? true : false;&lt;/P&gt;&lt;P&gt;/* Initialize the serial state buffer */&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[0] = NOTIF_REQUEST_TYPE; /* bmRequestType */&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[1] = USB_DEVICE_CDC_NOTIF_SERIAL_STATE; /* bNotification */&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[2] = 0x00; /* wValue */&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[3] = 0x00;&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[4] = 0x00; /* wIndex */&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[5] = 0x00;&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[6] = UART_BITMAP_SIZE; /* wLength */&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[7] = 0x00;&lt;BR /&gt; /* Notifiy to host the line state */&lt;BR /&gt; acmInfo-&amp;gt;serialStateBuf[4] = acmReqParam-&amp;gt;interfaceIndex;&lt;BR /&gt; /* Lower byte of UART BITMAP */&lt;BR /&gt; uartBitmap = (uint8_t *)&amp;amp;acmInfo-&amp;gt;serialStateBuf[NOTIF_PACKET_SIZE + UART_BITMAP_SIZE - 2];&lt;BR /&gt; uartBitmap[0] = acmInfo-&amp;gt;uartState &amp;amp; 0xFFu;&lt;BR /&gt; uartBitmap[1] = (acmInfo-&amp;gt;uartState &amp;gt;&amp;gt; 8) &amp;amp; 0xFFu;&lt;BR /&gt; len = (uint32_t)(NOTIF_PACKET_SIZE + UART_BITMAP_SIZE);&lt;BR /&gt; if (0 == ((usb_device_cdc_acm_struct_t *)handle)-&amp;gt;hasSentState)&lt;BR /&gt; {&lt;BR /&gt; error = USB_DeviceCdcAcmSend(handle, USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT, acmInfo-&amp;gt;serialStateBuf, len);&lt;BR /&gt; if (kStatus_USB_Success != error)&lt;BR /&gt; {&lt;BR /&gt; usb_echo("kUSB_DeviceCdcEventSetControlLineState error!");&lt;BR /&gt; }&lt;BR /&gt; ((usb_device_cdc_acm_struct_t *)handle)-&amp;gt;hasSentState = 1;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;/* Update status */&lt;BR /&gt; if (acmInfo-&amp;gt;dteStatus &amp;amp; USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION) {&lt;BR /&gt; /* To do: CARRIER_ACTIVATED */&lt;BR /&gt;}&lt;BR /&gt; else {&lt;BR /&gt; /* To do: CARRIER_DEACTIVATED */&lt;BR /&gt; }&lt;BR /&gt; if (acmInfo-&amp;gt;dteStatus &amp;amp; USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE)&lt;BR /&gt; {&lt;BR /&gt; /* DTE_ACTIVATED */&lt;BR /&gt; if (1 == s_cdcVcom.attach)&lt;BR /&gt; {&lt;BR /&gt; &lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;usbCMDMsg.header = CMD_REQUEST_CONNECT;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt; CMDMSGISR(usbCMDMsg)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt; s_cdcVcom.startTransactions = 1;&lt;BR /&gt;#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) &amp;amp;&amp;amp; (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED &amp;gt; 0U) &amp;amp;&amp;amp; \&lt;BR /&gt; defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) &amp;amp;&amp;amp; (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE &amp;gt; 0U) &amp;amp;&amp;amp; \&lt;BR /&gt; defined(FSL_FEATURE_USB_KHCI_USB_RAM) &amp;amp;&amp;amp; (FSL_FEATURE_USB_KHCI_USB_RAM &amp;gt; 0U)&lt;BR /&gt; s_waitForDataReceive = 1;&lt;BR /&gt; USB0-&amp;gt;INTEN &amp;amp;= ~USB_INTEN_SOFTOKEN_MASK;&lt;BR /&gt; s_comOpen = 1;&lt;BR /&gt; usb_echo("USB_APP_CDC_DTE_ACTIVATED\r\n");&lt;BR /&gt;#endif&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; /* DTE_DEACTIVATED */&lt;BR /&gt; if (1 == s_cdcVcom.attach)&lt;BR /&gt; {&lt;BR /&gt; &lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;usbCMDMsg.header = CMD_REQUEST_DISCONNECT;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt; CMDMSGISR(usbCMDMsg)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt; s_cdcVcom.startTransactions = 0;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; break;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't if you would call these modifications "elegant" but they do the job.&amp;nbsp; I have the two "disconnect" locations as I have found that different apps and situations (ie unplugging the cable) will result in different code locations executing - but there are no observed conditions where there is something like "disconnect" - "connect" - "disconnect".&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that as this code is executing in the USB callback, I'm treating it like an ISR (and using the ISR Message Send APIs).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there's a better way of detecting connections/disconnections I'm interested in seeing it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Jun 2020 20:02:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087662#M57641</guid>
      <dc:creator>myke_predko</dc:creator>
      <dc:date>2020-06-11T20:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: MKL27Z64VLH4 detect USB disconnect</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087663#M57642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Myke,&lt;/P&gt;&lt;P&gt;thanks, but to be honest, I don't understand how the cable disconnect event detection can work with your code. Why is it implemented in CDC-related code (FYI I use HID device and I would like to have application-agnostic cable disconnect event)? Can you please explain?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Jun 2020 19:57:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087663#M57642</guid>
      <dc:creator>dusek_martin</dc:creator>
      <dc:date>2020-06-14T19:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: MKL27Z64VLH4 detect USB disconnect</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087664#M57643</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;&lt;/P&gt;&lt;P&gt;Sorry, when you said "device", I assumed CDC and not HID - it's not specified in your original post.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't looked at the HID device code, but I would suggest that you look for similar events in the code as I found in the CDC device and see if you can determine&amp;nbsp;when&amp;nbsp;the device is connected/enumerated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck, let me know if you have any other questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Jun 2020 20:34:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/MKL27Z64VLH4-detect-USB-disconnect/m-p/1087664#M57643</guid>
      <dc:creator>myke_predko</dc:creator>
      <dc:date>2020-06-14T20:34:46Z</dc:date>
    </item>
  </channel>
</rss>

