How to select a USB device at startup?
Hi everyone.
I need to activate a different USB device (one only, no multi role) at startup, depending for example on a GPIO status. I have two versions of an application on a STM32WB55 Nucleo board working as MSC in a version and CDC in the other. I tried to combine the codes creating two different descriptors, registering the requested device in function MX_USB_Device_Init() and allocating PMA's in USBD_LL_Init() according to the device.
As I integrated the CDC code in MSC code, the MSC device works well, but the CDC startup code CDC_Init_FS() is never called. My USB init function is:
void MX_USB_Device_Init(void)
{
/* USB Clock Initialization */
USBD_Clock_Config(); // MSC and CD codes are the same
/* Init Device Library, add supported class and start the library. */
switch (USBDmode) {
case USB_DEVICE_MSC:
if (USBD_Init(&hUsbDeviceFS, &MSC_Desc, DEVICE_FS) != USBD_OK) {
Error_Handler();
}
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_MSC) != USBD_OK) {
Error_Handler();
}
if (USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS) != USBD_OK) {
Error_Handler();
}
break;
case USB_DEVICE_CDC:
if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) {
Error_Handler();
}
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) {
Error_Handler();
}
if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) {
Error_Handler();
}
break;
}
if (USBD_Start(&hUsbDeviceFS) != USBD_OK) {
Error_Handler();
}
}
I already increased stack and heap, with no success. Any suggestion will be welcome.
