cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMx error in usb code generation

jl
Associate
Posted on June 29, 2016 at 11:17

i have generate sample usb-cdc code for stm32F103c8 with CubeMx. The real code generate hardfaults in disconnect from usb. This is the Problem in usbd_conf.c:

-------------------------------------

/** * @brief static single allocation. * @param size: size of allocated memory * @retval None */

void

*USBD_static_malloc(uint32_t size) {

static

uint32_t mem[(

sizeof

(USBD_CDC_HandleTypeDef)/

4

)+

1

];

//On 32-bit boundary

return

mem; }

/** * @brief Dummy memory free * @param *p pointer to allocated memory address * @retval None */

void

USBD_static_free(

void

*p) { free(p); // !!!!!!!!!! error !!!!!!! } ---------------------------------------------------

USBD_static_malloc map memory to static a static variable. USBD_static_free call free(void *)! This corrupt the memory from p.

(sorry, my english ist not good)

2 REPLIES 2
slimen
Senior
Posted on June 29, 2016 at 13:40

Hi,

I confirm with STM32CubeMx 4.15.1, it generates a USB code with a call to free() in usbd_conf.c and this can crashes the software when disconnect USB.

Regards

slimen
Senior
Posted on September 08, 2016 at 16:29

Hi,

This bug is already fixed in the release CubeMX 4.16

Regards