Flexcan Receiving issue

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

Flexcan Receiving issue

6,588 次查看
bharathn3402
Contributor III

 

I’m using the MPC5775B microcontroller with FlexCAN. During runtime, the FlexCAN suddenly stops receiving standard CAN IDs, even though the CAN IDs are present on the bus. However, it can still receive extended CAN IDs and can send both standard and extended CAN IDs. The system returns to normal functionality after resetting the MCU. What could be causing this issue, and how can it be resolved?

Here’s how I’m initializing the transmit and receive message boxes:

 

// Configure Transmit box 
FLEXCAN_DRV_ConfigTxMb(INST_FLEXCANC, 0, &FlexCAN_transmitMsgInfo, 0x69); FLEXCAN_DRV_ConfigTxMb(INST_FLEXCANC, 1, &FlexCAN_transmitMsgInfo, 0x69); 
// Configure Receive box 
FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 2, &FlexCAN_receiveMsgInfo, 0x210); FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 3, &FlexCAN_receiveMsgInfo, 0x210); FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 4, &FlexCAN_receiveMsgInfo, 0x210); FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 5, &FlexCAN_receiveMsgInfo_ext, DUMMY_CAN_ID_2);
FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 6, &FlexCAN_receiveMsgInfo_ext, 0x210);

i used global mask to accept to receive all the canids

Can you please help me out on how to resolve this.

#flexcan #Mpc5775b 

0 项奖励
回复
15 回复数

5,924 次查看
bharathn3402
Contributor III

Hi @PetrS ,

How can we determine if a message buffer (MB) is in an overrun state or any other state? Is there an interrupt to check the status in FlexCAN?

In my case, I’m using FlexCAN with a callback function to copy the received data triggered by the `FLEXCAN_EVENT_RX_COMPLETE` event. However, occasionally, my application fails to catch that interrupt and process the data in time. As a result, when a new message arrives in the same MB, the MB cannot receive the data.

How can I detect when the MB goes into an overrun state to service it appropriately? How should I address this issue?

5,843 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

overrun is only indicated by MB CODE field. So once MB interrupt is serviced the user RXbuffer is updated with MB content, RXbuffer.CS contains value of MB's CS word where CODE field can be read. 
You should ensure MB is read in time. Try to set higher priority for FlexCAN module MB interrupts.

BR, Petr

0 项奖励
回复

6,567 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

from this piece of code it cannot be much commented regarding a root cause.
I can recommend to check in debugger for module's registers and MBs setting/content, if this is as expected. If the MB is still configured to receive given ID, then it would be updated if such message is received.

BR, Petr

0 项奖励
回复

6,533 次查看
bharathn3402
Contributor III

Hi Peter,

Actually, the issue occurs suddenly while the application is running on the MCU, and at that moment, we can’t check the register contents, correct? I’m also unable to recreate the issue.

I have another question: What is the global mask value to receive all CAN IDs without any filter?

0 项奖励
回复

6,519 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

refer to RXMGMASK register description. 
If mask register is cleared then received ID is don't care. In that case first RX MB will be updated still if global mask scheme is used.

BR, Petr

0 项奖励
回复

6,479 次查看
bharathn3402
Contributor III

Hi petrs

1.)Is there a feature in FlexCAN to stop receiving CAN data when the error counter for a particular message buffer (MB) reaches the threshold?
2.)or is there any condition to stop receiving?
3.) i used 0x69,0x210 as mask for MB0 ,1  what range of canid's it will receive?

0 项奖励
回复

6,454 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

1) no, there is no such functionality. Also there is no individual error counters for each MB. ECR register contains contains error counters for received and transmitted messages. The rules for
increasing and decreasing these counters are described in the CAN protocol and basic rules are listed in ECR description.
You can get warning interrupt, see TWRNINT/RWRNINT and user have to react as needed.
2) Reception is stopped if RX MBs are inactivated, or module is in Freeze mode
3) you have an ID and IDE bit configured in the MB and corresponding mask register, from that you can see which ID bits will be don't care.

BR, Petr 

0 项奖励
回复

6,438 次查看
bharathn3402
Contributor III

Hi Petrs,

1. Under which situations are RX message buffers (MBs) deactivated?
2. When the RXERRCNT in the Error Counter Register (ECR) reaches its maximum value, what happens? Does the CAN controller enter any specific state? In this state, can it still receive or transmit CAN IDs?

 

0 项奖励
回复

6,423 次查看
PetrS
NXP TechSupport
NXP TechSupport

HI,

