CDC_Transmit_FS function always returns USBD_BUSY
I am now trying to implement CDC-VCP connection between a PC and a STM32 board. Just my goal is a STM32 echo server.
I have done like this:
- STM32 Cube MX :
- USB FS endable
- USB Device : CDC Enable, rx/tx buffer size as 128<-1000
- Clock config : USB 48MHz and other config is done by "resolve clock issue"
- SYS : serial debug enabled
- RCC : Enable LSC as Crystal/Ceramic
- Code :
- in "while" body,
- #include "usbd_cdc_if.h"
- add Hal_Delay(500)
- CDC_Transmit_FS(tx, strlen(tx));
- in "while" body,
- Debug :
- debug by STLink
- connection : PC <-USB cable->STM32 (L432KC, L073RZ both)
- Result :
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
/* USER CODE BEGIN 7 */
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
if (hcdc->TxState != 0){
return USBD_BUSY; //<-Always triggered
}
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
/* USER CODE END 7 */
return result;
}
Can anybody tell me how resolve this problem?
