Skip to main content
Associate II
July 22, 2026
Solved

USBX configuration check - potential bug with USBX System Stack Size

  • July 22, 2026
  • 3 replies
  • 93 views

I encountered a potential bug in CubeMXs Configuration Checks for USBX.

I am trying to configure USBX in standalone mode. When i try to increase the value of “USBX System Stack Size” to be higher than 1024 i get a warning that it needs to be lower than the USBX memory pool size, even when this is the case.

Attached is a screenshot with example settings. To reproduce the error set USBX System Stack Size to 1025.
The used MCU is a STM32U385CGTx

Best regards, Cecil
 

 

Best answer by Ghofrane GSOURI

Hello ​@CecilW 

Your contribution is much appreciated.

Issue has been escalated to dev team under internal ticket ID #0064608

As a workaround, generate the project code first, then manually edit app_usbx.h and change:

#define USBX_MEMORY_STACK_SIZE

to the value required by your application.

This allows the desired USBX system stack size to be set even when STM32CubeMX rejects the value in the GUI.

Note: this manual change may be overwritten if the project is regenerated from STM32CubeMX, so it should be reapplied after each code generation

THX

Ghofrane

3 replies

Ghofrane GSOURI
Ghofrane GSOURIBest answer
ST Technical Moderator
July 22, 2026

Hello ​@CecilW 

Your contribution is much appreciated.

Issue has been escalated to dev team under internal ticket ID #0064608

As a workaround, generate the project code first, then manually edit app_usbx.h and change:

#define USBX_MEMORY_STACK_SIZE

to the value required by your application.

This allows the desired USBX system stack size to be set even when STM32CubeMX rejects the value in the GUI.

Note: this manual change may be overwritten if the project is regenerated from STM32CubeMX, so it should be reapplied after each code generation

THX

Ghofrane

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.
TDJ
Senior III
September 1, 2026

Hello ​@Ghofrane GSOURI and ​@CecilW 

I may experience a similar issue with STM32U5G9.
My USBX setup is very basic, only MSC class is enabled - scrsht see below.
USBX memory is configured as follows:

#define USBX_MEMORY_STACK_SIZE       8*1024
#define UX_APP_MEM_POOL_SIZE            256*1024 // max allowed value

No matter how I increase the available memory, function MX_USBX_Host_Stack_Init() fails calling
    ux_host_stack_hcd_register()
        hcd_init_function()
            _ux_hcd_stm32_initialize() - returns status UX_MEMORY_INSUFFICIENT trying to “Allocate the list of eds.” (file ux_hcd_stm32_initialize.c, line 122)

I am clueless.

 

TDJ
Senior III
September 1, 2026

Update: I found that increasing USBX_MEMORY_STACK_SIZE to min 9 kB helps just to initialize the host. Default value is far too small. Practically 24 kB should be used. See here.
UX_APP_MEM_POOL_SIZE can probably stay as small as 40 kB. See this thread.

Note: CubeMX has a bug. USBX_MEMORY_STACK_SIZE needs to be modified in code. Changing it in Cube MX make no difference, Cube MX does not persist this value. When *.ioc file is open again “USBX System Stack Size” reverts to default 1024.
Needless to say, Cube MX overwrites USBX_MEMORY_STACK_SIZE set in code! It has been already reported here.