I have been trying to implement a way to wake the system up after doing sys_poweroff() but no matter what nothing seems to work. I already tried many examples and none of them work on thingy52. On the other hand, every example worked on nrf52dk (that has the same chip as thingy52). I aleready compared devicetrees and couln't make it work. The objective is to wake up when a shaking movement is detected but now I was just testing with the press of sw0 since the shaking wasn't waking up the system. Below is my current code based on the sample code of nordic for sys_poweroff() (that does work on the nrf52dk but not on thingy52):
#include "bt_service.h"
#include <inttypes.h>
#include <stdio.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
#include <zephyr/pm/device.h>
#include <zephyr/sys/poweroff.h>
#include <zephyr/sys/util.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
LOG_MODULE_REGISTER(STATE_MACHINE, LOG_LEVEL_INF);
int main(void)
{
int rc;
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
init_bt_service();
init_advertise();
k_sleep(K_SECONDS(10));
if (!device_is_ready(cons)) {
LOG_INF("%s: device not ready.\n", cons->name);
return 0;
}
LOG_INF("\n%s system off demo\n", CONFIG_BOARD);
/* configure sw0 as input, interrupt as level active to allow wake-up */
rc = gpio_pin_configure_dt(&sw0, GPIO_INPUT);
if (rc < 0) {
LOG_INF("Could not configure sw0 GPIO (%d)\n", rc);
return 0;
}
rc = gpio_pin_interrupt_configure_dt(&sw0, GPIO_INT_LEVEL_ACTIVE);
if (rc < 0) {
LOG_INF("Could not configure sw0 GPIO interrupt (%d)\n", rc);
return 0;
}
LOG_INF("Entering system off; press sw0 to restart\n");
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
if (rc < 0) {
LOG_INF("Could not suspend console (%d)\n", rc);
return 0;
}
sys_poweroff();
return 0;
}
In bt_service.c I only have the functions to initialize bluetooth and the advertisement so I can see when the device is reseted without the console. Also in my proj.conf I have this
CONFIG_PM_DEVICE=y
CONFIG_GPIO=y
CONFIG_CRC=y
CONFIG_POWEROFF=y
CONFIG_LOG=y
# Bluetooth LE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Test"