cancel
Showing results for 
Search instead for 
Did you mean: 

I'm getting USBD_BUSY when i try to transmit data via virtual com port

EGüle.1
Associate
char *data = "Hello World";    
 
while (1)   {    	
 
HAL_GPIO_TogglePin(LD2_GPIO_Port,LD2_Pin); 	
 
HAL_Delay(1000); 	
 
CDC_Transmit_FS((uint8_t*)data,strlen(data));    }

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

I'm trying to transmit MPU6050 sensor readings to my computer via virtual comport.I'm using STM32 Nucleo F446RE. As far as i can see in debug mode there is no issue in sensor and sensor readings. Problem is I can't transmit them using USB. Are there anyone who have experienced this issue before?

1 REPLY 1
gbm
Lead III
  1. Do you have the F446 USB connected to your PC? The target MCU USB connector in not present on the Nucleo64 board - you need to use some extension borad with USB connector.
  2. You cannot transfer anything via VCOM until it's connected, physically and logically - the terminal is open. Typically, the VCOM is operational about 50 ms after the terminal connection is established.
  3. Calling CDC_Transmit_FS() from main will sooner or later lead to a hangup - you may call it only from an ISR of the same priority as USB interrupt.
  4. Start with VCOM character echo, then try to add your functionality.
My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice