Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[NRF SDK 17] Trooble with app_timer when migrate from sdk 16 to 17

Hi,

I have an issue when I migrate my app from nrf52 sdk v16 to v17.

I have setup an app with an uart communication, an app timer and a watchdog. All off these (uart and timer) have an irq priority set to 6.

All works fine in sdk 16 but when I try to migrate it to sdk 17, the timer and uart doesn't create interrupt (so don't work) but after the watchdog rebooting the app after 30s, all works.

But each time I reboot the board / debug the app, I need to wait the watchdog reboot.

What can cause this issue ?

// Application main function.
int main(void)
{
    // Initialize logs.
    log_init();

    // Initialize timer and power manager.
    app_timer_init();
    nrf_drv_clock_init();
    nrf_drv_clock_lfclk_request(NULL);
    
    // Initialize the power manager.
    nrf_pwr_mgmt_init();

    // Initialize the watchdog
    watchdog_init();

    // Initialize uart and serial.
    uart_init();

    // Start timer
    uint32_t res = app_timer_create(&m_process_timer, APP_TIMER_MODE_REPEATED, timer_process);
    res = app_timer_start(m_process_timer, APP_TIMER_TICKS(100), NULL);

    // Enter main loop.
    for (;;)
    {
      (void)watchdog_feed();
      (void)idle_state_handle();
    }
}

#define UART_TX_BUF_SIZE  256   
#define UART_RX_BUF_SIZE  256 

// The uart event handler (invoke when a byte is receive)
void uart_event_handle(app_uart_evt_t * p_event)
{ 
  static uint8_t byte_receive = 0;

  switch (p_event->evt_type)
  {
    case APP_UART_DATA_READY:
    {
      UNUSED_VARIABLE(app_uart_get(&byte_receive));
      serial_receive_byte(byte_receive);
      break;
    }
    case APP_UART_COMMUNICATION_ERROR:
      NRF_LOG_INFO("Uart : Communication error");
      APP_ERROR_HANDLER(p_event->data.error_communication);
      break;
    case APP_UART_FIFO_ERROR:
      NRF_LOG_INFO("Uart : Fifo error");
      APP_ERROR_HANDLER(p_event->data.error_code);
      break;
    default:
      break;
  }
}

// Initialize the uart communication
void uart_init(void)
{
    uint32_t err_code;

    app_uart_comm_params_t const comm_params =
    {
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        .rts_pin_no   = RTS_PIN_NUMBER,
        .cts_pin_no   = CTS_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
        .baud_rate    = NRF_UART_BAUDRATE_115200
    };

    APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_event_handle, APP_IRQ_PRIORITY_LOW, err_code);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_INFO("Uart initialized");
}

// The watchdog timeout in seconds
#define WATCHDOG_TIMEOUT_S 30

// Initialize the watch dog
void watchdog_init(void)
{
  NRF_WDT->CONFIG = (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos) | ( WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos);
  // Set the watch dog timeout
  NRF_WDT->CRV = WATCHDOG_TIMEOUT_S*32768;             
  NRF_WDT->RREN |= WDT_RREN_RR0_Msk;

  // Enable WDT interrupt:
  NVIC_EnableIRQ(WDT_IRQn);
  NRF_WDT->INTENSET = WDT_INTENSET_TIMEOUT_Msk;	

  NRF_WDT->TASKS_START = 1;
}

// Feed the watchdog
void watchdog_feed(void)
{
  NRF_WDT->RR[0] = WDT_RR_RR_Reload;
}

Regards

Board used: nrf52840 development board

Sdk used : nrf_sdk_7.0.2

Parents Reply Children
  • Hi,

    I just saw that I'm not using the app_timer but the app_timer_mesh.c because I'm based on the sdk coexist example.

    The problem disappear when I remove the watch dog so I think its this that cause the issue.

    Is my watchdog specific code correct for sdk 17 and mesh sdk 5.0 ?

    Regards

  • Hi, I have tried to update my watchdog code but it didn't work anymore.

    My watchdog init without error but never be trigger even if i never feed it. (I never enter in the event handler function and the board never reboot)

    #include "watchdog.h"
    
    #include "nrfx_wdt.h"
    #include "boards.h"
    #include "nrf_log.h"
    
    // The watchdog timeout in seconds
    #define WATCHDOG_TIMEOUT_S 30
    // The watchdog channel
    static nrfx_wdt_channel_id* wtd_channel;
    
    // Watchdog event handler
    void watdog_evt_handler(void)
    {
      NRF_LOG_INFO("WDT Evt");
    }
    
    // Initialize the watch dog
    void watchdog_init(void)
    {
      nrfx_wdt_config_t wdt_config = NRFX_WDT_DEAFULT_CONFIG;
      uint32_t err = nrfx_wdt_init(&wdt_config, &watdog_evt_handler);  
      uint32_t err2 =nrfx_wdt_channel_alloc(wtd_channel);
      nrfx_wdt_enable();
      NRF_LOG_INFO("Watchdog init %x - %x", err, err2);
    }
    
    // Feed the watchdog
    void watchdog_feed(void)
    {
      nrfx_wdt_channel_feed(*wtd_channel);
    }

    Regards

  • Hi,

    Please try to remove the ampersand reference from the event handler in the init function:

    uint32_t err = nrfx_wdt_init(&wdt_config, watdog_evt_handler);  

    Also, make sure that NRFX_WDT_CONFIG_NO_IRQ is not set in your sdk_config.h file.

    Have you verified that the error codes returned from nrfx_wdt_init() and nrfx_wdt_channel_alloc() is NRF_SUCCESS/zero?

    Best regards,
    Jørgen

  • Hi,

    I have remove the ampersand reference but the same issue appear. 

    When I don't use WDT, all works fine but when I use it (only init it, not feed it => to try if its works if its never feed) my timer never create an interrupt and the WDT never reboot the board or call the event function.

    All of my interrupt (WDT, timer and uart) have their irq priority set to 6.

    Some of my WDT config in my sdk config :

    // <1=> Run in SLEEP, Pause in HALT
    // <8=> Pause in SLEEP, Run in HALT
    // <9=> Run in SLEEP and HALT
    // <0=> Pause in SLEEP and HALT
    #ifndef NRFX_WDT_CONFIG_BEHAVIOUR
    #define NRFX_WDT_CONFIG_BEHAVIOUR 1
    #endif
    
    
    // <1=> Run in SLEEP, Pause in HALT
    // <8=> Pause in SLEEP, Run in HALT
    // <9=> Run in SLEEP and HALT
    // <0=> Pause in SLEEP and HALT
    #ifndef WDT_CONFIG_BEHAVIOUR
    #define WDT_CONFIG_BEHAVIOUR 1
    #endif
    
    
    // <0=> Include WDT IRQ handling
    // <1=> Remove WDT IRQ handling
    #ifndef NRFX_WDT_CONFIG_NO_IRQ
    #define NRFX_WDT_CONFIG_NO_IRQ 0
    #endif
    

    Regards

  • I see that you have mixed configs in the posted snippet (NRFX configs and legacy nrf_drv configs). If you have the legacy configs defined (regardless of whether they are set to 1 or 0), the NRFX configs will be overwritten in apply_old_config.h.

    Can you post the full project for us to reproduce and debug this issue?

Related