Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renesas SmartBond(tm) power management #61857

Merged
merged 7 commits into from
Apr 25, 2024

Conversation

kasjer
Copy link
Contributor

@kasjer kasjer commented Aug 24, 2023

Power management

This PR introduces power management to SmartBond(tm) family.
With all subsequent changes MCU can enter low power mode where CPU is powered down, GPIOs are latched unused power domains are powered down to reduce power consumption.

First thing needed to accomplished this is usage of TIMER2 which can run event when CPU is powered off. When this timer is used Cortex Tick timer is not needed and CPU can be powered off.

  • Standby mode handling added (in standby mode CPU is powered off, while RAM is preserved, sleep.S provides code to that restores system state when CPU is waken up)

  • This adds timer driver for Renesas SmartBond(tm) family.
    It uses TIMER2 block which is in PD_TIM power domain so it can work even if ARM core is disabled, thus can work as a sleep timer.

  • GPIOs are latched before CPU is powered down and PD_COM domain is also powered off during sleep.

  • GPIOs functionality is restored when system wakes up. When drivers: gpio: Smartbond: Improve GPIO compatibility #61844 is merged GPIOs changes will also be able to wake platform.

  • DC/DC converter is can be configured to be used instead of LDO

How to test

There is no separate application to test that system actually enters standby mode.
To test it's possibly to use standard blinky example with DA1469X-DK_PRO kit that has blue LED on the mother board. LED is lit when power consumption of MCU is above certain threshold detected by OpAMPs.
When blinky sample is run without power management code. Blue LED is lit all the time.
When power management (CONFIG_PM=y) is enabled with code in this PR blinky example will enter standby mode. When standby mode is entered and normal RED LED is off power consumption drops to the level that let BLUE LED to be turned off.


#define COUNTER_SPAN BIT(24)
#define CYC_PER_TICK (sys_clock_hw_cycles_per_sec() / CONFIG_SYS_CLOCK_TICKS_PER_SEC)
#define MAX_TICKS ((COUNTER_SPAN / 2 - CYC_PER_TICK) / CYC_PER_TICK)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the max_ticks should be adjusted depending on watchdog settings, i.e. watchdog is always enabled after entering extended sleep so we need to make sure that we'll wake up before it expires

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I tried to add this functionality I'm not sure it's needed.
If CONFIG_WDT_SMARTBOND is not set. power.c will disable watchdog after wakeup.
If watchdog is configured. Whatever task is feeding watchdog must wakeup before watchdog timer expires.
If task/work or something else is not armed to be ready before watchdog bites, even if platform is woken from sleep responsible task will not be triggered and watchdog timeout will expire anyway.
Unless I'm missing something...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I see.
When watchdog is disabled it will start when PD_SYS is powered off and sleep time should not exceed this time.
Which can be RCX or RC32K based so it should be computed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, so code should be only enabled if CONFIG_PM is enabled to prevent watchdog from expiring during extended sleep period. as you said, in other case something should feed watchdog before it expires.

@kasjer kasjer force-pushed the kasjer/da1469x-pm branch 3 times, most recently from c621367 to 213f101 Compare September 7, 2023 06:15
@andrzej-kaczmarek
Copy link
Collaborator

@kasjer fixes look good, please squash them with appropriate commits

@kasjer
Copy link
Contributor Author

kasjer commented Sep 12, 2023

@kasjer fixes look good, please squash them with appropriate commits

done

@kasjer
Copy link
Contributor Author

kasjer commented Sep 18, 2023

rebased without changes, maybe twister will work this time

@kasjer kasjer dismissed stale reviews from jhedberg, sjanc, and andrzej-kaczmarek via aedc022 April 19, 2024 07:55
@kasjer kasjer force-pushed the kasjer/da1469x-pm branch 2 times, most recently from aedc022 to 8ad7382 Compare April 19, 2024 07:59
jhedberg
jhedberg previously approved these changes Apr 20, 2024
sjanc
sjanc previously approved these changes Apr 24, 2024
@@ -318,12 +413,16 @@ static const struct gpio_driver_api gpio_smartbond_drv_api_funcs = {
.wkup_regs = (volatile struct gpio_smartbond_wkup_regs *) \
DT_INST_REG_ADDR_BY_NAME(id, wkup), \
.wkup_trig_select = id, \
GPIO_PM_DEVICE_CFG(.ngpios, DT_PROP(DT_NODELABEL(gpio##id), ngpios)) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still wrong. You can't use nodelabels in instance-based macros. Instance 0 may be gpio1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@gmarull gmarull dismissed their stale review April 25, 2024 10:42

main concerns addressed, thanks for the continued effort

andrzej-kaczmarek and others added 7 commits April 25, 2024 13:51
This adds timer driver for Renesas SmartBond(tm) family.
It uses TIMER2 block which is in PD_TIM power domain so it can work even
if ARM core is disabled, thus can work as a sleep timer.

Signed-off-by: Andrzej Kaczmarek <[email protected]>
Signed-off-by: Jerzy Kasenberg <[email protected]>
Platform specific init is needed once power management is introduced.

Signed-off-by: Andrzej Kaczmarek <[email protected]>
This enabled extended sleep for Renesas SmartBond(tm).

Extended sleep is low power mode where ARM core is powered off and can
be woken up by PDC. This is default sleep mode when CONFIG_PM is
enabled.

Signed-off-by: Andrzej Kaczmarek <[email protected]>
Signed-off-by: Jerzy Kasenberg <[email protected]>
This enables cache retainability while in sleep so there's no penalty
when executing from QSPI after wakeup.

Signed-off-by: Andrzej Kaczmarek <[email protected]>
This adds automatic GPIO latching before going to extended sleep and
restoring state after wakeup.

Mode and state for each pin is stored, then ports are latched to retain
state when PD_COM is disabled during sleep. On wakeup mode and state for
each pin is restored and ports are unlatched to make it work again.

Signed-off-by: Andrzej Kaczmarek <[email protected]>
Signed-off-by: Jerzy Kasenberg <[email protected]>
This change restore DCDC configuration after system resumes.

When CONFIG_PM_DEVICE is enabled each of the four rails that
support DCDC handle resume in regulator_da1469x_pm_action function.

Signed-off-by: Jerzy Kasenberg <[email protected]>
Update hal_renesas to include sleep code

Signed-off-by: Jerzy Kasenberg <[email protected]>
@kasjer
Copy link
Contributor Author

kasjer commented Apr 25, 2024

Last force-push is just rebase to main

@carlescufi carlescufi merged commit 2765d23 into zephyrproject-rtos:main Apr 25, 2024
56 of 65 checks passed
@kasjer kasjer deleted the kasjer/da1469x-pm branch April 26, 2024 06:21
@swift-tk
Copy link
Collaborator

I believe this PR broke "select GPIO"
See #72556
@andrzej-kaczmarek @carlescufi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.