message: Move USB CDC block to case statement + formatting
diff: ******************************************************************************
  */
  -#include <sys/unistd.h>
  #include <cmsis_os.h>
  +#include <commands.h>
  #include <freertos_vars.h>
  -#include <usbd_cdc_if.h>
  +#include <sys/unistd.h>
  #include <usart.h>
  -#include <commands.h>
  -
  +#include <usbd_cdc_if.h>
  //int _read(int file, char *data, int len) {}
  //int _close(int file) {}
  @@ -28,11 +27,20 @@ int _write(int file, char *data, int len) {
  //number of bytes written
  int written = 0;
  switch (serial_printf_select) {
  -
  case SERIAL_PRINTF_IS_USB: {
  // transmit over CDC
  uint8_t status = CDC_Transmit_FS((uint8_t*)data, len);
  written = (status == USBD_OK) ? len : 0;
  +
  + // Wait for transmission to complete
  + USBD_CDC_HandleTypeDef* hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
  + while (hcdc->TxState != 0) {
  + osSemaphoreWait(sem_usb_irq, 0);
  + // We have a new incoming USB transmission: handle it
  + HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
  + // Let the irq (OTG_FS_IRQHandler) fire again.
  + HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
  + }
  } break;
  case SERIAL_PRINTF_IS_UART: {
  @@ -46,25 +54,15 @@ int _write(int file, char *data, int len) {
  memcpy(uart_tx_buf, data, len);
  // Start DMA background trasnfer
  HAL_UART_Transmit_DMA(&huart4, uart_tx_buf, len);
  - } break;
  while (huart4.gState != HAL_UART_STATE_READY) {
  // Do nothing
  }
  + } break;
  default: {
  written = 0;
  } break;
  }
  - // Wait for transmission to complete
  - USBD_CDC_HandleTypeDef* hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
  - while (hcdc->TxState != 0) {
  - osSemaphoreWait(sem_usb_irq, 0);
  - // We have a new incoming USB transmission: handle it
  - HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
  - // Let the irq (OTG_FS_IRQHandler) fire again.
  - HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
  - }
  -
  return written;
  }
  