CDC Virtual Com MKW24D: how to detect if port is opened?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CDC Virtual Com MKW24D: how to detect if port is opened?

1,059 Views
mangramarco
Contributor III

Hello,

i have a usb dongle with mkw24d kinetis mcu and it work correctly as Usb Device.

I need to reset the state machine of firmware when a port reopening occurs. So i need to detect a port open/close event to reset the state machine.

I'm searching since a few days but i only found this post https://community.nxp.com/t5/LPCXpresso-IDE/detecting-usb-attachment/m-p/564984.

i verified several line coding events during open or close procedure but this method not appear rigorous for me. How can i do this task? there is other way?

firmware wasn't created by me the line code events are handled inside USB_DeviceCdcVcomCallback Function ->

/* USB device class information */
static usb_device_class_config_struct_t s_cdcAcmConfig[1] = {{
USB_DeviceCdcVcomCallback, 0, &g_UsbDeviceCdcVcomConfig,
}};


Thank you
Marco

0 Kudos
3 Replies

1,055 Views
myke_predko
Senior Contributor III

Hey @mangramarco 

I haven't worked with the MKW24D but I do have some experience with the SDK USB CDC drivers and I can detect connection events in "USB_DeviceCdcVcomCallback" and then the code:

case kUSB_DeviceCdcEventSetControlLineState:
{
  :
  if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE)
  {
/* DTE_ACTIVATED */
    if (1 == s_cdcVcom.attach)
    {
      usbCMDMsg.header = CMD_REQUEST_CONNECT;  // myke's code to report connection
      CMDMSGISR(usbCMDMsg)
      s_cdcVcom.startTransactions = 1;
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
   defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
   defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
      s_waitForDataReceive = 1;
      USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
      s_comOpen = 1;
      usb_echo("USB_APP_CDC_DTE_ACTIVATED\r\n");
#endif
    }    
  }
:

I don't know if the MKW24D's SDK has the same code, but this is the place where the connection is reported.  

Good luck!

myke

0 Kudos

1,039 Views
mangramarco
Contributor III

Hello @myke_predko 

Thank for your help.

I already found this part of code although the #if #endif block is ignored. I used the segger printf to view some logs and i seen follows:

- when mcu start (usb connected) -> SET s_cdcVcom.startTransactions = 0

- when open port  -> SET s_cdcVcom.startTransactions = 0

- when Send Message -> SET s_cdcVcom.startTransactions = 1

- When Close Port -> Set s_cdcVcom.startTransactions = 0 after a few set to 1

Honestly i thought that s_cdcVcom.startTransactions would be set to 1 during port opening. However for my usage could be still useful this flow of events.

Thank you again

0 Kudos

1,035 Views
myke_predko
Senior Contributor III

Hi @mangramarco 

You've basically discovered what I did - when the code changes "s_cdcVcom.startTransactions" I notify the command task of the USB connection state rather than monitor "s_cdcVcom.startTransactions".

Good luck on your application.

myke

 

0 Kudos