This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AWR1843BOOST: CAN rx issue: application crashes when receive new CAN message

Expert 2050 points
Part Number: AWR1843BOOST
Other Parts Discussed in Thread: SYSBIOS

In mrr_18xx lab demo, I understand below code is for receiving the CAN message from external device. 

void Can_Initialize(void){
...
rxMsgObjectParams.direction = CANFD_Direction_RX;
rxMsgObjectParams.msgIdType = CANFD_MCANXidType_11_BIT;
rxMsgObjectParams.msgIdentifier = 0xA1 | CAN_MESSAGE_PARK_SENS_POS;
rxMsgObjHandle = CANFD_createMsgObject (canHandle, &rxMsgObjectParams, &errCode);
if (rxMsgObjHandle == NULL)
{
    System_printf ("Error: CANFD create Rx message object failed [Error code %d]\n", errCode);
    return ;
}
...
}

...

static void MCANAppCallback(CANFD_MsgObjHandle handle, CANFD_Reason reason){
  ...
  retVal = CANFD_getData (handle, &id, &rxFrameType, &rxIdType, &rxDataLength, &rxData[0], &errCode);
  ...
}

I tested mrr_18xx lab demo's CAN Rx feature by sending one CAN message (ID: 0xA1) from PCAN example tool to AWR1843BOOST. The demo running in AWR1843BOOST crashes once the message was send.

In debug mode, I get the below error:

ti.sysbios.gates.GateMutex: line 99: assertion failure: A_badContext: bad calling context. See GateMutex API doc for details.
xdc.runtime.Error.raise: terminating execution

Does mrr-18xx demo support CAN Rx? Could you please check this issue in your side?

Thanks

  • Hi,

    I have a hunch for why this might be happening. As per this thread, System_printf cannot be called from an interrupt context (there is more to it, the thread explains it well). In the callback, I think the following section of code is causing this error:

    if (rxFrameType != frameType)
    {
        System_printf ("Error: CAN received incorrect frame type Sent %d Received %d for iteration %d failed\n", frameType, rxFrameType, iterationCount);
        return;
    }

    Essentially, System_printf tries to acquire a mutex in an interrupt context, which is not allowed. Can you comment this out, recompile and see if it works?

    Also, in general, it is good practice to create a separate task for an operation this big (I see some memset and memcpy calls). If you want, you could also restructure the code like so:

    //pseudocode
    
    void MCANAppCallBackTask(){
        while(true){
            Semaphore_pend(MCANReadSem); //waits for semaphore
            doMCANProcessing();   //does the more involved processing in task context
        }
    }
    
    static void MCANAppCallback(){
        semaphore_post(MCANReadSem);  //posts the semaphore, returns quickly
    }

    Let me know if this works for you.

    Regards,

    Aayush

  • Thanks. I comment all System_printf in callback, it works.