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

STM32: configure wake-up pins with GPIOs from devicetree for exiting Poweroff #73058

Merged

Conversation

ajarmouni-st
Copy link
Collaborator

@ajarmouni-st ajarmouni-st commented May 21, 2024

This PR implements end-to-end configuration of GPIO pins as sources for STM32 PWR wake-up pins behind the scenes exclusively from devicetree information for all series using a newly introduced public stm32_pwr_wkup_pin_cfg_gpio() function inside gpio_stm32.c driver during initial GPIO pin configuration.

For this, we add a devicetree binding for the STM32 power contoller (PWR) peripheral which manages all device power supplies and power modes transitions, including the control of wake-up pins. We note that this initial PWR binding is focused on wake-up pins.

We also introduce a STM32 specific sample application that demonstrates how GPIO pins can be used to power on the system after a Poweroff, just like a reset pin.
The user only needs to add the STM32_GPIO_WKUP custom GPIO flag to the GPIO pin in "gpios" property of a DT device, such as a button or a sensor.
The sample powers off the system after a delay then the user can power it on again with the user button that has the STM32_GPIO_WKUP flag in DT.
Will only work on STM32 boards that support Zephyr POWEROFF (U5, WL, WB, & L4 SoC series), & also happen to have a user button whose GPIO pin is associated with a wake-up pin (see PWR node in SoC dtsi file).

For more information about how wake-up pins are managed & configured on a given STM32 SoC, please refer to the "Power control (PWR)" section in the Reference Manual. Information about GPIOs associated with wake-up pins can be found in the "pinouts and pin description" section in the datasheet.

@ajarmouni-st ajarmouni-st added the platform: STM32 ST Micro STM32 label May 21, 2024
@erwango
Copy link
Member

erwango commented May 21, 2024

@nandojve ^^

@ajarmouni-st ajarmouni-st force-pushed the dev_stm32_wkup_pins_gpios branch 3 times, most recently from 16a250e to e825ab6 Compare May 21, 2024 09:17
@ajarmouni-st ajarmouni-st marked this pull request as ready for review May 21, 2024 09:32
@zephyrbot zephyrbot added area: GPIO area: Devicetree Binding PR modifies or adds a Device Tree binding area: Samples Samples labels May 21, 2024
@nandojve nandojve self-requested a review May 21, 2024 10:33
@decsny decsny removed their request for review May 21, 2024 19:43
@ajarmouni-st
Copy link
Collaborator Author

ajarmouni-st commented May 22, 2024

Additional context: this PR introduced a STM32 custom GPIO flag, STM32_GPIO_WKUP, to be used to signal to GPIO driver that a GPIO pin should be setup as a source for wake-up pins, instead of using the wakeup-source property, because using a flag is more generic, & allows for use cases, beyond just GPIO Keys, where a DT device could have multiple GPIO pins in its gpiosproperty, & only one of those GPIO pins is supposed to be used as wake-up source.

@ajarmouni-st
Copy link
Collaborator Author

Hi @bjarki-trackunit, I would appreciate your feedback, thanks!

Add DT binding for stm32 PWR peripheral that controlls wake-up pins.
This binding primarily introduces wake-up pins configuration in
a unifed way that takes into consideration the variations between
STM32 SoC series & facilitates the association of GPIO pins with
their corresponding wake-up pins.

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
Add devicetree node of stm32 PWR peripheral that controlls wake-up pins.
The new node includes child nodes for wake-up pins configuration.
We only add these nodes for STM32 SoC series that support Poweroff.

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
@ajarmouni-st
Copy link
Collaborator Author

Rebase

@erwango
Copy link
Member

erwango commented May 27, 2024

Moving assignee from @galak to @henrikbrixandersen as the owner of the next impacted subsystem (GPIO)

soc/st/stm32/common/stm32_wkup_pins.c Show resolved Hide resolved
soc/st/stm32/common/stm32_wkup_pins.c Show resolved Hide resolved
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM in the general lines.

samples/boards/stm32/power_mgmt/wkup_pins/src/main.c Outdated Show resolved Hide resolved
include/zephyr/dt-bindings/gpio/st-stm32-gpio.h Outdated Show resolved Hide resolved
include/zephyr/dt-bindings/gpio/st-stm32-gpio.h Outdated Show resolved Hide resolved
@zafersn
Copy link

zafersn commented Jun 4, 2024

Hi, @ajarmouni-st , I am not quite sure to discuss an issue here about your implementation. I just tested wake up pin sample you implemented in your repo: https://github.com/ajarmouni-st/zephyr_dev/tree/dev_stm32_wkup_pins_gpios on the stm32u575zq dev board.

  1. the user button couldnt wake up the system.
    image

Before powering the system off, current consumption: ~ 12mA

image

After powering the system off, current consumption: 14uA

image

I was expecting less than 500 nA of consumption in shutdown mode:
image

So, I was wondering if I was following up on the correct repo and steps? And any ideas?

@ajarmouni-st
Copy link
Collaborator Author

ajarmouni-st commented Jun 4, 2024

