Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > USB Controllers > Reading single Bytes from UART

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Reading single Bytes from UART
Moderator:
RSKV

Post Reply
Follow this topic



Reading single Bytes from UART

frw posted on 04 Dec 2012 4:14 AM PST
Member
3 Forum Posts

Hi all,

for my Application ( Composite Device UVC + CDC-ACM ) I need to receive single bytes from the FX3 UART and forward them to the appropriate CDC Bulk EP..
Using DMA doesn't work because the data will transferred only if a buffer is filled, what means that at least 16 bytes have to be read.
When using the UART in register mode the function CyU3PUartReceiveBytes(...) seems to Block the whole system for a while if no bytes are available, even if I use it in a separate thread! Is there any possibility to avoid this?




Re: Reading single Bytes from UART

Lumpi6 posted on 04 Dec 2012 05:38 AM PST
Top Contributor
183 Forum Posts

Hi,

see FX3ReleaseNotes.pdf file at known issues why DMA mode is not working....

7. Any UART/I2C/SPI read transfers in DMA mode that do not fill up the entire DMA buffer will
not trigger a DMA callback or a transfer complete event. The application needs to check for
transfer completion based on the UART/I2C/SPI events and then invoke the
CyU3PDmaChannelSetWrapUp() API on the DMA channel.

 

For register mode your device on the rx has to send something, otherwise the error code timeout is returned from the function call and with that you may be can handle it.

regards,

lumpi



Re: Reading single Bytes from UART

frw posted on 04 Dec 2012 10:01 AM PST
Member
3 Forum Posts

I registered an Interrupt callback function with CyU3PRegisterUartCallback().

But I do not receive any Events there. The Callback-Function is never called.

Do I have to enable UART Interrupt? If yes, how can i do it?

Regards

frw



Re: Reading single Bytes from UART

Gayathri posted on 04 Dec 2012 09:08 PM PST
Cypress Employee
327 Forum Posts

 Hi,

 

You may set the number of bytes to be received using CyU3PUartRxSetBlockXfer API. Aftre you receive so  many number of bytes in UART, as set in CyU3PUartRxSetBlockXfer, you will enter UART callback. We have an example for demonstrating the same. If you would like to get the same, please create a tech support case at www.cypress.com.

 

Regards,

Gayathri



Re: Reading single Bytes from UART

frw posted on 06 Dec 2012 12:46 AM PST
Member
3 Forum Posts

Hi,

OK, I receive Interrupts now, After setting CyU3PUartRxSetBlockTransfer( 1 )

In my application I use two DMA Auto channels:
One from UART to the USB-CDC Bulk-EP and another one vice versa.
I changed my Application to use the Interrupt callback to call CyU3PDmaChannelSetWrapUp(..).
Now I receive an interrupt and send the Bytes. BUT: One byte received by the UART always stucks in the System and it is only sent, when the next byte is written into the UART. E.g. sending "1234" pause "5" into the UART RX, the Host receives "123" pause "4".
Any Idea how I can Fix it?

Regards
frw



Re: Reading single Bytes from UART

Garyio posted on 06 Dec 2012 01:55 PM PST
Member
8 Forum Posts

I have been having the same issue and I have some code that is working but I'm not sure how reliable it is. I am still testing.

What I did was to setup the UART in DMA mode and also setup an interrupt callback function and use a thread to manage the data if I do not receive enough data for the DMA callback function to be triggered.

In the interrupt callback function I check if it is being called because of an RX DONE event and if so I increment a counter and set an event. In my thread it is waiting forever on this event. As soon as the thread wakes up by the event I clear the event. Then I have a do while loop that first saves the current interrupt count and then sleeps for a while (Some amount of time to allow more bytes to be received by the UART. This might depend on your baud rate.). When it wakes up from sleeping it checks if the current interrupt count is the same as it was before sleeping. If it is the same then no more data has arrived and I call the wrapup function. If not the while part quits if the interupt count is zero or after a timeout count. So I only wait for maybe four times in the loop. In the DMA callback function I clear the interrupt counter and do whatever I want with the data. This way if the DMA callback happens while I'm sleeping I will see there is no more data and go back to waiting for the event.

The whole idea is that if some data arrives but it's not enough to trigger the DMA callback then I call the wrapup function to cause the DMA callback function to be called and process the data that has arrived. If the DMA callback gets called while waiting for more data then everything worked and we don't need to call the wrapup funciton. Also if more data arrives after the wrapup was called the event will get set so the thread will go back to the begining and do it again.

Like I said it is working but I have been told that it's not always reliable. If someone comes up with some new ideas it would be great to hear about them.

Thanks,

Gary

 

 






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.