This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USB-CDC

Hi im currently working on USB drivers for LP2468 MCU.I want to send data to the host PC as fast as I can.Since i dont have much knowledge on USB HID development on the PC end Ive decided to implement USBCDC class which will appear as a virtual comport on PC.
In my code i have initialised USB using the following statements

CDC_Init (); /*VCOM Initialization*/
USB_Init( EA_BOARD_LPC24XX );
USB_Connect(TRUE);

After i get USB_Configuration flag when an USB cable is
connected i send data to PC using

USB_WriteEP (CDC_DEP_IN,str,len );

Where str is the string i want to write and len is the length

This works as far as I insert a delay between 2 succesive USB writes.
If i reduce the delay the MCU hangs.Ive tried increasing the buffer size by sending more data collectively by changing usbpacket size
#define USBPKTLEN 1000

i have also commented out the following code as im not using CDC to send data packets to the serial port

void USB_EndPoint2 (DWORD event) {

switch (event) { case USB_EVT_OUT: /// CDC_BulkOut (); /* data received from Host */ break; case USB_EVT_IN: // CDC_BulkIn (); /* data expected from Host */ break; }
}

Can someone please suggest what measures can i take to increase the throughput of USBCDC or is there anyway to monitor the status of USB clear to send flag if any
Thank you

Parents
  • My advise to you is simple: stop the spaghettization of the sample code. Revert back to the original sample and dp not comment anything without fully understanding what the implication would be. Remember that when you act as a device, USB is still a host driven bus - so you should never 'USB_WriteEP' unless the host addressed your device using the 'BulkOut' callback (you can reply from other pieces of the program, of couse). Once you 'USB_WriteEP', you can expect 'BulkIn' callbacks until you transmitted all the data.

Reply
  • My advise to you is simple: stop the spaghettization of the sample code. Revert back to the original sample and dp not comment anything without fully understanding what the implication would be. Remember that when you act as a device, USB is still a host driven bus - so you should never 'USB_WriteEP' unless the host addressed your device using the 'BulkOut' callback (you can reply from other pieces of the program, of couse). Once you 'USB_WriteEP', you can expect 'BulkIn' callbacks until you transmitted all the data.

Children
  • Hi thanks for your pointing that out,following which i have made modified my code as below

    In my custom USB_write I fill the bytes to be transmitted in a global buffer.
    When the call back even from usb stack is triggered.I send my buffer on USB using writeEP in CDC_BulkIn(); and i clear the counters to indicate my buffer is empty again.

    void USB_EndPoint2 (DWORD event) {

    switch (event) { case USB_EVT_OUT: CDC_BulkOut (); /* data received from Host */ break; case USB_EVT_IN: CDC_BulkIn (); /* data expected from Host */ break; }
    }

    However im facing the following problem
    USB_EndPoint2 call back function is not being called automatically.Hence CDC_bulkin(); doesnt get called.Also i would like to point out that when iam directly writing to writeEP the call back function CDC_BulkIn (); gets called.
    Please suggest how do i get over this issue.

  • Also i would like to point out that when iam directly writing to writeEP the call back function CDC_BulkIn (); gets called. Please suggest how do i get over this issue.

    this is not an issue at all but normal behavior. did you not figure that out from my first post? I posted:

    Once you 'USB_WriteEP', you can expect 'BulkIn' callbacks until you transmitted all the data

    yes?

    if 'CDC_BulkOut' is not called then you probably changed your USB stack somehow or your connection is not alive.

  • Yeah i think that hit it...Its working with good speed now thanks so much

  • Hello,

    From the MCB2300 USBCDC example I'm trying to write a CDC driver but since I can ready any incoming character, there's no way for me to get the CDC_BulkIn function called on the Endpoint2.

    As far as I can see from the example, whenever a character is read from the UART there's a call to USB_WriteEP but what I want is that the CDC_BulkIn function is called automatically requesting data from my internal buffer.

    Is there any 'straightforward' way to modify this example in order to get a 'simple' virtual com driver?

    Thanks and best regards,
    Daniel