-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Conversation
c99633d
to
c82c49b
Compare
drivers/timer/smartbond_timer.c
Outdated
|
||
#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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
c621367
to
213f101
Compare
@kasjer fixes look good, please squash them with appropriate commits |
ad2a386
to
280d621
Compare
done |
f117fcc
to
98d8d3e
Compare
rebased without changes, maybe twister will work this time |
aedc022
aedc022
to
8ad7382
Compare
drivers/gpio/gpio_smartbond.c
Outdated
@@ -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)) \ |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
8ad7382
to
04177ce
Compare
main concerns addressed, thanks for the continued effort
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 <andrzej.kaczmarek@codecoup.pl> Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
Platform specific init is needed once power management is introduced. Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
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 <andrzej.kaczmarek@codecoup.pl> Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
This enables cache retainability while in sleep so there's no penalty when executing from QSPI after wakeup. Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
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 <andrzej.kaczmarek@codecoup.pl> Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
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 <jerzy.kasenberg@codecoup.pl>
Update hal_renesas to include sleep code Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
04177ce
to
0668ff0
Compare
Last force-push is just rebase to main |
I believe this PR broke "select GPIO" |
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.