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?
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.