S32K344 FlexCAN Change Highest-priority message buffer first to Lowest-number message buffer first

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

S32K344 FlexCAN Change Highest-priority message buffer first to Lowest-number message buffer first

1,294 Views
bruceyun
Contributor II

Hi all, 

I am working on a project to route CAN messages. I found out that CAN write block by default has arbitration process, which choose highest-priority CAN message buffer to send first. I want to change it to lowest-number message buffer to send first. 

After I read document, there are some lines: 

73.3.3.1
Lowest-number message buffer first
"If CTRL1[LBUF] is 1, the first (lowest number) active transmission message buffer found is the arbitration winner. MCR[LPRIOEN] has no effect when CTRL1[LBUF] is 1."

So I am trying to write CTRL1[LBUF] to 1. I believe that I need to change to Freeze Mode. 

"MCR[FRZ] must be 1 and the module must not be in a low-power mode"

"After requesting Freeze mode, you must wait for MCR[FRZACK] to become 1 before executing any other action, otherwise FlexCAN may operate unpredictably. In Freeze mode, all memory-mapped registers are accessible."

 

I tried to write MCR[FRZ] to 1 but I failed to change to Freeze mode. Can anyone here have the knowledge about this? I appreciate it. 

 

##S32K34 #FlexCAN #CAN #Route #AUTOSAR #NXP

0 Kudos
Reply
1 Reply

1,276 Views
SorinIBancila
NXP Employee
NXP Employee

Hello,

 

To put the FLEXCAN module into FreezeMode, we can use the S32K3 RTD functions:

  • FlexCAN_Ip_EnterFreezeMode_Privileged(uint8 instance)
  • FlexCAN_Ip_ExitFreezeMode_Privileged(uint8 instance)
 
To test this I've added the following blocks to an already existing model that sends messages over CAN. Basically, I have a variable CAN_0_enterfreeze which I modify from the FreeMASTER to have one of the following values:
  • 0: Do nothing
  • 1: read MCR register for CAN 0 instance and store the result in CAN_0_MCR
  • 2: Enter FreezeMode
  • 3: Exit FreezeMode
SorinIBancila_0-1754053072043.png

 

Inside case 2 and case 3, you have to add a MATLAB function block. The custom code to enter/exit freezemode can be found below:

SorinIBancila_1-1754053486901.png

 

To validate this I've done the following:

  • Reset the development board and read the content of MCR register for CAN 0 instance. 
SorinIBancila_2-1754053730649.png

 

  • Set CAN_0_enterfreeze to 2 and read the content of the MCR register. Note! The FlexCAN is not working in FreezeMode.SorinIBancila_3-1754053812864.png
 SorinIBancila_5-1754053865424.png

 

  •  Set CAN_0_enterfreeze to and read the content of the MCR register. The CAN is working again. I just send a message (ID = 101) from CAN analyzer tool and the board replies with a message ID=0.
SorinIBancila_6-1754053942109.pngSorinIBancila_7-1754053978440.png

 

The S32K3 RTD sources can be found inside the toolbox, where you can check the implementation for a specific module in case you need it. To open the root of the S32K3 folder, you can type the following command in MATLAB command window : cd(mbd_find_s32k3_root)

SorinIBancila_0-1754059684536.png

 

 

 

Do not hesitate to reply in case you have any other questions.

 

Best regards,

