PSoC6 USB device Cy_USB_Dev_RegisterSerialNumStringCallback

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

cross mob
OnPi_2263161
Level 4
Level 4
First like received Code Expert

Hi all,

I have working USB peripheral device and I would like to provide my own serial number (It is different for each product). In the PDL is Cy_USB_Dev_RegisterSerialNumStringCallback. It should register provided function in the USB device and when the serial number is requested call it. My question is What should I fill in the Cypress USB configurator to enable this functionality?

From cy_usb_dev.c it looks that I had to register a serial number string and in the cycfg_usbdev.c replace its pointer in the usb_0_stringPtr struct with the null otherwise USB device always use this string and doesn't call registered function. Is it the correct way?

Regards

Ondrej

0 Likes
1 Solution

Sorry, you actually have to set the iSerialNumber to "User Call Back" in the USB Configurator, so the callback can be correctly invoked.

View solution in original post

0 Likes
4 Replies
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

Hi,

You don't need to fill anything in the Cypress USB configurator. The callback function you registered is responsible to generate the serial number. Note that this callback should look something like this:

uint8_t * callback_function(void);

In there, you can generate this number as you like. Just make sure to return the serial number as a string.

0 Likes

Hi Rodolfo,

when I register only callback function without change in the Cypress USB configurator. Callback function doesn't get called. I investigated more in the PDL internals and found following code:

/* Check that string exists */

                if ((NULL != descr->stringDescriptors) && (descr->numStrings > 0U) && (idx < descr->numStrings))

                {

                    /* Get string from descriptors */

                    strDescr = (uint8_t *) descr->stringDescriptors[idx];

                    /* Check whether requested string is serial number */

                    if ((idx != STRING_LANGID_INDEX) &&

                        (idx == context->devDescriptors->deviceDescriptor[DEVICE_DESCR_ISN_STRING_POS]))

                    {

                       /* Check options for serial string */

                        if (strDescr != NULL)

                        {

                            /* Serial number is part of device descriptor */

                            retStatus = CY_USB_DEV_SUCCESS;

                        }

                        else

                        {

                            if (context->getSerialNumString != NULL)

                            {

                                /* Get serial number using callback */

                                strDescr = context->getSerialNumString();

                                if (strDescr != NULL)

                                {

                                    retStatus = CY_USB_DEV_SUCCESS;

                                }

                            }

                            else

                            {

                                /* Get serial number using silicon ID */

                                strDescr = &context->serialNumDescr[0];

                                retStatus = CY_USB_DEV_SUCCESS;

                            }

                        }

                    }

                    else

                    {

                        retStatus = CY_USB_DEV_SUCCESS;

                    }

                }

There are two conditions which tell me that I had to assign an idx (string number) for the serial string and set descr->stringDescriptors[idx] to null. Otherwise string from the USB configuration has higher priority than registered function call. How can I achive such configuration with the USB configurator?

Why does callback function return uint8_t * without const?

Regards

Ondrej

0 Likes

Sorry, you actually have to set the iSerialNumber to "User Call Back" in the USB Configurator, so the callback can be correctly invoked.

0 Likes
OnPi_2263161
Level 4
Level 4
First like received Code Expert

Thank you. I wasn't expecting that string field can change to dropdown menu.

Regards

Ondrej

0 Likes