From 49cf92f5e6f1e1dbfac7c9f9301be657f645ad80 Mon Sep 17 00:00:00 2001 From: jflyper Date: Mon, 8 Jul 2019 01:38:22 +0900 Subject: [PATCH] [G4] Persistent object support --- src/main/drivers/persistent.c | 15 +++++++++++++++ src/main/drivers/system.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/persistent.c b/src/main/drivers/persistent.c index bc937093f..eee8fed59 100644 --- a/src/main/drivers/persistent.c +++ b/src/main/drivers/persistent.c @@ -51,18 +51,33 @@ void persistentObjectWrite(persistentObjectId_e id, uint32_t value) void persistentObjectRTCEnable(void) { +#if !defined(STM32G4) + // G4 library V1.0.0 __HAL_RTC_WRITEPROTECTION_ENABLE/DISABLE macro does not use handle parameter RTC_HandleTypeDef rtcHandle = { .Instance = RTC }; +#endif #if !defined(STM32H7) __HAL_RCC_PWR_CLK_ENABLE(); // Enable Access to PWR #endif + HAL_PWR_EnableBkUpAccess(); // Disable backup domain protection +#if defined(STM32G4) + /* Enable RTC APB clock */ + __HAL_RCC_RTCAPB_CLK_ENABLE(); + + /* Peripheral clock enable */ + __HAL_RCC_RTC_ENABLE(); + +#else // !STM32G4, F7 and H7 case + #if defined(__HAL_RCC_RTC_CLK_ENABLE) // For those MCUs with RTCAPBEN bit in RCC clock enable register, turn it on. __HAL_RCC_RTC_CLK_ENABLE(); // Enable RTC module #endif +#endif // STM32G4 + // We don't need a clock source for RTC itself. Skip it. __HAL_RTC_WRITEPROTECTION_ENABLE(&rtcHandle); // Reset sequence diff --git a/src/main/drivers/system.h b/src/main/drivers/system.h index 3d5b01229..86c1066b9 100644 --- a/src/main/drivers/system.h +++ b/src/main/drivers/system.h @@ -66,7 +66,7 @@ bool isMPUSoftReset(void); void cycleCounterInit(void); uint32_t clockCyclesToMicros(uint32_t clockCycles); uint32_t getCycleCounter(void); -#if defined(STM32H7) +#if defined(STM32H7) || defined(STM32G4) void systemCheckResetReason(void); #endif