diff options
-rw-r--r-- | stmhal/boards/PYBV10/mpconfigboard.h | 3 | ||||
-rw-r--r-- | stmhal/boards/PYBV3/mpconfigboard.h | 3 | ||||
-rw-r--r-- | stmhal/boards/PYBV4/mpconfigboard.h | 3 | ||||
-rw-r--r-- | stmhal/rtc.c | 13 |
4 files changed, 21 insertions, 1 deletions
diff --git a/stmhal/boards/PYBV10/mpconfigboard.h b/stmhal/boards/PYBV10/mpconfigboard.h index fd203a17b8..cb14efe49e 100644 --- a/stmhal/boards/PYBV10/mpconfigboard.h +++ b/stmhal/boards/PYBV10/mpconfigboard.h @@ -20,6 +20,9 @@ #define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) +// The pyboard has a 32kHz crystal for the RTC +#define MICROPY_HW_RTC_USE_LSE (1) + // USRSW has no pullup or pulldown, and pressing the switch makes the input go low #define MICROPY_HW_USRSW_PIN (pin_B3) #define MICROPY_HW_USRSW_PULL (GPIO_PULLUP) diff --git a/stmhal/boards/PYBV3/mpconfigboard.h b/stmhal/boards/PYBV3/mpconfigboard.h index 011fc639c6..2b387554e7 100644 --- a/stmhal/boards/PYBV3/mpconfigboard.h +++ b/stmhal/boards/PYBV3/mpconfigboard.h @@ -19,6 +19,9 @@ #define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) +// The pyboard has a 32kHz crystal for the RTC +#define MICROPY_HW_RTC_USE_LSE (1) + // USRSW has no pullup or pulldown, and pressing the switch makes the input go low #define MICROPY_HW_USRSW_PIN (pin_A13) #define MICROPY_HW_USRSW_PULL (GPIO_PULLUP) diff --git a/stmhal/boards/PYBV4/mpconfigboard.h b/stmhal/boards/PYBV4/mpconfigboard.h index bbb05ae588..61b161028b 100644 --- a/stmhal/boards/PYBV4/mpconfigboard.h +++ b/stmhal/boards/PYBV4/mpconfigboard.h @@ -19,6 +19,9 @@ #define MICROPY_HW_ENABLE_SPI3 (0) #define MICROPY_HW_ENABLE_CAN (1) +// The pyboard has a 32kHz crystal for the RTC +#define MICROPY_HW_RTC_USE_LSE (1) + // USRSW has no pullup or pulldown, and pressing the switch makes the input go low #define MICROPY_HW_USRSW_PIN (pin_B3) #define MICROPY_HW_USRSW_PULL (GPIO_PULLUP) diff --git a/stmhal/rtc.c b/stmhal/rtc.c index 2bbe5b10cf..b4fa69e862 100644 --- a/stmhal/rtc.c +++ b/stmhal/rtc.c @@ -256,18 +256,29 @@ void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc) { __HAL_RCC_BACKUPRESET_RELEASE(). - Configure the needed RTc clock source */ - // set LSE as RTC clock source + // RTC clock source uses LSE (external crystal) only if relevant + // configuration variable is set. Otherwise it uses LSI (internal osc). + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + #if defined(MICROPY_HW_RTC_USE_LSE) && MICROPY_HW_RTC_USE_LSE RCC_OscInitStruct.LSEState = RCC_LSE_ON; RCC_OscInitStruct.LSIState = RCC_LSI_OFF; + #else + RCC_OscInitStruct.LSEState = RCC_LSE_OFF; + RCC_OscInitStruct.LSIState = RCC_LSI_ON; + #endif if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { //Error_Handler(); return; } PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; + #if defined(MICROPY_HW_RTC_USE_LSE) && MICROPY_HW_RTC_USE_LSE PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; + #else + PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI; + #endif if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { //Error_Handler(); return; |