S32K358 CAN RTD Watermark

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

S32K358 CAN RTD Watermark

Jump to solution
2,222 Views
Greavesinator85
Contributor III

I'm trying to use the FlexCAN_Ip RTD drivers for an efficient CAN receive loop. I've been able to do this with FreeRTOS, using interrupt mode and enhanced RX. In this mode, I configure watermark to be 8, but in my FlexCAN_UserCallback only FLEXCAN_EVENT_ENHANCED_RXFIFO_COMPLETE fires, and if I do not add a call to FlexCAN_Ip_RxFifo when this happens, no more interrupts fire. 

 

How am I meant to use watermark mode? Is it only available with DMA?

0 Kudos
Reply
1 Solution
2,154 Views
Greavesinator85
Contributor III

I now have this working. The qualifiers around the buffer was key to avoid the corruption;

__attribute__(( aligned(32) )) static Flexcan_Ip_MsgBuffType gEnhancedRxFifoBuffer[ENHANCED_RXFIFO_WATERMARK] __attribute__ ((section (".mcal_bss_no_cacheable")));

 

Thanks for all your help!

View solution in original post

6 Replies
2,155 Views
Greavesinator85
Contributor III

I now have this working. The qualifiers around the buffer was key to avoid the corruption;

__attribute__(( aligned(32) )) static Flexcan_Ip_MsgBuffType gEnhancedRxFifoBuffer[ENHANCED_RXFIFO_WATERMARK] __attribute__ ((section (".mcal_bss_no_cacheable")));

 

Thanks for all your help!

2,161 Views
Greavesinator85
Contributor III

Apologies for the spam, I'm just actively debugging this. Setting FlexCAN_Ip_RxFifo before FlexCAN_Ip_SetStartMode has solved the EDMA->ES is set to SBE_1 error. Now I am investigating why the buffer is not holding the correct data. I'm sending ID 0x200 with 64 bytes counting up. I see some of this counting data but it is in chunks and can be missing large pieces, generally looks corrupted, and the address ID is always 0

0 Kudos
Reply
2,161 Views
Greavesinator85
Contributor III

Looks like after FlexCAN_Ip_SetStartMode, EDMA->ES is set to SBE_1

0 Kudos
Reply
2,161 Views
Greavesinator85
Contributor III

Ok, I have the DMA working in my application, thanks for your help. The example pointed me to Dma_Mux_IP_init which I was missing.

Now I do get the interrupt when it works, the first call to FlexCAN_Ip_RxFifo may pass or fail, but everything is smooth beyond that. This failure is at Static_Dma_Ip_GetLogicChannelError inside Dma_Ip_SetLogicChannelTransferList. I am using FreeRTOS as mentioned, any idea why this might be occurring? LocChState->LogicChErrors is returning 0x80000002

Also, I'm testing with 1 buffer, but the data seems corrupt, i.e. the ID is never correct

0 Kudos
Reply
2,195 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @Greavesinator85,

RTD driver is written in a way you need to call FlexCAN_Ip_RxFifo first, an interrupt is called once there is at least 1 message in the RXFIFO, driver reads single message from RXFIFO, and user has to call FlexCAN_Ip_RxFifo to enable interrupt again.

This was previously discussed with a colleague in this community post: Solved: S32K344 Using FlexCAN with RX FIFO and Interrupts - NXP Community.

You can refer to the routine below for enhanced RXFIFO configuration with watermark: Example S32K344 FlexCAN_Ip TX/RX/EnhanceRXFIFO DMA test S32DS3.5 RTD400 - NXP Community. It does also configure DMA, though.

Best regards,
Julián

0 Kudos
Reply
2,168 Views
Greavesinator85
Contributor III

Ok, so interrupt mode is working as expected in my case, where there is no way to use the watermark feature, as FlexCAN_Ip_RxFifo must be called on each interrupt. At max can speeds I see my RXTask taking up to 20% CPU time which is not acceptable.

 

