This post was last edited by xiaolinen on 2023-9-28 15:28
Read "RT-Thread Device Driver Development Guide" --- PM device driver learning
Part 1: Understanding PM Components
The PM component adopts a layered design concept, separating the architecture and chip-related parts, and extracting the common parts as the core, which not only ensures the uniformity of the interface called by the application layer, but also realizes the flexibility of the underlying driver adaptation. The framework structure diagram is as follows:
My humble opinion:
1) PM component is a management framework. We should use it according to the actual situation. It is not a restriction that requires using PM component when using rt-thread.
2) Since it is a framework, we need to adapt it, modify and verify it according to the business requirements of the application layer, so as to achieve optimal power consumption .
3) The PM component framework is not only applicable to rt-thred, but can also be ported to other rtos.
Part 2: Using PM Components
In the ENV tool, turn on the PM component, as shown in the figure:
File location:
Part III: Some codes and experimental phenomena
Code:
/*
功能:深度睡眠
*/
void pm_bsp_enter_deepsleep(struct rt_pm *pm)
{
HAL_SysTickDisable();
if (pm->run_mode == PM_RUN_MODE_LOW_SPEED)
{
/* Enter LP SLEEP Mode, Enable low-power regulator */
pmu_to_deepsleepmode(PMU_LDO_LOWPOWER,PMU_LOWDRIVER_ENABLE,WFI_CMD);
}
else
{
/* Enter SLEEP Mode, Main regulator is ON */
pmu_to_deepsleepmode(PMU_LDO_LOWPOWER,PMU_LOWDRIVER_ENABLE,WFI_CMD);
}
HAL_SysTickEnable();
}
/*
功能:深度睡眠1
*/
void pm_bsp_enter_deepsleep_1(struct rt_pm *pm)
{
HAL_SysTick_IRQ_Disable();
if (pm->run_mode == PM_RUN_MODE_LOW_SPEED)
{
/* Enter LP SLEEP Mode, Enable low-power regulator */
pmu_to_deepsleepmode_1(PMU_LDO_LOWPOWER,PMU_LOWDRIVER_ENABLE,WFI_CMD);
}
else
{
/* Enter SLEEP Mode, Main regulator is ON */
pmu_to_deepsleepmode_1(PMU_LDO_LOWPOWER,PMU_LOWDRIVER_ENABLE,WFI_CMD);
}
HAL_SysTick_IRQ_Enable();
}
/*
功能:深度睡眠2
*/
void pm_bsp_enter_deepsleep_2(struct rt_pm *pm)
{
rt_base_t level;
//level = rt_hw_interrupt_disable();
HAL_SysTick_IRQ_Disable();
if (pm->run_mode == PM_RUN_MODE_LOW_SPEED)
{
/* Enter LP SLEEP Mode, Enable low-power regulator */
pmu_to_deepsleepmode_2(PMU_LDO_LOWPOWER,PMU_LOWDRIVER_ENABLE,WFI_CMD);
}
else
{
/* Enter SLEEP Mode, Main regulator is ON */
pmu_to_deepsleepmode_2(PMU_LDO_LOWPOWER,PMU_LOWDRIVER_ENABLE,WFI_CMD);
}
//system_lowpower_set(SCB_LPM_DEEPSLEEP);
HAL_SysTick_IRQ_Enable();
// rt_hw_interrupt_enable(level);
}
/*
功能:待机模式
*/
void pm_bsp_enter_standby(struct rt_pm *pm)
{
pmu_to_standbymode(WFI_CMD);
}
Realization phenomenon:
Normal operation of the equipment: 165mA;
Device sleep state (external sensor power-off operation): 27uA;
Summarize:
Adjusting the power consumption of equipment is a technical job and a physical job. You will inevitably encounter various problems when adjusting the power consumption. If you can sit still and work hard, there will be fewer and fewer problems. Remember not to lose your mind for a while and then lose your mind again. It is useless to lose your mind for many times. After all, the work is yours and you need to finish it!!! Now, with the PM framework, we cannot say that our problems are completely solved, but at least it points out some solutions for us. I personally think that the essence of rt-thread is not only its system, but more of its components. These components provide convenience and show us a programming idea. RT-Thread is a beautiful product that deserves our in-depth study and full application.