Skip to main content
Visitor II
December 15, 2023
Solved

how to get usb status

  • December 15, 2023
  • 2 replies
  • 1132 views

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.
    Best answer by TDK

    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.

    2 replies

    TDKAnswer
    Super User
    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.

    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