LPC546 MCANRxFifo assert

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

LPC546 MCANRxFifo assert

跳至解决方案
811 次查看
Hector_Jimenez
Contributor III

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!

 

0 项奖励
回复
1 解答
738 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Hector_Jimenez 

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

在原帖中查看解决方案

0 项奖励
回复
4 回复数
773 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Hector_Jimenez 

In the MCAN_ReadRxFifo function, 

assert(NULL != rxFrame)  is a necessary condition.

 

Snipaste_2025-02-24_16-03-00.png

So it could not be sorted out by skipping that reading.

BR

Harry

0 项奖励
回复
768 次查看
Hector_Jimenez
Contributor III

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

0 项奖励
回复
739 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Hector_Jimenez 

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

0 项奖励
回复
710 次查看
Hector_Jimenez
Contributor III

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!

0 项奖励
回复