Flexcan callback is not executed ocassionally I have implemented flexcan callback to receive FLEXCAN_EVENT_RX_COMPLETE and FLEXCAN_EVENT_TX_COMPLETE events. When RX event is generated, the received can buffer is copied into a queue. And when TX event is generated a can_available flag is set to true to send the next can frame. Please find the code snippet below void flexcan1_callback(uint8 instance, Flexcan_Ip_EventType eventType, uint32 buffIdx,
const Flexcan_Ip_StateType *flexcanState)
{
(void)flexcanState;
(void)buffIdx;
if (eventType == FLEXCAN_EVENT_RX_COMPLETE)
{
can_frame_t cebms_can_frame = {.type_e=CAN_EXTD_ID};
if (buffIdx == can_md_idx_rx_u8[CAN_STD_ID])
{
cebms_can_frame.type_e = CAN_STD_ID;
}
xQueueSendFromISR(chg_rx_queue[1], (const void*)&cebms_can_frame, &xHigherPriorityTaskWoken);
FlexCAN_Ip_Receive(instance, buffIdx, &rxData[instance][cebms_can_frame.type_e], FALSE);
}
else if ((FLEXCAN_EVENT_TX_COMPLETE == eventType))
{
can_tx_available[instance] = TRUE;
}
} boolean Can_Tx(uint8_t instance, can_frame_t* can_frame)
{
uint16_t can_timeout = 0xFFFFU;
boolean can_return = FALSE;
while ((can_tx_available[instance] == FALSE) && (can_timeout))
{
can_timeout--;
}
if (can_tx_available[instance] == TRUE)
{
can_tx_available[instance] = FALSE;
FlexCAN_Ip_Send(instance, can_md_idx_tx_u8[can_frame->type_e], &can_data_info[can_frame->type_e],
can_frame->id.u32, (uint8 *)&can_frame->data.u8a);
can_return = TRUE;
printf("SUCCESS: 0x%08X", (unsigned int)can_frame->id.u32);
}
else
{
printf("FAILED: 0x%08X", (unsigned int)can_frame->id.u32);
}
return can_return;
} Here, sometimes when I try to transmit multiple can frames sequentially using the above function, FAILED is printed multiple times for those can ids in the sequence for approx 20 seconds. And suddenly can frames start getting transmitted and SUCCESS is printed. I have also attached a CAN logger to verify this, and the result is same on the CAN logger. When FAILED is printed, no messages are seen on the CAN logger. Please help me out on this matter and whether my implementation is correct or not. Thanks Gauri #s32k311 #flexcan Re: Flexcan callback is not executed ocassionally Hello @geeznxp,
I will assume RTD 3.0.0 is used (based on you post history). I will also assume your other node is the PCAN-USB analyzer.
From your description, I cannot immediately diagnose your application, however, here are some points to check:
1. Is can_tx_available declared as volatile? Since it is written inside an ISR (TX_COMPLETE callback) and read inside a task-level while-loop. Without the volatile qualifier, the compiler is free to cache false or never reload the variable in other iterations.
2. The ~20 second interval may also point to a bus-off event. Add a bus-off error case in the callback, to detect and handle the bus-off event.
3. I would also check ESR1 registers in the interval where FAILED is printed multiple times.
Lastly, general points to check, CAN bus termination, bit rate configuration, FlexCAN_Ip return value, FlexCAN error callback registered.
Best regards, Julián
View full article