USB CDC, reloaded

The Processor Expert USB CDC component posted in USB or not: CDC with Processor Expert has found many friends :-). A new version is available for download here with examples. It adds a bunch of new features and makes many things: simpler dependencies and setup, generation of an easily accessible cdc.inf and availability of error hooks. I have it running now with the TWR-MCF52259 and the DEMOJM (MCF51JM128 and S08JM60).

  1. The Init_USB component is now an inherited component. The settings for the Init component are automatically set up at creation time.So adding FSL_USB_Stack just needs two things to configure: the CPU and the Init_USB:
    Inherited USB_Init Component

    Inherited USB_Init Component

    Selection of USB Init

    Selection of USB Init

  2. The component generates the Windows driver .inf file into the Documenation folder, based on the component settings. The cdc.inf is a combined file supporting both 32bit and 64bit Windows machines:

    Generated .inf File

    Generated .inf File

  3. The .inf and the code generation supports now many settings, including PID/VID:

    USB driver and .inf settings

    USB driver and .inf settings

  4. The component has an optional OnError() hook which catches common errors:

    OnError() Hook

    OnError() Hook

  5. Many small improvements and fixes.

Note: The post in USB or not: CDC with Processor Expert is updated to reflect the changes and improvements.

Happy CDCing 🙂

19 thoughts on “USB CDC, reloaded

  1. Pingback: FSL_USB_Stack updated: sending 16 or 32 byte blocks | MCU on Eclipse

  2. Pingback: USB CDC goes medical | MCU on Eclipse

  3. Pingback: Tutorial: USB CDC with the KL25Z Freedom Board | MCU on Eclipse

  4. Hi Erich, I just updated from your github, and updated MCU10.5 with the updates from Freescale for the PE, etc. (and FSL USB stack 4.1.1) and (after adding critical sections) I’m getting these two errors :

    Generator: FAILURE: at line 5: Error in including “Drivers\FSL_USB_Stack\FSL_USB_Stack_Config.h” (file: Drivers\FSL_USB_Stack_Files.prg) ips-hwtest USB1 Processor Expert Problem

    Generator: FAILURE: at line 54: Unknown macro: “UseUSBStackInitialization” (file: Drivers\FSL_USB_Stack\Device\app\cdc\user_config.h) ips-hwtest CDC1 Processor Expert Problem

    So if I click on the first one and the line is:

    %include FSL_USB_Stack\FSL_USB_Stack_Config.h

    … which is odd because there is no file Drivers\FSL_USB_Stack\FSL_USB_Stack_Config.h in Processor Expert/CWMCU_PE5_00….

    And the second on is pure mystery…

    Like

  5. Hi Erich, do you think that work the usb cdc to connect in the raspberry PI? I mean, I dont want to use a USB Serial chip converter like FTDI, the OS that I’ll be use is raspbian, do you think that works? thanks, best regards

    Like

  6. Hi Erich,

    Came across this ‘issue’ with the CDC_usb_Device component. everything runs fine when the usb is enumerated. but when i unplug the usb it remains in the while loop in CDC1_SendDataBlock:

    is there some way to detect the usb unplug and prevent this from happening?

    uint8_t CDC1_SendDataBlock(uint8_t *data, uint16_t dataSize)
    {
    uint8_t res = ERR_OK;

    transactionOngoing = TRUE;
    if (USB_Class_CDC_Interface_DIC_Send_Data(CONTROLLER_ID, data, dataSize)!=USB_OK) {
    transactionOngoing = FALSE;
    return ERR_FAULT;
    }
    /* wait for transaction finish */
    while(transactionOngoing) { /* wait until transaction is finished */
    /*lint -save -e522 function lacks side-effects */
    CDC1_RunUsbEngine();
    /*lint -restore */
    }
    return res;
    }

    Like

    • Hi David,
      if you are using my latest components from SourceForge: a while ago I have implemented a timout option you can turn on for SendDataBlock() in the component properties. Then it uses a timeout like this:
      uint8_t CDC1_SendDataBlock(uint8_t *data, uint16_t dataSize)
      {
      TMOUT1_CounterHandle timeout;
      uint8_t res = ERR_OK;

      transactionOngoing = TRUE;
      if (USB_Class_CDC_Interface_DIC_Send_Data(CONTROLLER_ID, data, dataSize)!=USB_OK) {
      transactionOngoing = FALSE;
      return ERR_FAULT;
      }
      /* wait for transaction finish */
      timeout = TMOUT1_GetCounter(50/TMOUT1_TICK_PERIOD_MS); /* set up timeout counter */
      while(transactionOngoing) { /* wait until transaction is finished */
      /*lint -save -e522 function lacks side-effects */
      CDC1_RunUsbEngine();
      /*lint -restore */
      if (TMOUT1_CounterExpired(timeout)) {
      res = ERR_FAILED;
      break;
      }
      WAIT1_WaitOSms(10); /* wait some time */
      }
      TMOUT1_LeaveCounter(timeout); /* return timeout counter */
      return res;
      }

      See https://github.com/ErichStyger/mcuoneclipse/commit/d0f99ca66684120b916c9bf402d8acc95429093b what I have done. You need a periodic timer (e.g. 10ms) and call TMOUT1_AddTick() too.

      I hope this helps,
      Erich

      Like

  7. hi Erich,

    the following function get stuck in it’s while loop after i unplug the usb cable.

    uint8_t CDC1_SendDataBlock(uint8_t *data, uint16_t dataSize)
    .
    .
    while(transactionOngoing) { /* wait until transaction is finished */
    /*lint -save -e522 function lacks side-effects */
    CDC1_RunUsbEngine();
    /*lint -restore */
    }
    .
    .
    .
    is there some way to detect a disconnect of the cable so this does not happen? i put a breakpoint to the usb_isr and it breaks there when plugging the cable, but not unplugging.

    thanks
    david

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.