How to send or receive CANFD message using FlexCAN component on MPC5748G DEVKIT?

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

How to send or receive CANFD message using FlexCAN component on MPC5748G DEVKIT?

1,713 Views
shingo
Contributor II

HI:

/**************************

Using MPC5748G Devkit, and some key configuration to FlexCAN component in S32DS for PA:

Baudrate: arbitration phase: 500kbps, data phase: 2Mpbs.

Enable CANFD, and payload size is "FLEXCAN_PAYLOAD_SIZE_64"

Module clock and pe clock keep default.(80MHz, 40MHz)

MB number is set 16; 

Please see the attachment(config flexcan.jpg) for details。

******************************/

The following soures is to config the flexcan using S32_SDK_S32PA_RTM_3.0.3:

/* CAN hardware MB(Message Buffer) configuration */
flexcan_data_info_t CAN_TX_MB1_Config = {
    .msg_id_type = FLEXCAN_MSG_ID_STD,
    .data_length = 8,
    .fd_enable = false,
    .fd_padding = 0x00,
    .enable_brs = false,
    .is_remote = false};

flexcan_data_info_t CAN_TX_MB2_Config = {
    .msg_id_type = FLEXCAN_MSG_ID_STD,
    .data_length = 64,
    .fd_enable = true,
    .fd_padding = 0x00,
    .enable_brs = true,
    .is_remote = false};

flexcan_data_info_t CAN_RX_MB1_Config = {
    .msg_id_type = FLEXCAN_MSG_ID_STD,
    .data_length = 8,
    .fd_enable = false,
    .fd_padding = 0x00,
    .enable_brs = false,
    .is_remote = false};

flexcan_data_info_t CAN_RX_MB2_Config = {
    .msg_id_type = FLEXCAN_MSG_ID_STD,
    .data_length = 64,
    .fd_enable = true,
    .fd_padding = 0x00,
    .enable_brs = true,
    .is_remote = false};

    /* initialize the FlexCAN PD driver */
    FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);

    /* install the event handler call back */
    FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1,CAN_TX_RX_Callback, NULL);

    /* install the FlexCAN error ISR callback */
    FLEXCAN_DRV_InstallErrorCallback(INST_CANCOM1, CAN_Error_Callback,NULL);

    /* configure the TX MB */
    FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1,TX_MB1, &CAN_TX_MB1_Config,0x000);
    FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1,TX_MB2, &CAN_TX_MB2_Config,0x000);

    /* configure the RX MB with receive acceptance ID */
    FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1,RX_MB1, &CAN_RX_MB1_Config,0x000);
    FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1,RX_MB2, &CAN_RX_MB2_Config,0x000);

 FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1,FLEXCAN_MSG_ID_STD,FLEXCAN_RX_MASK_GLOBAL);

    /* start the individual MB CAN message receive */
    FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MB1, &CAN_RX_Message_Buffer[0]);
    FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MB2, &CAN_RX_Message_Buffer[1]);
  FLEXCAN_DRV_SendBlocking(INST_CANCOM1, TX_MB1, &CAN_TX_MB1_Config, 0x111, &TX_MB1_Data, 1000);
  FLEXCAN_DRV_SendBlocking(INST_CANCOM1, TX_MB2, &CAN_TX_MB2_Config, 0x222, &TX_MB2_Data, 1000);

Debug on the DEVKIT, and connect pins to CANOE. The result is TX_MB1 and RX_MB1 can send and receive the CAN2.0 message, but TX_MB2 and RX_MB2 can not work normally,  How to config the S32DS IDE or MB to send and receive CANFD message?

Tags (1)
0 Kudos
5 Replies

1,699 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

from the code it is not clear which MBs is used for TX/RX operation. But if e.g MBs 0 to 3 is used, then the code should be functional. Or do you see any errors detected on FlexCAN or CANoe? If yes then check CAN bit timing setting, use same sample point on MCU and CANoe side.

Setting same ID for both RX MBs could cause the receive message will be stored only into lowest number RX MB, depending if this MB is free to receive or not. 

BR, Petr 

0 Kudos

1,688 Views
shingo
Contributor II

@PetrS :

    Thanks for your advice.

    Finally, I found the problem point. There is a string "1N81M" on the MPC5748G IC on DEVKIT board, And Config the CANFD non-ISO Standard on CANOE. The flexcan OK.

But There is another question: Added freeRTOS component in my project first, F5(Step into) Debuging, Execute the statement "FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, CAN_TX_RX_Callback, NULL);", and then the PC jumped to the statement "

IVOR1_Vector:
e_b IVOR1_Handler"

what's going on?

0 Kudos

1,681 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

not sure for FreeRTOS. But there should be FlexCAN + FreeRTOS demo within SDK. Check "flexcan_mpc5746c" demo example.

BR, Petr 

0 Kudos

1,657 Views
shingo
Contributor II

@PetrS 

Hi:

     "flexcan_mpc5746c" demo example, unfortunately, it's Using the method of "wait ... until to receive the CAN message". This method is easier style to learn, but cannot work well for actual project. In general, we used to the method of "interrupt to receive CAN messages" instead of "wait ... until".

    Could you provide an example for "FreeRTOS+FlexCAN(using initerrupt mode to receive message)".

BR, Shingo

0 Kudos

1,645 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I am not aware of other example

BR, Petr

0 Kudos