cancel
Showing results for 
Search instead for 
Did you mean: 

USBX + FileX + ThreadX (USB Host MSC) — RAM minimum?

Marcus3
Associate

Hi everyone,

I’m building a coffee machine project using STM32C071 (C0) mainly because it has USB. I need USB Host MSC to:

  • Mount a USB flash drive (FAT)

  • Read/write files (params/logs)

  • Firmware update from USB drive

The “official” ST stack seems to be ThreadX + USBX + FileX. Since there’s no USB Host MSC example for C0, I used an STM32L4R5 example (much larger RAM) as reference and adapted it.

Issue: To pass ThreadX/USBX init, I kept increasing stacks/pools until I’m using ~20 kB of RAM. Then, when I plug the flash drive, enumeration fails with out-of-memory errors (e.g., UX_DEVICE_ENUMERATION_FAILURE / allocation failure).

Questions:

  1. Is ~20 kB RAM just to init (and still fail at enumeration) expected for USBX Host MSC + FileX, or does it strongly suggest misconfiguration?

  2. Is there any official guideline/table (ST/Azure RTOS) for typical/minimum RAM for USBX Host + MSC + FileX (FAT)?

  3. Is there a practical RAM “floor” to enumerate + mount FAT + read/write files (single device, no HUB)? Like “below X kB is unrealistic”?

  4. When enumeration fails due to memory, is it usually related to:

    • USBX memory pool size,

    • thread stack sizes,

    • MSC/FileX buffers (sector/cache/FAT),

    • enabled features (HUB, multiple devices/classes)?

  5. Which macros/settings would you reduce first for a minimal use case (e.g., UX_MAX_DEVICES, class drivers, HUB, etc.)?

  6. Does using dynamic allocation (properly) make sense here, or is the right approach simply fixed pools/stacks sized conservatively?

  7. Any recommended method/tooling to size memory without pure trial-and-error? (byte pool stats, stack high-water mark, ThreadX/USBX tracing)

Setup: STM32C071, single USB flash drive MSC + FAT (FileX), no HUB, L4 reference code.

If anyone has a known working baseline for small-RAM MCUs (C0 or similar), any pools/stacks/macros values would be extremely helpful. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

Hi @Marcus3 

USBX requires between 24 KBytes and 64 KBytes of Read Only Memory (ROM) on the target in host mode. The amount of memory required is dependent on the type of controller used and the USB classes linked to USBX. Another 32 KBytes of the target's Random Access Memory (RAM) are required for USBX global data structures and memory pool. This memory pool can also be adjusted depending on the expected number of devices on the USB and the type of USB controller. The USBX device side requires roughly 10-12 K of ROM depending on the type of device controller. The RAM memory usage depends on the type of class emulated by the device.

USBX also relies on ThreadX semaphores, mutexes, and threads for multiple thread protection, and I/O suspension and periodic processing for monitoring the USB bus topology.

You can follow recommendations here.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

View solution in original post

2 REPLIES 2
Pavel A.
Super User

Instead of USB Host function, consider the Device function, it is simpler and needs less resources. Consider MTP or MSC device class, or even DFU class. The latter is even simpler but requires a custom program on the host side.

The described tasks probably can be done in device mode with a simpler USB stack and no RTOS (=> much less RAM). For reading logs in real time you can use something like a TTL UART ->  USB adapter, the UART connector hidden under cover.

 

FBL
ST Employee

Hi @Marcus3 

USBX requires between 24 KBytes and 64 KBytes of Read Only Memory (ROM) on the target in host mode. The amount of memory required is dependent on the type of controller used and the USB classes linked to USBX. Another 32 KBytes of the target's Random Access Memory (RAM) are required for USBX global data structures and memory pool. This memory pool can also be adjusted depending on the expected number of devices on the USB and the type of USB controller. The USBX device side requires roughly 10-12 K of ROM depending on the type of device controller. The RAM memory usage depends on the type of class emulated by the device.

USBX also relies on ThreadX semaphores, mutexes, and threads for multiple thread protection, and I/O suspension and periodic processing for monitoring the USB bus topology.

You can follow recommendations here.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL