mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #14243 from boraozgen/feature/stm32-rtc-hse
STM32: Add HSE support to RTCpull/14455/head
commit
f00ce59769
|
@ -16,6 +16,7 @@
|
|||
#include "cmsis.h"
|
||||
#include "objects.h"
|
||||
#include "platform/mbed_error.h"
|
||||
#include "rtc_api_hal.h"
|
||||
|
||||
int mbed_sdk_inited = 0;
|
||||
extern void SetSysClock(void);
|
||||
|
@ -285,7 +286,15 @@ void mbed_sdk_init()
|
|||
|
||||
/* Start LSI clock for RTC */
|
||||
#if DEVICE_RTC
|
||||
#if !MBED_CONF_TARGET_LSE_AVAILABLE
|
||||
#if (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_HSE)
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||
PeriphClkInitStruct.RTCClockSelection = (RCC_RTCCLKSOURCE_HSE_DIVX | RTC_HSE_DIV << 16);
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||
{
|
||||
error("PeriphClkInitStruct RTC failed with HSE\n");
|
||||
}
|
||||
#elif ((MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_LSE_OR_LSI) && !MBED_CONF_TARGET_LSE_AVAILABLE) || (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_LSI)
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
|
||||
if (__HAL_RCC_GET_RTC_SOURCE() != RCC_RTCCLKSOURCE_NO_CLK) {
|
||||
|
|
|
@ -62,7 +62,14 @@ void rtc_init(void)
|
|||
while (LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID)) {
|
||||
}
|
||||
#endif /* DUAL_CORE */
|
||||
#if MBED_CONF_TARGET_LSE_AVAILABLE
|
||||
#if (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_HSE)
|
||||
(void)RCC_OscInitStruct;
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||
PeriphClkInitStruct.RTCClockSelection = (RCC_RTCCLKSOURCE_HSE_DIVX | RTC_HSE_DIV << 16);
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
||||
error("PeriphClkInitStruct RTC failed with HSE\n");
|
||||
}
|
||||
#elif (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_LSE_OR_LSI) && MBED_CONF_TARGET_LSE_AVAILABLE
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
#if MBED_CONF_TARGET_LSE_BYPASS
|
||||
|
@ -82,7 +89,7 @@ void rtc_init(void)
|
|||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
||||
error("PeriphClkInitStruct RTC failed with LSE\n");
|
||||
}
|
||||
#else /* MBED_CONF_TARGET_LSE_AVAILABLE */
|
||||
#else /* Fallback to LSI */
|
||||
#if TARGET_STM32WB
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI1;
|
||||
#else
|
||||
|
@ -101,7 +108,7 @@ void rtc_init(void)
|
|||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
||||
error("PeriphClkInitStruct RTC failed with LSI\n");
|
||||
}
|
||||
#endif /* MBED_CONF_TARGET_LSE_AVAILABLE */
|
||||
#endif /* MBED_CONF_TARGET_RTC_CLOCK_SOURCE */
|
||||
#if defined(DUAL_CORE) && (TARGET_STM32H7)
|
||||
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT);
|
||||
#endif /* DUAL_CORE */
|
||||
|
|
|
@ -38,7 +38,26 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_TARGET_LSE_AVAILABLE
|
||||
// Possible choices of the RTC_CLOCK_SOURCE configuration set in json file
|
||||
#define USE_RTC_CLK_LSE_OR_LSI 1
|
||||
#define USE_RTC_CLK_LSI 2
|
||||
#define USE_RTC_CLK_HSE 3
|
||||
|
||||
#if !((MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_LSE_OR_LSI) || (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_LSI) || (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_HSE))
|
||||
#error "RTC clock configuration is invalid!"
|
||||
#endif
|
||||
|
||||
#if (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_HSE) && !(TARGET_STM32F2 || TARGET_STM32F3 || TARGET_STM32F4)
|
||||
#error "RTC from HSE not supported for this target"
|
||||
#endif
|
||||
|
||||
#if (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_HSE)
|
||||
#define RTC_CLOCK 1000000U
|
||||
#define RTC_HSE_DIV (HSE_VALUE / RTC_CLOCK)
|
||||
#if RTC_HSE_DIV > 31
|
||||
#error "HSE value too high for RTC"
|
||||
#endif
|
||||
#elif (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_LSE_OR_LSI) && MBED_CONF_TARGET_LSE_AVAILABLE
|
||||
#define RTC_CLOCK LSE_VALUE
|
||||
#else
|
||||
#define RTC_CLOCK LSI_VALUE
|
||||
|
@ -47,7 +66,11 @@ extern "C" {
|
|||
#if DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM
|
||||
/* PREDIV_A : 7-bit asynchronous prescaler */
|
||||
/* PREDIV_A is set to set LPTICKER frequency to RTC_CLOCK/4 */
|
||||
#if (MBED_CONF_TARGET_RTC_CLOCK_SOURCE == USE_RTC_CLK_HSE)
|
||||
#define PREDIV_A_VALUE 124
|
||||
#else
|
||||
#define PREDIV_A_VALUE 3
|
||||
#endif
|
||||
|
||||
/** Read RTC counter with sub second precision
|
||||
*
|
||||
|
|
|
@ -1220,6 +1220,10 @@
|
|||
"help": "Define if a Low Speed External xtal (LSE) is available on the board (0 = No, 1 = Yes). If Yes, the LSE will be used to clock the RTC, LPUART, ... otherwise the Low Speed Internal clock (LSI) will be used",
|
||||
"value": "1"
|
||||
},
|
||||
"rtc_clock_source": {
|
||||
"help": "Define the RTC clock source. USE_RTC_CLK_LSE_OR_LSI, USE_RTC_CLK_LSI, USE_RTC_CLK_HSE. LPTICKER is not available for HSE and should be removed from the target configuration.",
|
||||
"value": "USE_RTC_CLK_LSE_OR_LSI"
|
||||
},
|
||||
"lpuart_clock_source": {
|
||||
"help": "Define the LPUART clock source. Mask values: USE_LPUART_CLK_LSE, USE_LPUART_CLK_PCLK1, USE_LPUART_CLK_HSI",
|
||||
"value": "USE_LPUART_CLK_LSE|USE_LPUART_CLK_PCLK1"
|
||||
|
|
Loading…
Reference in New Issue