This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Thingy52 sleep_mode_enter() Runs Bootloader Instead of Restarting Program

Hi, when my program calls sleep_mode_enter(), it enters system off (deep sleep) as expected. However, when I press the button on the Thingy52 to wake up, the bootloader starts running instead of my program restarting.

Below is my sleep_mode_enter() function. Any advice on how to get my program to restart instead of running the bootloader upon a button press would be appreciated. Thanks in advance.

/**@brief Function for putting Thingy into sleep mode.
 *
 * @note This function will not return.
 */
static void sleep_mode_enter(void)
{
    uint32_t err_code;
    drv_ext_light_rgb_intensity_t color;

    NRF_LOG_INFO("Entering sleep mode \r\n");

    err_code = support_func_configure_io_shutdown();
    APP_ERROR_CHECK(err_code);

    // Enable wake on button press.
    nrf_gpio_cfg_sense_input(BUTTON, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);

    color.r = 128;
    color.g = 12
    color.b = conf_ui.data.mode_const.b;

    err_code = drv_ext_light_rgb_intensity_set(DRV_EXT_RGB_LED_LIGHTWELL, &color);

    // nrf_gpio_cfg_input(MIC_DOUT, NRF_GPIO_PIN_NOPULL);
    // err_code = drv_ext_gpio_pin_set(SX_MIC_PWR_CTRL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_FLUSH();
    nrf_delay_ms(5);
    // Go to system-off (sd_power_system_off() will not return; wakeup will cause a reset). When debugging, this function may return and code execution will continue.
    err_code = sd_power_system_off();
    NRF_LOG_WARNING("sd_power_system_off() returned. -Probably due to debugger being used. Instructions will still run. \r\n");
    NRF_LOG_FLUSH();

    #ifdef DEBUG
        if(!support_func_sys_halt_debug_enabled())
        {
            APP_ERROR_CHECK(err_code); // If not in debug mode, return the error and the system will reboot.
        }
        else
        {
            NRF_LOG_WARNING("Exec stopped, busy wait \r\n");
            NRF_LOG_FLUSH();

            while(true) // Only reachable when entering emulated system off.
            {
                // Infinte loop to ensure that code stops in debug mode.
            }
        }
    #else
        APP_ERROR_CHECK(err_code);
    #endif
}

Parents
  • Hi,

    When you have a bootloader then the bootloader will always start on reset. Normal behavior of the bootloader is to start the application immediately. The exception to this is if DFU mode is requested. In that case it will enter DFU mode. It will also enter DFU mode if no valid application is found. Can you  confirm that it enters DFU mode?

    In order to give more advice on how to move forward on this one, I need to know the versions of bootloader, firmware, etc. that you are using.

    Regards,
    Terje

  • I see, I figured it out. Thank you very much for your help!

    The problem was that the button I was using to toggle wakeup is the same button that is used to request DFU mode. Perhaps it would be good to add a debouncing of the button in the bootloader to sense between wakeup and DFU request.

Reply Children
No Data
Related