Hi @zafersn, was it a nucleo_u575zi_q board? I just tested it on my side & the user button is working.

/ {
	aliases {
		wkup-src = &user_button;
	};
};

&user_button {
	gpios = <&gpioc 13 (GPIO_ACTIVE_HIGH | STM32_GPIO_WKUP)>;
};

&pwr {
	status = "okay";
};

Just to verify quickly that the system actually goes into shutdown mode, LED 1 will be turned off.

Will try to verify current consumption on nucleo_u575zi_q.

@zafersn
Copy link

zafersn commented Jun 4, 2024

Hi @zafersn, was it a nucleo_u575zi_q board? I just tested it on my side & the user button is working.

/ {
	aliases {
		wkup-src = &user_button;
	};
};

&user_button {
	gpios = <&gpioc 13 (GPIO_ACTIVE_HIGH | ST_STM32_GPIO_WKUP)>;
};

&pwr {
	status = "okay";
};

Just to verify quickly that the system actually goes into shutdown mode, LED 1 will be turned off.

Will try to verify current consumption on nucleo_u575zi_q.

Thanks for quick reply @ajarmouni-st :

I see the differences now that you have (GPIO_ACTIVE_HIGH | ST_STM32_GPIO_WKUP) flag configs. I tried with this configs and now button works. and also I have new current consumtion of 5.5uA but it is still not even close to 160nA shutdown mode consumption. :

image

@ajarmouni-st
Copy link
Collaborator Author

ajarmouni-st commented Jun 5, 2024

also I have new current consumtion of 5.5uA but it is still not even close to 160nA shutdown mode consumption.

@zafersn I got 1 uA but I don't know if it's the real consu. or it's bcz my ammeter cannot go lower.

In any case, feel free to open an issue regarding current consumption in shutdown mode on STM32U575 & we can continue the discussion there.

@zafersn
Copy link

zafersn commented Jun 5, 2024

also I have new current consumtion of 5.5uA but it is still not even close to 160nA shutdown mode consumption.

@zafersn I got 1 uA but I don't know if it's the real consu. or it's bcz my ammeter cannot go lower.

In any case, feel free to open an issue regarding current consumption in shutdown mode on STM32U575 & we can continue the discussion there.

Ok thanks for this information.

BTW, I also tried to get reset cause information.

hwinfo_get_reset_cause(&cause);

cause return with 0 after waking up from LL_PWR_SHUTDOWN_MODE
Is there any possibility to get the correct cause info?

@ajarmouni-st
Copy link
Collaborator Author

BTW, I also tried to get reset cause information.

hwinfo_get_reset_cause(&cause);

cause return with 0 after waking up from LL_PWR_SHUTDOWN_MODE Is there any possibility to get the correct cause info?

@zafersn I had it in the PR previously but decided to remove it cz I couldn't get consistent results on all boards, see https://github.com/zephyrproject-rtos/zephyr/compare/4235e22f6c855f3c58386a04812f57ce084618a0..601e1ded1dc99273ab9ce6c4b253fdfd4363279a

Implement GPIO pins configuration as sources for STM32 PWR wake-up pins
behind the scenes exclusively from devicetree information for all series
using the public stm32_pwr_wkup_pin_cfg_gpio() function.
Introduce macros for parsing & storing DT wake-up pins config in C structs.
Introduce user-configurable STM32_WKUP_PINS Kconfig flag.

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
Introduce public functions for GPIO pins configuration as sources for
STM32 PWR wake-up pins, in stm32 drivers & routines such gpio_stm32
& poweroff.

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
Introduce a custom STM32_GPIO_WKUP GPIO flag.
Use the newly introduced stm32_pwr_wkup_pin_cfg_gpio() public
function to configure GPIO pins, that have the STM32_GPIO_WKUP
flag in DT, as sources for STM32 PWR wake-up pins, on the condition
that there is a wake-up pin that corresponds to each of them.
These GPIO pins can then be used to power on the system after Poweroff
like a reset pin.

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
Complete wake-up pins configuration before powering off
the system when the CONFIG_STM32_WKUP_PINS flag is enabled.

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
This sample demonstrates how gpio pins can be used to power on
the system after a Poweroff, just like a reset pin.
The user only needs to add the STM32_GPIO_WKUP flag to the gpio pin
in "gpios" property of a DT device such a button or a sensor.
The samples Powers off the system after a delay then the user can power it
on with the user button that has the STM32_GPIO_WKUP flag in DT.
Only works on STM32 boards that support Zephyr POWEROFF
(U5, WL, WB, & L4 SoC series), & also have a user button whose GPIO pin
is associated with a wake-up pin (see PWR node in SoC dtsi file).

Signed-off-by: Abderrahmane Jarmouni <[email protected]>
@dleach02 dleach02 merged commit 8018018 into zephyrproject-rtos:main Jun 5, 2024
22 checks passed
@ajarmouni-st ajarmouni-st deleted the dev_stm32_wkup_pins_gpios branch June 6, 2024 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: GPIO area: Samples Samples platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: introduce the STM32 system wakeup pins to exit low power modes
8 participants