cancel
Showing results for 
Search instead for 
Did you mean: 

how to get usb status

PESHWA
Associate II

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 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

2 REPLIES 2
TDK
Guru

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

Hello @PESHWA ,

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

Regards,
Roger