CAN buffer issue.

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

CAN buffer issue.

886 Views
ArendZAR
Contributor I

Hello, 

I have an issue with the fsl_mcan drivers that I'm not sure how to fix:

In the function: MCAN_TransferSendNonBlocking

The code that checks if the tx buffer is IDLE (kMCAN_StateIdle == handle->bufferState[xfer->bufferIdx])  returns 
kStatus_MCAN_TxBusy even though the line is completely IDLE


Eventually the Data will get sent but messages are lost here. Deleting this line of code as a test made the code work flawlessly, however, it is likely to cause errors in the future. 

How can I solve this problem? For extra information, I am sending the first type of message every 100ms, the second type of message every 150ms and a third type every 5 seconds or so. 

Thanks in advance.

0 Kudos
Reply
3 Replies

839 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @ArendZAR 

Could you please tell me which chip? And does the issue can be reproduced on SDK demo?

 

BR

Alice

0 Kudos
Reply

836 Views
ArendZAR
Contributor I

Hi there,

I'm using the LPC54628J512,

I can try test on an example, however this code runs very deep and I don't think I will be able to reproduce the conditions needed to create the issue.

I have had some success by using only buffer index [0] and using retries when it fails. For more context this issue is causing the timing of the CAN messages to become inconsistent as well as increasing the time between messages. Sometimes resulting in messages getting discarded. 

0 Kudos
Reply

770 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @ArendZAR 

For the situation you described, you can try adding a retry mechanism in the MCAN_TransferSendNonBlocking function. If the first check returns kStatus_MCAN_TxBusy, you can wait for a short period and then check again. For example:

status_t MCAN_TransferSendNonBlocking(MCAN_Type *base, mcan_handle_t *handle, const mcan_transfer_t *xfer)
{
status_t result = kStatus_MCAN_TxBusy;
uint32_t retryCount = 0;

while ((result == kStatus_MCAN_TxBusy) && (retryCount < MAX_RETRIES))
{
if (kMCAN_StateIdle == handle->bufferState[xfer->bufferIdx])
{
// Buffer is idle, proceed with sending
result = kStatus_Success;
// Your existing send logic here
break;
}
else
{
// Buffer is busy, wait and retry
SDK_DelayAtLeastUs(100, SDK_DEVICE_SYSCLK_CLOCKRATE); // Adjust delay as needed
retryCount++;
}
}

return result;
}

 

BR

Alice

0 Kudos
Reply