Commit 2c88cc08 authored by Adam Berlinger's avatar Adam Berlinger Committed by Anas Nashif
Browse files

drivers: timer: Fix timing in suspend-to-ram



Fix timing in suspend-to-ram when using STM32WBA.
Switch to use RTC timer should be done only when idle is set
and LPTIM clocks should be switched off

Signed-off-by: default avatarAdam Berlinger <adam.berlinger@st.com>
parent 36fb0279
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -204,7 +204,7 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)

	next = pm_policy_next_state(CURRENT_CPU, ticks);

	if ((next != NULL) && (next->state == PM_STATE_SUSPEND_TO_RAM)) {
	if ((next != NULL) && idle && (next->state == PM_STATE_SUSPEND_TO_RAM)) {
		uint64_t timeout_us =
			((uint64_t)ticks * USEC_PER_SEC) / CONFIG_SYS_CLOCK_TICKS_PER_SEC;

@@ -230,6 +230,9 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
		counter_get_value(stdby_timer, &stdby_timer_pre_stdby);
		lptim_cnt_pre_stdby = z_clock_lptim_getcounter();

		/* Stop clocks for LPTIM, since RTC is used instead */
		clock_control_off(clk_ctrl, (clock_control_subsys_t) &lptim_clk[0]);

		return;
	}
#endif /* CONFIG_STM32_LPTIM_STDBY_TIMER */