Timer not initialized after waking up from sleep mode - NRF52833

Hi All,

         I have implemented sleep mode in the firmware. I am using NRF52833 in my project. When the device is in idle state it goes in sleep mode. I am able to wakeup my device through GPIO interrupt. After waking up I have observed that the device is advertising but the timers are not getting initialized again. I have one timer under which I run certain tasks. This timer runs at an interval of 10 seconds. How can we reinitialize the timer after waking up?? I am also using FreeRtos in my project. Please find the attached code below:-

#define AQ_USER_BUTTON          NRF_GPIO_PIN_MAP(0,4)


void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
//bool erase_bonds;
   switch(pin)
   {
      case AQ_USER_BUTTON:
              NRF_LOG_INFO("ADVERTISING START\r\n");
              advertising_start(false);
            break;
   }

}

 void gpio_init(void)
{
    ret_code_t err_code;

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(AQ_USER_BUTTON, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(AQ_USER_BUTTON, true);

}


static void sleep_mode_enter(void)
	{
	  ret_code_t err_code;
	  sleep = 1;
	  NRF_LOG_INFO("SLEEP MODE ENTER\r\n");
	  err_code = bsp_indication_set(BSP_INDICATE_IDLE);
	  APP_ERROR_CHECK(err_code);

	  // Prepare wakeup buttons.
	  err_code = bsp_btn_ble_sleep_mode_prepare();
	  APP_ERROR_CHECK(err_code);

	  // Go to system-off mode (this function will not return; wakeup will cause a reset).
	  err_code = sd_power_system_off();
	  // APP_ERROR_CHECK(err_code);
}

static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
		uint32_t err_code;

		switch (ble_adv_evt) {
		case BLE_ADV_EVT_FAST:
		NRF_LOG_INFO("Fast advertising.");
		err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
		APP_ERROR_CHECK(err_code);
		break;

		case BLE_ADV_EVT_IDLE:
		sleep_mode_enter();
		break;

		default:
		break;
}
}

The timer configuration is as below:-

err_rc_t init_borrower_task(void)
{
    err_rc_t rc = RESULT_SUCCESS;
    do {
        /* Start the two tasks as described in the comments at the top of this
        file. */
        borrower_task_handle = xTaskCreateStatic(
                                 borrower_task,       /* Function that implements the task. */
                                 "BORROWER",          /* Text name for the task. */
                                 BORROWER_TASK_STACK_SIZE,      /* Number of indexes in the borrower_stack array. */
                                 ( void * ) 1,    /* Parameter passed into the task. */
                                 BORROWER_TASK_PRIORITY,/* Priority at which the task is created. */
                                 borrower_stack,          /* Array to use as the task's stack. */
                                 &task_borrower_tcb );  /* Variable to hold the task's data structure. */

        if(borrower_task_handle == NULL) {
            rc = RESULT_ERROR_FAILURE;
            break;
        }

        /* Create a queue */
        borrower_queue_handle = xQueueCreateStatic( QUEUE_LENGTH,
                              ITEM_SIZE,
                              borrower_queue_storage_area,
                              &xStaticQueue );

        if(borrower_queue_handle == NULL) {
            rc = RESULT_ERROR_FAILURE;
            break;
        }

        max17211_handle = xTimerCreateStatic("Max17211Timer",
                               10000,
                               pdTRUE,
                               ( void * ) 0,
                               max17211_timer_callback,
                               &max17211_timer);

        if( max17211_handle == NULL ) {
            /* The timer was not created */
            rc = RESULT_ERROR_FAILURE;
            break;
        }

    } while(0);

    return rc;
}



void max17211_timer_callback( TimerHandle_t xTimer )
{
    	
    nrf_drv_wdt_feed();
    
    get_max17201_data();
    read_bq2429_data();
    NRF_LOG_INFO("*******************************************\r\n");
    borrower_task_queue_event(BORROWER_TASK_EVT_NOTIF_EN);

}

I need some help on this. 

Thanks & Regards,

Snehal.

Parents
  • Hi Snehal,

    I am using NRF52833 in my project. When the device is in idle state it goes in sleep mode

    I am assuming that you are talking about the idle sleep (and now system off sleep) and also assuming that you are using tickless idle feature in the freertos to sleep.

    The timer is created only once at startup. Unless you are waking up from deep sleep (System OFF sleep) you do not need to recreate the timer. The timer_handle is still valid after waking up from idle sleep.

    Since you have created a one-shot timer (uxAutoReload = 0), you just start the timer again if you want to start the timer again using the same timerHandle you got from xTimerCreateStatic into xTimerStart.

Reply
  • Hi Snehal,

    I am using NRF52833 in my project. When the device is in idle state it goes in sleep mode

    I am assuming that you are talking about the idle sleep (and now system off sleep) and also assuming that you are using tickless idle feature in the freertos to sleep.

    The timer is created only once at startup. Unless you are waking up from deep sleep (System OFF sleep) you do not need to recreate the timer. The timer_handle is still valid after waking up from idle sleep.

    Since you have created a one-shot timer (uxAutoReload = 0), you just start the timer again if you want to start the timer again using the same timerHandle you got from xTimerCreateStatic into xTimerStart.

Children
Related