I am running into an issue when receiving data t 1Mbit/s. My setup is as followed: I have a MIMXRT1062 connected to a PEAK-CAN. I am using the FLEXCAN_TransferReceiveNonBlocking with a ISR that puts the received data into a FreeRTOS queue.
When sending two different type of messages using the PEAK-CAN both at 5ms or less I run into the following issue. Let's say the PEAK-CAN sends 500 messages with ID 1 and 500 with ID 2. Then the task that empties the FreeRTOS queue will find 550 messages with ID1 and 450 with ID 2. This indicates that the ISR is fired the correct amount but the data being put in the queue is being re-used of a previous message?
My ISR looks as followed:
void ITCMFUNC_ATTR MailBox::retrieveFrameFromISR(BaseType_t &higherPrioTaskWoken)
{
// Retrieve ID for message
auto &f = _frame;
bool isEff = f.format == kFLEXCAN_FrameFormatExtend;
bool isRtr = f.type == kFLEXCAN_FrameTypeRemote;
uint32_t id = isEff ? ((f.id & (CAN_ID_EXT_MASK | CAN_ID_STD_MASK)) >> CAN_ID_EXT_SHIFT) :
((f.id & CAN_ID_STD_MASK) >> CAN_ID_STD_SHIFT);
// Push back the message to the receivers
for(auto &receiver : _receivers)
{
if(receiver.filter.matches(id, isRtr, isEff))
{
receiver.obj->rxQueue.sendToBackFromISR(_frame, higherPrioTaskWoken);
}
}
// Setup the transfer
flexcan_mb_transfer_t xfer;
xfer.frame = &_frame;
xfer.mbIdx = _mbIdx;
FLEXCAN_TransferReceiveNonBlocking(_can->_base, &_can->_handle, &xfer);
}
The _frame is only accessed in the ISR. I call the FLEXCAN_TransferReceiveNonBlocking once to start receiving and keep calling it in the ISR to keep receiving after a message has been received.