Read bus-off state of MPC5642 from ESR.FLTCONF after CAN_H and CANL is short-wired

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

Read bus-off state of MPC5642 from ESR.FLTCONF after CAN_H and CANL is short-wired

2,229 Views
ZhouYiChuan
Contributor III

Hello NXP experts:

The too-chain is S32 DS V2.1, multi-link debugger. 

The design is CAN_A bus-off state can be read from ESR.FLTCONF after after CAN_H and CANL being kept short-wired for at least 5s. Error frame can be observed from CANoe. 

But the bus-off state is not confirmed, reason is from debugger view, ESR_FLTCONF value is always 0. as below:

ESR_value2.png

unfortunately, only general registers is displayed in my debugger 'register' window. 

So I copy value of ESR and ECR to a global variable, at the same time, try to read them for memory view.

Global variables value can match the result of memory view.

The global variable CanA_ErrStatusR = 0x2252, so ESR.FLTCONF should be 0x10.

but the code block if((0x10 == CAN_A.ESR.B.FLTCONF) ||(0x11 == CAN_A.ESR.B.FLTCONF)) is NOT executed. 

part of the bus-off handling code is below:

CanA_ErrStatusR = (uint32_t)CAN_A.ESR.R;
CanA_ErrCountR = (uint32_t)CAN_A.ECR.R;
if((0x10 == CAN_A.ESR.B.FLTCONF) ||(0x11 == CAN_A.ESR.B.FLTCONF))
{
    if(1 == CAN_A.ESR.B.BOFFINT) /*this line never be executed*/
    {
         bBusOffFlag_A = TRUE;
         BusOffState_A = BUS_OFF_DETECTED;
         BusOffDelayer_A = 0;
         fastRecoveryCnt_A = 0;
    }
}

And the CR.BOFFREC bit is set to 1 to disable the automatic bus-off recovery.

This setting succeeded and can be confirmed from the read-back global value --CanA_BOFFREC and memory view (addr 0xFFFC0004)

the initialization code is:

uint8_t i;
CAN_A.MCR.R = 0x5000003F; // Put in Freeze Mode & enable all 64 message buffers
// CAN_A.CR.R = 0x00DB0006; // Configure for 8MHz OSC, 500KHz bit time
CAN_A.CR.R = 0x00DB0046; // Configure for 8MHz OSC, 500KHz bit time; Automatic recovering from Bus Off state disabled

CanA_BOFFREC = CAN_A.CR.B.BOFFREC;

Even in user manual , the FLTCONF is bit26-bit27, but the reading sequence is from left to right, because bit0~bit13 should ALWAYS be 0, if ESR = 0x2252, the correct value mapping is below:

esr_userManual.PNG

Same solution works well in another product based on MPC5746R. 

Thanks and BR

Zhou YiChuan

 

 

0 Kudos
8 Replies

2,217 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

FLTCONF is 2 bits wide field so you should not have

if((0x10 == CAN_A.ESR.B.FLTCONF) ||(0x11 == CAN_A.ESR.B.FLTCONF))

but rather

if((0b10 == CAN_A.ESR.B.FLTCONF) ||(0b11 == CAN_A.ESR.B.FLTCONF)) or 

if((0x2 == CAN_A.ESR.B.FLTCONF) ||(0x3 == CAN_A.ESR.B.FLTCONF))

BR, Petr

0 Kudos

2,204 Views
ZhouYiChuan
Contributor III

hello Petr:

You'r correct, sorry for my wrong code. But now the issue is:

The ESR.FLTCONF is 1(== error passive), Bus-Off error was NOT created.

Even the CAN_H and CAN_L is short wired for at least 10s, and error frame is observed in CANoe,

Could you please tell me what register initialization was forgot?

Automatic bus-off recovering is disabled by setting CR.BOFFREC with following code:

CAN_A.CR.R = 0x00DB0046;

It can be confirmed from the memory view (addr 0xFFC00004) below:

Memory_0220.PNG

And from the memory view of FlexCAN registers, the ECR is 0x0085, so TXECNT is still 0x85, not the condition for bus-off mode. 

When I remove the CAN_H/L short wired, the transmission recovered automatically. 

It seems the automatic bus-off recovery is not disabled,

PS: another snapshot for your information:

ESR_value3.png

thanks and BR

Zhou YiChuan

 

 

0 Kudos

2,191 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

did you send message from MPC5742A with CANH/CANL shorted (or e.g. CANH grounded)?

BR, Petr

0 Kudos

2,186 Views
ZhouYiChuan
Contributor III

Hi, Petr:

Yes, 4 IDs of messages is sending from MPC5642A CAN_A cyclically. like below:

CanOe.PNG

The SW is running  on another 5642A ECU, same result is observed. 

The CAN_A.ESR.FLTCONF bit is 1 while CAN_H/L being kept short-wired.

thanks and BR

Zhou YiChuan

0 Kudos

2,181 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

could you please share project you have, so I can check it.
Also share measurement of TX/RX/bus lines on MCU running given code.

BR, Petr

0 Kudos

2,136 Views
ZhouYiChuan
Contributor III

Hi@PetrS 

I've uploaded my project, is there any update?

thanks and BR

Zhou YiCHuan

0 Kudos

2,059 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

sorry for a delay, unfortunately I havent got a board and later has no time.
Now I tested it on MPC5642A EVB board.
Starting your code, without CAN_A connected to the bus I see ACK error with error passive state but it does not go to CAN_A_AckErrorTask(). But seems it is not called by code at all. Adding below code   

PetrS_0-1646648379339.png

it can stop on testing ACK flag

PetrS_1-1646648552892.png

Connecting board to PCAN tool I see message transmitted by board.
Shorting CANH/CANL it pass BOFFINT flag testing

PetrS_2-1646648653029.png

So seems it is working as expected. Not sure of you further code, I did not get the meaning. Looks you do some reinit, etc. But there is no flag clearing. With BOFFREC set you need to clear it once you enter bus off state so you can leave it. This is how manual recovery works.

BR, Petr

 

connecting CAN_A with PCAN tool. 

0 Kudos

2,170 Views
ZhouYiChuan
Contributor III

Hello Petr:

Thank you very much for the following up. The Bus-off and ACKError were checked on CAN_A.

Maybe you just need to focus on CAN_Drv.c, function CAN_A_BufOffTask() and CAN_A_AckErrorTask()

thanks and BR

Zhou YiChuan

0 Kudos