2025-03-21 1:10 PM - edited 2025-03-21 1:21 PM
TL;DR - adding USBX and the USB CDC device class to my STM32U5 TouchGFX project causes it to fail during initialization, because the default memory settings are woefully inadequate.
I have a TouchGFX project running on an STM32U5G9J-DK2 using ThreadX. The TouchGFX component tosses up a splashscreen, and I have other tasks running, including a debug task putting out UART data. So that all works fine.
What doesn't work is when I add USBX and a simple USB CDC device class to the project. I can add it using CubeMX, but when I build and run it, it dies during initialization because of memory allocation issues. I would at least expect it to run out-of-the-box when adding it to a new or existing project.
Here are my steps to reproduce the failure:
USBX init fails
Tracing into the application, the call to ux_device_stack_initialize() (app_usbx_device.c, line 117) is failing because a call to _ux_utility_memory_allocate() (ux_device_stack_initialize.c, line 175) is failing. There appears to be only 24 bytes left in the USBX device driver memory pool, which is what's left over from the 512 bytes of "USBX Device System Stack Size". That's not enough to allocate even the first thing that ux_device_stack_initialize() wants to create.
If I put a breakpoint inside _ux_utility_memory_allocate() and add up all the memory that's allocated (including three allocations of UX_SLAVE_REQUEST_DATA_MAX_LENGTH == 2048), it totals 7124 bytes. This value dictates the minimum "USBX Device System Stack Size". This value plus the "USBX Device Application Thread Stack Size" (default 1024 bytes) must come in under the "UXDevice memory pool size". So if I set my USBX Device System Stack Size to 8000 bytes, and set the UXDevice memory pool size to 10000 bytes, then my application actually comes up.
So bottom line... please try to ensure that out-of-the-box configurations for components like USBX are able to function when built, instead of sending users down a rabbit hole. Thanks.
Dana M.