Skip to content

Commit 20d9780

Browse files
greavesinator85kartben
authored andcommitted
drivers: rtc: STM32U5XX rtc scalers
Allow RTC prescalers to be configurable via dts Signed-off-by: Jake Greaves <[email protected]>
1 parent 161d8a2 commit 20d9780

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

drivers/rtc/rtc_ll_stm32.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,17 +1110,17 @@ BUILD_ASSERT(DT_INST_CLOCKS_HAS_IDX(0, 1), "RTC source clock not defined in the
11101110
static const struct rtc_stm32_config rtc_config = {
11111111
#if DT_INST_CLOCKS_CELL_BY_IDX(0, 1, bus) == STM32_SRC_LSI
11121112
/* prescaler values for LSI @ 32 KHz */
1113-
.async_prescaler = 0x7F,
1114-
.sync_prescaler = 0x00F9,
1113+
.async_prescaler = DT_INST_PROP_OR(0, async_prescaler, 0x7F),
1114+
.sync_prescaler = DT_INST_PROP_OR(0, sync_prescaler, 0x00F9),
11151115
#elif DT_INST_CLOCKS_CELL_BY_IDX(0, 1, bus) == STM32_SRC_LSE
11161116
/* prescaler values for LSE @ 32768 Hz */
1117-
.async_prescaler = 0x7F,
1118-
.sync_prescaler = 0x00FF,
1117+
.async_prescaler = DT_INST_PROP_OR(0, async_prescaler, 0x7F),
1118+
.sync_prescaler = DT_INST_PROP_OR(0, sync_prescaler, 0x00FF),
11191119
#elif DT_INST_CLOCKS_CELL_BY_IDX(0, 1, bus) == STM32_SRC_HSE
11201120
/* prescaler values for HSE */
1121-
.async_prescaler = RTC_HSE_ASYNC_PRESCALER - 1,
1122-
.sync_prescaler = RTC_HSE_SYNC_PRESCALER - 1,
1123-
.hse_prescaler = RTC_HSE_PRESCALER,
1121+
.async_prescaler = DT_INST_PROP_OR(0, async_prescaler, RTC_HSE_ASYNC_PRESCALER - 1),
1122+
.sync_prescaler = DT_INST_PROP_OR(0, sync_prescaler, RTC_HSE_SYNC_PRESCALER - 1),
1123+
.hse_prescaler = DT_INST_PROP_OR(0, hse_prescaler, RTC_HSE_PRESCALER),
11241124
#else
11251125
#error Invalid RTC SRC
11261126
#endif

dts/bindings/rtc/st,stm32-rtc.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ properties:
1414
reg:
1515
required: true
1616

17+
sync-prescaler:
18+
type: int
19+
description: |
20+
RTC synchronous prescaler value. Optional, if not set defaulted in code to:
21+
- Selected to give 1 Hz tick rate, based on source clock frequency and asynchronous
22+
prescaler value.
23+
24+
async-prescaler:
25+
type: int
26+
description: |
27+
RTC asynchronous prescaler value. Optional, if not set defaulted in code to:
28+
- 0x7F if RTC source clock is LSE/LSI
29+
- 1 if using counter with CONFIG_COUNTER_RTC_STM32_SUBSECONDS option
30+
- 0x7C if RTC source clock is HSE
31+
32+
hse-prescaler:
33+
type: int
34+
description: |
35+
RTC HSE prescaler value. Applies only when RTC source clock is HSE.
36+
Optional, defaulting to the value calculated based on HSE clock frequency
37+
to give the highest possibly prescaled source frequency below 1MHz.
38+
1739
calib-out-freq:
1840
type: int
1941
description: |

0 commit comments

Comments
 (0)