Pin configured for wakeup from system off sleep misbehaving.

I am working on nrf52832 based custom board and I want system off sleep and wakeup using GPIO pin state change. For that I have configured MCU standby timeout in sdk_config.h.

There is a switch in the hardware that can be pressed to wake up the system from sleep. But the switch has alternate function when the system is awake. So I have configured the pin as wakeup just before the system is going to sleep. Initially this works, but sometime the system skips this configuration and directly goes to sleep. 

So I have modified the hardware and assigned two GPIO pins to the switch, one for normal switch mode and other for wakeup switch. Initially I have configured one of the pins for wakeup using "nrf_gpio_cfg_sense_input()" function. But after that the other pin is not working properly, that means when I configured one pin as wakeup pin the other pin won't working properly. Another issue is while system is awake any transition in the wakeup pin halts the code execution. 

Could anyone help me to solve this issue?

Thanks

Sachin

Parents
  • Hello,

    I have looked at the code and compared with the system off example from nRF5 SDK. 

    static void idle_state_handle(void)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            nrf_pwr_mgmt_run();
        }
    }

    You need to call this idle_state_handle() function in loop in main function like following way:

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

    I have not seen any handler for shutdown preparation in your code snippet. 

    This is from pwr_mgmt example of nRF5 SDK where nrf_pwr_mgmt_evt_t has 4 event types to wake up form sleep, staying in system off mode, preparation to enter DFU mode and to chip reset.

    bool shutdown_handler(nrf_pwr_mgmt_evt_t event)
    {
        uint32_t err_code;
    
        if (m_is_ready == false)
        {
            m_sysoff_started = true;
            return false;
        }
    
        switch (event)
        {
            case NRF_PWR_MGMT_EVT_PREPARE_SYSOFF:
                NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_SYSOFF");
                err_code = bsp_buttons_disable();
                APP_ERROR_CHECK(err_code);
                break;
    
            case NRF_PWR_MGMT_EVT_PREPARE_WAKEUP:
                NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_WAKEUP");
                err_code = bsp_buttons_disable();
                // Suppress NRF_ERROR_NOT_SUPPORTED return code.
                UNUSED_VARIABLE(err_code);
    
                err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
                // Suppress NRF_ERROR_NOT_SUPPORTED return code.
                UNUSED_VARIABLE(err_code);
    
                err_code = bsp_nfc_sleep_mode_prepare();
                // Suppress NRF_ERROR_NOT_SUPPORTED return code.
                UNUSED_VARIABLE(err_code);
                break;
    
            case NRF_PWR_MGMT_EVT_PREPARE_DFU:
                NRF_LOG_ERROR("Entering DFU is not supported by this example.");
                APP_ERROR_HANDLER(NRF_ERROR_API_NOT_IMPLEMENTED);
                break;
    
            case NRF_PWR_MGMT_EVT_PREPARE_RESET:
                NRF_LOG_INFO("NRF_PWR_MGMT_EVT_PREPARE_RESET");
                break;
        }
    
        err_code = app_timer_stop_all();
        APP_ERROR_CHECK(err_code);
    
        return true;
    }
    

  • Hi Kazi,

    Can you please explain in detail, what is the purpose calling idle_state_handle() function in while loop?

    I am not using shutdown_handler in my code, instead I am checking value of the variable 'm_standby_counter' in the loop and  if it's near 'NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S', the wake up pin is configured. 

    But now I understand that it is better to use shutdown handler. Can you please explain how to setup the shutdown handler?

    I have one another question. Assume that one GPIO pin is configured for wake up, initially in the code. That is, that pin is always configured for wake up from sleep and it has no other function while system is awake. So my question is, while system is awake, a transition (high to low or low to high) is occurred in that pin. Does it affect the normal code running?

  • Hello,

    You have to call the idle_state_handle() function inside main function what I showed in my previous reply. 

    I have one another question. Assume that one GPIO pin is configured for wake up, initially in the code. That is, that pin is always configured for wake up from sleep and it has no other function while system is awake. So my question is, while system is awake, a transition (high to low or low to high) is occurred in that pin. Does it affect the normal code running?

    I have asked my team and will answer this later.

    Thanks.

    BR

    Kazi 

Reply
  • Hello,

    You have to call the idle_state_handle() function inside main function what I showed in my previous reply. 

    I have one another question. Assume that one GPIO pin is configured for wake up, initially in the code. That is, that pin is always configured for wake up from sleep and it has no other function while system is awake. So my question is, while system is awake, a transition (high to low or low to high) is occurred in that pin. Does it affect the normal code running?

    I have asked my team and will answer this later.

    Thanks.

    BR

    Kazi 

Children
Related