2014-11-25 5:47 PM
I am using VCP firmware from STM, but I have a problem when I am transmitting my data using the CDC class
I am sending data from my firmware to my PC, if I did open the serial port in my PC side, and i am still sending data, i will be getting USBD_BUSY from USBD_TransmitPcket function..and when I open my serial port from PC now, my PC side will hang!How do i handle the USBD_BUSY?Is there anyway I can check the status of the USBD state? if it is busy or not?2014-11-25 10:28 PM
May I know how can I clear that USBD_BUSY?
I check the firmware code, the only way to clear the USBD_BUSY is when it is interupted in HAL_PCD_IRQHandler > HAL_PCD_DataInStageCallback > USBD_CDC_DataIn to clear the USBD_BUSY, I think in my firmware, it could be this interupt is not generated or missed..how can generate this interupt manually?2014-11-26 4:16 AM
I have the same problem for STM32F4-Discovery. I generated code using STM32CubeMX, just changed the CDC_Receive_FS and CDC_Transmit_FS functions to be like this:
static
int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 7 */
if
(*Len > 0) {
if
(Buf[0] == 
'A'
) {
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
} 
else
if
(Buf[0] == 
'B'
) {
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);
}
}
USBD_CDC_ReceivePacket(hUsbDevice_0);
return
(USBD_OK);
/* USER CODE END 7 */
}
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
/* USER CODE BEGIN 8 */
USBD_CDC_SetTxBuffer(hUsbDevice_0, Buf, Len); 
result = USBD_CDC_TransmitPacket(hUsbDevice_0);
/* USER CODE END 8 */
return
result;
}2014-11-26 4:07 PM
What i do is when it is USB BUSY state, i would empty the Tx buffer by calling this code
USBD_LL_DataInStage(pdev, 0x81, 0);then, it will trigger an interupt to clear the USB BUSY flag.But, i am not sure if this is a goof solution or there is anyone with better solutiion2014-11-26 6:14 PM
But, if I would run it long enough, i will still encounter the USB BUSY,
emptying the Tx buffer doesnt solve it..Anyone got better solution?2014-12-03 12:37 AM
Anything? Would it help if I upload my project's files? Thanks.
