Skip to content

soc: stm32u0: add PM #88878

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

Closed
wants to merge 85 commits into from
Closed

Conversation

mickael868
Copy link

AFAIK, the stm32u0 target does not support the Power Management (PM) for now.

This PR copies the PM code from the STM32U5 target with few adaptation (eg. LL_PWR_STOP0_MODE -> LL_PWR_MODE_STOP0).

  • Test 0 without this PR : 2mA

  • Test 1: no peripheral enabled, no way to wake up after entering the stop1 mode: 3µA with the following overlay:

  cpus {
    cpu0: cpu@0 {
      cpu-power-states = <&stop0 &stop1>;
    };

    stop0: state0 {
      compatible = "zephyr,power-state";
      power-state-name = "suspend-to-idle";
      substate-id = <1>;
      min-residency-us = <100>;
    };
    stop1: state1 {
      compatible = "zephyr,power-state";
      power-state-name = "suspend-to-idle";
      substate-id = <2>;
      min-residency-us = <500>;
    };
  };
  • Test 2: lptim2 (already not disabled in the dts/arm/st/u0/stm32u0.dtsi file) is used for a periodic wake up: 140µA with the following additional overlay:
stm32_lp_tick_source: &lptim2 {
  clocks = <&rcc STM32_CLOCK(APB1, 30U)>,
           <&rcc STM32_SRC_LSI LPTIM2_SEL(1)>;
  // st,prescaler = <8>; //doe not reduce power consumption
  status = "okay";
};

In both cases, it is necessary to disable the pm_policy_state_lock_get() calls from drivers/serial/uart_stm32.c because it takes the lock once at the first printk() call and never put it. This is the get backtrace if the banner is enabled:

Breakpoint 1, uart_poll_out (dev=<optimized out>, out_char=42 '*') at app/build/zephyr/include/generated/zephyr/syscalls/uart.h:108
108             z_impl_uart_poll_out(dev, out_char);
(gdb) backtrace
#0  uart_poll_out (dev=<optimized out>, out_char=42 '*') at app/build/zephyr/include/generated/zephyr/syscalls/uart.h:108
#1  console_out (c=42) at app/zephyr/drivers/console/uart_console.c:102
#2  0x080004a4 in char_out (c=<optimized out>, ctx_p=<optimized out>) at app/zephyr/lib/os/printk.c:98
#3  0x08004216 in vfprintf ()
#4  0x080004de in vprintk (fmt=0x8007689 "*** Booting Zephyr OS build v4.1.0-2646-ge41909a32ce9 ***\n", fmt@entry=0x1 <error: Cannot access memory at address 0x1>, ap=..., ap@entry=...) at app/zephyr/lib/os/printk.c:134
#5  0x0800560c in printk (fmt=0x8007689 "*** Booting Zephyr OS build v4.1.0-2646-ge41909a32ce9 ***\n") at app/zephyr/lib/os/printk.c:198
#6  0x08003ff0 in boot_banner () at app/zephyr/kernel/banner.c:46
#7  0x08002cc0 in bg_thread_main (unused1=<optimized out>, unused2=<optimized out>, unused3=<optimized out>) at app/zephyr/kernel/init.c:551
#8  0x08000508 in z_thread_entry (entry=0x8002cad <bg_thread_main>, p1=0x0, p2=0x0, p3=0x0) at app/zephyr/lib/os/thread_entry.c:48
#9  0x0800108c in arch_switch_to_main_thread (main_thread=0x8002cad <bg_thread_main>, stack_ptr=0x0, _main=0x8002cad <bg_thread_main>) at /home/mika/dev/embedded/zephyr/common/zephyr/arch/arm/core/cortex_m/thread.c:546
#10 0x20000608 in z_idle_threads ()

uart_stm32_pm_policy_state_lock_put_unconditional is never called. Tested with CONFIG_UART_INTERRUPT_DRIVEN=y.

I'm quiet new to Zephyr, does the UART issue comes an error I made?
Also, I think we should expect a lower power consumption when the LPTIM2 timer is used, do you have any idea how to improve this using only internal clocks? I will try to add a LSE oscillator in the next design (mainly for the LPUARTx peripherals) but I can not test it for now.

Thanks.

@github-actions github-actions bot added platform: STM32 ST Micro STM32 area: Timer Timer labels Apr 21, 2025
Copy link

Hello @mickael868, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

}

/* Initialize STM32 Power */
void stm32_power_init(void)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be called inside

void soc_early_init_hook(void)
if CONFIG_PM=y.

Copy link
Collaborator

@mathieuchopstm mathieuchopstm left a comment

Choose a reason for hiding this comment

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

First surface-level look.

This also lacks power states definition in Device Tree (dts/arm/st/u0/stm32u0.dtsi - see other series for reference)

mickael868 and others added 13 commits April 22, 2025 14:24
Add AndesTech Platforms section and add me jimmyzhe, kevinwang821020
as maintainer and collaborator.

