cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with STM32F4 USBX supporting both USB CDC and MSC

jason_gu
Associate

 

We are developing a product based on the STM32F469 with Azure RTOS / USBX.
The system requires both USB CDC and MSC device functionality:

  • CDC → serial communication
  • MSC → file transfer

Both operate as USB device classes.

We found that getting CDC and MSC working together on STM32F4 + USBX is difficult, and we have not found any official example demonstrating this.

The STM32F4 Azure RTOS package provides separate examples for CDC and MSC:

https://github.com/STMicroelectronics/x-cube-azrtos-f4/tree/main/Projects/STM32469I-Discovery/Applications/USBX

By following those examples, we can get either:

  • CDC working alone, or
  • MSC working alone

However, we need both classes in the same product.

We investigated two possible approaches:

  1. USB composite device (preferred)
  2. Runtime switching between CDC and MSC

Unfortunately, we have not been able to make either approach work reliably.


1. Composite Device Attempt

For the composite-device approach, we managed to get both classes successfully registered using:

 

 
_ux_device_stack_class_register()
 

Windows Device Manager correctly detects:

  • USB Composite Device
  • USB Mass Storage Device
  • USB Serial Device

However:

  • MSC works correctly
  • CDC does not function

Our suspicion is that the issue may be related to the USB FIFO configuration (HAL_PCDEx_SetRxFiFo() / HAL_PCDEx_SetTxFiFo()).

The STM32 examples only provide FIFO configurations for:

  • CDC alone, or
  • MSC alone

There is no example showing how FIFO sizes should be configured for CDC + MSC together.
We tried multiple FIFO combinations without success.

If anyone has a working FIFO configuration for STM32F469 + USBX CDC/MSC composite device, that would be very helpful.


2. Runtime Switching Attempt

As an alternative, we tried dynamically switching between CDC and MSC modes.

The idea was:

  • Tear down the current USB class
  • Reinitialize USBX
  • Start the other class

Simplified code:

 

 
void USBX_Start_CDC(void)
{
ux_system_initialize(...);

_ux_device_stack_initialize(...);

_ux_device_stack_class_register(
_ux_system_slave_class_cdc_acm_name,
_ux_device_class_cdc_acm_entry,
...);

HAL_PCD_Start(&hpcd_USB_OTG_FS);
}

void USBX_Start_MSC(void)
{
ux_system_initialize(...);

_ux_device_stack_initialize(...);

_ux_device_stack_class_register(
_ux_system_slave_class_storage_name,
_ux_device_class_storage_entry,
...);

HAL_PCD_Start(&hpcd_USB_OTG_FS);
}

void USBX_Switch_Mode(uint8_t new_mode)
{
HAL_PCD_Stop(&hpcd_USB_OTG_FS);

_ux_device_stack_disconnect();
_ux_device_stack_uninitialize();
ux_system_uninitialize();

HAL_Delay(200);

if (new_mode == USB_MODE_CDC)
USBX_Start_CDC();
else
USBX_Start_MSC();
}
 

However, this approach also fails.

It appears that the initialization sequence creates various RTOS objects and allocations:

  • threads
  • event flags
  • mutexes
  • memory allocations
  • etc.

During teardown, many (possibly all) of these resources do not appear to be fully deleted or released.

As a result:

  • The second initialization fails
  • Even reinitializing the same class can fail
  • Errors indicate corrupted/internal state or duplicate object creation

Our current conclusion is that:

USBX device stack initialization is effectively “one-time only” on STM32F4, and full teardown/reinitialization is not supported.


Questions

  1. Is there an official example of STM32F4 + USBX supporting CDC + MSC composite device?
  2. Are there recommended FIFO settings for CDC + MSC together?
  3. Does USBX officially support full device-stack teardown and reinitialization?
  4. If not, what is the recommended approach for products needing both CDC and MSC functionality?
0 REPLIES 0