I am getting an error of "undefined reference to `pm_state_force" .
Also, the output files, config file is not showing the command : CONFIG_PM=y
prj.conf file has :
I am getting an error of "undefined reference to `pm_state_force" .
Also, the output files, config file is not showing the command : CONFIG_PM=y
prj.conf file has :
Hello,
Can you try these configs
CONFIG_PM_DEVICE=y
CONFIG_GPIO=y
CONFIG_CRC=y
CONFIG_POWEROFF=y
CONFIG_HWINFO=y
in your pr.con file?
Hello Kazi,
I tried these configs. But Im getting the same error. Also, some reference to this case showed me that the function -pm_state_force(0, &(struct pm_state_info){.state = PM_STATE_SOFT_OFF,.substate_id = 0}); is not supported in versions after v2.5.0. If so, then how must I achieve a normal sleep and a deep sleep condition in nrf52833 ?
Hello,
''I tried these configs. But Im getting the same error. Also, some reference to this case showed me that the function -pm_state_force(0, &(struct pm_state_info){.state = PM_STATE_SOFT_OFF,.substate_id = 0}); You are correct. pm_state_force() fucntion and CONFIG_PM are not supported on latest NCS version after v2.5.0. The error "undefined reference to pm_state_force
" and the inability to set CONFIG_PM=y
are due to changes in Zephyr and NCS.
For system On idle, you do not need to call any special function for the CPU to enter sleep; simply using k_msleep()
is sufficient for normal low-power operation in System ON mode. The system will wake up on any interrupt (timer, GPIO, etc.)
For example:
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/printk.h>
#define SLEEP_TIME_MS 1
#define SW0_NODE DT_ALIAS(sw0)
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET(SW0_NODE, gpios);
static struct gpio_callback button_cb_data;
void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
printk("Button pressed! System woke up from sleep.\n");
}
void main(void)
{
int ret;
if (!gpio_is_ready_dt(&button)) {
return;
}
ret = gpio_pin_configure_dt(&button, GPIO_INPUT | GPIO_PULL_UP);
if (ret < 0) {
return;
}
ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE);
if (ret < 0) {
return;
}
/*/*These lines are used to register a callback function (button_pressed) that will be called
when a GPIO interrupt occurs on the specified pin. This means that when the button is
pressed (or released, depending on your interrupt configuration),
the button_pressed function will be executed*/
gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));
gpio_add_callback(button.port, &button_cb_data);
printk("System will sleep. Press the button to wake up.\n");
while (1) {
k_msleep(1000); // System will enter idle if nothing else is running
}
}
For system off, you need to use sys_poweroff()
function to enter System OFF mode (deepest sleep).
sys_poweroff()
, configure your wakeup sources (e.g., set up a GPIO pin with sense for wakeup).// Configure wakeup pin (example for a button)
nrf_gpio_cfg_input(WAKEUP_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_sense_set(WAKEUP_PIN, NRF_GPIO_PIN_SENSE_LOW);
// Enter System OFF
sys_poweroff();
Hello,
Thankyou very much, I also wanted to know about how to use RTC for sys_poweroff(); , as our custom board does not have a gpio switch for interrupt. We will have to move forward with RTC generated wakeup.
So, I went through the system_off sample code, where i tried to use the function :