Skip to content

Commit f00ba5f

Browse files
committed
[H7] Fix RTC clock init
H7 RCC_RTCCLKSOURCE_HSE_DIVn are up to 63. Shift is less also 12 bits instead 16. Signed-off-by: Frederic.Pillon <[email protected]>
1 parent d4edc4a commit f00ba5f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: cores/arduino/stm32/rtc.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,16 @@ static void RTC_initClock(sourceClock_t source)
146146
#ifndef RCC_RTCCLKSOURCE_HSE_DIVX
147147
#define RCC_RTCCLKSOURCE_HSE_DIVX 0x00000300U
148148
#endif /* RCC_RTCCLKSOURCE_HSE_DIVX */
149-
for (HSEDiv = 2; HSEDiv < 32; HSEDiv++) {
149+
#if defined(STM32H7xx)
150+
#define HSEDIV_MAX 64
151+
#define HSESHIFT 12
152+
#else
153+
#define HSEDIV_MAX 32
154+
#define HSESHIFT 16
155+
#endif
156+
for (HSEDiv = 2; HSEDiv < HSEDIV_MAX; HSEDiv++) {
150157
if ((HSE_VALUE / HSEDiv) <= HSE_RTC_MAX) {
151-
PeriphClkInit.RTCClockSelection = (HSEDiv << 16) | RCC_RTCCLKSOURCE_HSE_DIVX;
158+
PeriphClkInit.RTCClockSelection = (HSEDiv << HSESHIFT) | RCC_RTCCLKSOURCE_HSE_DIVX;
152159
break;
153160
}
154161
}

0 commit comments

Comments
 (0)