Noticed an off-by-one for the USB UART

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
baga_4725781
Level 3
Level 3
10 replies posted 5 replies posted 5 questions asked

I got the USB serial working.

Used GitHub - cypresssemiconductorco/mtb-example-psoc6-usb-cdc-echo: This example demonstrates how to con...

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

0 Likes
1 Solution
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello baga_4725781

We have tested the USB CDC Echo code example and noticed that the first letter that we provide is displayed on the Terminal immediately without the need to provide two bytes.

We have also tried programming the project (USB_CDC_Echo) provide by you in the thread: Issues with the USBFS UART example

and we have made the same observation.

We were using Tera Term for the testing.

Can you please let us know the terminal emulator that you have been using? Please let us know if the same issue can be observed using tera term.

Best Regards

Ekta

View solution in original post

0 Likes
2 Replies
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello baga_4725781

We have tested the USB CDC Echo code example and noticed that the first letter that we provide is displayed on the Terminal immediately without the need to provide two bytes.

We have also tried programming the project (USB_CDC_Echo) provide by you in the thread: Issues with the USBFS UART example

and we have made the same observation.

We were using Tera Term for the testing.

Can you please let us know the terminal emulator that you have been using? Please let us know if the same issue can be observed using tera term.

Best Regards

Ekta

0 Likes

I use putty by default.

I have some Windows serial port code.

I am trying to just use that to see if a low-leveli/o will work or have the same issue.

Stay tuned ... yours ... bandit

0 Likes