cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F2 VCP Tx Handling USBD_BUSY

hosweetim
Associate II
Posted on November 26, 2014 at 02:47

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?

5 REPLIES 5
hosweetim
Associate II
Posted on November 26, 2014 at 07:28

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?

qwer.asdf
Senior
Posted on November 26, 2014 at 13:16

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;
}

The first time I am using the function, e.g. CDC_Transmit_FS((uint8_t*)''AAA '', 4), I get USBD_OK and I receive the string in PC, the next time I am trying the send data using the same function I always get USBD_BUSY and don't receive anything in PC while I can send data from PC to the device and receive it inside CDC_Receive_FS function without any problem (I can see it by the toggled leds). For some reason the USBD_CDC_DataIn function (which is reseting the TxState) is being called by usbd_core only for the first time. Trying to debug further..
hosweetim
Associate II
Posted on November 27, 2014 at 01:07

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 solutiion

hosweetim
Associate II
Posted on November 27, 2014 at 03:14

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?

qwer.asdf
Senior
Posted on December 03, 2014 at 09:37

Anything? Would it help if I upload my project's files? Thanks.