summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-08 07:34:38 -0800
committerDamien George <damien.p.george@gmail.com>2014-01-08 07:34:38 -0800
commitea9e441a75d7ea6633b0ea95b21667c48a6f7b6a (patch)
tree8ec93e75c6e8b7f9c1821b7893b32730eaf414f6
parent9193f89296d6757955db7ebdfd4ca332f0b60f71 (diff)
parent5df3d47ee08a3829d499ca160ba906052dab8b31 (diff)
Merge pull request #112 from iabdalkader/master
Use LSI OSC for RTC clock when LSE is not detected
-rw-r--r--stm/main.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/stm/main.c b/stm/main.c
index 0ad638cde..fbbb35039 100644
--- a/stm/main.c
+++ b/stm/main.c
@@ -585,6 +585,9 @@ mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
}
static void rtc_init(void) {
+ uint32_t rtc_clksrc;
+ uint32_t timeout =10000;
+
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
@@ -595,11 +598,29 @@ static void rtc_init(void) {
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
- while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {
+ while((RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (--timeout > 0)) {
+ }
+
+ /* If LSE timed out, use LSI instead */
+ if (timeout == 0) {
+ /* Enable the LSI OSC */
+ RCC_LSICmd(ENABLE);
+
+ /* Wait till LSI is ready */
+ while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {
+ }
+
+ /* Use LSI as the RTC Clock Source */
+ rtc_clksrc = RCC_RTCCLKSource_LSI;
+ } else {
+ /* Use LSE as the RTC Clock Source */
+ rtc_clksrc = RCC_RTCCLKSource_LSE;
}
/* Select the RTC Clock Source */
- RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
+ RCC_RTCCLKConfig(rtc_clksrc);
+
+ /* Note: LSI is around (32KHz), these dividers should work either way */
/* ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
uint32_t uwSynchPrediv = 0xFF;
uint32_t uwAsynchPrediv = 0x7F;