cancel
Showing results for 
Search instead for 
Did you mean: 

USBX Device Stack: UX_MEMORY_INSUFFICIENT During MSC Endpoint Allocation

Grace_04
Associate II

I am using STM32N657 with USBX (MSC device).
The function ux_device_stack_initialize() is returning UX_ERROR, and after debugging inside USBX I found that the failure occurs when USBX tries to allocate endpoint transfer buffers.

The failing code inside USBX is:

#if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 0

/* Obtain some memory. */

endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer =

_ux_utility_memory_allocate(UX_NO_ALIGN, UX_CACHE_SAFE_MEMORY, UX_SLAVE_REQUEST_DATA_MAX_LENGTH);

/* Ensure we could allocate memory. */

if (endpoints_pool -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer == UX_NULL)

{

status = UX_MEMORY_INSUFFICIENT; //0x12

break;

}

#endif

So the device stack initialize fails because of UX_MEMORY_INSUFFICIENT.

My current USBX memory setup:

#define UX_APP_MEM_POOL_SIZE (128 * 1024) // 128 KB total pool
#define USBX_DEVICE_MEMORY_STACK_SIZE (5 * 1024) // only 5 KB given to USBX


I allocate memory for USBX like this:

tx_byte_allocate(byte_pool, (VOID **) &pointer, USBX_DEVICE_MEMORY_STACK_SIZE, TX_NO_WAIT);

ux_system_initialize(pointer, USBX_DEVICE_MEMORY_STACK_SIZE, UX_NULL, 0);

This means that even though my total pool is 128 KB, USBX actually receives only 5 KB for all internal allocations (endpoint buffers, MSC class buffers, descriptors, etc.).

My question:

Is 5 KB far too small for USBX MSC on STM32N6?
What is the recommended minimum memory size that must be passed to ux_system_initialize() when using MSC (Mass Storage Class)?

From debugging, USBX cannot allocate the MSC endpoint transfer buffers with only 5 KB, so initialization fails with UX_MEMORY_INSUFFICIENT.
I want to know the correct recommended memory size for MSC on STM32N6.

I am using USBX specifically for Mass Storage Device (MSC).

Thank you.

1 REPLY 1
T_Hamdi
ST Employee

Hello @Grace_04,

you can refer to the USBX Mass Storage Class (MSC) Device application provided in the STM32CubeN6 software package. This example will help you understand how to configure and use the MSC class with USBX.

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.
Hamdi Teyeb