CY8CKIT-059 usb device enumeration problem

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

cross mob
Anonymous
Not applicable

I have the following problem with device enumeration on a CY8CKIT-059:

Anytime I program the device from the kitprog and then connect the USB - everything works as expected.

However once I program the board and remove the kitprog usb the USBFS component fails to get past "while(!USBFS_GetConfiguration())".

I feel its not a power supply problem for the following reasons:

1. All code before "while(!USBFS_GetConfiguration())" runs when I connect the micro USB port to my computer

2. Even if I plug in the kitprog into the computer and then plug in the micro USB - the program halts at "while(!USBFS_GetConfiguration())".

I am using libusb on the host side to communicate with the device and the following code prints out "device not found" (unless of course I program the kit and then plug in the usb while the device is powered)

    dev = libusb_open_device_with_vid_pid(NULL, 0x1111, 0x2222);
    if (dev == NULL) {
        cout << "device not found" << endl;
        return false;
    }
0 Likes
1 Solution
Anonymous
Not applicable

Never mind, I got it to work. I was making a smaller project to show the problem and realized in the process that shifting the usb startup code to the start of main solves the problem - I would like to know why it solves the problem though.

So instead of

int main(){

    CyGlobalIntEnable;

   

    #ifdef MPU

    I2C_MPU6050_Start();

    MPU6050_selectLowerArm();

    MPU6050_initialize();

    MPU6050_selectUpperArm();

    MPU6050_initialize();

    #endif

   

    #ifdef USB

    USBFS_Start(USBFS_DEVICE, USBFS_5V_OPERATION);

    while (!USBFS_GetConfiguration());

    USBFS_EnableOutEP(OUT_EP_NUM);

    #endif

    led_pin_Write(1);

    ....

I now have

int main(){

    CyGlobalIntEnable;

   

    #ifdef USB

    USBFS_Start(USBFS_DEVICE, USBFS_5V_OPERATION);

    while (!USBFS_GetConfiguration());

    USBFS_EnableOutEP(OUT_EP_NUM);

    #endif

    led_pin_Write(1);

    #ifdef MPU

    I2C_MPU6050_Start();

    MPU6050_selectLowerArm();

    MPU6050_initialize();

    MPU6050_selectUpperArm();

    MPU6050_initialize();

    #endif

There is no problem connecting to the I2C device so Im not sure why this hack solves the problem.

View solution in original post

0 Likes
6 Replies
AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

Can you use this "USBFS_Start(0, USBUART_5V_OPERATION); " means 5V operation.Is the device is getting enumerated as unknown device when you remove the kitprog usb.

0 Likes
Anonymous
Not applicable

I have used USBFS_Start(0, USBFS_5V_OPERATION); since I am using the USBFS component and not the USBUART. When I remove the kitprog and plug in the micro usb the code in main starts running (led on the board switches on for example) but there seems to be some problem with the device not being able to authenticate itself as libusb cant find the device even though its plugged in.

Following is the initialization code:

USBFS_Start(0, USBFS_5V_OPERATION);

while(!USBFS_GetConfiguration());          

//Can never get past the line above unless i program the board and then plug in the usb into my laptop while the kitprog is plugged in too.

USBFS_EnableOutEP(OUT_EP_NUM);

0 Likes

Can you please provide us with your project

0 Likes
Anonymous
Not applicable

Never mind, I got it to work. I was making a smaller project to show the problem and realized in the process that shifting the usb startup code to the start of main solves the problem - I would like to know why it solves the problem though.

So instead of

int main(){

    CyGlobalIntEnable;

   

    #ifdef MPU

    I2C_MPU6050_Start();

    MPU6050_selectLowerArm();

    MPU6050_initialize();

    MPU6050_selectUpperArm();

    MPU6050_initialize();

    #endif

   

    #ifdef USB

    USBFS_Start(USBFS_DEVICE, USBFS_5V_OPERATION);

    while (!USBFS_GetConfiguration());

    USBFS_EnableOutEP(OUT_EP_NUM);

    #endif

    led_pin_Write(1);

    ....

I now have

int main(){

    CyGlobalIntEnable;

   

    #ifdef USB

    USBFS_Start(USBFS_DEVICE, USBFS_5V_OPERATION);

    while (!USBFS_GetConfiguration());

    USBFS_EnableOutEP(OUT_EP_NUM);

    #endif

    led_pin_Write(1);

    #ifdef MPU

    I2C_MPU6050_Start();

    MPU6050_selectLowerArm();

    MPU6050_initialize();

    MPU6050_selectUpperArm();

    MPU6050_initialize();

    #endif

There is no problem connecting to the I2C device so Im not sure why this hack solves the problem.

0 Likes

This I2C_MPU6050 may cause some delays (sometimes it waits for a command)because of which in the initial setup of code it was not getting enumerated properly.

Please do a debug step by step to see actually where the code is getting stuck in  this code -

"I2C_MPU6050_Start();

    MPU6050_selectLowerArm();

    MPU6050_initialize();

    MPU6050_selectUpperArm();

    MPU6050_initialize();"

GuNo_288966
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

I had a similar problem some time ago. I remember that there is a time restriction. The USB device has to react to some signals from the host within a rather short period of time. If it does not, then the configuration fails.

You have to move the USB configuration stuff to the beginning of your code, then it will work.

You can check if this information is correct by adding a delay before the USB stuff. You will see that the configuration fails if the delay is too big.

There are different types of USB commands. Some of them must be processed within 500ms, others even within 50ms.