Sorin Bancila

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2144812%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32K344%20FlexCAN%20Change%20Highest-priority%20message%20buffer%20first%20to%20Lowest-number%20message%20buffer%20first%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2144812%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20all%2C%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20working%20on%20a%20project%20to%20route%20CAN%20messages.%20I%20found%20out%20that%20CAN%20write%20block%20by%20default%20has%20arbitration%20process%2C%20which%20choose%26nbsp%3Bhighest-priority%20CAN%20message%20buffer%20to%20send%20first.%20I%20want%20to%20change%20it%20to%26nbsp%3Blowest-number%20message%20buffer%20to%20send%20first.%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20I%20read%20document%2C%20there%20are%20some%20lines%3A%26nbsp%3B%3C%2FP%3E%3CP%3E73.3.3.1%3CBR%20%2F%3ELowest-number%20message%20buffer%20first%3CBR%20%2F%3E%22If%20CTRL1%5BLBUF%5D%20is%201%2C%20the%20first%20(lowest%20number)%20active%20transmission%20message%20buffer%20found%20is%20the%20arbitration%20winner.%20MCR%5BLPRIOEN%5D%20has%20no%20effect%20when%20CTRL1%5BLBUF%5D%20is%201.%22%3C%2FP%3E%3CP%3ESo%20I%20am%20trying%20to%20write%20CTRL1%5BLBUF%5D%20to%201.%20I%20believe%20that%20I%20need%20to%20change%20to%20Freeze%20Mode.%26nbsp%3B%3C%2FP%3E%3CP%3E%22MCR%5BFRZ%5D%20must%20be%201%20and%20the%20module%20must%20not%20be%20in%20a%20low-power%20mode%22%3C%2FP%3E%3CP%3E%22After%20requesting%20Freeze%20mode%2C%20you%20must%20wait%20for%20MCR%5BFRZACK%5D%20to%20become%201%20before%20executing%20any%20other%20action%2C%20otherwise%20FlexCAN%20may%20operate%20unpredictably.%20In%20Freeze%20mode%2C%20all%20memory-mapped%20registers%20are%20accessible.%22%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EI%20tried%20to%20write%26nbsp%3BMCR%5BFRZ%5D%20to%201%20but%20I%20failed%20to%20change%20to%20Freeze%20mode.%20Can%20anyone%20here%20have%20the%20knowledge%20about%20this%3F%20I%20appreciate%20it.%26nbsp%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%23%23S32K34%20%23FlexCAN%20%23CAN%20%23Route%20%23AUTOSAR%26nbsp%3B%23NXP%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2145208%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20S32K344%20FlexCAN%20Change%20Highest-priority%20message%20buffer%20first%20to%20Lowest-number%20message%20buffer%20fir%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2145208%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ETo%20put%20the%20FLEXCAN%20module%20into%20FreezeMode%2C%20we%20can%20use%20the%20S32K3%20RTD%20functions%3A%3C%2FP%3E%0A%3CDIV%20class%3D%22rtcContent%22%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lineNode%22%3E%3CSPAN%3EFlexCAN_Ip_EnterFreezeMode_Privileged(uint8%20instance)%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CDIV%20class%3D%22rtcContent%22%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lineNode%22%3E%3CSPAN%3EFlexCAN_Ip_ExitFreezeMode_Privileged(uint8%20instance)%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CDIV%20class%3D%22lineNode%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lineNode%22%3ETo%20test%20this%20I've%20added%20the%20following%20blocks%20to%20an%20already%20existing%20model%20that%20sends%20messages%20over%20CAN.%20Basically%2C%20I%20have%20a%20variable%26nbsp%3B%3CSTRONG%3ECAN_0_enterfreeze%26nbsp%3B%3C%2FSTRONG%3Ewhich%20I%20modify%20from%20the%20FreeMASTER%20to%20have%20one%20of%20the%20following%20values%3A%3C%2FDIV%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lineNode%22%3E0%3A%20Do%20nothing%3C%2FLI%3E%0A%3CLI%20class%3D%22lineNode%22%3E1%3A%20read%20MCR%20register%20for%20CAN%200%20instance%20and%20store%20the%20result%20in%26nbsp%3B%3CSTRONG%3ECAN_0_MCR%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%20class%3D%22lineNode%22%3E2%3A%20Enter%20FreezeMode%3C%2FLI%3E%0A%3CLI%20class%3D%22lineNode%22%3E3%3A%20Exit%20FreezeMode%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CDIV%20class%3D%22lineNode%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22SorinIBancila_0-1754053072043.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22SorinIBancila_0-1754053072043.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350631iB5E751A958AE2A07%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SorinIBancila_0-1754053072043.png%22%20alt%3D%22SorinIBancila_0-1754053072043.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3CP%3EInside%20case%202%20and%20case%203%2C%20you%20have%20to%20add%20a%20MATLAB%20function%20block.%20The%20custom%20code%20to%20enter%2Fexit%20freezemode%20can%20be%20found%20below%3A%3C%2FP%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SorinIBancila_1-1754053486901.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22SorinIBancila_1-1754053486901.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350632iA67E3C78D6ED6D43%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SorinIBancila_1-1754053486901.png%22%20alt%3D%22SorinIBancila_1-1754053486901.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3CP%3ETo%20validate%20this%20I've%20done%20the%20following%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EReset%20the%20development%20board%20and%20read%20the%20content%20of%20MCR%20register%20for%20CAN%200%20instance.%26nbsp%3B%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22SorinIBancila_2-1754053730649.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22SorinIBancila_2-1754053730649.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350633iDBFBB2BF9415F59D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SorinIBancila_2-1754053730649.png%22%20alt%3D%22SorinIBancila_2-1754053730649.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3CUL%3E%0A%3CLI%3ESet%20CAN_0_enterfreeze%20to%26nbsp%3B%3CSTRONG%3E2%3C%2FSTRONG%3E%20and%20read%20the%20content%20of%20the%20MCR%20register.%20Note!%20The%20FlexCAN%20is%20not%20working%20in%20FreezeMode.%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SorinIBancila_3-1754053812864.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22SorinIBancila_3-1754053812864.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350634iA7D2E25FFDA45DC4%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SorinIBancila_3-1754053812864.png%22%20alt%3D%22SorinIBancila_3-1754053812864.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lineNode%22%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22SorinIBancila_5-1754053865424.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22SorinIBancila_5-1754053865424.png%22%20style%3D%22width%3A%20978px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350636i12B004EE689ADA75%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SorinIBancila_5-1754053865424.png%22%20alt%3D%22SorinIBancila_5-1754053865424.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3C%2FDIV%3E%0A%3CUL%3E%0A%3CLI%20class%3D%22lineNode%22%3E%26nbsp%3BSet%20CAN_0_enterfreeze%20to%26nbsp%3B%3CSTRONG%3E3%26nbsp%3B%3C%2FSTRONG%3Eand%20read%20the%20content%20of%20the%20MCR%20register.%20The%20CAN%20is%20working%20again.%20I%20just%20send%20a%20message%20(ID%20%3D%20101)%20from%20CAN%20analyzer%20tool%20and%20the%20board%20replies%20with%20a%20message%20ID%3D0.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SorinIBancila_6-1754053942109.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22SorinIBancila_6-1754053942109.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350637iFD2600671E5AC9E7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SorinIBancila_6-1754053942109.png%22%20alt%3D%22SorinIBancila_6-1754053942109.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22SorinIBancila_7-1754053978440.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22SorinIBancila_7-1754053978440.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350638iCCC8B227BA0FE9EA%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SorinIBancila_7-1754053978440.png%22%20alt%3D%22SorinIBancila_7-1754053978440.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3CP%3EThe%20S32K3%20RTD%20sources%20can%20be%20found%20inside%20the%20toolbox%2C%20where%20you%20can%20check%20the%20implementation%20for%20a%20specific%20module%20in%20case%20you%20need%20it.%20To%20open%20the%20root%20of%20the%20S32K3%20folder%2C%20you%20can%20type%20the%20following%20command%20in%20MATLAB%20command%20window%20%3A%26nbsp%3B%3CSTRONG%3Ecd(mbd_find_s32k3_root)%3C%2FSTRONG%3E.%26nbsp%3B%3C%2FP%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22SorinIBancila_0-1754059684536.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22SorinIBancila_0-1754059684536.png%22%20style%3D%22width%3A%20550px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F350643i82257A597E9849F2%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22SorinIBancila_0-1754059684536.png%22%20alt%3D%22SorinIBancila_0-1754059684536.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3CBR%20%2F%3E%0A%3CBR%20%2F%3E%0A%3CP%3EDo%20not%20hesitate%20to%20reply%20in%20case%20you%20have%20any%20other%20questions.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBest%20regards%2C%3C%2FP%3E%0A%3CP%3ESorin%20Bancila%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E