usb cdc class

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
gean_3054931
Level 5
Level 5
10 likes given 5 likes given First like received

Hello,

I have implemented successfully cdc class in fx2lp firmware,i can recieve data from the fx2lp to pc(usb serial).

how can i check baudrate in this situation like in normal uart baud rate (baudrate settings require on both tx and rx side)?

how it will be configured in fx2lp side(firmware)?

in windows side,we are setting 9600bps in hercules terminal?

regards,

geetha.

0 Likes
1 Solution
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi geetha,

If you have implemented CDC class in your firmware then you would have handled SET_LINE_CODING class request.

When you select a baud rate in your PC (using any terminal like teraterm/putty), the SET_LINE_CODING request is sent from the PC with the baud rate info. In the firmware when you receive this command you need to configure your UART hardware to that baud rate.

Regards,

Hemanth

Hemanth

View solution in original post

15 Replies
Hemanth
Moderator
Moderator
Moderator
First like given First question asked 750 replies posted

Hi geetha,

If you have implemented CDC class in your firmware then you would have handled SET_LINE_CODING class request.

When you select a baud rate in your PC (using any terminal like teraterm/putty), the SET_LINE_CODING request is sent from the PC with the baud rate info. In the firmware when you receive this command you need to configure your UART hardware to that baud rate.

Regards,

Hemanth

Hemanth

Hello,

I have found this code snippet in fw.c file

case SET_LINE_CODING:

        Len = 7;

  EUSB = 0 ;

  SUDPTRCTL = 0x01;

  EP0BCL = 0x00;

            SUDPTRCTL = 0x00;

  EUSB = 1;

         while (EP0BCL != Len);

  SYNCDELAY;

       for (i=0;i<Len;i++)

  LineCode = EP0BUF;

            Serial0Init();

  break;

we are using CY7C68013A-56LTXC ,doesnot support uart physically.

how can i change baud rate?what is the default baudrate according into the above code snippet?

and what about the serial0init(); function?is it require physical uart?

regards,

geetha.

0 Likes

Hello hemanth,

please let me know the answer for above question?

regards,

geetha

0 Likes

Hello Geetha,

Please refer to the definition of Serial0Init() function; the baud rate selected on the host application is sent over LineCode array and the corresponding baud rate checked in the function which loads the appropriate count value for the FX2LP timer to generate the required baud rate. Serial0Init() initialises the baud rate for the serial port selected, in the given project it is implemented over Serial Port 0.

Best Regards,

Sananya

0 Likes

Hello sananya,

we are using fx2lp 56 pin ,it doesnot support uart physically.

Serial0Init() is also apply for usb-serial port?

Serial0Init()  function using SCON register,is this SCON register is apply for usb-serial?

regards,

geetha.

0 Likes

Hello,

void  Serial0Init () // serial UART 0 with Timer 2 in mode 1 or high speed baud rate generator

{

        

       SCON0  = 0x5A;    // Set Serial Mode = 1, Recieve enable bit = 1

  T2CON  = 0x34;    // Int1 is detected on falling edge, Enable Timer0, Set Timer overflow Flag

  if ((LineCode[0] == 0x60) && (LineCode[1] == 0x09 ))  // 2400

  {

    RCAP2H = 0xFD;     //  Set TH2 value for timer2

  RCAP2L = 0x90;   // baud rate is set to 2400 baud

  }

   else if ((LineCode[0] == 0xC0) && (LineCode[1] == 0x12 ))  // 4800

  {

    RCAP2H = 0xFE;     //  Set TH2 value for timer2

  RCAP2L = 0xC8;   // baud rate is set to 4800 baud

  }

  else if ((LineCode[0] == 0x80) && (LineCode[1] == 0x25 ))  // 9600

  {

    RCAP2H = 0xFF;     //  Set TH2 value for timer2

  RCAP2L = 0x64;   // baud rate is set to 9600 baud

  }

  else if ((LineCode[0] == 0x00) && (LineCode[1] == 0x4B ))  // 19200

  {

    RCAP2H = 0xFF;     //  Set TH2 value for timer2

  RCAP2L = 0xB2;   // baud rate is set to 19200 baud

  }

  else if ((LineCode[0] == 0x80) && (LineCode[1] == 0x70 ))  // 28800

  {

    RCAP2H = 0xFF;     //  Set TH2 value for timer2

  RCAP2L = 0xCC;   // baud rate is set to 28800 baud

  }

  else if ((LineCode[0] == 0x00) && (LineCode[1] == 0x96 ))  // 38400

  {

    RCAP2H = 0xFF;     //  Set TH2 value for timer2

  RCAP2L = 0xD9;   // baud rate is set to 38400 baud

  }

  else if ((LineCode[0] == 0x00) && (LineCode[1] == 0xE1 ))  // 57600

  {

    RCAP2H = 0xFF;     //  Set TH2 value for timer2

  RCAP2L = 0xE6;   // baud rate is set to 57600 baud

  }

        else //if ((LineCode[0] == 0x21) && (LineCode[1] == 0x20 ))  // 115200 (LineCode[0] == 0x00) && (LineCode[1] == 0xC2 ))

  {

    RCAP2L = 0xF3;

           RCAP2H = 0xFF;

  }

  TH2    = RCAP2H; //  Upper 8 bit of 16 bit counter to FF

  TL2    = RCAP2L; //  value of the lower 8 bits of timer set to baud rate

      

}

