cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7508 USB-Stick -> Cannot allocate memory for MSC Handle

Roman REITER
Associate III

I have an STM32F508 board and want to connect a USB stick. However, the stick is not recognized. I get the following messages in the debug messages:

DEBUG : Cannot allocate memory for MSC Handle

Device not supporting MSC class.

Tried it with the same settings with a STM32F411 board. Here it works.

Can anyone tell me where the problem is?

1 ACCEPTED SOLUTION

Accepted Solutions
Roman REITER
Associate III

WTF

When I change the definitions it seems to work.

/** Alias for memory allocation. */
#define USBH_malloc         pvPortMalloc
 
/** Alias for memory release. */
#define USBH_free           vPortFree

View solution in original post

8 REPLIES 8

What are you building with?

What size is the heap?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Roman REITER
Associate III

I create the Gui with TouchGFX and the logic with CUBE-IDE.

The heap from what? Minimum-Heapsize ist 0x2000.

If these messages are coming from the F7, I'd suggest grep'ing the source and understanding the cause and context.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Roman REITER
Associate III

I already have. only I don't know anymore. can only be the "USBH_malloc"!?

In the usbh_msc.c i found the message with the allocation.

  phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc(sizeof(MSC_HandleTypeDef));
  MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
 
  if (MSC_Handle == NULL)
  {
    USBH_DbgLog("Cannot allocate memory for MSC Handle");
    return USBH_FAIL;
  }

Ok, so figure out what pool that's pulling from.

If you're malloc()ing large buffers for other purposes, or that the handle is excessively large.

Check it's using the pool you expect.

Check if it's using _sbrk() from newlibs/syscalls, and that the heap and stack resided in the same memory region, if the code is expecting that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Check how USBH_malloc is defined. It depends on some USB configuration .h file in your project. It can be mapped to malloc/free or something else.

In file usb_conf.h is the following definition.

/** Alias for memory allocation. */
#define USBH_malloc         malloc

Roman REITER
Associate III

WTF

When I change the definitions it seems to work.

/** Alias for memory allocation. */
#define USBH_malloc         pvPortMalloc
 
/** Alias for memory release. */
#define USBH_free           vPortFree