From ac3953dc77e789a80cf7547c0277ce80202b8830 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Wed, 28 Aug 2024 16:55:52 +0200 Subject: [PATCH 1/4] feat(u0): add STM32U0xx support Signed-off-by: Frederic Pillon --- src/rtc.c | 4 ++-- src/rtc.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rtc.c b/src/rtc.c index f3e0bca..15fa727 100644 --- a/src/rtc.c +++ b/src/rtc.c @@ -1194,8 +1194,8 @@ void RTC_Alarm_IRQHandler(void) #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \ defined(STM32F091xC) || defined(STM32F098xx) || defined(STM32F070xB) || \ defined(STM32F030xC) || defined(STM32G0xx) || defined(STM32H5xx) || \ - defined(STM32L0xx) || defined(STM32L5xx) || defined(STM32U5xx) || \ - defined(STM32WBAxx) + defined(STM32L0xx) || defined(STM32L5xx) || defined(STM32U0xx) ||\ + defined(STM32U5xx) || defined(STM32WBAxx) // In some cases, the same vector is used to manage WakeupTimer, // but with a dedicated HAL IRQHandler HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle); diff --git a/src/rtc.h b/src/rtc.h index 80319e4..365698e 100644 --- a/src/rtc.h +++ b/src/rtc.h @@ -134,7 +134,7 @@ typedef void(*voidCallbackPtr)(void *); #define RTC_Alarm_IRQn RTC_IRQn #define RTC_Alarm_IRQHandler RTC_IRQHandler #endif -#if defined(STM32G0xx) +#if defined(STM32G0xx) || defined(STM32U0xx) #define RTC_Alarm_IRQn RTC_TAMP_IRQn #define RTC_Alarm_IRQHandler RTC_TAMP_IRQHandler #endif @@ -148,7 +148,7 @@ typedef void(*voidCallbackPtr)(void *); #elif defined(STM32MP1xx) // global RTC interrupt #define ONESECOND_IRQn RTC_WKUP_ALARM_IRQn -#elif defined(STM32G0xx) +#elif defined(STM32G0xx) || defined(STM32U0xx) // global RTC/TAMP interrupt #define ONESECOND_IRQn RTC_TAMP_IRQn #elif defined(CORE_CM0PLUS) && \ From d1eed86f7ce07d06c1b461372d95b6386739fa39 Mon Sep 17 00:00:00 2001 From: Martin Schuster Date: Sun, 24 Nov 2024 19:36:10 +0100 Subject: [PATCH 2/4] Avoid overflow during conversion from ms to ticks. E.g. when having predivSync=255, a value of subSeconds=2^24 (still well below UINT32_MAX and thus using the 32bit computation branch) would be multiplied by 256 and result in an overflow during computation. In fact, 2^24 ms is about 4 hours 40 minutes. --- src/rtc.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/rtc.c b/src/rtc.c index 15fa727..904c11c 100644 --- a/src/rtc.c +++ b/src/rtc.c @@ -947,14 +947,11 @@ void RTC_StartAlarm64(alarm_t name, uint8_t day, uint8_t hours, uint8_t minutes, if ((initMode == MODE_BINARY_ONLY) || (initMode == MODE_BINARY_MIX)) { /* We have an SubSecond alarm to set in RTC_BINARY_MIX or RTC_BINARY_ONLY mode */ /* The subsecond in ms is converted in ticks unit 1 tick is 1000 / fqce_apre - * It keeps the subsecond accuracy on 64 bits if needed + * For the conversion, we keep the accuracy on 64 bits, since otherwise we might + * have an overflow even though the conversion result still fits in 32 bits. */ - if (subSeconds > (uint64_t)UINT32_MAX) { - uint64_t tmp = (subSeconds * (uint64_t)(predivSync + 1)) / (uint64_t)1000; - RTC_AlarmStructure.AlarmTime.SubSeconds = (uint32_t)UINT32_MAX - (uint32_t)tmp; - } else { - RTC_AlarmStructure.AlarmTime.SubSeconds = (uint32_t)((uint32_t)UINT32_MAX - (uint32_t)(subSeconds * (predivSync + 1)) / 1000); - } + uint64_t tmp = (subSeconds * (uint64_t)(predivSync + 1)) / (uint64_t)1000; + RTC_AlarmStructure.AlarmTime.SubSeconds = (uint32_t)UINT32_MAX - (uint32_t)tmp; } else #endif /* RTC_ICSR_BIN */ { From afae297bd52d6ebd8d134d22678116bc7ea40e5c Mon Sep 17 00:00:00 2001 From: Martin Schuster Date: Sun, 24 Nov 2024 19:36:10 +0100 Subject: [PATCH 3/4] chore(ci): add new series to core config STM32UOx and STM32WBAx Signed-off-by: Frederic Pillon --- extras/rtc_cores_config.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extras/rtc_cores_config.json b/extras/rtc_cores_config.json index 32a8293..3190b19 100644 --- a/extras/rtc_cores_config.json +++ b/extras/rtc_cores_config.json @@ -811,7 +811,7 @@ { "pattern": "^[^F][^1].*", "applicable": true, - "boards": [ + "boards": [ "NUCLEO_C031C6", "NUCLEO_F091RC", "NUCLEO_F103RB", @@ -829,8 +829,10 @@ "NUCLEO_L452REP", "NUCLEO_L4R5ZI_P", "NUCLEO_L552ZE_Q", + "NUCLEO_U083RC", "NUCLEO_U575ZI_Q", "NUCLEO_WB15CC", + "NUCLEO_WBA55CG", "NUCLEO_WL55JC1" ] }, @@ -842,7 +844,7 @@ { "pattern": "RTC_Seconds", "applicable": false, - "boards": [ + "boards": [ "NUCLEO_C031C6" ] } From a3036e0e9605ddc0e13c7cc259082bfe394b6e77 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Wed, 27 Nov 2024 17:08:28 +0100 Subject: [PATCH 4/4] chore: update library version Signed-off-by: Frederic Pillon --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index c485639..cf4eec8 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/stm32duino/STM32RTC" }, - "version": "1.5.0", + "version": "1.6.0", "frameworks": "arduino", "platforms": "ststm32", "build": { diff --git a/library.properties b/library.properties index 814896b..50700df 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duino RTC -version=1.5.0 +version=1.6.0 author=STMicroelectronics maintainer=stm32duino sentence=Allows to use the RTC functionalities of STM32 based boards.