CAN RX continuously using eDMA

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAN RX continuously using eDMA

496 Views
AmanKumbhani
Contributor II

Hi All,

I have a use case where I continuously get data via CAN every 20 milliseconds, and I have to send the data as is via UART. For CAN reception, I did not want the CPU to be checking and reinitializing DMA every 20 milliseconds post completion.

My idea was to set the source of the DMA MUX channel to the CAN FIFO, and use a ping pong buffer to continuously save data in memory. However, the CAN RX EDMA drivers callback aborts DMA transfer everytime the ISR is triggered. Second approach that I tired was to add a periodic timer and enable trigger mode for channel 0 (one I am using for CAN), and every 20 milliseconds when the timer elapses, a DMA request will be generated and if there is a peripheral request from CAN too, data will move from the CAN FIFO to the memory. I tired this approach as well and this ended up into me getting bus errors.

Is there a better way of doing this or an example code for the same? Thank you!

Tags (1)
0 Kudos
Reply
1 Reply

463 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Using a timer to trigger DMA for CAN can cause bus errors due to unsynchronized peripheral requests. FlexCAN already supports DMA request generation on FIFO events—use that instead.
To prevent ISR abort, instead, use major loop completion interrupt to switch buffers.

BR,
Omar

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2184828%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ECAN%20RX%20continuously%20using%20eDMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2184828%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3EI%20have%20a%20use%20case%20where%20I%20continuously%20get%20data%20via%20CAN%20every%2020%20milliseconds%2C%20and%20I%20have%20to%20send%20the%20data%20as%20is%20via%20UART.%20For%20CAN%20reception%2C%20I%20did%20not%20want%20the%20CPU%20to%20be%20checking%20and%20reinitializing%20DMA%20every%2020%20milliseconds%20post%20completion.%3C%2FP%3E%3CP%3EMy%20idea%20was%20to%20set%20the%20source%20of%20the%20DMA%20MUX%20channel%20to%20the%20CAN%20FIFO%2C%20and%20use%20a%20ping%20pong%20buffer%20to%20continuously%20save%20data%20in%20memory.%20However%2C%20the%20CAN%20RX%20EDMA%20drivers%20callback%20aborts%20DMA%20transfer%20everytime%20the%20ISR%20is%20triggered.%20Second%20approach%20that%20I%20tired%20was%20to%20add%20a%20periodic%20timer%20and%20enable%20trigger%20mode%20for%20channel%200%20(one%20I%20am%20using%20for%20CAN)%2C%20and%20every%2020%20milliseconds%20when%20the%20timer%20elapses%2C%20a%20DMA%20request%20will%20be%20generated%20and%20if%20there%20is%20a%20peripheral%20request%20from%20CAN%20too%2C%20data%20will%20move%20from%20the%20CAN%20FIFO%20to%20the%20memory.%20I%20tired%20this%20approach%20as%20well%20and%20this%20ended%20up%20into%20me%20getting%20bus%20errors.%3C%2FP%3E%3CP%3EIs%20there%20a%20better%20way%20of%20doing%20this%20or%20an%20example%20code%20for%20the%20same%3F%20Thank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2186019%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20CAN%20RX%20continuously%20using%20eDMA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2186019%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EUsing%20a%20timer%20to%20trigger%20DMA%20for%20CAN%20can%20cause%20bus%20errors%20due%20to%20unsynchronized%20peripheral%20requests.%20FlexCAN%20already%20supports%20DMA%20request%20generation%20on%20FIFO%20events%E2%80%94use%20that%20instead.%3CBR%20%2F%3ETo%20prevent%20ISR%20abort%2C%20instead%2C%20use%20major%20loop%20completion%20interrupt%20to%20switch%20buffers.%3C%2FP%3E%0A%3CP%3EBR%2C%3CBR%20%2F%3EOmar%3C%2FP%3E%3C%2FLINGO-BODY%3E