LPC546 MCANRxFifo assert

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC546 MCANRxFifo assert

Jump to solution
809 Views
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 Kudos
Reply
1 Solution
736 Views
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

View solution in original post

0 Kudos
Reply
4 Replies
771 Views
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 Kudos
Reply
766 Views
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 Kudos
Reply
737 Views
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 Kudos
Reply
708 Views
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 Kudos
Reply