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

Related