You are here

USBUART not always read from PC | Cypress Semiconductor

USBUART not always read from PC

Summary: 10 Replies, Latest post by ANKS on 25 Apr 2017 01:00 AM PDT
Verified Answers: 1
Last post
Log in to post new comments.
dzuy_1446756's picture
User
13 posts

We have a PSoC5 MCU with USBUART (CDC) enabled.

Tested that PSoC can talk to PC and vice versa.  We have a process on the PC that listens on its USB port and can receive everything the PSoC sends.  Problem is, the PSoC doesn't always get data from the PC.  We had to send multiple times and one of those times, it would get it.

In our main.c, we start and init USBUART.  The code basically has 2 functions: poll for data from PC and do something else.  In the PC polling function, we have

 if (0u != USBUART_DataIsReady()){

    // process data

}

I assume when the PC sends the data, the USBUART_DataIsReady() API should return true, but in this case, not all the time.

user_242978793's picture
User
1284 posts

Use the Volatile  for the interrupts.  Please post you code so we can check it. 

user_242978793's picture
User
1284 posts

In C#, volatile ensures that code accessing the field is not subject to some thread-unsafe optimizations that may be performed by the compiler, the CLR, or by hardware. Only the following types can be marked volatile: all reference types, Single, Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Char, and all enumerated types with an underlying type of Byte, SByte, Int16, UInt16, Int32, or UInt32.[10]

Basically volatile is a shorthand for calling Thread.VolatileRead and Thread.VolatileWrite. These methods are special. In effect, these methods disable some optimizations usually performed by the C# compiler, the JIT compiler, and the CPU itself . The methods work as follows:[11]

The Thread.VolatileWrite method forces the value in address to be written to at the point of the call. In addition, any earlier program-order loads and stores must occur before the call to VolatileWrite.
The Thread.VolatileRead method forces the value in address to be read from at the point of the call. In addition, any later program-order loads and stores must occur after the call to VolatileRead.
The Thread.MemoryBarrier method does not access memory but it forces any earlier program order loads and stores to be completed before the call to MemoryBarrier. It also forces any later program-order loads and stores to be completed after the call to MemoryBarrier. MemoryBarrier is much less useful than the other two methods

dzuy_1446756's picture
User
13 posts

The problem is not on the PC side.  It's on the PSoC side.  I have a process that poll on the USB serial port ttyACM (linux, C), and it doesn't miss any packet from PSoC.  It's when I send packets from the PC to PSoC and the PSoC only gets them some of the time.

It's no very well documented to the packets sent to PSoC if it doesn't get picked up right away?  Does it get lost? queued up?  What should be done?  Is there anything I can do besides the API functions?

PSOC BUDDY's picture
User
4 posts

Are you working on a system with Linux as OS

dzuy_1446756's picture
User
13 posts

Yes, but what does it have to do with PSoC?

dzuy_1446756's picture
User
13 posts

On page 97 of the USBFS v3 document, it states:

uint8 USBUART_DataIsReady(void)

    Description: This function returns a nonzero value if the component received data or received a zerolength packet. The USBUART_GetAll() or USBUART_GetData() API should be called to read data from the buffer and reinitialize the OUT endpoint even when a zero-length packet is received. These APIs will return zero value when zero-length packet is received.

    Parameters: None

    Return Value: uint8: If the OUT packet is received, this function returns a nonzero value. Otherwise, it returns zero. Side

    Effects: None 
 

What is OUT endpoint and how to reinitialize it?

HIMA's picture
Cypress Employee
352 posts

Hello,

Out endpoint is the data memory which will receive the data from PC. More detaisl on Endpoint please have a look at the document:http://www.cypress.com/mwg-internal/de5fs23hu73ds/progress?id=msOLCPOg_i...

Thanks,

Hima

dzuy_1446756's picture
User
13 posts

HIMA,

Your link says Page not found.

HIMA's picture
Cypress Employee
352 posts

Apologies. Can you check this link:(http://www.cypress.com/documentation/application-notes/an57294-usb-101-i...).This Application Note(AN57294 - USB 101: An Introduction to Universal Serial Bus 2.0)  explains basics of USB protocol.

Thanks,

Hima

ANKS's picture
Cypress Employee
216 posts
Log in to post new comments.