pm_system_suspend() is flagged as warning: implicit declaration of function 'pm_system_suspend' [-Wimplicit-function-declaration] even when CONFIG_PM_DEVICE_SYSTEM_MANAGED = y. https://docs.zephyrproject.org/latest/services/pm/device.html

  • Hi Edgar

    Which version of NCS are you using? 

    Regards

    Runar

  • Thanks. As far as I know the 52 series only support the power state system on and system off as mention hereRegarding pm_system_suspend() that is not a function you should call, but it is called by the kernel to inform listeners if enabled by CONFIG_PM. You can read more about the Zephyr power management system here.

    Regards

    Runar

  • I have abandoned pm_system_suspend() and switched to pm_policy_next_state. Below is my code for this including PM notifiers:

    // Custom power management policy
    const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
    {
        static const struct pm_state_info suspend_state = {
            .state = PM_STATE_SUSPEND_TO_RAM,
            .substate_id = 0,
            .min_residency_us = 1000,
            .exit_latency_us = 500,
        };

        if (!is_active_mode && !advertising_active && !ble_active) {
            return &suspend_state;
        }

        return NULL;
    }

    static void on_pm_entry(enum pm_state state)
    {
        if (state == PM_STATE_SUSPEND_TO_RAM) {
            DEBUG_PRINT("Entering suspend state...\n");
        }
    }

    static void on_pm_exit(enum pm_state state)
    {
        if (state == PM_STATE_SUSPEND_TO_RAM) {
            resume_peripherals();
            DEBUG_PRINT("Exiting suspend state...\n");
        }
    }

    static struct pm_notifier pm_cb = {
        .state_entry = on_pm_entry,
        .state_exit  = on_pm_exit,
    };
    I have this function for debugging:
    void show_next_pm_state(void)
    {
        const struct pm_state_info *info = pm_policy_next_state(0, INT32_MAX);
        if (info) {
            printk("System would enter sleep state: %d\n", info->state);
        } else {
            printk("System would stay active.\n");
        }
    }


    Then in my main(), I have this:
    int main(void) {
    // ... some init codes...
        pm_notifier_register(&pm_cb);
    // ... more codes ..
        /* Main loop - sleep forever until interrupted */
        while (1) {
        //  k_sleep(K_FOREVER);  // Sleep indefinitely
            show_next_pm_state();
            k_sleep(K_SECONDS(60));  // Sleep for 60 second (temporary for testing)
        }
        return 0;
    }
    I have SPI, UART, I2C, ADC, PWM, and Bluetooth suspended or disabled, but my system just wont go to sleep. I would appreciate very much if you or anyone can tell me what could be wrong?

    Regards,
  • Hi runsive,

    I would appreciate feed back from you regarding my recent message.

    Regards,

Related