I'm using MCAN module in LPC54616 MCU in a very unstable environment, which causes assertion in MCAN_ReadRxFifo function when receiving null frames (rxFrame = NULL).
fsl_mcan.c
[...]
status_t MCAN_ReadRxFifo(CAN_Type *base, uint8_t fifoBlock, mcan_rx_buffer_frame_t *rxFrame)
{
/* Assertion. */
assert((0U == fifoBlock) || (1U == fifoBlock));
assert(NULL != rxFrame);[...]
leading into MCU continiously stalling.
Is this a real assertion reason or could it be sorted out by skipping that reading?
Perhaps it's already been solved in later versions of SDK, can anyone confirm this? My SDK version is 2.10.
Thank you!
解決済! 解決策の投稿を見る。
Yes, you can add related code.
Or you can add a new function.
status_t CheckFrame(CAN_Type *base, uint8_t fifoBlock, mcan_rx_buffer_frame_t *rxFrame)
{
/* Assertion. */
assert((0U == fifoBlock) || (1U == fifoBlock));
if (NULL == rxFrame) {
/* Acknowledge the read. */
if (0U == fifoBlock)
{
base->RXF0A = (base->RXF0S & CAN_RXF0S_F0GI_MASK) >> CAN_RXF0S_F0GI_SHIFT;
}
else
{
base->RXF1A = (base->RXF1S & CAN_RXF1S_F1GI_MASK) >> CAN_RXF1S_F1GI_SHIFT;
}
return kStatus_Fail;
}
else {
MCAN_ReadRxFifo(base, fifoBlock, rxFrame);
}
[...]
BR
Harry
In the MCAN_ReadRxFifo function,
assert(NULL != rxFrame) is a necessary condition.
So it could not be sorted out by skipping that reading.
BR
Harry
Hello @Harry_Zhang.
What if we ack the read and return failure? This return value could be checked when calling to MCAN_ReadRxFifo function and set a different status for CAN bus, like kStatus_MCAN_RxFifo0Lost.
status_t MCAN_ReadRxFifo(CAN_Type *base, uint8_t fifoBlock, mcan_rx_buffer_frame_t *rxFrame)
{
/* Assertion. */
assert((0U == fifoBlock) || (1U == fifoBlock));
if (NULL == rxFrame) {
/* Acknowledge the read. */
if (0U == fifoBlock)
{
base->RXF0A = (base->RXF0S & CAN_RXF0S_F0GI_MASK) >> CAN_RXF0S_F0GI_SHIFT;
}
else
{
base->RXF1A = (base->RXF1S & CAN_RXF1S_F1GI_MASK) >> CAN_RXF1S_F1GI_SHIFT;
}
return kStatus_Fail;
}
[...]
Kind regards
Yes, you can add related code.
Or you can add a new function.
status_t CheckFrame(CAN_Type *base, uint8_t fifoBlock, mcan_rx_buffer_frame_t *rxFrame)
{
/* Assertion. */
assert((0U == fifoBlock) || (1U == fifoBlock));
if (NULL == rxFrame) {
/* Acknowledge the read. */
if (0U == fifoBlock)
{
base->RXF0A = (base->RXF0S & CAN_RXF0S_F0GI_MASK) >> CAN_RXF0S_F0GI_SHIFT;
}
else
{
base->RXF1A = (base->RXF1S & CAN_RXF1S_F1GI_MASK) >> CAN_RXF1S_F1GI_SHIFT;
}
return kStatus_Fail;
}
else {
MCAN_ReadRxFifo(base, fifoBlock, rxFrame);
}
[...]
BR
Harry
Hi, @Harry_Zhang .
We are testing the code I posted and it seems to work fine in these unstable conditions. Some frames are lost, but MCU doesn't get stalled.
Thanks for your help.
Regards!