CAN filter not working as expected in S32K144

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

CAN filter not working as expected in S32K144

1,416 Views
hiren_virapara
Contributor I

I'm using CAN0 using PAL library in my test code.

I have following configuration of CAN0

/*! @brief PAL instance information */
const can_instance_t BmsSbcCAN0_instance = {CAN_INST_TYPE_FLEXCAN, 0U};

/*! @brief Rx FIFO extension */
extension_flexcan_rx_fifo_t BmsSbcCAN0_rx_fifo_ext0 = {
.numIdFilters = FLEXCAN_RX_FIFO_ID_FILTERS_8,
.idFormat = FLEXCAN_RX_FIFO_ID_FORMAT_A,
/* User must pass reference to the ID filter table. */
.idFilterTable = NULL
};

/*! @brief User configuration structure */
const can_user_config_t BmsSbcCAN0_Config0 = {
.maxBuffNum = 16UL,
.mode = CAN_NORMAL_MODE,
.peClksrc=CAN_CLK_SOURCE_OSC,
.enableFD = false,
.payloadSize = CAN_PAYLOAD_SIZE_8,
.nominalBitrate = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.dataBitrate = {
.propSeg = 7,
.phaseSeg1 = 4,
.phaseSeg2 = 1,
.preDivider = 0,
.rJumpwidth = 1
},
.extension = &BmsSbcCAN0_rx_fifo_ext0
};

==================CAN Init section================
flexcan_id_table_t filterTable[NUMBER_OF_ID];
uint32_t IDlist[NUMBER_OF_ID] = uint32_t IDlist[NUMBER_OF_RCV_CNA_MSG_ID] = {0x1BF01D00, 0x1BF01E00 ,0x1BF01F00, 0x1BF02600, 0x1BF02800};
for(uint8_t id_counter=0;id_counter<NUMBER_OF_ID;id_counter++)
{
filterTable[id_counter].isRemoteFrame = false;
filterTable[id_counter].isExtendedFrame = true;
filterTable[id_counter].id = IDlist[id_counter] ;
}
BmsSbcCAN0_rx_fifo_ext0.idFilterTable = &filterTable;
/* Can Init */
CAN_Init(&BmsSbcCAN0_instance, &BmsSbcCAN0_Config0);
CAN_ConfigTxBuff(&BmsSbcCAN0_instance, TX_MAILBOX, &txBuffCfg);
CAN_ConfigRxBuff(&BmsSbcCAN0_instance, RX_MAILBOX, &rxBuffCfg, RX_MSG_ID);
CAN_InstallEventCallback(&BmsSbcCAN0_instance, &CAN0_cb, NULL);
CAN_SetRxFilter(&BmsSbcCAN0_instance,CAN_MSG_ID_EXT,RX_MAILBOX,0x1FFF00FF); //0x1FFF00FF is mask for CAN IDs
CAN_Receive(&BmsSbcCAN0_instance, RX_MAILBOX, &rxMessage);
========================================================




I have set extended can filter ID for 5 message ID which I want to receive from CAN bus.
But out of 5, CAN0 is receiving only 3 message ID and remaking two can message is not able to receive.

Able to receive
0x1BF01D00
0x1BF01E00
0x1BF02800


Not able to received
0x1BF01F00
0x1BF02600


Can anyone help me to get out of this issue or any leads for the same.

Please find the attachment of Source code for the test example.

feel free to ask for more information.

0 Kudos
3 Replies

1,391 Views
hiren_virapara
Contributor I

Please find the attachment of SDK details

I have tried the following test case scenarios
Scenario 1:
I have changed only RX_MAILBOX (2UL) from RX_MAILBOX (0UL) and the rest of the things remain unchanged.
Test Result : Not able to receive any message from CNA bus.

Scenario 2:
Commented CAN_ConfigRxBuff() and CAN_SetRxFilter() function and the rest of the things remain unchanged
Test Result : Able to Receive the following message
0x1BF01D00
0x1BF01E00
0x1BF02800

Not able to received
0x1BF01F00
0x1BF02600

