cancel
Showing results for 
Search instead for 
Did you mean: 

USB Tx-state Busy

Roger Sacchelli
Associate

Hi,

I have an application running on STM32F429ZIT6 using USB stack to communicate with PC client.

MCU receives one type of message of 686 bytes every second and receives another type of message of 14 bytes afterwards with 0,5 secods of delay between messages. The 14 bytes message is a heartbeat so it needs to replied by MCU.

It happens that after 5 to 10 minutes of continuous operation, MCU is not able to send data because hcdc->TxState is alway 1, ie, busy. Reception works fine.

During Rx interruption, application only adds data to ring buffer, so that this buffer is later serialized and processed by main function.

static int8_t CDC_Receive_HS(uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 11 */
 
 
  /* Message RX Completed, Send it to Ring Buffer to be processed at FMC_Run()*/
  for(uint16_t i = 0; i < *Len; i++){
	  ring_push(RMP_RXRingBuffer, (uint8_t *) &Buf[i]);
  }
 
 
  USBD_CDC_SetRxBuffer(&hUsbDeviceHS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceHS);
 
  return (USBD_OK);
  /* USER CODE END 11 */
}

USB TX is also kept as simple as possible:

uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len)
{
  uint8_t result = USBD_OK;
  /* USER CODE BEGIN 12 */
  USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceHS.pClassData;
  if (hcdc->TxState != 0){
	ZF_LOGE("Tx failed, resource busy\n\r");
    return USBD_BUSY;
  }
  USBD_CDC_SetTxBuffer(&hUsbDeviceHS, Buf, Len);
  result = USBD_CDC_TransmitPacket(&hUsbDeviceHS);
 
  ZF_LOGD("TX Message Result:%d\n\r", result);
 
  /* USER CODE END 12 */
  return result;
}

I'm using latest HAL Drivers and software from CubeIDE (1.27.1).

Thanks in advance, any support is appreciated.

0 REPLIES 0