stmhal: Add config option to use LSE/LSI for RTC.
Most boards (except the pyboard) don't have a 32kHz crystal so they should use the LSI for the RTC.
This commit is contained in:
parent
3cb766344d
commit
49fe6dc89a
@ -20,6 +20,9 @@
|
|||||||
#define MICROPY_HW_ENABLE_SPI3 (0)
|
#define MICROPY_HW_ENABLE_SPI3 (0)
|
||||||
#define MICROPY_HW_ENABLE_CAN (1)
|
#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
|
// 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_PIN (pin_B3)
|
||||||
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)
|
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
#define MICROPY_HW_ENABLE_SPI3 (0)
|
#define MICROPY_HW_ENABLE_SPI3 (0)
|
||||||
#define MICROPY_HW_ENABLE_CAN (1)
|
#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
|
// 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_PIN (pin_A13)
|
||||||
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)
|
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
#define MICROPY_HW_ENABLE_SPI3 (0)
|
#define MICROPY_HW_ENABLE_SPI3 (0)
|
||||||
#define MICROPY_HW_ENABLE_CAN (1)
|
#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
|
// 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_PIN (pin_B3)
|
||||||
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)
|
#define MICROPY_HW_USRSW_PULL (GPIO_PULLUP)
|
||||||
|
13
stmhal/rtc.c
13
stmhal/rtc.c
@ -256,18 +256,29 @@ void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc) {
|
|||||||
__HAL_RCC_BACKUPRESET_RELEASE().
|
__HAL_RCC_BACKUPRESET_RELEASE().
|
||||||
- Configure the needed RTc clock source */
|
- 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.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
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.LSEState = RCC_LSE_ON;
|
||||||
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
|
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) {
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||||
//Error_Handler();
|
//Error_Handler();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||||
|
#if defined(MICROPY_HW_RTC_USE_LSE) && MICROPY_HW_RTC_USE_LSE
|
||||||
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||||
|
#else
|
||||||
|
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
|
||||||
|
#endif
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
||||||
//Error_Handler();
|
//Error_Handler();
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user