flexcan bug in SDK version RTM2.0.0 and BETA_2.9.0

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

flexcan bug in SDK version RTM2.0.0 and BETA_2.9.0

Jump to solution
1,286 Views
cheney
Contributor III

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 '&' */
}
}

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,138 Views
alexandrunan
NXP Employee
NXP Employee

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

View solution in original post

0 Kudos
Reply
1 Reply
1,139 Views
alexandrunan
NXP Employee
NXP Employee

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

0 Kudos
Reply