Skip to content

[NUCLEO_F446RE] RTC+LSE+init #1548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ void HAL_RCC_CSSCallback(void);
#define RCC_BDCR_BYTE0_ADDRESS (PERIPH_BASE + RCC_BDCR_OFFSET)

#define RCC_DBP_TIMEOUT_VALUE ((uint32_t)100)
#define RCC_LSE_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
#define RCC_LSE_TIMEOUT_VALUE ((uint32_t)5000) /* 5000 ms */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need 5 seconds?


#define HSE_TIMEOUT_VALUE HSE_STARTUP_TIMEOUT
#define HSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define DEVICE_SPISLAVE 1

#define DEVICE_RTC 1
#define DEVICE_RTC_LSI 0

#define DEVICE_PWMOUT 1

Expand Down
25 changes: 18 additions & 7 deletions libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/rtc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

#include "mbed_error.h"

#if DEVICE_RTC_LSI
static int rtc_inited = 0;
#endif

static RTC_HandleTypeDef RtcHandle;

Expand All @@ -42,8 +44,9 @@ void rtc_init(void)
RCC_OscInitTypeDef RCC_OscInitStruct;
uint32_t rtc_freq = 0;

if (rtc_inited) return;
#if DEVICE_RTC_LSI
rtc_inited = 1;
#endif

RtcHandle.Instance = RTC;

Expand All @@ -57,6 +60,7 @@ void rtc_init(void)
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();

#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! */
Expand All @@ -66,7 +70,11 @@ void rtc_init(void)
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE);
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
rtc_freq = LSE_VALUE;
} else {
}
else {
error("RTC error: LSE clock initialization failed.");
}
#else
// Enable LSI clock
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
Expand All @@ -80,10 +88,7 @@ void rtc_init(void)
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
// [TODO] This value is LSI typical value. To be measured precisely using a timer input capture
rtc_freq = LSI_VALUE;
}

// Check if RTC is already initialized
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return;
#endif

// Enable RTC
__HAL_RCC_RTC_ENABLE();
Expand Down Expand Up @@ -122,13 +127,19 @@ void rtc_free(void)
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

#if DEVICE_RTC_LSI
rtc_inited = 0;
#endif
}

int rtc_isenabled(void)
{
#if DEVICE_RTC_LSI
return rtc_inited;
#else
if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) return 1;
else return 0;
#endif
}

/*
Expand Down