summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2023-09-18 22:10:10 +0200
committerDamien George <damien@micropython.org>2023-10-02 11:35:00 +1100
commit4e5611c55a4a82805ae972f8f9bc10ac2110ea19 (patch)
tree449a620bf5c1d6b17a77293a944ee943005acaf7
parent6482eb142c6d9b88b3897356d00399226056c603 (diff)
mimxrt/machine_rtc: Improve the RTC init at boot.
By clearing the tamper bits and enabling access to the registers for all code, just in case that this was set. It keeps the clock running on battery and the calibration setting. Signed-off-by: robert-hh <robert@hammelrath.com>
-rw-r--r--ports/mimxrt/Makefile1
-rw-r--r--ports/mimxrt/machine_rtc.c7
2 files changed, 8 insertions, 0 deletions
diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile
index 577cc9c1e..f44518a8a 100644
--- a/ports/mimxrt/Makefile
+++ b/ports/mimxrt/Makefile
@@ -137,6 +137,7 @@ SRC_HAL_IMX_C += \
$(MCU_DIR)/drivers/fsl_pit.c \
$(MCU_DIR)/drivers/fsl_pwm.c \
$(MCU_DIR)/drivers/fsl_sai.c \
+ $(MCU_DIR)/drivers/fsl_snvs_hp.c \
$(MCU_DIR)/drivers/fsl_snvs_lp.c \
$(MCU_DIR)/drivers/fsl_wdog.c \
$(MCU_DIR)/system_$(MCU_SERIES)$(MCU_CORE).c \
diff --git a/ports/mimxrt/machine_rtc.c b/ports/mimxrt/machine_rtc.c
index 702c1b903..54a19dacb 100644
--- a/ports/mimxrt/machine_rtc.c
+++ b/ports/mimxrt/machine_rtc.c
@@ -30,6 +30,7 @@
#include "modmachine.h"
#include "ticks.h"
#include "fsl_snvs_lp.h"
+#include "fsl_snvs_hp.h"
typedef struct _machine_rtc_obj_t {
mp_obj_base_t base;
@@ -41,6 +42,12 @@ STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}};
// Start the RTC Timer.
void machine_rtc_start(void) {
+ // Enable Non-Privileged Software Access
+ SNVS->HPCOMR |= SNVS_HPCOMR_NPSWA_EN_MASK;
+ // Do a basic init.
+ SNVS_LP_Init(SNVS);
+ // Disable all external Tamper
+ SNVS_LP_DisableAllExternalTamper(SNVS);
SNVS_LP_SRTC_StartTimer(SNVS);
// If the date is not set, set it to a more recent start date,