title: STML4 USB virtual com port
body: <p>I have the nucleo board (nucleo-L4R5ZI) and want to write a code to be able to send data from a uC to a PC via the USB. I followed some tutorials, used STM32CubeMx, other solutions found across the Internet, but anyways I failed. I can open the vcp on the PC side (using Hterm, TeraTerm and Realterm), but cannot get any data.</p>
  
  <p>I use Eclipse and the buildin debugger, which I flashed to JLink. </p>
  
  <p>The main loop:</p>
  
  <pre><code>int main(void)
  {
  
    HAL_Init();    
    SystemClock_Config();    
    MX_GPIO_Init();    
    MX_USB_DEVICE_Init();    
    HAL_Delay(10000);
  
    uint8_t HiMsg[] = "0123456789987654321001234567899876543210\r\n";
    while (1)
    {    
         if( CDC_Transmit_FS(HiMsg, 20) == USBD_OK )
         {
             HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // blue LED
         }
         HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14); // red LED
         HAL_Delay(1000);
    }    
  }
  </code></pre>
  
  <p>After executing this function, the blue LED lights only once and never changes its state (does not blink). It means that the CDC_Transmit_FS(...) returns USBD_OK only once, and next calls give USBD_Busy. </p>
  
  <p>The MX_USB_DEVICE_Init() looks as follow:</p>
  
  <pre><code>void MX_USB_DEVICE_Init(void)
  {
    USBD_Init(&amp;hUsbDeviceFS, &amp;FS_Desc, DEVICE_FS);
    USBD_RegisterClass(&amp;hUsbDeviceFS, &amp;USBD_CDC);
    USBD_CDC_RegisterInterface(&amp;hUsbDeviceFS, &amp;USBD_Interface_fops_FS);
    USBD_Start(&amp;hUsbDeviceFS);
    USBD_CDC_Init (&amp;hUsbDeviceFS, &amp;USBD_CDC); // I need to init it somewhere so I think here is a good place
  }
  </code></pre>
  
  <p>The CDC_Transmit_FS looks like that:</p>
  
  <pre><code>uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
  {
  
    uint8_t result = USBD_OK;
    /* USER CODE BEGIN 7 */
    CDC_Init_FS();
    USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
    if (hcdc-&gt;TxState != 0){
      return USBD_BUSY;
    }
    USBD_CDC_SetTxBuffer(&amp;hUsbDeviceFS, Buf, Len);
    result = USBD_CDC_TransmitPacket(&amp;hUsbDeviceFS);
    CDC_Init_FS();
    /* USER CODE END 7 */
    return result;
  }
  </code></pre>
  
  <p>Does anyone know how to make it running? What do I miss?</p>
  
  <p>Best,</p>