Dear support team:
I found a bug in flexcan module, it leads to the interrupt can't disable correctly.
Description:
file:
flexcan_hw_access.c
function:
void FLEXCAN_SetErrIntCmd(CAN_Type * base, flexcan_int_type_t errType, bool enable)
{
uint32_t temp = (uint32_t)errType;
if (enable)
{
if((errType == FLEXCAN_INT_RX_WARNING) || (errType == FLEXCAN_INT_TX_WARNING))
{
base->MCR = (base->MCR & ~CAN_MCR_WRNEN_MASK) | CAN_MCR_WRNEN(1U);
}
#if FEATURE_CAN_HAS_FD
if (errType == FLEXCAN_INT_ERR)
{
base->CTRL2 = (base->CTRL2 & ~CAN_CTRL2_ERRMSK_FAST_MASK) | CAN_CTRL2_ERRMSK_FAST(1U);
}
#endif
(base->CTRL1) = ((base->CTRL1) | (temp));
}
else
{
if((errType == FLEXCAN_INT_RX_WARNING) || (errType == FLEXCAN_INT_TX_WARNING))
{
base->MCR = (base->MCR & ~CAN_MCR_WRNEN_MASK) | CAN_MCR_WRNEN(0U);
}
#if FEATURE_CAN_HAS_FD
if (errType == FLEXCAN_INT_ERR)
{
base->CTRL2 = (base->CTRL2 & ~CAN_CTRL2_ERRMSK_FAST_MASK) | CAN_CTRL2_ERRMSK_FAST(0U);
}
#endif
(base->CTRL1) = ((base->CTRL1) | ~(temp)); /** here, the '|' should modify to '&' */
}
}
Solved! Go to Solution.
Hello,
Thank you for feedback, yes it's a bug there and will be fixed in the next SDK release.
The fix will be :
void FLEXCAN_SetErrIntCmd(CAN_Type * base, flexcan_int_type_t errType, bool enable)
{
uint32_t temp = (uint32_t)errType;
if (enable)
{
if((errType == FLEXCAN_INT_RX_WARNING) || (errType == FLEXCAN_INT_TX_WARNING))
{
base->MCR = (base->MCR & ~CAN_MCR_WRNEN_MASK) | CAN_MCR_WRNEN(1U);
}
#if FEATURE_CAN_HAS_FD
if (errType == FLEXCAN_INT_ERR)
{
base->CTRL2 = (base->CTRL2 & ~CAN_CTRL2_ERRMSK_FAST_MASK) | CAN_CTRL2_ERRMSK_FAST(1U);
}
#endif
(base->CTRL1) = ((base->CTRL1) | (temp));
}
else
{
(base->CTRL1) = ((base->CTRL1) & ~(temp));
#if FEATURE_CAN_HAS_FD
if (errType == FLEXCAN_INT_ERR)
{
base->CTRL2 = (base->CTRL2 & ~CAN_CTRL2_ERRMSK_FAST_MASK) | CAN_CTRL2_ERRMSK_FAST(0U);
}
#endif
temp = base->CTRL1;
if (((temp & (uint32_t)FLEXCAN_INT_RX_WARNING) == 0U) && ((temp & (uint32_t)FLEXCAN_INT_TX_WARNING) == 0U))
{
/* If WRNEN disabled then both FLEXCAN_INT_RX_WARNING and FLEXCAN_INT_TX_WARNING will be disabled */
base->MCR = (base->MCR & ~CAN_MCR_WRNEN_MASK) | CAN_MCR_WRNEN(0U);
}
}
}
BR,
Alexandru Nan
Hello,
Thank you for feedback, yes it's a bug there and will be fixed in the next SDK release.
The fix will be :
void FLEXCAN_SetErrIntCmd(CAN_Type * base, flexcan_int_type_t errType, bool enable)
{
uint32_t temp = (uint32_t)errType;
if (enable)
{
if((errType == FLEXCAN_INT_RX_WARNING) || (errType == FLEXCAN_INT_TX_WARNING))
{
base->MCR = (base->MCR & ~CAN_MCR_WRNEN_MASK) | CAN_MCR_WRNEN(1U);
}
#if FEATURE_CAN_HAS_FD
if (errType == FLEXCAN_INT_ERR)
{
base->CTRL2 = (base->CTRL2 & ~CAN_CTRL2_ERRMSK_FAST_MASK) | CAN_CTRL2_ERRMSK_FAST(1U);
}
#endif
(base->CTRL1) = ((base->CTRL1) | (temp));
}
else
{
(base->CTRL1) = ((base->CTRL1) & ~(temp));
#if FEATURE_CAN_HAS_FD
if (errType == FLEXCAN_INT_ERR)
{
base->CTRL2 = (base->CTRL2 & ~CAN_CTRL2_ERRMSK_FAST_MASK) | CAN_CTRL2_ERRMSK_FAST(0U);
}
#endif
temp = base->CTRL1;
if (((temp & (uint32_t)FLEXCAN_INT_RX_WARNING) == 0U) && ((temp & (uint32_t)FLEXCAN_INT_TX_WARNING) == 0U))
{
/* If WRNEN disabled then both FLEXCAN_INT_RX_WARNING and FLEXCAN_INT_TX_WARNING will be disabled */
base->MCR = (base->MCR & ~CAN_MCR_WRNEN_MASK) | CAN_MCR_WRNEN(0U);
}
}
}
BR,
Alexandru Nan