This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit ce90f2aac80bfa2b3c3f2569924f93157f6d6edc
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Wed Nov 22 09:19:00 2023 +0100

    mcu/stm32: Use ST HAL for hal_nvreg
    
    hal_nvreg relied on BPKxR registers being part of RTC
    peripheral.
    This is not the case for all STM32 devices.
    Some H7 and some L0 devices and G0 have backup registers in
    TAMP peripheral.
    
    Fortunately ST provides HAL_RTCEx_BKUPWrite/HAL_RTCEx_BKUPRead
    functions for all devices and those will be used instead of
    previous implementation that assumes that RTC should be used.
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 hw/mcu/stm/stm32_common/src/hal_nvreg.c | 53 ++++-----------------------------
 1 file changed, 5 insertions(+), 48 deletions(-)

diff --git a/hw/mcu/stm/stm32_common/src/hal_nvreg.c 
b/hw/mcu/stm/stm32_common/src/hal_nvreg.c
index 20b9a2b83..c2953aa21 100644
--- a/hw/mcu/stm/stm32_common/src/hal_nvreg.c
+++ b/hw/mcu/stm/stm32_common/src/hal_nvreg.c
@@ -20,7 +20,7 @@
 #include <hal/hal_nvreg.h>
 #include <mcu/stm32_hal.h>
 
-#if defined(RTC_BACKUP_SUPPORT) && defined(HAL_PWR_MODULE_ENABLED)
+#if (defined(RTC_BACKUP_SUPPORT) || defined(RTC_BKP_NUMBER)) && 
defined(HAL_PWR_MODULE_ENABLED)
 #define PWR_ENABLED 1
 #endif
 
@@ -33,58 +33,14 @@
 /* RTC backup registers are 32-bits wide */
 #define HAL_NVREG_WIDTH_BYTES (4)
 
-#if PWR_ENABLED
-static volatile uint32_t *regs[HAL_NVREG_MAX] = {
-#if HAL_NVREG_MAX > 0
-    &RTC->BKP0R,
-    &RTC->BKP1R,
-    &RTC->BKP2R,
-    &RTC->BKP3R,
-    &RTC->BKP4R,
-#endif /* HAL_NVREG_MAX > 0 */
-#if HAL_NVREG_MAX > 5
-    &RTC->BKP5R,
-    &RTC->BKP6R,
-    &RTC->BKP7R,
-    &RTC->BKP8R,
-    &RTC->BKP9R,
-    &RTC->BKP10R,
-    &RTC->BKP11R,
-    &RTC->BKP12R,
-    &RTC->BKP13R,
-    &RTC->BKP14R,
-    &RTC->BKP15R,
-#endif /* HAL_NVREG_MAX > 5 */
-#if HAL_NVREG_MAX > 16
-    &RTC->BKP16R,
-    &RTC->BKP17R,
-    &RTC->BKP18R,
-    &RTC->BKP19R,
-#endif /* HAL_NVREG_MAX > 16 */
-#if HAL_NVREG_MAX > 20
-    &RTC->BKP20R,
-    &RTC->BKP21R,
-    &RTC->BKP22R,
-    &RTC->BKP23R,
-    &RTC->BKP24R,
-    &RTC->BKP25R,
-    &RTC->BKP26R,
-    &RTC->BKP27R,
-    &RTC->BKP28R,
-    &RTC->BKP29R,
-    &RTC->BKP30R,
-    &RTC->BKP31R,
-#endif /* HAL_NVREG_MAX > 20 */
-};
-#endif /* PWR_ENABLED */
-
 void
 hal_nvreg_write(unsigned int reg, uint32_t val)
 {
 #if PWR_ENABLED
+    RTC_HandleTypeDef hrtc = { .Instance = RTC };
     if (reg < HAL_NVREG_MAX) {
         HAL_PWR_EnableBkUpAccess();
-        *regs[reg] = val;
+        HAL_RTCEx_BKUPWrite(&hrtc, reg, val);
         HAL_PWR_DisableBkUpAccess();
     }
 #endif
@@ -95,9 +51,10 @@ hal_nvreg_read(unsigned int reg)
 {
     uint32_t val = 0;
 #if PWR_ENABLED
+    RTC_HandleTypeDef hrtc = { .Instance = RTC };
     if (reg < HAL_NVREG_MAX) {
         HAL_PWR_EnableBkUpAccess();
-        val = *regs[reg];
+        val = HAL_RTCEx_BKUPRead(&hrtc, reg);
         HAL_PWR_DisableBkUpAccess();
     }
 #endif

Reply via email to