From 66972e1fd84bdb0a97324470390bc33846502764 Mon Sep 17 00:00:00 2001 From: Aymane Bahssain Date: Mon, 2 Feb 2026 14:30:26 +0100 Subject: [PATCH] fix(RTC): RTC_Tests example for new STM32RTC prediv API (uint32_t) - use uint32_t for userPredA, userPredS and local prediv variables (a, s), - call rtc.getPrediv() and rtc.setPrediv() with uint32_t arguments, - use PREDIVA_MAX + 1 and PREDIVS_MAX + 1 to reset prescalers to computed values REF: https://github.com/stm32duino/STM32RTC/commit/9d07ee5d5865488788aa32c2c2dd658fa4cda9f6 Signed-off-by: Aymane Bahssain --- examples/NonReg/RTC/RTC_Tests/RTC_Tests.ino | 24 +++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/examples/NonReg/RTC/RTC_Tests/RTC_Tests.ino b/examples/NonReg/RTC/RTC_Tests/RTC_Tests.ino index d034413..5d66579 100644 --- a/examples/NonReg/RTC/RTC_Tests/RTC_Tests.ino +++ b/examples/NonReg/RTC/RTC_Tests/RTC_Tests.ino @@ -38,12 +38,8 @@ static const char* mytime = __TIME__; clk = RTCCLK / ((predA +1) * (predS +1)) clk = 1000000 / ((99 +1) * (9999+1)) = 1 Hz */ -#if defined(STM32F1xx) static uint32_t userPredA = 99; -#else -static int8_t userPredA = 99; -#endif /* STM32F1xx */ -static int16_t userPredS = 9999; +static uint32_t userPredS = 9999; /* */ static byte seconds = 0; @@ -112,35 +108,35 @@ void loop() #if defined(STM32F1xx) Serial.println("Testing only asynchronous prescaler setting"); - uint32_t a; #else Serial.println("Testing asynchronous and synchronous prescaler setting"); - int8_t a; #endif /* STM32F1xx */ - int16_t s = 0; + uint32_t a = 0; + uint32_t s = 0; + rtc.getPrediv(&a, &s); Serial.print("Async/Sync for default LSI clock: "); - Serial.printf("%i/%i\n", a, s); + Serial.printf("%lu/%lu\n", (unsigned long)a, (unsigned long)s); rtc_config(clkSource, rtc.HOUR_24, mydate, mytime); Serial.print("Async/Sync for selected clock: "); rtc.getPrediv(&a, &s); - Serial.printf("%i/%i\n", a, s); + Serial.printf("%lu/%lu\n", (unsigned long)a, (unsigned long)s); rtc.end(); if (clkSource == rtc.HSE_CLOCK) { - Serial.printf("User Async/Sync set to %i/%i:", userPredA, userPredS); + Serial.printf("User Async/Sync set to %lu/%lu:", (unsigned long)userPredA, (unsigned long)userPredS); rtc.setPrediv(userPredA, userPredS); rtc_config(clkSource, rtc.HOUR_24, mydate, mytime); rtc.getPrediv(&a, &s); - Serial.printf("%i/%i\n", a, s); + Serial.printf("%lu/%lu\n", (unsigned long)a, (unsigned long)s); printDateTime(10, 1000, false); } Serial.print("User Async/Sync reset to use the computed one: "); - rtc.setPrediv(-1, -1); + rtc.setPrediv(PREDIVA_MAX + 1, PREDIVS_MAX + 1); rtc_config(clkSource, rtc.HOUR_24, mydate, mytime); rtc.getPrediv(&a, &s); - Serial.printf("%i/%i\n", a, s); + Serial.printf("%lu/%lu\n", (unsigned long)a, (unsigned long)s); // Check date change Serial.println("Testing date and time");