1) to inactivate a message buffer, the CPU must update its CODE field to INACTIVE (either 0b or 1000b). see more in chapter 73.3.7.2 Message buffer inactivation

2) a module will continue to run in error passive state;  It takes part in bus communication,
but when an error has been detected only a PASSIVE Error flag is sent. Also after a transmission,
an error-passive node will wait before initiating a further transmission.

BR, Petr

0 项奖励
回复

6,392 次查看
bharathn3402
Contributor III

Hi Petrs,

Could you please share a code snippet on how to inactivate the message buffer (MB) after initializing the FlexCAN module for the MPC5775B MCU?

0 项奖励
回复

6,292 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

SDK does not have function to inactivate RX MB, so if needed you need to write MB directly.
FLEXCAN_DRV_AbortTransfer can be the one you can refer to. For RX MB, it finally deactivates the MB, but then activate it again.

BR, Petr

0 项奖励
回复

6,249 次查看
bharathn3402
Contributor III

Hi Petrs,

I identified the issue behind the stop in receiving. After reading the code value of the MBs, I found that when it stops receiving the CAN IDs, it's in the OVERRUN state (0x6). Can you help me resolve this and get it back to a normal state where it can receive the CAN IDs again?

Here’s the code snippet I used for recovery:

`
static inline uint32_t FLEXCAN_GetMessageBufferCode(const CAN_Type *base, uint32_t mbIdx) {
if (mbIdx >= FEATURE_CAN_MAX_MB_NUM) {
return UINT32_MAX; // Invalid index
}
volatile uint32_t *flexcan_mb = FLEXCAN_GetMsgBuffRegion(base, mbIdx);
uint32_t flexcan_mb_config = *flexcan_mb; // Read the control/status register
uint32_t code = (flexcan_mb_config & FLEX_CAN_CS_CODE_MASK) >> 24; // Extract the CODE field
return code;
}

void UnlockOverrunMailbox(CAN_Type *base, uint32_t mbIdx) {
// Enter Freeze Mode to safely modify the mailbox
if (!FLEXCAN_EnterFreezeMode(base)) {
printf("Failed to enter Freeze Mode\n");
return;
}
// Check if the MB is in OVERRUN state
uint32_t mbCode = FLEXCAN_GetMessageBufferCode(base, mbIdx);
if (mbCode == FLEXCAN_RX_BUFFER_OVERRUN) {
printf("MB %u is in OVERRUN state. Unlocking it...\n", mbIdx);
// Reset the MB state to EMPTY (0x4) or INACTIVE (0x0)
base->RAMn[mbIdx * 4] = (base->RAMn[mbIdx * 4] & ~FLEX_CAN_CS_CODE_MASK) | (0b0100 << 24);
// Unlock the MB by reading the Free Running Timer
volatile uint32_t unlock = base->TIMER;
printf("MB %u unlocked and reset to EMPTY state.\n", mbIdx);
}
// Exit Freeze Mode
FLEXCAN_ExitFreezeMode(base);
}
```

However, the recovery is still not working.

I have a few questions related to this issue:
1. I configured three message buffers (MBs) for receiving, all filtered with the same CAN ID. In this case, the second MB went into the OVERRUN state, but why aren't the remaining two MBs receiving messages?
2. Is there any other process or method, apart from the code snippet above, to recover from this situation and resume receiving CAN IDs?

Thanks for your help!

标记 (1)
0 项奖励
回复

6,172 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

if a code field is OVERRUN, still this MB is seen as free-to-receive during matching process, if the MB is not locked. So maybe in your case the second MB is recognized as matched and  free-to-receive MB and so other are not updated.
If the driver is not able to read a MB (call MB interrupt, etc) you can try to check MB flag and interrupt mask bit and content of driver status variable for given MB.

To recover you can try to call AbortTransfer function and then Receive function again.

Not sure of the SDK version you have, but be sure you have the latest one (3.0.0 I think).

BR, Petr

0 项奖励
回复

5,827 次查看
bharathn3402
Contributor III

Hi @PetrS ,

Thank you for the prompt response. I will try to set the priority to high.

I have another question: In flexcan While configuring the RX buffers, we can apply individual masks to each buffer as required. Similarly, is it possible to configure TX buffers with individual masks? If not, how does the system handle multiple CAN IDs in the TX buffers?

0 项奖励
回复

5,810 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

no mask is done for TX buffers. User configures MB with given ID for transmission. If more TX MBs are prepared for transmission, internal arbitration process is performed to select a winner, that is going to be send on first opportunity window on the bus. See more in Arbitration process chapter.  

BR, Petr

0 项奖励
回复