2 Replies Latest reply on Jul 13, 2020 3:11 PM by baga_4725781

    Noticed an off-by-one for the USB UART

    baga_4725781

      I got the USB serial working.

      Used GitHub - cypresssemiconductorco/mtb-example-psoc6-usb-cdc-echo: This example demonstrates how to configure the USB block…

       

      Wrote a little function to make the calling code cleaner. Noticed I need to give 2 bytes for the first one to show up.

      There is a non-flushed buffer somewhere.

      I isolated it down to the below.

       

      (Same case with the original code.)

       

      //========================================================================
      // int is_data_ready( uint32_t port )
      // call:    port:   port number
      //
      // driver function just returns a boolean. If error, returns false
      //
      // NOTE: This has an off-by-one bug
      //  Cy_USB_Dev_CDC_IsDataReady() is behind one byte
      // The finction is in .\libs\usbdev\cy_usb_dev_cdc.c
      // It calls Cy_USBFS_Dev_Drv_GetEndpointState()
      // which is an inline macro in libs\psoc6pdl\drivers\include\cy_usbfs_dev_drv.h
      // It uses:
      //     cy_stc_usbfs_dev_drv_context_t const *context
      //     context->epPool[CY_USBFS_DEV_DRV_EP2PHY(endpoint)].state
      // we will need to deal with it.
      // Note we are sending data across the USB from a computer.
      // We can just send an extra NL
      //
      //========================================================================

      int is_data_ready( uint32_t port )
      {
          if( Cy_USB_Dev_CDC_IsDataReady( port, &usb_cdcContext ))
              return( 1 );
          else
              return( 0 );
      }