AnsweredAssumed Answered

How to properly stop and restart a Timer using HAL?

Question asked by Lukasz Przenioslo on Mar 2, 2017
Latest reply on Mar 2, 2017 by Lukasz Przenioslo

Hello there,

I am having problems with Timers 6 and 7 configuration in STM32F0 device. What I am trying to do is to implement a way to start a timer, restart it (make it count from 0 without stopping) and stop it. Each of those actions should not trigger the update event. As for a test, I have setup my timer prescaller and period to 0xFFFF both. this should give me about 90 s time before the interrupt would trigger. I am resetting and disabling the timer in the meanwhile and even though I am getting an interrupt. What Am I doing wrong? Those are my restart and stop timer routines:

 

/*
 * @brief    Resets the rx timeout timer for specified generic struct
 * @param    uart: generic struct pointer
 * @return    HAL_OK if all ok.
 */
HAL_StatusTypeDef mbg_ResetRxTimer(mbgUart_t* uart)
{
    assert_param(uart);
    assert_param(uart->rxQ.toutTim);
    HAL_StatusTypeDef retVal = HAL_OK;

 

    retVal += HAL_TIM_Base_Stop_IT(uart->rxQ.toutTim); // turn off
    uart->rxQ.toutTim->Instance->CNT = 0; // reset counter
    retVal += HAL_TIM_Base_Start_IT(uart->rxQ.toutTim); // turn on

 

    return retVal;
}

 

/*
 * @brief    Turns off the rx timeout timer for specified generic struct
 * @param    uart: generic struct pointer
 * @return    HAL_OK if all ok.
 */
HAL_StatusTypeDef mbg_DisableRxTimer(mbgUart_t* uart)
{
    assert_param(uart);
    assert_param(uart->rxQ.toutTim);
    HAL_StatusTypeDef retVal = HAL_OK;

 

    retVal += HAL_TIM_Base_Stop_IT(uart->rxQ.toutTim); // turn off
    uart->rxQ.toutTim->Instance->CNT = 0; // reset counter

 

    return retVal;
}

I would appreciate all help

Outcomes