#11046·rt-thread

[Bug] pm组件对于peripheral device已经进入对应 的suspend,后续可能不执行对应的resume

Author: tu461987807Created Dec 12, 2025Updated Sep 22, 2026
Labelsin progress

RT-Thread Version

5.2.2

Hardware Type/Architectures

CORTEX-M4

Develop Toolchain

Other

Describe the bug

pm组件对于peripheral `device已经进入低功耗后,因tickless进入低功耗,会导致sleep_mode这个变量可能会变,导致后续执行resume不会执行对应的退出功耗代码

/* Notify app will enter sleep mode */
        if (_pm_notify.notify)
            _pm_notify.notify(RT_PM_ENTER_SLEEP, pm->sleep_mode, _pm_notify.data);

        /* Suspend all peripheral device */
#ifdef PM_ENABLE_SUSPEND_SLEEP_MODE
        int ret = _pm_device_suspend(pm->sleep_mode);
        if (ret != RT_EOK)
        {
            _pm_device_resume(pm->sleep_mode);
            if (_pm_notify.notify)
                _pm_notify.notify(RT_PM_EXIT_SLEEP, pm->sleep_mode, _pm_notify.data);
            if (pm->sleep_mode > PM_SUSPEND_SLEEP_MODE)
            {
                pm->sleep_mode = PM_SUSPEND_SLEEP_MODE;
            }
            pm->ops->sleep(pm, pm->sleep_mode); /* suspend failed */
             rt_pm_exit_critical(level, pm->sleep_mode);
            return;
        }
#else
        _pm_device_suspend(pm->sleep_mode); //假如sleep_mode 等于3
#endif

        /* Tickless*/
        if (pm->timer_mask & (0x01 << pm->sleep_mode)) //哪些低功耗模式需要启用tickless
        {
            pre_tick = timeout_tick = pm_timer_next_timeout_tick(pm->sleep_mode);
            
            timeout_tick = timeout_tick - rt_tick_get();

            /* Judge sleep_mode from threshold time */
            pm->sleep_mode = pm_get_sleep_threshold_mode(pm->sleep_mode, timeout_tick); //这里会修改稿sleep_mode的值

            if (pm->timer_mask & (0x01 << pm->sleep_mode))
            {
                if (pre_tick == RT_TICK_MAX)
                {
                    pm_lptimer_start(pm, RT_TICK_MAX);
                }
                else
                {
                    pm_lptimer_start(pm, timeout_tick);
                }
            }
        }

        /* enter lower power state */
        pm_sleep(pm, pm->sleep_mode);

        /* wake up from lower power state*/
        if (pm->timer_mask & (0x01 << pm->sleep_mode))
        {
            delta_tick = pm_lptimer_get_timeout(pm);
            pm_lptimer_stop(pm);
            if (delta_tick)
            {
                rt_tick_set(rt_tick_get() + delta_tick);
            }
        }

        /* resume all device */
        _pm_device_resume(pm->sleep_mode); //如果sleep_mode的值被修改了,就不会执行与suspend对应的resume了

Other additional context

No response