cancel
Showing results for 
Search instead for 
Did you mean: 

Code Examples

New Contributor II

In the Cypress example projects for the CX3 device, the USB string descriptors are defined like this:

/* Standard manufacturer string descriptor */

const uint8_t CyCx3USBManufactureDscr[] =

{

    0x10,                               /* Descriptor size */

    CY_U3P_USB_STRING_DESCR,            /* Device descriptor type */

    'C',0x00,                           /* Manufacturer String */

    'y',0x00,

    'p',0x00,

    'r',0x00,

    'e',0x00,

    's',0x00,

    's',0x00

};

I would like to suggest a tidier method, which is easier to read, and less prone to bugs. First we define a macro:

#define USB_STRING_DESC(S)  ((char const*)&(struct{ char const p[2]; wchar_t const s[sizeof(S)]; }) { {(sizeof(S)), CY_U3P_USB_STRING_DESCR}, S})

Now we can define our descriptors using a single line each:

const uint8_t *CyCx3USBManufactureDscr = USB_STR_DESC(L"Cypress");

const uint8_t *CyCx3USBProductDscr     = USB_STR_DESC(L"CX3 Camera");

const uint8_t *CyCx3USBConfigSSDscr    = USB_STR_DESC(L"USB-3.0");

const uint8_t *CyCx3USBConfigHSDscr    = USB_STR_DESC(L"USB-2.1");

const uint8_t *CyCx3USBConfigFSDscr    = USB_STR_DESC(L"USB-1.1");

2 Replies
Moderator
Moderator

Hi,

The macro is defined as USB_STRING_DESC and you have used USB_STR_DESC while assigning it to descriptors (CyCx3USBManufactureDscr, etc..). I have corrected it my code.

I couldn't get the string descrptors after using the above method.

Can you please upload an example firmware for testing?

USB_STRING_DESC

0 Likes
Reply
Moderator
Moderator

Hello,

The default settings for wchar_t are set to UNICODE 32 bits. But as per USB spec. we need UNICODE 16 bits.

This is the reason why the above code snippet was not working expectedly at my end.

Please let me know what you have done in stddef.h and stdini.h to set the wchar_t to 16 bit.

Regards,

Sridhar

0 Likes
Reply
Top labels