I will try to use the example. I have refreshed it with my RTD 6.0.0 but I do not see any interrupts firing, I will investigate. I also see Rm_Init is not found?

I will look into DMA today to see if it can offer improvements. I am still unclear, will DMA only notify me once my watermark of messages  (8) is received?

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2200213%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K358%20CAN%20RTD%20Watermark%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2200213%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI'm%20trying%20to%20use%20the%26nbsp%3BFlexCAN_Ip%20RTD%20drivers%20for%20an%20efficient%20CAN%20receive%20loop.%20I've%20been%20able%20to%20do%20this%20with%20FreeRTOS%2C%20using%20interrupt%20mode%20and%20enhanced%20RX.%20In%20this%20mode%2C%20I%20configure%20watermark%20to%20be%208%2C%20but%20in%20my%26nbsp%3BFlexCAN_UserCallback%20only%26nbsp%3B%3CSPAN%3EFLEXCAN_EVENT_ENHANCED_RXFIFO_COMPLETE%20fires%2C%20and%20if%20I%20do%20not%20add%20a%20call%20to%26nbsp%3BFlexCAN_Ip_RxFifo%20when%20this%20happens%2C%20no%20more%20interrupts%20fire.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSPAN%3EHow%20am%20I%20meant%20to%20use%20watermark%20mode%3F%20Is%20it%20only%20available%20with%20DMA%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2200868%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K358%20CAN%20RTD%20Watermark%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2200868%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20now%20have%20this%20working.%20The%20qualifiers%20around%20the%20buffer%20was%20key%20to%20avoid%20the%20corruption%3B%3C%2FP%3E%3CP%3E__attribute__((%20aligned(32)%20))%20static%20Flexcan_Ip_MsgBuffType%20gEnhancedRxFifoBuffer%5BENHANCED_RXFIFO_WATERMARK%5D%20__attribute__%20((section%20(%22.mcal_bss_no_cacheable%22)))%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThanks%20for%20all%20your%20help!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2200842%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K358%20CAN%20RTD%20Watermark%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2200842%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EApologies%20for%20the%20spam%2C%20I'm%20just%20actively%20debugging%20this.%20Setting%26nbsp%3B%3CSTRONG%3EFlexCAN_Ip_RxFifo%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3Bbefore%26nbsp%3BFlexCAN_Ip_SetStartMode%20has%20solved%20the%26nbsp%3BEDMA-%26gt%3BES%20is%20set%20to%20SBE_1%20error.%20Now%20I%20am%20investigating%20why%20the%20buffer%20is%20not%20holding%20the%20correct%20data.%20I'm%20sending%20ID%200x200%20with%2064%20bytes%20counting%20up.%20I%20see%20some%20of%20this%20counting%20data%20but%20it%20is%20in%20chunks%20and%20can%20be%20missing%20large%20pieces%2C%20generally%20looks%20corrupted%2C%20and%20the%20address%20ID%20is%20always%200%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2200838%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K358%20CAN%20RTD%20Watermark%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2200838%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3ELooks%20like%20after%26nbsp%3BFlexCAN_Ip_SetStartMode%2C%20EDMA-%26gt%3BES%20is%20set%20to%20SBE_1%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2200833%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K358%20CAN%20RTD%20Watermark%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2200833%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EOk%2C%20I%20have%20the%20DMA%20working%20in%20my%20application%2C%20thanks%20for%20your%20help.%20The%20example%20pointed%20me%20to%20Dma_Mux_IP_init%20which%20I%20was%20missing.%3C%2FP%3E%3CP%3ENow%20I%20do%20get%20the%20interrupt%20when%20it%20works%2C%20the%20first%20call%20to%26nbsp%3BFlexCAN_Ip_RxFifo%20may%20pass%20or%20fail%2C%20but%20everything%20is%20smooth%20beyond%20that.%20This%20failure%20is%20at%26nbsp%3BStatic_Dma_Ip_GetLogicChannelError%20inside%26nbsp%3BDma_Ip_SetLogicChannelTransferList.%20I%20am%20using%20FreeRTOS%20as%20mentioned%2C%20any%20idea%20why%20this%20might%20be%20occurring%3F%26nbsp%3BLocChState-%26gt%3BLogicChErrors%20is%20returning%26nbsp%3B0x80000002%3C%2FP%3E%3CP%3EAlso%2C%20I'm%20testing%20with%201%20buffer%2C%20but%20the%20data%20seems%20corrupt%2C%20i.e.%20the%20ID%20is%20never%20correct%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2200751%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K358%20CAN%20RTD%20Watermark%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2200751%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EOk%2C%20so%20interrupt%20mode%20is%20working%20as%20expected%20in%20my%20case%2C%20where%20there%20is%20no%20way%20to%20use%20the%20watermark%20feature%2C%20as%26nbsp%3B%3CSTRONG%3EFlexCAN_Ip_RxFifo%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3Bmust%20be%20called%20on%20each%20interrupt.%20At%20max%20can%20speeds%20I%20see%20my%20RXTask%20taking%20up%20to%2020%25%20CPU%20time%20which%20is%20not%20acceptable.%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSPAN%3EI%20will%20try%20to%20use%20the%20example.%20I%20have%20refreshed%20it%20with%20my%20RTD%206.0.0%20but%20I%20do%20not%20see%20any%20interrupts%20firing%2C%20I%20will%20investigate.%20I%20also%20see%20Rm_Init%20is%20not%20found%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI%20will%20look%20into%20DMA%20today%20to%20see%20if%20it%20can%20offer%20improvements.%20I%20am%20still%20unclear%2C%20will%20DMA%20only%20notify%20me%20once%20my%20watermark%20of%20messages%26nbsp%3B%20(8)%20is%20received%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2200355%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K358%20CAN%20RTD%20Watermark%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2200355%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F256454%22%20target%3D%22_blank%22%3E%40Greavesinator85%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ERTD%20driver%20is%20written%20in%20a%20way%20you%20need%20to%20call%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3CSTRONG%3EFlexCAN_Ip_RxFifo%3C%2FSTRONG%3E%20first%2C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Ean%20interrupt%20is%20called%20once%20there%20is%20at%20least%201%20message%20in%20the%20RXFIFO%2C%20driver%20reads%20single%20message%20from%20RXFIFO%2C%20and%20user%20has%20to%20call%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%3CSTRONG%3EFlexCAN_Ip_RxFifo%3C%2FSTRONG%3E%26nbsp%3Bto%20enable%20interrupt%20again.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThis%20was%20previously%20discussed%20with%20a%20colleague%20in%20this%20community%20post%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K%2FS32K344-Using-FlexCAN-with-RX-FIFO-and-Interrupts%2Fm-p%2F1543382%22%20target%3D%22_blank%22%3ESolved%3A%20S32K344%20Using%20FlexCAN%20with%20RX%20FIFO%20and%20Interrupts%20-%20NXP%20Community%3C%2FA%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20refer%20to%20the%20routine%20below%20for%20enhanced%20RXFIFO%20configuration%20with%20watermark%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K-Knowledge-Base%2FExample-S32K344-FlexCAN-Ip-TX-RX-EnhanceRXFIFO-DMA-test-S32DS3-5%2Fta-p%2F2015832%22%20target%3D%22_blank%22%3EExample%20S32K344%20FlexCAN_Ip%20TX%2FRX%2FEnhanceRXFIFO%20DMA%20test%20S32DS3.5%20RTD400%20-%20NXP%20Community%3C%2FA%3E.%20It%20does%20also%20configure%20DMA%2C%20though.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EBest%20regards%2C%3CBR%20%2F%3EJuli%C3%A1n%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E