2018-05-21 4:12 AM
when I am sending data using USB, when the callback in my firmware gives me USB BUSY? i am using STM32F303VC discovery board ......USB code generated using STM32CubeMX.
Once, I received USB Busy state, dynamically sends correct data sometimes and sometimes i am losing data which i am sending...
here he is the code snippet.
i feel some issue with state change....
i am calling CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) API fro two different places alternatively....
when i call from one place it is working fine....
issue arising when calling from 2 places akternatively
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; } USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); /* USER CODE END 7 */ return result;}
#usb-cdc-f3 #usb-busy-state-issue #cdc_transmit_fs #stm32f3032018-07-03 3:42 AM
Hi,
This is Mohan and I too struggle on this issues can you get any other solution from this issues
2018-07-05 5:59 AM
Temporally you can use like this..
while(((USBD_CDC_HandleTypeDef*)(hUsbDeviceFS.pClassData))->TxState!=0);
CDC_Transmit_FS((BYTE*)&sentarray[0],count);2018-07-06 8:14 AM
Hi ,
Thanks for your reply.I have implemented the solution,which you have describe in the previous post.but the solution is
not consistent . some times working and some times return USB BUSY state.Kindly provide another solution for this issue.
2018-07-06 9:25 AM
when i call from one place it is working fine....
issue arising when calling from 2 places akternatively
CDC_Transmit_FS (and underlying ST USB library) is not reentrant, do not call it from 2 places without protecton (a semaphore or whatever).
- pa
2018-07-09 1:55 AM
Hi,
Could you please confirm is it possible reason for returning USB BUSY Flag,may be due to __HAL_LOCK state occurrence in the data packet transmission.
2018-07-09 1:27 PM
I don't want even start about their
__HAL_LOCK ... sorry. But yes.-- pa
2018-07-13 12:40 AM
Hi,
along with that you can use this interface before
HAL_NVIC_DisableIRQ(USB_LP_CAN_RX0_IRQn);
__HAL_LOCK(hpcd);
and
__HAL_UNLOCK(hpcd);
HAL_NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);in HAL_PCD_EP_Transmit () function.
this is ensuring while writing into USB transmit register to avoid USB RX interrupt
It is working for me without any data loss...
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.