This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52832 app_timer bug?

SDK version :15.2

question; when i use app_timer , i got interrupt which is not i wanted.

i creat and start  timer :

app_timer_create(&m_timer,APP_TIMER_MODE_REPEATED,sec_timer_hook);:  

m_sec_context = 0xa5;
app_timer_start(m_timer,APP_TIMER_TICKS(20),&m_sec_context);  

and hook like:

void sec_timer_hook(void *p_context)
{
if(*(uint32_t*)p_context != 0xa5)
{
     led_toggle();
}
}

many times led toggled, is that means some interrupt is not i wanted ,is that a app timer bug?

Parents
  • Hi,

    Please post a minimal working example of this issue. From what you posted, it is not clear how m_sec_context is declared. What data type is m_sec_context? Where is it declared? Is it static?

    My guess is that m_sec_context was declared in a function (i.e. not in main()), which means that it lives on the stack. When that function returns, the variable is gone, and the memory address to which &m_sec_context points is no longer valid. Then, when you check the memory to which p_context points, it is most likely garbage. To check if this is the case, you can declare m_sec_context as static and see if the problem goes away.

    I doubt there is an issue with app_timer here.

  • nonono,uint32_t m_sec_context ;m_sec_context is globle   variable 

Reply Children
  • nrf52832 run like : keeping scanning,  in main function ,start timer.when timer is up. send scanning data though UART , i guess maybe scanning process affect this timer? i can understand maybe timer delay, but   that interrupt  clearly is not belong to that timer 

  • If you look inside app_timer.h, you can see that the input of APP_TIMER_TICKS(..) is milliseconds. 

    /**@brief Convert milliseconds to timer ticks.
     *
     * This macro uses 64-bit integer arithmetic, but as long as the macro parameters are
     *       constants (i.e. defines), the computation will be done by the preprocessor.
     *
     * @param[in]  MS          Milliseconds.
     *
     * @return     Number of timer ticks.
     */
    #ifndef FREERTOS
    #define APP_TIMER_TICKS(MS)                                \
                ((uint32_t)ROUNDED_DIV(                        \
                (MS) * (uint64_t)APP_TIMER_CLOCK_FREQ,         \
                1000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1)))
    .
    .
    .

    You have input 20, which will make the function sec_timer_hook() run every 0,02 second, which is quite often. Is this your intention?

    Best regards,

    Simon

Related