always automatic wakeup after entering SYSTEM OFF mode

Hi everyone,

I wanna implement the wakeup from SYSTEM OFF by button. The project is based on the ble_app_uart example. After receiving a command from BLE, nrf will go to SYSTEM OFF , the code is here: 

 case 29:  // SYSTEM OFF mode
                                  nrf_delay_ms(500);
                                  sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                                  sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                                  sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                                  nrf_delay_ms(500);
                                  err_code = bsp_wakeup_button_enable(BUTTON_5);
                                  APP_ERROR_CHECK(err_code);
                                 
                                  nrf_delay_ms(500);
                                  /*err_code = sd_power_system_off();
                                  APP_ERROR_CHECK(err_code);*/
                                  NRF_POWER->SYSTEMOFF = 1;

Every time it goes to OFF mode, it will automatically restart booting after about 1-2 seconds

I used the sd_power_reset_reason_get() and it shows that it's reset from soft reset detected (SREQ)

I read several post about this topic and it looks like sd_power_system_off() doesn't work in debugging mode. I don't know how to check if I'm in debug mode or not, so I used both sd_power_system_off() and NRF_POWER->SYSTEMOFF = 1, same problem, no difference. And I tried both connect our pcb to the nRF52DK and pcb runs separately communicating with nRF52DK through BLE, same problem.

Can anyone help with this? Thanks in advance

  • It's already pullup in bsp.c when I #define BSP_BUTTON_4   BUTTON_5

    And during the 4-5 seconds before it automatic wakeup, the button doesn't work(won't wakeup the chip on press) and after the wakeup, pressing the button will enter the bsp_event

    Following is all the code about this button

    // in pca10040.h
    #define BUTTONS_NUMBER 5   //4------>5
    #define BUTTON_5  NRF_GPIO_PIN_MAP(0,24)
    #define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5 }
    #define BSP_BUTTON_4   BUTTON_5
    
    // in sdk_config.h
    #define GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 5   //4--->5
    
    // in bsp.c
    #ifdef BSP_BUTTON_4
        {BSP_BUTTON_4, false, BUTTON_PULL, bsp_button_event_handler},
        #endif
        
    // in main.c
    // in bsp_event_handler
    case BSP_EVENT_KEY_4:  //BUTTON_5
                sprintf(bletext,"button_pcb detected\r\n");BLE_TEXT(bletext);
                break;
    // in ble_nus_event_handler
    case 29:  // SYSTEM OFF mode
                nrf_delay_ms(500);
                sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                sprintf(bletext,"SYSTEM OFF......\r\n"); BLE_TEXT(bletext);
                nrf_delay_ms(500);
    
                err_code = bsp_wakeup_button_enable(BUTTON_5);
                APP_ERROR_CHECK(err_code);
                                     
                nrf_delay_ms(500);
                /*err_code = sd_power_system_off();
                APP_ERROR_CHECK(err_code);*/
                NRF_POWER->SYSTEMOFF = 1;

  • Still can't get why "bsp_wakeup_button_enable(BUTTON_5);" will cause the auto wakeup, but if I use "configure_gpio_wakeup(BUTTON_5, NRF_GPIO_PIN_SENSE_LOW);", everything's fine.

  • Hi,

    I don't see anything obviously wrong here. Just to sum up:

    • The device always wakes up after 4-5 seconds in system off, but only if you have called bsp_wakeup_button_enable(BUTTON_5); before entering system OFF.
    • And you cannot wake up before this from system of by pressing the button.
    • If wakeup button was not configured, device stays in system off forever.

    Is that correct?

    I noticed another thing from one of your earlier posts. There you wrote that "RESETREAS register always shows reset by soft reset". That is not expected. You should see that it had woken up from system-off mode. Could it be that you are not testing system off mode, but rather emulated system off? Do you have a debugger attached when doing this test? I ask because system off does not work while debugging.

    Other questions: have you tested that this button works as expected when not using it to wake up from system off mode, so that the HW is good? Do you have a WDT running? If yes, have you tested without it?

  • The sum up is right.

    The custom pcb runs separately and the DK is used to receive the BLE data and show it on DC serial port, is that considered as debugging mode? And I tried both sd_power_system_off() and NRF_POWER->SYSTEMOFF = 1, I guess it's not emulated off? I'm not sure about WDT, if it's not set by default, I have no code for that.

    As I mentioned below, if I use

    void configure_gpio_wakeup(uint32_t pin_number, nrf_gpio_pin_sense_t sense)
    
    {
    
    nrf_gpio_pin_latch_clear(pin_number);
    
    nrf_gpio_cfg_watcher(pin_number);
    
    nrf_gpio_cfg_sense_set(pin_number, sense);
    
    }
    
    configure_gpio_wakeup(BUTTON_5, NRF_GPIO_PIN_SENSE_LOW);
    everything is fine, no auto reset and wake up on button, RESETREAS shows wakeup on GPIO DETECT

  • Hi,

    Yuank said:
    sd_power_system_off() and NRF_POWER->SYSTEMOFF = 1, I guess it's not emulated off?

    As long as you are not debugging, then both these methods will enter system OFF mode.

    Yuank said:
    I'm not sure about WDT, if it's not set by default, I have no code for that.

    Then you are not using the WDT.

    Yuank said:
    everything is fine, no auto reset and wake up on button, RESETREAS shows wakeup on GPIO DETECT

    Ah, I see. I did not think to ask what you did in configure_gpio_wakeup(), but that is interesting. The call to nrf_gpio_cfg_sense_set() is also done by bsp_wakeup_button_enable(), but this does not clear the latch state of that pin. If for some reason there is a latched interrupt this will cause problems without it. I cannot see why this is, though.

Related