summaryrefslogtreecommitdiff
path: root/stmhal/modmachine.c
diff options
context:
space:
mode:
authorT S <tsp@esg-workstation.com>2015-11-07 12:03:12 +0100
committerDamien George <damien.p.george@gmail.com>2015-11-23 23:23:07 +0000
commit86aa16bea61da8a8d156a7a928902a0bf4c85b73 (patch)
tree27afb25b8dc0a6f78ed17951a5f07ba438d82fda /stmhal/modmachine.c
parent4dea24e10590928310f3b03703e966c9f774871c (diff)
stmhal: Implement delayed RTC initialization with LSI fallback.
If RTC is already running at boot then it's left alone. Otherwise, RTC is started at boot but startup function returns straight away. RTC startup is then finished the first time it is used. Fallback to LSI if LSE fails to start in a certain time. Also included: MICROPY_HW_CLK_LAST_FREQ hold pyb.freq() parameters in RTC backup reg MICROPY_HW_RTC_USE_US option to present datetime sub-seconds in microseconds MICROPY_HW_RTC_USE_CALOUT option to enable RTC calibration output CLK_LAST_FREQ and RTC_USE_CALOUT are enabled for PYBv1.0.
Diffstat (limited to 'stmhal/modmachine.c')
-rw-r--r--stmhal/modmachine.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c
index c495573fb..25977e789 100644
--- a/stmhal/modmachine.c
+++ b/stmhal/modmachine.c
@@ -39,6 +39,7 @@
#include "pin.h"
#include "timer.h"
#include "usb.h"
+#include "rtc.h"
#include "i2c.h"
#include "spi.h"
@@ -281,6 +282,9 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
} else {
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
}
+ uint32_t h = RCC_ClkInitStruct.AHBCLKDivider >> 4;
+ uint32_t b1 = RCC_ClkInitStruct.APB1CLKDivider >> 10;
+ uint32_t b2 = RCC_ClkInitStruct.APB2CLKDivider >> 10;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
goto fail;
}
@@ -312,6 +316,23 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
// re-init TIM3 for USB CDC rate
timer_tim3_init();
+ #if defined(MICROPY_HW_CLK_LAST_FREQ) && MICROPY_HW_CLK_LAST_FREQ
+ #if defined(MCU_SERIES_F7)
+ #define FREQ_BKP BKP31R
+ #else
+ #define FREQ_BKP BKP19R
+ #endif
+ // qqqqqqqq pppppppp nnnnnnnn nnmmmmmm
+ // qqqqQQQQ ppppppPP nNNNNNNN NNMMMMMM
+ // 222111HH HHQQQQPP nNNNNNNN NNMMMMMM
+ p = (p / 2) - 1;
+ RTC->FREQ_BKP = m
+ | (n << 6) | (p << 16) | (q << 18)
+ | (h << 22)
+ | (b1 << 26)
+ | (b2 << 29);
+ #endif
+
return mp_const_none;
fail:;
@@ -349,6 +370,8 @@ STATIC mp_obj_t machine_sleep(void) {
MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep);
STATIC mp_obj_t machine_deepsleep(void) {
+ rtc_init_finalise();
+
#if defined(MCU_SERIES_F7)
printf("machine.deepsleep not supported yet\n");
#else