the above code is for baudrate generation,

that is , serial UART 0 with Timer 2 in mode 1 or high speed baud rate generator.

we dont have UART 0 physically.will this code is also work without uart 0?

please let me know.

regards,

geetha.

0 Likes

Hello Geetha,

Yes, SCON register is used to control Serial Port 0. No, since the 56-pin FX2LP part does not support Serial ports, data transfer cant be carried out using this project.

Best Regards,

Sananya

Hello sananya,

thanks for your reply.

we are able to transfer data using this project.

why we cant use this project?

we are implemented cdc class,we are able to get usb port as usb-serial,its detecting in the com port and data transferring is happening,we are looking for baudrate settings.

how to set baudrate when we implemented cdc class in usb descriptor?

please let me know.

regards,

geetha.

0 Likes

Hello Geetha,

How are you carrying out the data transfer? Please explain your connection and how you are receiving data on the FX2LP.

Best Regards,

Sananya

0 Likes

Hello sananya,

we are using cdc usb class.fx2lp is connected to image sensor in slavefifo interface.

we are recieving data from the sensor in the endpoint 8,we are commiting this data to pc using cdc class.

we changed descriptor file for cdc class.when we implemented cdc class,its detecting as usb-serial port under com port and also we are able to recieve the data in the hercules terminal and also in hyper terminal.

regards,

geetha.

0 Likes

Hello Geetha,

If you are using the slave FIFO interface to transfer data, you dont need to set the baud rate as per the project. The baud rate applies to only serial communication which is not possible in your 56-pin device. If you are committing the data from your slave FIFO interface to endpoint 8, then it shouldnt matter what baud rate you set in your terminal.

Best Regards,

Sananya

0 Likes

Hello sananya,

we are not using vendor class,we are using cdc class.

when i programmed fx2lp,device is not renumerating in the default control center as expected.

its detecting under com port.in this case why dont we need baud rate.

when its in vendor class,we dont need baud rate.

please explain me clearly.

regards,

geetha.

0 Likes

Hello Geetha,

Even if you use CDC class, baud rate only applies to serial communication i.e. in case of UART communication. If you are using a terminal, it sets the baud rate for communicating over serial port which you are not using in your project. You cannot set it for transferring data over slave fifo interface from your image sensor. Please let me know if you have any other query?

Best Regards,

Sananya

0 Likes

Hello sananya,

if we use cdc class,device is under com port.why?

if cdc class is not using baudrate for communication,then how data transfer is happening?how to identify the speed or throughput?

in virtual com port example,they are using physical uart,so they are using scon register and baudrate selection for this uart?is it right?

regards,

geetha.

0 Likes

Hello Geetha,

If you configure it as CDC class, it will be visible under COM port. Data transfer is occurring since you are committing the data from the slave FIFO interface to the same endpoints instead of using serial port to communicate with another UART device. For data transfer over slave FIFO interface, you need to set IFCLK to proper rate.

Yes, right, the project initializes the parameters for the serial port using the above mentioned registers.

Best Regards,

Sananya

0 Likes