Flexcan Mailbox not proper unlocking under freertos (maybe cache problem)

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

Flexcan Mailbox not proper unlocking under freertos (maybe cache problem)

2,032 Views
moritzkunze
Contributor I

So i use the flexcan drivers with mailboxes under the sdk 0.8.6 with freertos on the s32k144 (engineering samples right now).

Problem:

First receiveBlocking call to can works properly, any subsequent is blocking forever/timeouting with status TIMEOUT despite there are can messages qualifiying are on the bus and received by the can core. It happens on can and canfd packages.

Mitigation in debugger:

A. Read !any! of the registers of the Flexcan peripheral between receives does allow a subsequent receive

B. Doing the RxMailbox Configuration again will allow one more package to be received (tested doing this after a timeout will result in an timeout/success/timeout cycle).

Mitigation in runtime:

use nonblocking and callback works

Environment:

CAN or CANFD with 500kbits, CPU Clock from PLL with 80MHz, Busclock with 10/20/40MHz tested, PE Clock is CPU/Sys Clock with 80MHz, but 16MHz from SOSC does also not work. 

CAN PE works, as the frames are acknowledged.

Optimization is disabled.

Idea:

Cache problems might be an issue due to to rather "tricky" way to lock and unlock mailboxes and the read to the timer to unlock "(void)*base->TIMER" is cached?

Todo:

check if cache disable will help, but need info howto do it

Code:

INIT:

INT_SYS_SetPriority(CAN0_ORed_IRQn, 4);
INT_SYS_SetPriority(CAN0_Error_IRQn, 4);
INT_SYS_SetPriority(CAN0_Wake_Up_IRQn, 4);
INT_SYS_SetPriority(CAN0_ORed_0_15_MB_IRQn, 4);
INT_SYS_SetPriority(CAN0_ORed_16_31_MB_IRQn, 4);

FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);

FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_EXT, 0x00);
FLEXCAN_DRV_SetRxMbGlobalMask(INST_CANCOM1, FLEXCAN_MSG_ID_STD, 0x00);

Task:

flexcan_data_info_t info = {
.msg_id_type = FLEXCAN_MSG_ID_STD, /*!< Type of message ID (standard or extended)*/
.data_length = 64, /*!< Length of Data in Bytes*/
.fd_enable = true, /*!< Enable or disable FD*/
.fd_padding = 0, /*!< Set a value for padding. It will be used when the data length code (DLC)
specifies a bigger payload size than data_length to fill the MB */
.enable_brs = true, /*!< Enable bit rate switch inside a CAN FD format frame*/
.is_remote = false, /*!< Specifies if the frame is standard or remote */
};

FLEXCAN_DRV_ConfigRxMb (INST_CANCOM1, 0 , &info, 0);

flexcan_msgbuff_t msgIn;

while(1) {

      status = FLEXCAN_DRV_ReceiveBlocking(INST_CANCOM1, 0 , &msgIn, 1000);

      if (status == STATUS_SUCCESS) {
 
    /* process frame */
    } else {
     /* reset mbx */
     FLEXCAN_DRV_ConfigRxMb (INST_CANCOM1, 0 , &info, 0);
    }

}

Labels (1)
3 Replies

1,175 Views
jay_zhang
Contributor II

Hi Morizt,

Can you share your project with flexcan on FreeRTOS, I am doing the same thing, but failed to porting flexcan to FreeRTOS.

Another thread for my issue:

https://community.nxp.com/thread/481750 

Thanks

0 Kudos

1,175 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

Seems the MB is not properly unlocked when single MB is prepared for the reception using blocking functions.

Try to put reading of TIMER register after successful reception and let us know the result.

status = FLEXCAN_DRV_ReceiveBlocking(INST_CANCOM1, 0 , &msgIn, 1000);

      if (status == STATUS_SUCCESS) {
 
          /* process frame */

         dummy = CAN0->TIMER;
    } else {

BR,

Petr

1,175 Views
moritzkunze
Contributor I

Im currently not using freertos anymore, but i agree with your solution. Lets keep it here for reference if somebody else runs into this problem (or i have time to check it).

0 Kudos