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.

AM2634-Q1: MCAN_getErrCounters() API Bug

Part Number: AM2634-Q1

Hi Champs:

     I reported MCAN_getErrCounters() API in SDK has bug before and fixed issue. However, until SDK9.1.0.41, this bug still there and did not be fixed.

Can you please double check?

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1162034/can-error-frame-and-sample-point-issue/4374643?tisearch=e2e-sitesearch&keymatch=%20user%3A8447#4374643

Customer report issue that canErrLogCnt always reports "zero" when recErrCnt is increasing.

typedef struct
{
uint32_t transErrLogCnt;
/**< Transmit Error Counter */
uint32_t recErrCnt;
/**< Receive Error Counter */
uint32_t rpStatus;
/**< Receive Error Passive
* 0 = The Receive Error Counter is below the error passive level(128)
* 1 = The Receive Error Counter has reached the error passive level(128)
*/
uint32_t canErrLogCnt;
/**< CAN Error Logging */
}MCAN_ErrCntStatus;

The API  MCAN_getErrCounters()  use to access ECR register to get error count:

/* Checking for Rx Errors */
MCAN_getErrCounters(gMcanBaseAddr, &errCounter);

According to MCAN manual which can be downloaded from here : https://www.bosch-semiconductors.com/ip-modules/can-ip-modules/m-can/

Byte access: Reading byte 2 will reset CEL to zero, reading bytes 3/1/0 has no impact.

However in SDK8.03 driver source code:

void MCAN_getErrCounters(uint32_t baseAddr,
MCAN_ErrCntStatus *errCounter)
{

errCounter->transErrLogCnt = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
MCAN_ECR_TEC);
errCounter->recErrCnt = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
MCAN_ECR_REC);
errCounter->rpStatus = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
MCAN_ECR_RP);

errCounter->canErrLogCnt = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
MCAN_ECR_CEL);
}

The first 3x 32bits access  will reset CEL field so the last call will always read "zero" into canErrLogCnt.

SDK driverlib needs to be modified and change counter read order to get correct result. 

void MCAN_getErrCounters(uint32_t baseAddr,
MCAN_ErrCntStatus *errCounter)
{
errCounter->canErrLogCnt = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
MCAN_ECR_CEL);
errCounter->transErrLogCnt = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
MCAN_ECR_TEC);
errCounter->recErrCnt = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
MCAN_ECR_REC);
errCounter->rpStatus = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
MCAN_ECR_RP);
// Issue: 2022/10. 17
// CEL always read as "zero" when access struct MCAN_ErrCntStatus;
// Change the access the order to ECR register since CEL will be reset after it is read
// errCounter->canErrLogCnt = HW_RD_FIELD32(MCAN_CfgAddr(baseAddr) + MCAN_ECR,
// MCAN_ECR_CEL);
// TEC, REC, and RP will not be impact by read access to ECR register
}

 Please double confirm and fix this issue in next version of SDK.