NordicSemiconductor / Nordic-Thingy52-FW

Nordic Thingy:52 software development kit. This kit is designed to assist users in developing their own custom firmware for Thingy. Please see http://www.nordicsemi.com/thingy for the latest news and software releases.
Other
210 stars 133 forks source link

SOLVED: Thingy fails to enter sleep on BLE adv timeout #16

Closed binaryfields closed 6 years ago

binaryfields commented 6 years ago

Upon BLE adv timeout, thingy_ble_evt_handler in main.c calls sleep_mode_enter function. This function in turn will call:

err_code = sd_power_system_off();

The problem is that this will return without putting device into sleep. This is without debugger attached to the device.

Repro steps:

Expected:

Actual:

binaryfields commented 6 years ago

I changed sleep_mode-enter function to have a delay right after call to sd_power_system_off:

err_code = sd_power_system_off(); nrf_delay_ms(5000); // <--- added

This in turn will cause a pause between reset that happens immediately after call to sd_power_system_off and in turn LED blinking will stop during that period. After the delay, the device resets and LED blinking along with adv starts again.

binaryfields commented 6 years ago

Also please note this behavior is observed in release mode (DEBUG flag in CFLAGS not set).

binaryfields commented 6 years ago

I also commented out low power accelerator configuration to make sure its not interfering with sleep.

In sleep_mode_enter:

// err_code = m_motion_sleep_prepare(true); ... // nrf_gpio_cfg_sense_input(LIS_INT1, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);

binaryfields commented 6 years ago

Apparently the good old "did you try to power it off and on again" may be the culprit here. I think the issue I was running into was that upon disconnecting debugger, you have to power off and on the device. Resetting the device is not enough.

koffes commented 6 years ago

Nice to see that you found a solution. If you want to know the Thingy debug status, try checking the following flag: DWT->CYCCNT != 0 (Active debug session). There are seven different methods of resetting the nRF52832, and only some resets the device from debug. Consult the nRF52832 Product Specification chapter 18.8 for more information.