Scenario 3:
Commented CAN_ConfigRxBuff(), CAN_SetRxFilter() and CAN_Receive() inside CAN0_cb() callback function and the rest of the things remain unchanged
Test Result : Able to Receive the following message
0x1BF02800

Not able to received
0x1BF01D00
0x1BF01E00
0x1BF01F00
0x1BF02600


Can you please suggest other test scenarios that I need to try

0 Kudos

1,376 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

 

try to do below modifications to your code...

 

#define RX_FIFO (0UL)
#define RX_MAILBOX (2UL)

#define NUMBER_OF_ID 8

static void CAN0_cb (uint32_t instance, can_event_t eventType, uint32_t objIdx, void *driverState) {

(void)driverState;

switch(eventType)
{
case CAN_EVENT_RX_COMPLETE:
if(objIdx==RX_FIFO) // message received into RXFIFO
{
//PRINTF("rxMsg id= %d\r\n", rxMessage.id);
CAN_Receive(&BmsSbcCAN0_instance, RX_FIFO, &rxMessage);
}
if(objIdx==RX_MAILBOX) // message received into RX_MAILBOX
{
//PRINTF("rxMsg id= %d\r\n", rxMessage.id);
CAN_Receive(&BmsSbcCAN0_instance, RX_MAILBOX, &rxMessage);
}
break;
case CAN_EVENT_TX_COMPLETE:

break;
default:
break;
}
}


static void Init_SBCCAN (void)
{

//PRINTF("TEST_SBC with CAN: Prog Start... Initializing peripheries\r\n");

flexcan_id_table_t filterTable[NUMBER_OF_ID];
uint32_t IDlist[NUMBER_OF_ID] = {0x1BF01D00, 0x1BF01E00 ,0x1BF01F00, 0x1BF02600, 0x1BF02800, 0x1BF01D00, 0x1BF01D00, 0x1BF01D00};
for(uint8_t id_counter=0;id_counter<NUMBER_OF_ID;id_counter++)
{
filterTable[id_counter].isRemoteFrame = false;
filterTable[id_counter].isExtendedFrame = true;
filterTable[id_counter].id = IDlist[id_counter] ;
}
BmsSbcCAN0_rx_fifo_ext0.idFilterTable = &filterTable;
/* Can Init */
CAN_Init(&BmsSbcCAN0_instance, &BmsSbcCAN0_Config0);
CAN_ConfigTxBuff(&BmsSbcCAN0_instance, TX_MAILBOX, &txBuffCfg);
CAN_ConfigRxBuff(&BmsSbcCAN0_instance, RX_MAILBOX, &rxBuffCfg, RX_MSG_ID);
CAN_InstallEventCallback(&BmsSbcCAN0_instance, &CAN0_cb, NULL);
//CAN_SetRxFilter(&BmsSbcCAN0_instance,CAN_MSG_ID_EXT,0,0x1FFFFFFF);// mask for 1st item in filter table
for(uint8_t id_counter=1;id_counter<NUMBER_OF_ID;id_counter++)
{
CAN_SetRxFilter(&BmsSbcCAN0_instance,CAN_MSG_ID_EXT,id_counter,0x1FFFFFFF);// mask for "id_counter+1" item in filter table
}
CAN_SetRxFilter(&BmsSbcCAN0_instance,CAN_MSG_ID_EXT,RX_MAILBOX+NUMBER_OF_ID,0x1FFFFFFF);// mask for RX_MAILBOX
CAN_Receive(&BmsSbcCAN0_instance, RX_FIFO, &rxMessage);
CAN_Receive(&BmsSbcCAN0_instance, RX_MAILBOX, &rxMessage);

//PRINTF("All Init Done\r\n");
}

 

 

BR, Petr

0 Kudos

1,409 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

 

what SDK version do you use?

I think, you should not ever pass CAN_ConfigRxBuff() and CAN_SetRxFilter() functions if buffer 0 is used.

When Rx FIFO feature is enabled, buffer 0 (zero) cannot be used for transmission or reconfigured for reception using those functions.

And you have #define RX_MAILBOX (0UL) in your code. Try to use #define RX_MAILBOX (2UL).

 

BR, Petr

0 Kudos