AnsweredAssumed Answered

printf over USB VCP

Question asked by lowpowermcu on Jun 19, 2014
Latest reply on Jun 19, 2014 by Clive One
Hi all,

I am trying to retarget printf over USB-VCP and I am stcuk !
I implemented the putc function in the following way:
****************************************
int fputc(int ch, FILE *f)
{
  USBD_CDC_SetTxBuffer(&hUSBDDevice, (uint8_t *)&ch, 1);
  if(USBD_CDC_TransmitPacket(&hUSBDDevice) != USBD_OK)
  {
    /* Device is busy */
    /* what should I return ? */
  }
  return ch;
}
*****************************************
As you know fputc is called by printf for printing a single character and it is called in a loop until all characters are printed.
What I am facing is that it may happen the USB is busy while sending the previous character. What do I have to do at this condition? fputc return -1 ?
PS: I am STM32 Cube V2.0.0 "18-February-2014"

Thanks

Outcomes