cancel
Showing results for 
Search instead for 
Did you mean: 

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 STMCUBEMX

shankargowda m
Associate II
Posted on May 21, 2018 at 13:12

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 #stm32f303
7 REPLIES 7
mohan raj
Associate II
Posted on July 03, 2018 at 12:42

Hi, 

    This is Mohan and I too struggle on this issues can you get any other solution from this issues

shankargowda m
Associate II
Posted on July 05, 2018 at 14:59

Temporally  you can use like this..

while(((USBD_CDC_HandleTypeDef*)(hUsbDeviceFS.pClassData))->TxState!=0);

CDC_Transmit_FS((BYTE*)&sentarray[0],count);
Posted on July 06, 2018 at 15:14

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.

Pavel A.
Evangelist III
Posted on July 06, 2018 at 18:25

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

Posted on July 09, 2018 at 08:55

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.

Posted on July 09, 2018 at 20:27

I don't want even start about their 

__HAL_LOCK ... sorry. But yes.

-- pa

Posted on July 13, 2018 at 07:40

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...