AnsweredAssumed Answered

Bug in UART1_GetITStatus() of peripheral library 2.0.0

Question asked by saviane.giorgio on Jul 11, 2012
According to what is documented on declaration of UART1_IT_TypeDef in file stm8s_uart1.h
it seems the function UART1_GetITStatus() calculate a wrong mask for the IT flags.

The UART1_IT_TypeDef says the lables were declared as ZYX, but the function uses Y and X swapped for their original meaning.

Changing the function as below makes things working:

ITStatus UART1_GetITStatus(UART1_IT_TypeDef UART1_IT)
{
    uint8_t itposSR = 0;
    uint8_t itposCR2 = 0;

    /* Check parameters */
    assert_param(IS_UART1_GET_IT_OK(UART1_IT));

    /* Get the UART1 IT index mainly for CR2 */
    itposCR2 = (uint8_t)((uint8_t)1 << (uint8_t)(UART1_IT & 0x0F));
    /* Get the UART1 IT index mainly for SR */
    itposSR =  (uint8_t)((uint8_t)1 << (uint8_t)((uint8_t)(UART1_IT & 0xF0) >> (uint8_t)4));


    /* Check the status of the specified UART1 pending bit*/
    if (UART1_IT == UART1_IT_PE)
    {
        /* Check the status of the specified UART1 interrupt*/

        if (((UART1->SR & itposSR) != (uint8_t)0x00) && ((uint8_t)UART1->CR1 & itposCR2))
        {
            /* Interrupt occurred*/
            return SET;
        }
        else
        {
            /* Interrupt not occurred*/
            return RESET;
        }
    }

    else if (UART1_IT == UART1_IT_LBDF)
    {
        /* Check the status of the specified UART1 interrupt*/
        if (((UART1->CR4 & itposSR) != (uint8_t)0x00) && ((uint8_t)UART1->CR4 & itposCR2))
        {
            /* Interrupt occurred*/
            return SET;
        }
        else
        {
            /* Interrupt not occurred*/
            return RESET;
        }
    }
    else
    {
        /* Check the status of the specified UART1 interrupt*/
        if (((UART1->SR & itposSR) != (uint8_t)0x00) && ((uint8_t)UART1->CR2 & itposCR2))
        {
            /* Interrupt occurred*/
            return SET;
        }
        else
        {
            /* Interrupt not occurred*/
            return RESET;
        }
    }

    /* Return the UART1_IT status*/
    return  RESET;
}

Functions for UART 2 & 3 could be affect by the bug too (I didn't check).

Bye

Giorgio

Outcomes