Skip to content

Commit e013574

Browse files
KozhinovAlexandermathieuchopstm
authored andcommitted
drivers: rtc: rtc_ll_stm32: update to new EXTI API
integrate EXTI driver Co-authored-by: Mathieu CHOPLAIN <[email protected]> Signed-off-by: Alexander Kozhinov <[email protected]>
1 parent de22c56 commit e013574

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

drivers/rtc/rtc_ll_stm32.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2023 Prevas A/S
33
* Copyright (c) 2023 Syslinbit
44
* Copyright (c) 2024 STMicroelectronics
5+
* Copyright (c) 2025 Alexander Kozhinov <[email protected]>
56
*
67
* SPDX-License-Identifier: Apache-2.0
78
*
@@ -24,7 +25,7 @@
2425
#include <stm32_ll_rcc.h>
2526
#include <stm32_ll_rtc.h>
2627
#ifdef CONFIG_RTC_ALARM
27-
#include <stm32_ll_exti.h>
28+
#include <zephyr/drivers/interrupt_controller/intc_exti_stm32.h>
2829
#endif /* CONFIG_RTC_ALARM */
2930

3031
#include <zephyr/logging/log.h>
@@ -93,11 +94,8 @@ LOG_MODULE_REGISTER(rtc_stm32, CONFIG_RTC_LOG_LEVEL);
9394
| RTC_ALARM_TIME_MASK_HOUR | RTC_ALARM_TIME_MASK_WEEKDAY \
9495
| RTC_ALARM_TIME_MASK_MONTHDAY)
9596

96-
#if DT_INST_NODE_HAS_PROP(0, alrm_exti_line)
97-
#define RTC_STM32_EXTI_LINE CONCAT(LL_EXTI_LINE_, DT_INST_PROP(0, alrm_exti_line))
98-
#else
99-
#define RTC_STM32_EXTI_LINE 0
100-
#endif /* DT_INST_NODE_HAS_PROP(0, alrm_exti_line) */
97+
#define RTC_STM32_EXTI_LINE_NUM DT_INST_PROP_OR(0, alrm_exti_line, 0)
98+
10199
#endif /* STM32_RTC_ALARM_ENABLED */
102100

103101
struct rtc_stm32_config {
@@ -131,6 +129,35 @@ struct rtc_stm32_data {
131129
#endif /* STM32_RTC_ALARM_ENABLED */
132130
};
133131

132+
#ifdef STM32_RTC_ALARM_ENABLED
133+
134+
static inline void exti_enable_rtc_alarm_it(uint32_t line_num)
135+
{
136+
#if defined(CONFIG_SOC_SERIES_STM32U5X) || defined(CONFIG_SOC_SERIES_STM32WBAX)
137+
/* in STM32U5 & STM32WBAX series, RTC Alarm event is not routed to EXTI */
138+
#else
139+
int ret;
140+
141+
ret = stm32_exti_enable(line_num, STM32_EXTI_TRIG_RISING, STM32_EXTI_MODE_IT);
142+
if (ret != 0) {
143+
LOG_ERR("Failed to enable EXTI line number %d (error %d)", line_num, ret);
144+
}
145+
#endif
146+
}
147+
148+
static inline void exti_clear_rtc_alarm_flag(uint32_t line_num)
149+
{
150+
#if defined(CONFIG_SOC_SERIES_STM32U5X) || defined(CONFIG_SOC_SERIES_STM32WBAX)
151+
/* in STM32U5 & STM32WBAX series, RTC Alarm (EXTI event) is not routed to EXTI */
152+
#else
153+
if (stm32_exti_is_pending(line_num)) {
154+
stm32_exti_clear_pending(line_num);
155+
}
156+
#endif
157+
}
158+
159+
#endif /* STM32_RTC_ALARM_ENABLED */
160+
134161
static int rtc_stm32_configure(const struct device *dev)
135162
{
136163
const struct rtc_stm32_config *cfg = dev->config;
@@ -305,7 +332,7 @@ void rtc_stm32_isr(const struct device *dev)
305332
}
306333
}
307334

