S32K1xx SDK FlexCAN sample projects to demonstrate its basic and advanced features

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

S32K1xx SDK FlexCAN sample projects to demonstrate its basic and advanced features

S32K1xx SDK FlexCAN sample projects to demonstrate its basic and advanced features

Hi Everyone,

Here I'd like to share three S32K1xx SDK FlexCAN PD and PAL component sample projects to demonstrate its basic and advanced features:

1. S32K144_CAN_PAL_SamplePrj_Basic_TxRx_ID_FiltersConfig_SDKRTM3P0

34.png

Functions implementation key points and tips:

This sample project is made to demonstrate the following S32K1xx FlexCAN features with SDK FlexCAN PAL driver:

1. Configure to receiver the following exact 16 standard ID CAN message with RxFIFO 8x ID filter table with format type-B(2x 16-bit ID)
Standard ID: 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
0x111, 0x222, 0x333, 0x444, 0x555, 0x666, 0x777, 0x788

The RxFIFO is configured to use CPU interrupt for CAN message receive, and CAN_PAL cannot support DMA for RxFIFO directly.

Note: A. FlexCAN of S32K1xx dose not support to receive CAN-FD message frame with RxFIFO, so no CAN-FD support in this demo project.
B. All the filter table elements must be configured to contain only standard or extend ID, if it contains both standard and extend ID, the IDE-bit mask will be ignored. 
C. After RxFIFO enabled, MB0~MB5 is used as the RX FIFO, at least MB6~MB7 are used as the ID filter table(to store the acceptance ID), the actual available MB number is determined by RxFIFO ID filter table size, details please refer to section--55.4.6 Rx FIFO structure of S32K1xx RM Rev.12.1 

2. Configure two extra individual MBs to receive:

RX_MB1: 16 standard ID CAN 2.0 message with the lower 4LSB masked(mask=0x7F0, acceptance ID = 0x123): 0x120 ~ 0x12F and 
RX_MB2: 4 standard ID CAN 2.0 message with the ID8 and ID9 masked(mask=0x4FF, acceptance ID = 0x256): 0x056, 0x156, 0x256 and 0x356

Both the RxFIFO and individual MBs RX use non-blocking receive method/API with MB TX/RX complete ISR callback installed to set a new circle buffer for next message frame receive

