@@ -83,8 +83,13 @@ int sys_clock_driver_init(const struct device *dev)
8383 ARG_UNUSED (dev );
8484
8585 /* enable LPTIM clock source */
86+ #if defined(LL_APB1_GRP1_PERIPH_LPTIM1 )
8687 LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_LPTIM1 );
8788 LL_APB1_GRP1_ReleaseReset (LL_APB1_GRP1_PERIPH_LPTIM1 );
89+ #elif defined(LL_APB3_GRP1_PERIPH_LPTIM1 )
90+ LL_APB3_GRP1_EnableClock (LL_APB3_GRP1_PERIPH_LPTIM1 );
91+ LL_SRDAMR_GRP1_EnableAutonomousClock (LL_SRDAMR_GRP1_PERIPH_LPTIM1AMEN );
92+ #endif
8893
8994#if defined(CONFIG_STM32_LPTIM_CLOCK_LSI )
9095 /* enable LSI clock */
@@ -137,28 +142,51 @@ int sys_clock_driver_init(const struct device *dev)
137142 LL_LPTIM_SetClockSource (LPTIM1 , LL_LPTIM_CLK_SOURCE_INTERNAL );
138143 /* configure the LPTIM1 prescaler with 1 */
139144 LL_LPTIM_SetPrescaler (LPTIM1 , LL_LPTIM_PRESCALER_DIV1 );
145+ #ifdef CONFIG_SOC_SERIES_STM32U5X
146+ LL_LPTIM_OC_SetPolarity (LPTIM1 , LL_LPTIM_CHANNEL_CH1 ,
147+ LL_LPTIM_OUTPUT_POLARITY_REGULAR );
148+ #else
140149 LL_LPTIM_SetPolarity (LPTIM1 , LL_LPTIM_OUTPUT_POLARITY_REGULAR );
150+ #endif
141151 LL_LPTIM_SetUpdateMode (LPTIM1 , LL_LPTIM_UPDATE_MODE_IMMEDIATE );
142152 LL_LPTIM_SetCounterMode (LPTIM1 , LL_LPTIM_COUNTER_MODE_INTERNAL );
143153 LL_LPTIM_DisableTimeout (LPTIM1 );
144154 /* counting start is initiated by software */
145155 LL_LPTIM_TrigSw (LPTIM1 );
146156
157+ #ifdef CONFIG_SOC_SERIES_STM32U5X
158+ /* Enable the LPTIM1 before proceeding with configuration */
159+ LL_LPTIM_Enable (LPTIM1 );
160+
161+ LL_LPTIM_DisableIT_CC1 (LPTIM1 );
162+ while (LL_LPTIM_IsActiveFlag_DIEROK (LPTIM1 ) == 0 ) {
163+ }
164+ LL_LPTIM_ClearFlag_DIEROK (LPTIM1 );
165+ LL_LPTIM_ClearFLAG_CC1 (LPTIM1 );
166+ #else
147167 /* LPTIM1 interrupt set-up before enabling */
148168 /* no Compare match Interrupt */
149169 LL_LPTIM_DisableIT_CMPM (LPTIM1 );
150170 LL_LPTIM_ClearFLAG_CMPM (LPTIM1 );
171+ #endif
151172
152173 /* Autoreload match Interrupt */
153174 LL_LPTIM_EnableIT_ARRM (LPTIM1 );
175+ #ifdef CONFIG_SOC_SERIES_STM32U5X
176+ while (LL_LPTIM_IsActiveFlag_DIEROK (LPTIM1 ) == 0 ) {
177+ }
178+ LL_LPTIM_ClearFlag_DIEROK (LPTIM1 );
179+ #endif
154180 LL_LPTIM_ClearFLAG_ARRM (LPTIM1 );
155181 /* ARROK bit validates the write operation to ARR register */
156182 LL_LPTIM_ClearFlag_ARROK (LPTIM1 );
157183
158184 accumulated_lptim_cnt = 0 ;
159185
186+ #ifndef CONFIG_SOC_SERIES_STM32U5X
160187 /* Enable the LPTIM1 counter */
161188 LL_LPTIM_Enable (LPTIM1 );
189+ #endif
162190
163191 /* Set the Autoreload value once the timer is enabled */
164192 if (IS_ENABLED (CONFIG_TICKLESS_KERNEL )) {
@@ -175,7 +203,12 @@ int sys_clock_driver_init(const struct device *dev)
175203
176204#ifdef CONFIG_DEBUG
177205 /* stop LPTIM1 during DEBUG */
206+ #if defined(LL_DBGMCU_APB1_GRP1_LPTIM1_STOP )
178207 LL_DBGMCU_APB1_GRP1_FreezePeriph (LL_DBGMCU_APB1_GRP1_LPTIM1_STOP );
208+ #elif defined(LL_DBGMCU_APB3_GRP1_LPTIM1_STOP )
209+ LL_DBGMCU_APB3_GRP1_FreezePeriph (LL_DBGMCU_APB3_GRP1_LPTIM1_STOP );
210+ #endif
211+
179212#endif
180213 return 0 ;
181214}
@@ -210,14 +243,24 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
210243
211244 if (ticks == K_TICKS_FOREVER ) {
212245 /* disable LPTIM clock to avoid counting */
246+ #if defined(LL_APB1_GRP1_PERIPH_LPTIM1 )
213247 LL_APB1_GRP1_DisableClock (LL_APB1_GRP1_PERIPH_LPTIM1 );
248+ #elif defined(LL_APB3_GRP1_PERIPH_LPTIM1 )
249+ LL_APB3_GRP1_DisableClock (LL_APB3_GRP1_PERIPH_LPTIM1 );
250+ #endif
214251 return ;
215252 }
216253
217254 /* if LPTIM clock was previously stopped, it must now be restored */
255+ #if defined(LL_APB1_GRP1_PERIPH_LPTIM1 )
218256 if (!LL_APB1_GRP1_IsEnabledClock (LL_APB1_GRP1_PERIPH_LPTIM1 )) {
219257 LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_LPTIM1 );
220258 }
259+ #elif defined(LL_APB3_GRP1_PERIPH_LPTIM1 )
260+ if (!LL_APB3_GRP1_IsEnabledClock (LL_APB3_GRP1_PERIPH_LPTIM1 )) {
261+ LL_APB3_GRP1_EnableClock (LL_APB3_GRP1_PERIPH_LPTIM1 );
262+ }
263+ #endif
221264
222265 /* passing ticks==1 means "announce the next tick",
223266 * ticks value of zero (or even negative) is legal and
0 commit comments