308-
ll_func_exti_clear_rtc_alarm_flag(RTC_STM32_EXTI_LINE);
335+
exti_clear_rtc_alarm_flag(RTC_STM32_EXTI_LINE_NUM);
309336
}
310337

311338
static void rtc_stm32_irq_config(const struct device *dev)
@@ -404,7 +431,7 @@ static int rtc_stm32_init(const struct device *dev)
404431
#ifdef STM32_RTC_ALARM_ENABLED
405432
rtc_stm32_irq_config(dev);
406433

407-
ll_func_exti_enable_rtc_alarm_it(RTC_STM32_EXTI_LINE);
434+
exti_enable_rtc_alarm_it(RTC_STM32_EXTI_LINE_NUM);
408435

409436
K_SPINLOCK(&data->lock) {
410437
memset(&(data->rtc_alrm_a), 0, sizeof(struct rtc_stm32_alrm));
@@ -874,7 +901,7 @@ static int rtc_stm32_alarm_set_time(const struct device *dev, uint16_t id, uint1
874901
/* Enable Alarm IT */
875902
rtc_stm32_enable_interrupt_alarm(RTC, id);
876903

877-
ll_func_exti_enable_rtc_alarm_it(RTC_STM32_EXTI_LINE);
904+
exti_enable_rtc_alarm_it(RTC_STM32_EXTI_LINE_NUM);
878905

879906
/* Enable the write protection for RTC registers */
880907
LL_RTC_EnableWriteProtection(RTC);

drivers/rtc/rtc_ll_stm32.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2024 STMicroelectronics
3+
* Copyright (c) 2025 Alexander Kozhinov <[email protected]>
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -35,31 +36,6 @@
3536
#define RTC_STM32_ALRM_DATEWEEKDAYSEL_WEEKDAY LL_RTC_ALMA_DATEWEEKDAYSEL_WEEKDAY
3637
#define RTC_STM32_ALRM_DATEWEEKDAYSEL_DATE LL_RTC_ALMA_DATEWEEKDAYSEL_DATE
3738

38-
static inline void ll_func_exti_enable_rtc_alarm_it(uint32_t exti_line)
39-
{
40-
#if defined(CONFIG_SOC_SERIES_STM32H7X) && defined(CONFIG_CPU_CORTEX_M4)
41-
LL_C2_EXTI_EnableIT_0_31(exti_line);
42-
LL_EXTI_EnableRisingTrig_0_31(exti_line);
43-
#elif defined(CONFIG_SOC_SERIES_STM32U5X) || defined(CONFIG_SOC_SERIES_STM32WBAX)
44-
/* in STM32U5 & STM32WBAX series, RTC Alarm event is not routed to EXTI */
45-
#else
46-
LL_EXTI_EnableIT_0_31(exti_line);
47-
LL_EXTI_EnableRisingTrig_0_31(exti_line);
48-
#endif /* CONFIG_SOC_SERIES_STM32H7X and CONFIG_CPU_CORTEX_M4 */
49-
}
50-
51-
static inline void ll_func_exti_clear_rtc_alarm_flag(uint32_t exti_line)
52-
{
53-
#if defined(CONFIG_SOC_SERIES_STM32H7X) && defined(CONFIG_CPU_CORTEX_M4)
54-
LL_C2_EXTI_ClearFlag_0_31(exti_line);
55-
#elif defined(CONFIG_SOC_SERIES_STM32U5X) || defined(CONFIG_SOC_SERIES_STM32WBAX)
56-
/* in STM32U5 & STM32WBAX series, RTC Alarm event is not routed to EXTI */
57-
#elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32g0_exti)
58-
LL_EXTI_ClearRisingFlag_0_31(exti_line);
59-
#else
60-
LL_EXTI_ClearFlag_0_31(exti_line);
61-
#endif /* CONFIG_SOC_SERIES_STM32H7X and CONFIG_CPU_CORTEX_M4 */
62-
}
6339
#endif /* CONFIG_RTC_ALARM && !CONFIG_SOC_SERIES_STM32WB0X */
6440

6541
#endif /* ZEPHYR_DRIVERS_RTC_RTC_LL_STM32_H_ */

0 commit comments

Comments
 (0)