3. Configure one individual MB to blocking transmit a standard CAN 2.0 message with ID = 0x100 periodically(period = 5ms), and also send back the received CAN messages(if it's available) to the CAN bus as a response.

4. Provide the FlexCAN bus-off manual recovery configuration API and interrupt ISR callback codes for reference, changing the macro CAN_BUSOFF_RECOVERY_MANUAL(in include/Config.h) to select the bus off recovery method(enable the macro definition: manual recovery, comment the macro definition: automatic recovery);

Note: In this sample project, the macro CAN_BUSOFF_RECOVERY_MANUA is commented by default, so manual recovery codes does not work.

To make the bus-off recovery callback work, user should replace the flexcan PD driver codes and S32K144_feature.h with S32K1xx RTM 4.0.0(which can be downloaded from nxp.com with registered account login and then installed stand-alone or installed via S32DS v3.3 IDE update). This is not done this sample project!!! 

5. There 3 on-board RGB LED are used to indicate the FlexCAN working status:

red RGB LED will be toggled after RXFIFO received a CAN message;
blue RGB LED will be toggled after individual MB received a CAN message;
green RGB LED will be turn ON after enter bus-off and turn OFF after exist bus-off(recover successfully).

To run this sample project, the following HW and SW require:

SW: S32DS for ARM v2.2 IDE with S32K1xx SDK RTM 3.0.3 installation
HW: S32K144EVB-Q100 Rev.C with a DC-12V adapter for its power supply by J16 and a USB-to-CAN adapter(such as PEAK CAN) to connect PC with J13 of the EVB

2.S32K144_CAN_PAL_CANFD_ClassicCAN_Mix_TxRx_Wakeup_SDKRTM3P0

39.png

Functions implementation key points and tips:

This sample project is made to demonstrate the following S32K1xx FlexCAN features with SDK FlexCAN PAL driver:

1. Configure to enable CAN-FD with 500 Kbit/s arbitration phase bitrate and 2Mbit/s data phase bitrate, so it can support both classic CAN 2.0 A/B and CAn-FD message frame transfer.

Note: A. The RxFIFO is disabled to work with CAN-FD message frame.
B. After CAN-FD enabled, CAN-FD message frame data length can support up to 64 Bytes, so the actual available MB number is determined by the max frame data length need to support, details please refer to section--55.4.5 FlexCAN message buffer memory map of S32K1xx RM Rev.12.1 
C. In order to support bitrate bigger than 1Mbit/s for CAN-FD data phase with bitrate switch enabed, PE clock source of CAN_PAL should be configured to use peripheral clock(80MHz generated from SPLL) instead of 8MHz oscillator clock;

2. Configure 3 individual MBs to receive:

RX_MB0: 16 extend ID CAN 2.0/FD message with the lower 4LSB masked(mask=0x1FFFFFF0, acceptance ID = 0xfff021): 0xfff020 ~ 0xfff02F
RX_MB1: 16 standard ID CAN 2.0/FD message with the lower 4LSB masked(mask=0x7F0, acceptance ID = 0x123): 0x120 ~ 0x12F
RX_MB2: 4 standard ID CAN 2.0/FD message with the ID8 and ID9 masked(mask=0x4FF, acceptance ID = 0x256): 0x056, 0x156, 0x256 and 0x356

Both the RxFIFO and individual MBs RX use non-blocking receive method/API with MB TX/RX complete ISR callback installed to set a new circle buffer for next message frame receive

3. Configure 3 individual MBs to transmit:

TX_MB0: send back any CAN(2.0/FD) messages received from RX_MB0;
TX_MB1: send back any CAN(2.0/FD) messages received from RX_MB1;
TX_MB2: send back any CAN(2.0/FD) messages received from RX_MB2;

4. Configure one individual MB(TX_MB3) to blocking transmit a standard CAN FD message with ID = 0x100 periodically(period = 5ms) and length = 64 bytes, and also send back the received CAN messages(if it's available) to the CAN bus as a response.

5. Provide the FlexCAN bus-off manual recovery configuration API and interrupt ISR callback codes for reference, changing the macro CAN_BUSOFF_RECOVERY_MANUAL(in include/Config.h) to select the bus off recovery method(enable the macro definition: manual recovery, comment the macro definition: automatic recovery);

Note: In this sample project, the macro CAN_BUSOFF_RECOVERY_MANUA is commented by default, so manual recovery codes does not work.

To make the bus-off recovery callback work, user should replace the flexcan PD driver codes and S32K144_feature.h with S32K1xx RTM 4.0.0(which can be downloaded from nxp.com with registered account login and then installed stand-alone or installed via S32DS v3.3 IDE update). This is not done this sample project!!! 

6. Provided the sample codes of how to configure FlexCAN as the VLPS low-power mode wakeup source, RXD of FlexCAN0 is configured as GPIO IRQ interrupt with falling edge trigger before entering VLPS mode, and after wakeup, re-configure it back to RXD function.

Note: A. S32K1xx FlexCAN is unable to work as the VLPS wakeup source
B. After wakeup, it's necessary to call SDK clock_manager's API--CLOCK_SYS_UpdateConfiguration() to reconfigure the system clock, or it will use 8MHz SIRC, 48 MHZ FIRC and SPLL are disabled after wakeup.
c. By default, after receive ID = 0x123(it can be configured via macro LP_REQUEST_ID in /include/Config.h ) standard CAN(CAN 2.0 or CAN-FD), the MCU will go to VLPS mode

7. There 3 on-board RGB LED are used to indicate the FlexCAN working status:

blue RGB LED will be toggled after individual MB received a CAN message;
green RGB LED will be turn ON after enter bus-off and turn OFF after exist bus-off(recover successfully).

To run this sample project, the following HW and SW require:

SW: S32DS for ARM v2.2 IDE with S32K1xx SDK RTM 3.0.3 installation
HW: S32K144EVB-Q100 Rev.C with a DC-12V adapter for its power supply by J16 and a USB-to-CAN adapter(such as PEAK CAN) to connect PC with J13 of the EVB

3.S32K144_FlexCAN_PD_SamplePrj_RxFIFO_DMA_Receive_SDKRTM3P0

36.png

Functions implementation key points and tips:

This sample project is made to demonstrate the following S32K1xx FlexCAN features with SDK FlexCAN PD driver:

1. Configure to receiver the following exact 16 standard ID CAN message with RxFIFO 8x ID filter table with format type-B(2x 16-bit ID)
Standard ID: 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
0x111, 0x222, 0x333, 0x444, 0x555, 0x666, 0x777, 0x788

The RxFIFO is also configured to use eDMA channel 0 for CAN message receive, user can easily change to use CPU interrupt for RxFIFO in processor expert flexcan component configuration if required.

Note: A. FlexCAN of S32K1xx dose not support to receive CAN-FD message frame with RxFIFO, so no CAN-FD support in this demo project.
B. all the filter table elements must be configured to contain only standard or extend ID, if it contains both standard and extend ID, the IDE-bit mask will be ignored. 
C. After RxFIFO enabled, MB0~MB5 is used as the RX FIFO, at least MB6~MB7 are used as the ID filter table(to store the acceptance ID), the actual available MB number is determined by RxFIFO ID filter table size, details please refer to section--55.4.6 Rx FIFO structure of S32K1xx RM Rev.12.1 

2. Configure one extra individual MB(MB8) to receive 16 standard ID CAN 2.0 message with the lower 4LSB masked(mask=0x7F0, acceptance ID = 0x123): 0x120 ~ 0x12F;

Both RxFIFO and individual MB RX use non-blocking receive method/API with MB TX/RX complete ISR callback installed to set a new circle buffer for next message frame receive

3. Configure one individual MB(MB9) to blocking transmit a standard CAN 2.0 message with ID = 0x100 periodically(period = 5ms), and also send back the received CAN messages(if it's available) to the CAN bus as a response.

4. Provide the FlexCAN bus-off manual recovery configuration API and interrupt ISR callback codes for reference, changing the macro CAN_BUSOFF_RECOVERY_MANUAL(in include/Config.h) to select the bus off recovery method(enable the macro definition: manual recovery, comment the macro definition: automatic recovery);

Note: In this sample project, the macro CAN_BUSOFF_RECOVERY_MANUA is enabled by default, and manual recovery codes works.

To make the bus-off recovery callback work, user should replace the flexcan PD driver codes and S32K144_feature.h with S32K1xx RTM 4.0.0(which can be downloaded from nxp.com with registered account login and then installed stand-alone or installed via S32DS v3.3 IDE update). This is already done this sample project!!! 

5. There 3 on-board RGB LED are used to indicate the FlexCAN working status:

red RGB LED will be toggled after RXFIFO received any CAN message;
blue RGB LED will be toggled after individual MB received any CAN message;
green RGB LED will be turn ON after enter bus-off and turn OFF after exist bus-off(recover successfully).

To run this sample project, the following HW and SW require:

SW: S32DS for ARM v2.2 IDE with S32K1xx SDK RTM 3.0.3 installation
HW: S32K144EVB-Q100 Rev.C with a DC-12V adapter for its power supply by J16 and a USB-to-CAN adapter(such as PEAK CAN) to connect PC with J13 of the EVB

Attached are the sample project for your reference, and details can also be fiound with the detailed comments in source codes.

Hope it can help you, and any comments/questions are welcomed, and you can just ask in this thread and I will try to anwser them.

Best regard,

Enwei Hu(胡恩伟).

 

Attachments
Comments

The following 2 original technical sharing articles about S32K1xx FlexCAN and its SDK driver on my WeChat public account can also help you to understand more details:

S32K1xx系列MCU应用指南之FlexCAN模块功能与应用详解》;

S32K SDK使用详解之can_pal组件和flexcan组件使用详解(含RxFIFO DMA和ID滤波器以及总线关闭恢复等)》;

 

B.R.

Enwei Hu.

100% helpful (1/1)
Version history
Last update:
‎11-22-2020 09:44 PM
Updated by: