AnsweredAssumed Answered

issue:s32k144 CAN0 Rx With Fifo DMA

Question asked by qh c on Feb 2, 2020
Latest reply on Jun 3, 2020 by Manuj Agrawal

I want to Receive 2 CAN messages with CAN0,I use the Fifo with DMA.

I modify on the “Example S32K144 FlexCAN RXFIFO DMA S32DS.ARM.2018.R1”.

Example S32K144 FlexCAN RXFIFO DMA S32DS.ARM.2018.R1 ;

The main configuration as flows:

1、filter table

void J1939_CAN0_init(void)
{
YCECU2FDM1.id=0x18F2E100 ;
YCECU2FDM2.id=0x14FD3E83 ;
/*--第0个报文匹配--*/
filterTable[0].isRemoteFrame = false;
filterTable[0].isExtendedFrame =true;
filterTable[0].id = YCECU2FDM1.id ;
/*--第1个报文匹配--*/
filterTable[1].isRemoteFrame = false;
filterTable[1].isExtendedFrame = true;
filterTable[1].id = YCECU2FDM2.id ;
}

2、Initialization 

/*Initialize eDMA driver */
EDMA_DRV_Init(&dmaController1_State, &dmaController1_InitConfig0, edmaChnStateArray, edmaChnConfigArray, EDMA_CONFIGURED_CHANNELS_COUNT);

/*Initialize FlexCAN driver */
FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
/* Install callback function */
FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, flexcan0_Callback, NULL);

/* Set information about the data to be received */
flexcan_data_info_t dataInfo =
{
.data_length = 1U,
.msg_id_type = FLEXCAN_MSG_ID_STD,
.enable_brs = false,
.fd_enable = false,
.fd_padding = 0U
};

/* Configure RX message buffer with index RX_MSG_ID and RX_MAILBOX */
FLEXCAN_DRV_ConfigRxMb(INST_CANCOM1, RX_MAILBOX, &dataInfo, RX_MSG_ID);

J1939_CAN0_init();
/* Configure RX FIFO ID filter table elements based on filter table defined above*/
FLEXCAN_DRV_ConfigRxFifo(INST_CANCOM1, FLEXCAN_RX_FIFO_ID_FORMAT_A, filterTable);
/* set individual masking type */
FLEXCAN_DRV_SetRxMaskType(INST_CANCOM1, FLEXCAN_RX_MASK_INDIVIDUAL);
/* first 14 filter items are masked with RXIMR0-RXIMR9 */
for(id_counter=0;id_counter<10;id_counter++)
FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, id_counter, 0xffffffff);
/* rest of filter items are masked with RXFGMASK */
FLEXCAN_DRV_SetRxFifoGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, 0xffffffff);

/* set mask affecting MB10 */
FLEXCAN_DRV_SetRxIndividualMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, RX_MAILBOX, 0xFFFFFFFF);

/* Start receiving data in RX_MAILBOX. */
FLEXCAN_DRV_Receive(INST_CANCOM1, RX_MAILBOX, &recvBuff1);
/* Start receiving data in RX_RXFIFO. */
FLEXCAN_DRV_RxFifo(INST_CANCOM1,&recvBuff2);

3、call back

void flexcan0_Callback(uint8_t instance, flexcan_event_type_t eventType,uint32_t buffIdx,
flexcan_state_t *flexcanState)
{
(void)flexcanState;
(void)instance;
(void)buffIdx;
uint8_t idx;

switch(eventType)
{
case FLEXCAN_EVENT_RX_COMPLETE:
{
rxMBdone = 1;
}
break;
case FLEXCAN_EVENT_RXFIFO_COMPLETE:
{

}
break;
case FLEXCAN_EVENT_DMA_COMPLETE:
{
if(recvBuff2.msgId==YCECU2FDM1.id)
{
for(idx=0;idx<recvBuff2.dataLen;idx++)
YCECU2FDM1.Data[idx]=recvBuff2.data[idx];
}

if(recvBuff2.msgId==YCECU2FDM2.id)
{
for(idx=0;idx<recvBuff2.dataLen;idx++)
YCECU2FDM2.Data[idx]=recvBuff2.data[idx];
}
rxFIFOdone=1;
}
break;
case FLEXCAN_EVENT_TX_COMPLETE:
{
}
break;
default:
break;
}
}

4、The "while"loop:

while(1)
{

if(rxFIFOdone==1)
{
rxFIFOdone=0;
FLEXCAN_DRV_RxFifo(INST_CANCOM1,&recvBuff2);
}

}

The project can receive the two CAN messages correctly.

But when I modify  the "callback" and the "while loop" as flow, the project can only receive the two messages once and the project seems halt.I guess the problem is the interrupt, so What could be the cause?

3、callback

void flexcan0_Callback(uint8_t instance, flexcan_event_type_t eventType,uint32_t buffIdx,
flexcan_state_t *flexcanState)
{
(void)flexcanState;
(void)instance;
(void)buffIdx;
uint8_t idx;

switch(eventType)
{
case FLEXCAN_EVENT_RX_COMPLETE:
{
rxMBdone = 1;
}
break;
case FLEXCAN_EVENT_RXFIFO_COMPLETE:
{

}
break;
case FLEXCAN_EVENT_DMA_COMPLETE:
{
if(recvBuff2.msgId==YCECU2FDM1.id)
{
for(idx=0;idx<recvBuff2.dataLen;idx++)
YCECU2FDM1.Data[idx]=recvBuff2.data[idx];
}

if(recvBuff2.msgId==YCECU2FDM2.id)
{
for(idx=0;idx<recvBuff2.dataLen;idx++)
YCECU2FDM2.Data[idx]=recvBuff2.data[idx];
}
//rxFIFOdone=1;
FLEXCAN_DRV_RxFifo(INST_CANCOM1,&recvBuff2);
}
break;
case FLEXCAN_EVENT_TX_COMPLETE:
{
CANFillBufferTx();

}
break;
default:
break;
}
}

4、while loop

while(1)
{

 

}

Outcomes