USBUART not always read from PC

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

cross mob
DzNg_1446756
Level 3
Level 3
First like received First like given

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.

0 Likes
10 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

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

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

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

0 Likes
DzNg_1446756
Level 3
Level 3
First like received First like given

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?

0 Likes
PSBU_2325551
Level 4
Level 4
First like received

Are you working on a system with Linux as OS

0 Likes

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

0 Likes
DzNg_1446756
Level 3
Level 3
First like received First like given

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?

0 Likes
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

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_iK-re3H2gSUjOZYkDrPn5eIAC33jd...

   

Thanks,

   

Hima

0 Likes

HIMA,

   

Your link says Page not found.

0 Likes
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

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

   

Thanks,

   

Hima

0 Likes