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

Events in App_button cause endless loop

I use app_button with simple handle function. When button is pressed the led is on, when released the led is off. Everything works fine, but after some random number button is pressed, the system go in an endless loop and nothing works anymore. The loop is in the timer_timeouts_check() function:

    // Expire all timers within ticks_elapsed and collect ticks_expired.
    while (p_timer != NULL)
    {
        // Do nothing if timer did not expire.
        if (ticks_elapsed < p_timer->ticks_to_expire)
        {
            break;
        }

        // Decrement ticks_elapsed and collect expired ticks.
        ticks_elapsed -= p_timer->ticks_to_expire;
        ticks_expired += p_timer->ticks_to_expire;

        // Move to next timer.
        p_previous_timer = p_timer;
        p_timer = p_timer->next;

        // Execute Task.
        if (p_previous_timer->is_running)
        {
            p_previous_timer->is_running = false;
            timeout_handler_exec(p_previous_timer);
        }
    }

I don't use Softdevice, I am using SDK12.1.0 and have a custom board. What can I do?

Parents
  • I tried reproducing the issue you described, but without luck.

    The main.c file I used looks like this:

    #include <stdbool.h>
    #include <stdint.h>
    #include "boards.h"
    #include "bsp.h"
    #include "app_timer.h"
    #include "nordic_common.h"
    #include "nrf_error.h"
    
    #define APP_TIMER_PRESCALER      0                           /**< Value of the RTC1 PRESCALER register. */
    #define APP_TIMER_OP_QUEUE_SIZE  5                           /**< Size of timer operation queues. */
    
    #define BUTTON_COUNT 1
    
    
    static void bsp_button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        switch (button_action)
        {
            case APP_BUTTON_PUSH:     
                LEDS_ON(BSP_LED_2_MASK);            
                break;
            
            case APP_BUTTON_RELEASE:
                LEDS_OFF(BSP_LED_2_MASK); 
                break;
            
            default:
                break;
        }
    }
    
    static const app_button_cfg_t app_buttons[BUTTON_COUNT] =
            { {BUTTON_1, false, BUTTON_PULL, bsp_button_event_handler}};
            
    void clock_initialization()
    {
        NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    
        while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
        {
            // Do nothing.
        }
    }
    
    int main(void)
    {
        clock_initialization();
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
        
        app_button_init((app_button_cfg_t *)app_buttons, BUTTON_COUNT,
                              APP_TIMER_TICKS(30, APP_TIMER_PRESCALER));
        app_button_enable();
        
        LEDS_CONFIGURE(BSP_LED_2_MASK);
        LEDS_OFF(BSP_LED_2_MASK);
        
        while (true)
        {
            __SEV();
            __WFE();
            __WFE();
        }
    }
    
    /** @} */
    
  • That's a very strange problem. For the DK, all the button and led defines are defined in the board header file pca10040.h. Have you made a custom board header to match your custom board? Make sure the clock source, pins, number of leds and buttons are correct.

    You should also test with a "clean" SDK folder, in case something have been unintentionally modified. Try the new SDK 12.2 here.

Reply
  • That's a very strange problem. For the DK, all the button and led defines are defined in the board header file pca10040.h. Have you made a custom board header to match your custom board? Make sure the clock source, pins, number of leds and buttons are correct.

    You should also test with a "clean" SDK folder, in case something have been unintentionally modified. Try the new SDK 12.2 here.

Children
No Data
Related