mirror of https://github.com/ARMmbed/mbed-os.git
commit
53fd30ab31
|
@ -147,7 +147,7 @@
|
||||||
#endif /* LSE_VALUE */
|
#endif /* LSE_VALUE */
|
||||||
|
|
||||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||||
#define LSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for LSE start up, in ms */
|
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
|
||||||
#endif /* HSE_STARTUP_TIMEOUT */
|
#endif /* HSE_STARTUP_TIMEOUT */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#define DEVICE_SPISLAVE 1
|
#define DEVICE_SPISLAVE 1
|
||||||
|
|
||||||
#define DEVICE_RTC 1
|
#define DEVICE_RTC 1
|
||||||
|
#define DEVICE_RTC_LSI 0
|
||||||
|
|
||||||
#define DEVICE_PWMOUT 1
|
#define DEVICE_PWMOUT 1
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#define DEVICE_SPISLAVE 1
|
#define DEVICE_SPISLAVE 1
|
||||||
|
|
||||||
#define DEVICE_RTC 1
|
#define DEVICE_RTC 1
|
||||||
|
#define DEVICE_RTC_LSI 0
|
||||||
|
|
||||||
#define DEVICE_PWMOUT 1
|
#define DEVICE_PWMOUT 1
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#define DEVICE_SPISLAVE 1
|
#define DEVICE_SPISLAVE 1
|
||||||
|
|
||||||
#define DEVICE_RTC 1
|
#define DEVICE_RTC 1
|
||||||
|
#define DEVICE_RTC_LSI 1
|
||||||
|
|
||||||
#define DEVICE_PWMOUT 1
|
#define DEVICE_PWMOUT 1
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#define DEVICE_SPISLAVE 1
|
#define DEVICE_SPISLAVE 1
|
||||||
|
|
||||||
#define DEVICE_RTC 1
|
#define DEVICE_RTC 1
|
||||||
|
#define DEVICE_RTC_LSI 1
|
||||||
|
|
||||||
#define DEVICE_PWMOUT 1
|
#define DEVICE_PWMOUT 1
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#define DEVICE_SPISLAVE 1
|
#define DEVICE_SPISLAVE 1
|
||||||
|
|
||||||
#define DEVICE_RTC 1
|
#define DEVICE_RTC 1
|
||||||
|
#define DEVICE_RTC_LSI 0
|
||||||
|
|
||||||
#define DEVICE_PWMOUT 1
|
#define DEVICE_PWMOUT 1
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#define DEVICE_SPISLAVE 1
|
#define DEVICE_SPISLAVE 1
|
||||||
|
|
||||||
#define DEVICE_RTC 1
|
#define DEVICE_RTC 1
|
||||||
|
#define DEVICE_RTC_LSI 0
|
||||||
|
|
||||||
#define DEVICE_PWMOUT 1
|
#define DEVICE_PWMOUT 1
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#define DEVICE_SPISLAVE 1
|
#define DEVICE_SPISLAVE 1
|
||||||
|
|
||||||
#define DEVICE_RTC 1
|
#define DEVICE_RTC 1
|
||||||
|
#define DEVICE_RTC_LSI 0
|
||||||
|
|
||||||
#define DEVICE_PWMOUT 1
|
#define DEVICE_PWMOUT 1
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,9 @@
|
||||||
|
|
||||||
#include "mbed_error.h"
|
#include "mbed_error.h"
|
||||||
|
|
||||||
|
#if DEVICE_RTC_LSI
|
||||||
static int rtc_inited = 0;
|
static int rtc_inited = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
static RTC_HandleTypeDef RtcHandle;
|
static RTC_HandleTypeDef RtcHandle;
|
||||||
|
|
||||||
|
@ -41,11 +43,27 @@ void rtc_init(void) {
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||||
uint32_t rtc_freq = 0;
|
uint32_t rtc_freq = 0;
|
||||||
|
|
||||||
|
#if DEVICE_RTC_LSI
|
||||||
if (rtc_inited) return;
|
if (rtc_inited) return;
|
||||||
rtc_inited = 1;
|
rtc_inited = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
RtcHandle.Instance = RTC;
|
RtcHandle.Instance = RTC;
|
||||||
|
|
||||||
|
#if !DEVICE_RTC_LSI
|
||||||
|
// Enable LSE Oscillator
|
||||||
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
||||||
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
|
||||||
|
RCC_OscInitStruct.LSEState = RCC_LSE_ON; // External 32.768 kHz clock on OSC_IN/OSC_OUT
|
||||||
|
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
|
||||||
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) { // Check if LSE has started correctly
|
||||||
|
// Connect LSE to RTC
|
||||||
|
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
|
||||||
|
rtc_freq = LSE_VALUE;
|
||||||
|
} else {
|
||||||
|
error("Cannot initialize RTC with LSE\n");
|
||||||
|
}
|
||||||
|
#else
|
||||||
// Enable Power clock
|
// Enable Power clock
|
||||||
__PWR_CLK_ENABLE();
|
__PWR_CLK_ENABLE();
|
||||||
|
|
||||||
|
@ -56,31 +74,19 @@ void rtc_init(void) {
|
||||||
__HAL_RCC_BACKUPRESET_FORCE();
|
__HAL_RCC_BACKUPRESET_FORCE();
|
||||||
__HAL_RCC_BACKUPRESET_RELEASE();
|
__HAL_RCC_BACKUPRESET_RELEASE();
|
||||||
|
|
||||||
// Enable LSE Oscillator
|
// Enable LSI clock
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
|
||||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON; // External 32.768 kHz clock on OSC_IN/OSC_OUT
|
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
|
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||||
// Connect LSE to RTC
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||||
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
|
error("Cannot initialize RTC with LSI\n");
|
||||||
rtc_freq = LSE_VALUE;
|
}
|
||||||
} else {
|
// Connect LSI to RTC
|
||||||
// Enable LSI clock
|
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
|
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
|
rtc_freq = LSI_VALUE;
|
||||||
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
|
#endif
|
||||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
|
||||||
error("RTC error: LSI clock initialization failed.");
|
|
||||||
}
|
|
||||||
// Connect LSI to RTC
|
|
||||||
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
|
|
||||||
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
|
|
||||||
rtc_freq = LSI_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if RTC is already initialized
|
|
||||||
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return;
|
|
||||||
|
|
||||||
// Enable RTC
|
// Enable RTC
|
||||||
__HAL_RCC_RTC_ENABLE();
|
__HAL_RCC_RTC_ENABLE();
|
||||||
|
@ -98,6 +104,7 @@ void rtc_init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void rtc_free(void) {
|
void rtc_free(void) {
|
||||||
|
#if DEVICE_RTC_LSI
|
||||||
// Enable Power clock
|
// Enable Power clock
|
||||||
__PWR_CLK_ENABLE();
|
__PWR_CLK_ENABLE();
|
||||||
|
|
||||||
|
@ -110,6 +117,7 @@ void rtc_free(void) {
|
||||||
|
|
||||||
// Disable access to Backup domain
|
// Disable access to Backup domain
|
||||||
HAL_PWR_DisableBkUpAccess();
|
HAL_PWR_DisableBkUpAccess();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Disable LSI and LSE clocks
|
// Disable LSI and LSE clocks
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||||
|
@ -119,11 +127,21 @@ void rtc_free(void) {
|
||||||
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
|
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
|
||||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||||
|
|
||||||
|
#if DEVICE_RTC_LSI
|
||||||
rtc_inited = 0;
|
rtc_inited = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtc_isenabled(void) {
|
int rtc_isenabled(void) {
|
||||||
return rtc_inited;
|
#if DEVICE_RTC_LSI
|
||||||
|
return rtc_inited;
|
||||||
|
#else
|
||||||
|
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue