Skip to main content
PESHWA
Associate III
December 15, 2023
Solved

how to get usb status

HELLO

I am working with Xmodem  file transferring vai usb  I want to know how i get know about USB status like  Ready or not how we get in UART 

 

while (!(HAL_UART_GetState(&huart4) == HAL_UART_STATE_READY) && wTimeout) {
wTimeout--;
}

if (HAL_UART_GetState(&huart4) == HAL_UART_STATE_READY)
break;
}
like this we have any things in USB i may not aware let me know 

 

This topic has been closed for replies.
TDK
TDKBest answer
December 15, 2023

There isn't a built-in function to do this, but you can make your own.

It depends on the USB class you're using. Here is the check for CDC:

uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len)
{
 uint8_t result = USBD_OK;
 /* USER CODE BEGIN 12 */
 USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceHS.pClassData;
 if (hcdc->TxState != 0) {
 return USBD_BUSY;
 }
 USBD_CDC_SetTxBuffer(&hUsbDeviceHS, Buf, Len);
 result = USBD_CDC_TransmitPacket(&hUsbDeviceHS);
 /* USER CODE END 12 */
 return result;
}

Be careful not to dereference null pointers.

"If you feel a post has answered your question, please click ""Accept as Solution""."

2 replies

TDK
TDKBest answer
December 15, 2023

There isn't a built-in function to do this, but you can make your own.

It depends on the USB class you're using. Here is the check for CDC:

uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len)
{
 uint8_t result = USBD_OK;
 /* USER CODE BEGIN 12 */
 USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceHS.pClassData;
 if (hcdc->TxState != 0) {
 return USBD_BUSY;
 }
 USBD_CDC_SetTxBuffer(&hUsbDeviceHS, Buf, Len);
 result = USBD_CDC_TransmitPacket(&hUsbDeviceHS);
 /* USER CODE END 12 */
 return result;
}

Be careful not to dereference null pointers.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Roger SHIVELY
ST Employee
December 15, 2023

Hello @PESHWA ,

There has been a case created to resolve this question and we will be reaching out to you directly.

Regards,
Roger