Signed-off-by: Jimmy Zheng <[email protected]>
Added driver for the PAJ7620 gesture sensor. For now,
just added basic gesture mode, although sensor also
has other modes (proximity and cursor modes).

Signed-off-by: Paul Timke Contreras <[email protected]>
Added paj7620 to the testcase so that it is in build.

Signed-off-by: Paul Timke Contreras <[email protected]>
Added a sample for using the PAJ7620 gesture sensor

Signed-off-by: Paul Timke Contreras <[email protected]>
Extend driver to support single lane and 1-4-4 IO modes.
Move flash chip quirks to a separate file.

Signed-off-by: Marcin Szymczyk <[email protected]>
Separate compatible is required for Flash MSPI quirks.

Signed-off-by: Marcin Szymczyk <[email protected]>
Move MSPI NOR commands to rodata.
Replace array with empty padding (~1kB) with macro-based assignments.

Ref: NCSDK-32779

Signed-off-by: Tomasz Chyrowicz <[email protected]>
Add additional conversion helpers for `deci` and `centi` output units.

Signed-off-by: Jordan Yates <[email protected]>
nashif and others added 15 commits April 22, 2025 16:55
Fix grouping and general doxygen fixups.

Signed-off-by: Anas Nashif <[email protected]>
Fix grouping and general doxygen fixups.

Signed-off-by: Anas Nashif <[email protected]>
Fix grouping and general doxygen fixups.

Signed-off-by: Anas Nashif <[email protected]>
Fix grouping and general doxygen fixups.

Signed-off-by: Anas Nashif <[email protected]>
Group test using doxygen.

Signed-off-by: Anas Nashif <[email protected]>
Group test using doxygen.

Signed-off-by: Anas Nashif <[email protected]>
Create top level doxygen groups to be used by tests and move to
dedidcated dox file for tests.

Signed-off-by: Anas Nashif <[email protected]>
Group test using doxygen and other doxygen fixups.

Signed-off-by: Anas Nashif <[email protected]>
Group test using doxygen and general fixes to structure.

Signed-off-by: Anas Nashif <[email protected]>
Add missing fields for DMA tx and rx configuration macros

Signed-off-by: Simon Gilbert <[email protected]>
Add stub functions for the I2C DMA callbacks, which are invoked
during or upon completion of DMA-based I2C transactions. Without
these, NULL pointer calls occur on DMA transfer complete or error
events, leading to faults within ISR context.

Signed-off-by: Simon Gilbert <[email protected]>
In STM32N6, AXISRAM1 is next to the 400kB FLEXRAM.
By default, the FLEXRAM is configured to extend the AXISRAM1 which put
its total size to 1024kB.

Signed-off-by: Guillaume Gautier <[email protected]>
In Clang 16 run with some flags, the compiler does not accept a static
const variables as struct initializer. This caused build errors in only
some contexts. Always use the devicetree macros to access the source
device node as a workaround.

Signed-off-by: Josuah Demangeon <[email protected]>
Copy link

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
tf-m-tests zephyrproject-rtos/tf-m-tests@502ea90 (v3.7-branch) zephyrproject-rtos/tf-m-tests@c712761 (main) zephyrproject-rtos/[email protected]
trusted-firmware-m zephyrproject-rtos/trusted-firmware-m@857f369 zephyrproject-rtos/trusted-firmware-m@e2288c1 (main) zephyrproject-rtos/[email protected]

Additional metadata changed:

Name URL Submodules West cmds module.yml
trusted-firmware-m

DNM label due to: 1 project with metadata changes

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-trusted-firmware-m manifest-tf-m-tests DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Apr 22, 2025
@mickael868
Copy link
Author

Sorry, I made a mess with the git remotes and it resulted in external commits being incorporated here.
Should I close this PR and start again ?

@mathieuchopstm
Copy link
Collaborator

Sorry, I made a mess with the git remotes and it resulted in external commits being incorporated here. Should I close this PR and start again ?

You should be able to fix the branch by resetting the tree (e.g., git reset --hard b8d4a6aa592bfb79e723b2c7a8374b3439f220a8) and re-applying your commits via cherry-pick (git cherry-pick 28a55e61c1a34fe02f7f46cf5eae02e9fb9af482 b31046e86b0a3990ff96fcae5babc213a8933b03 112e4b51e9ef6ac40cc0529cbe02a79ec204d025 4341a2c1f2a9eeaeaf6d16f846b4f6f6f4696537 f5502937aad0ecf1e72ef26b3c4514e8c1d7a60f c5998dc3d7b0b87e20baee7e067dc57dc76146be 4cf36b18ef8c3287b83521306b04d3466f2a8919 ac0676a678cf1f495a34f6aee2fe2341590b1341), then force-pushing to the branch (git push --force-with-lease or possibly git push --force)... but if you prefer, close the PR and open a new one.

@mickael868
Copy link
Author

Closing and reopening to start from a clean local repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Timer Timer DNM (manifest) This PR should not be merged (controlled by action-manifest) manifest manifest-tf-m-tests manifest-trusted-firmware-m platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.