Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USART interrupt handler, handle Rx timeout #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ek-ap
Copy link

@ek-ap ek-ap commented Dec 17, 2021

On an ATSAME70N19B, the Harmony 3 USART interrupt handler USARTx_InterruptHandler( void ) currently discards the TIMEOUT interrupt that is generated when the timeout delay period (US_RTOR.TO) expires. Commit acc4c82 therefore adds a hook to the interrupt handler to process the Rx timeout interrupt. I would strongly ask for such a hook (as in the commit or similar) to be included in the next release, as it helps when receiving variable-length messages.

It could also make sense to enable/disable the timeout feature via the Harmony 3 Configuration interface. I'm unfortunately not familiar with how to include such options in the GUI. A similar hook could be implemented for the transmitter timeguard register (US_TTGR), and also for the LIN mode. As I only work with the standard USART mode, these are not included in the patches below.

Additionally, commit f692803 contains user interface functions to set/enable, reset, and clear/disable the Rx timeout for the standard USART interface. These are not as urgently needed as the hook in acc4c82, but it would also be nice to have such an interface.

@vishalnxt
Copy link
Collaborator

@ek-ap , thank you for reporting the issue and providing the fix. We will review it. Meanwhile, did you try using the Ring buffer mode of UART PLIB? Based on your description, it seems you are receiving variable length messages and the ring buffer mode is better suited for such requirements. You can find an example application here.

@ek-ap
Copy link
Author

ek-ap commented Dec 17, 2021

Yes I did. Unfortunately, the Ring buffer mode does not provide DMA transfer out-of-the-box. All data transfer seems to go through the processor. As we're receiving data at 2 MBaud (not a typo) on one USART interface (and also want to use the processor for other tasks), we rely on DMA data transfer. I would love to see the DMA transfer feature on the PLIB ring buffer off-the-shelf, but meanwhile the above patch will do.

We've found a way to configure the DMA linked-list mode to act similar to a ring buffer. But we need to flush the DMA data transfer after receiving of a full message (i.e. upon Rx timeout). So we need to be able to catch the USART Rx timeout interrupt.

@ek-ap
Copy link
Author

ek-ap commented May 15, 2023

How is the status of this request?

In the mean time we added cache invalidation code to the MCAN peripheral lib to make it work wit data-cache enabled. Since MCVN uses DMA for the transfers to/from the message RAM, data is corrupted if cache is not cleared/invalidated correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants