Skip to content

Commit 5af2264

Browse files
mathieuchopstmkartben
authored andcommitted
drivers: rtc: stm32: handle STM32WB0 series when RTC_ALARM is enabled
RTC alarm is not supported by the driver for now due to the complexity it would take to work around an hardware erratum. However, it is not possible to prevent CONFIG_RTC_ALARM from being enabled at Kconfig level. Modify the RTC driver such that enabling CONFIG_RTC_ALARM on STM32WB0 series does not cause build errors anymore. Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
1 parent 4a9f883 commit 5af2264

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

drivers/rtc/rtc_ll_stm32.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ LOG_MODULE_REGISTER(rtc_stm32, CONFIG_RTC_LOG_LEVEL);
7878
/* Timeout in microseconds used to wait for flags */
7979
#define RTC_TIMEOUT 1000000
8080

81-
#ifdef CONFIG_RTC_ALARM
81+
#ifdef STM32_RTC_ALARM_ENABLED
8282
#define RTC_STM32_ALARMS_COUNT DT_INST_PROP(0, alarms_count)
8383

8484
#define RTC_STM32_ALRM_A 0U
@@ -95,7 +95,7 @@ LOG_MODULE_REGISTER(rtc_stm32, CONFIG_RTC_LOG_LEVEL);
9595
#else
9696
#define RTC_STM32_EXTI_LINE 0
9797
#endif /* DT_INST_NODE_HAS_PROP(0, alrm_exti_line) */
98-
#endif /* CONFIG_RTC_ALARM */
98+
#endif /* STM32_RTC_ALARM_ENABLED */
9999

100100
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
101101
/*
@@ -120,7 +120,7 @@ struct rtc_stm32_config {
120120
#endif
121121
};
122122

123-
#ifdef CONFIG_RTC_ALARM
123+
#ifdef STM32_RTC_ALARM_ENABLED
124124
struct rtc_stm32_alrm {
125125
LL_RTC_AlarmTypeDef ll_rtc_alrm;
126126
/* user-defined alarm mask, values from RTC_ALARM_TIME_MASK */
@@ -129,14 +129,14 @@ struct rtc_stm32_alrm {
129129
void *user_data;
130130
bool is_pending;
131131
};
132-
#endif /* CONFIG_RTC_ALARM */
132+
#endif /* STM32_RTC_ALARM_ENABLED */
133133

134134
struct rtc_stm32_data {
135135
struct k_mutex lock;
136-
#ifdef CONFIG_RTC_ALARM
136+
#ifdef STM32_RTC_ALARM_ENABLED
137137
struct rtc_stm32_alrm rtc_alrm_a;
138138
struct rtc_stm32_alrm rtc_alrm_b;
139-
#endif /* CONFIG_RTC_ALARM */
139+
#endif /* STM32_RTC_ALARM_ENABLED */
140140
};
141141

142142
static int rtc_stm32_configure(const struct device *dev)
@@ -185,7 +185,7 @@ static int rtc_stm32_configure(const struct device *dev)
185185
return err;
186186
}
187187

188-
#ifdef CONFIG_RTC_ALARM
188+
#ifdef STM32_RTC_ALARM_ENABLED
189189
static inline ErrorStatus rtc_stm32_init_alarm(RTC_TypeDef *rtc, uint32_t format,
190190
LL_RTC_AlarmTypeDef *ll_alarm_struct, uint16_t id)
191191
{
@@ -329,7 +329,7 @@ static void rtc_stm32_irq_config(const struct device *dev)
329329
rtc_stm32_isr, DEVICE_DT_INST_GET(0), 0);
330330
irq_enable(DT_INST_IRQN(0));
331331
}
332-
#endif /* CONFIG_RTC_ALARM */
332+
#endif /* STM32_RTC_ALARM_ENABLED */
333333

334334
static int rtc_stm32_init(const struct device *dev)
335335
{
@@ -421,7 +421,7 @@ static int rtc_stm32_init(const struct device *dev)
421421
LL_PWR_DisableBkUpAccess();
422422
#endif /* RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION */
423423

424-
#ifdef CONFIG_RTC_ALARM
424+
#ifdef STM32_RTC_ALARM_ENABLED
425425
rtc_stm32_irq_config(dev);
426426

427427
ll_func_exti_enable_rtc_alarm_it(RTC_STM32_EXTI_LINE);
@@ -430,7 +430,7 @@ static int rtc_stm32_init(const struct device *dev)
430430
memset(&(data->rtc_alrm_a), 0, sizeof(struct rtc_stm32_alrm));
431431
memset(&(data->rtc_alrm_b), 0, sizeof(struct rtc_stm32_alrm));
432432
k_mutex_unlock(&data->lock);
433-
#endif /* CONFIG_RTC_ALARM */
433+
#endif /* STM32_RTC_ALARM_ENABLED */
434434

435435
return err;
436436
}
@@ -600,7 +600,7 @@ static int rtc_stm32_get_time(const struct device *dev, struct rtc_time *timeptr
600600
return 0;
601601
}
602602

603-
#ifdef CONFIG_RTC_ALARM
603+
#ifdef STM32_RTC_ALARM_ENABLED
604604
static void rtc_stm32_init_ll_alrm_struct(LL_RTC_AlarmTypeDef *p_rtc_alarm,
605605
const struct rtc_time *timeptr, uint16_t mask)
606606
{
@@ -995,7 +995,7 @@ static int rtc_stm32_alarm_is_pending(const struct device *dev, uint16_t id)
995995
k_mutex_unlock(&data->lock);
996996
return ret;
997997
}
998-
#endif /* CONFIG_RTC_ALARM */
998+
#endif /* STM32_RTC_ALARM_ENABLED */
999999

10001000
#ifdef CONFIG_RTC_CALIBRATION
10011001
#if !defined(CONFIG_SOC_SERIES_STM32F2X) && \
@@ -1078,13 +1078,13 @@ static int rtc_stm32_get_calibration(const struct device *dev, int32_t *calibrat
10781078
static DEVICE_API(rtc, rtc_stm32_driver_api) = {
10791079
.set_time = rtc_stm32_set_time,
10801080
.get_time = rtc_stm32_get_time,
1081-
#ifdef CONFIG_RTC_ALARM
1081+
#ifdef STM32_RTC_ALARM_ENABLED
10821082
.alarm_get_supported_fields = rtc_stm32_alarm_get_supported_fields,
10831083
.alarm_set_time = rtc_stm32_alarm_set_time,
10841084
.alarm_get_time = rtc_stm32_alarm_get_time,
10851085
.alarm_set_callback = rtc_stm32_alarm_set_callback,
10861086
.alarm_is_pending = rtc_stm32_alarm_is_pending,
1087-
#endif /* CONFIG_RTC_ALARM */
1087+
#endif /* STM32_RTC_ALARM_ENABLED */
10881088
#ifdef CONFIG_RTC_CALIBRATION
10891089
#if !defined(CONFIG_SOC_SERIES_STM32F2X) && \
10901090
!(defined(CONFIG_SOC_SERIES_STM32L1X) && !defined(RTC_SMOOTHCALIB_SUPPORT))

drivers/rtc/rtc_ll_stm32.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@
77
#ifndef ZEPHYR_DRIVERS_RTC_RTC_LL_STM32_H_
88
#define ZEPHYR_DRIVERS_RTC_RTC_LL_STM32_H_
99

10-
#ifdef CONFIG_RTC_ALARM
10+
/**
11+
* ES0584 / ES0631 §2.5.2; ES0632 §2.6.2 (both Rev. 2)
12+
* """
13+
* RTC interrupts cannot be reliably used for real-time
14+
* control functions, since some occurences of RTC
15+
* interrupts may be missed.
16+
* """
17+
* Since alarm IRQs are unreliable, don't allow RTC alarm
18+
* to be used on STM32WB0 series. For this, we have to
19+
* create a #define only valid when both the Kconfig is
20+
* enabled, and we're on a supported series. This must
21+
* be done because the RTC driver has to build properly
22+
* on all targets regardless of which Kconfig options have
23+
* been enabled.
24+
*/
25+
#if defined(CONFIG_RTC_ALARM) && !defined(CONFIG_SOC_SERIES_STM32WB0X)
26+
#define STM32_RTC_ALARM_ENABLED 1
1127

1228
/* STM32 RTC alarms, A & B, LL masks are equal */
1329
#define RTC_STM32_ALRM_MASK_ALL LL_RTC_ALMA_MASK_ALL
@@ -44,6 +60,6 @@ static inline void ll_func_exti_clear_rtc_alarm_flag(uint32_t exti_line)
4460
LL_EXTI_ClearFlag_0_31(exti_line);
4561
#endif /* CONFIG_SOC_SERIES_STM32H7X and CONFIG_CPU_CORTEX_M4 */
4662
}
47-
#endif /* CONFIG_RTC_ALARM */
63+
#endif /* CONFIG_RTC_ALARM && !CONFIG_SOC_SERIES_STM32WB0X */
4864

4965
#endif /* ZEPHYR_DRIVERS_RTC_RTC_LL_STM32_H_ */

0 commit comments

Comments
 (0)