2014-11-25 05: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 04: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;
}
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..
2014-11-26 04: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 06: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.