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 LPTIM clock with prescaler to adjust the TICKS_PER_SEC #63563

Merged
merged 6 commits into from
Dec 12, 2023

Conversation

FRASTM
Copy link
Collaborator

@FRASTM FRASTM commented Oct 5, 2023

When the LPTIM is enabled for the lowPower (PM) purpose, the SYS_CLOCK_TICKS_PER_SEC is set to a lower value (than default 10000)

  • 4000 if LPTIM is clocked by LSI (32000Hz)
  • 4096 if LPTIM is clocked by LSE (32768Hz)

However when the lptim has a that divides the clock source , this SYS_CLOCK_TICKS_PER_SEC is even too high, resulting in numerous system wakeup during sleep mode (no more sleeping indeed)
Consequently the SYS_CLOCK_TICKS_PER_SEC is set to a value depending
on the clock input LSE/LSI and the clock prescaler property set in the DTS

  • 1000 if LPTIM is clocked by LSI (32000Hz) divided by 32
  • 1024 if LPTIM is clocked by LSE (32768Hz) divided by 32
  • 2000 if LPTIM is clocked by LSI (32000Hz) divided by 16
  • 2048 if LPTIM is clocked by LSE (32768Hz) divided by 16

Removing SYS_CLOCK_TICKS_PER_SEC in the board config and adding
Warning build message to check the coherency between

  • clock source definition (LSI/LSE) and the board DTS (lptim node property)
  • SYS_CLOCK_TICKS_PER_SEC and the LPTIM clock ratio (lptim node <st,prescaler> property)

Fixes #61099

@FRASTM FRASTM changed the title stm32 LPTIM clock to adjust the TICKS_PER_SEC stm32 LPTIM clock with prescaler to adjust the TICKS_PER_SEC Oct 5, 2023
@FRASTM FRASTM requested a review from gautierg-st October 5, 2023 09:48
@FRASTM FRASTM force-pushed the issue61099 branch 2 times, most recently from c8726ab to 1478bec Compare October 5, 2023 12:19
@FRASTM FRASTM marked this pull request as ready for review October 5, 2023 13:06
@zephyrbot zephyrbot added the area: Timer Timer label Oct 5, 2023
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.

I think this is a good occasion to remove the deprecation message on "#if DT_INST_NUM_CLOCKS(0) == 1
#warning Kconfig for LPTIM source clock (LSI/LSE) is deprecated, use device tree."

drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
@zephyrbot zephyrbot added the area: Devicetree Binding PR modifies or adds a Device Tree binding label Oct 12, 2023
@FRASTM
Copy link
Collaborator Author

FRASTM commented Oct 12, 2023

Rebase on 68365d5
Update the SYS_CLOCK_TICKS_PER_SEC in the soc/arm/st_stm32/common/Kconfig.defconfig.series
to retrieve the prescaler from the deviceTree.
Requires to define the lptim prescaler property as <clock-prescaler> (instead of "st,prescaler")
because it is not accepted by the macro but $(dt_node_int_prop_int,$(DT_STM32_LPTIM_PATH),clock-prescaler)
Add a generic name stm32_lp_tick_source to the lptim node (= the lptim enabled for low power tick counter)
a board overlay is now defining the prescaler with :

&stm32_lp_tick_source {
	clock-prescaler = <32>;
};

drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
soc/arm/st_stm32/common/Kconfig.defconfig.series Outdated Show resolved Hide resolved
soc/arm/st_stm32/common/Kconfig.defconfig.series Outdated Show resolved Hide resolved
@FRASTM FRASTM force-pushed the issue61099 branch 2 times, most recently from 643bf1a to 7c72f85 Compare October 17, 2023 11:48
drivers/timer/stm32_lptim_timer.c Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Show resolved Hide resolved
drivers/timer/stm32_lptim_timer.c Outdated Show resolved Hide resolved
@FRASTM FRASTM force-pushed the issue61099 branch 2 times, most recently from 6148636 to 3c5dcf3 Compare November 23, 2023 17:25
@FRASTM
Copy link
Collaborator Author

FRASTM commented Nov 23, 2023

rebase on #65683 which removes the lptim clock source divider of the stm32u5

@FRASTM
Copy link
Collaborator Author

FRASTM commented Nov 29, 2023

rebase on 9521371

@FRASTM FRASTM marked this pull request as ready for review November 29, 2023 08:16
@FRASTM FRASTM force-pushed the issue61099 branch 4 times, most recently from 7f023c1 to 7abb247 Compare November 30, 2023 09:47
Rename to LPTIM_PRESCALER, the <st,property> prescaler of
the stm32 LPTimer. This commit gives better readability than
LPTIM_CLOCK_RATIO.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
With low LPTIM freq when prescaler is set to 16 or 32,
the CONFIG_SYS_CLOCK_TICKS_PER_SEC must be reduced to
LPTIM CLOCK_/prescaler to avoid spurious timer wakeup activity.
Assert error if the CONFIG_SYS_CLOCK_TICKS_PER_SEC
is not compatible with the lptim clock freq.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Configure the SYS_CLOCK_TICKS_PER_SEC directly from the
DTS st-prescaler property of the lptim node
aka stm32_lp_tick_source

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Change the name of the node for the lptim used as lowpower
tick source to stm32_lp_tick_source.
Once enabled, this node is known as stm32_lp_tick_source
That will avoid naming the node lptim1 or lptim2 or lptim, etc.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Update migration guide to introduce the stm32_lp_tick_source
for stm32 device when choosing the LPTIM fo lowPower modes.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
@FRASTM
Copy link
Collaborator Author

FRASTM commented Dec 7, 2023

  • rebase on f46a27f
  • add comment to soc/arm/st_stm32/common/Kconfig.defconfig.series
  • update the /doc/releases/migration-guide-3.6.rst

erwango
erwango previously approved these changes Dec 7, 2023
Set the prescaler for the stm32_lp_tick_source lptim node.
When the LPTIM is clocked by the LSE with a prescaler
of 16 (lptim freq at 2048Hz) expecting 2048 for the TICKS_PER_SEC.
When the LPTIM is clocked by the LSE with a prescaler
of 32 (lptim freq at 1024Hz) expecting 1024 for the TICKS_PER_SEC.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
@FRASTM
Copy link
Collaborator Author

FRASTM commented Dec 7, 2023

adding more text to the README.rst

@fabiobaltieri fabiobaltieri merged commit bf2b467 into zephyrproject-rtos:main Dec 12, 2023
38 checks passed
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: Power Management area: Samples Samples area: Timer Timer platform: STM32 ST Micro STM32 Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sample STM32PM Blinky higher energy usage on nucleo_wb55rg since adding prescaler for lptim1
5 participants