Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX Configure USB Host



I am currently using STM32CubeMX version 6.4.0 to configure the STM32H7 series. I have configured it as a USB host, and I want to send messages through USB. Therefore, I called the USBH_CDC_Transmit function. However, when this function reaches the if condition, it directly jumps into the HardFault_Handler. I don't know why. Below is the specific function USBH_CDC_Transmit:

USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)


USBH_StatusTypeDef Status = USBH_BUSY;

CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;

if ((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA))


CDC_Handle->pTxData = pbuff;

CDC_Handle->TxDataLength = length;

CDC_Handle->state = CDC_TRANSFER_DATA;

CDC_Handle->data_tx_state = CDC_SEND_DATA;

Status = USBH_OK;

#if (USBH_USE_OS == 1U) phost->os_msg = (uint32_t)USBH_CLASS_EVENT;

#if (osCMSIS < 0x20000U) (void)osMessagePut(phost->os_event, phost->os_msg, 0U);

#else (void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL);




return Status;



Pavel A.
Evangelist III

Hi, the CubeIDE debugger has a convenient tool, Fault analyzer. Whenever you see a hard fault, use it to determine the reason.

"I'm developing with Clion and STM32CubeMX. When debugging with Clion, I found that it first reported an unrelated range for 0x00000000fffffff9, then jumped to HardFault_Handler. Does this indicate a null pointer situation?"