mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Dec 17 11:00:05 2013 +0000
Revision:
62:7731d679ae64
Parent:
60:142c6c6f5949
Child:
70:c1fbde68b492
Synchronized with git revision 1eec522274f4b78e86504ad3cde3c10574392441

Full URL: https://github.com/mbedmicro/mbed/commit/1eec522274f4b78e86504ad3cde3c10574392441/

[NUCLEO_F103RB] Use HSI/LSI instead of HSE/LSE (board rev C constraint)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 60:142c6c6f5949 1 /* mbed Microcontroller Library
mbed_official 60:142c6c6f5949 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 60:142c6c6f5949 3 *
mbed_official 60:142c6c6f5949 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 60:142c6c6f5949 5 * you may not use this file except in compliance with the License.
mbed_official 60:142c6c6f5949 6 * You may obtain a copy of the License at
mbed_official 60:142c6c6f5949 7 *
mbed_official 60:142c6c6f5949 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 60:142c6c6f5949 9 *
mbed_official 60:142c6c6f5949 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 60:142c6c6f5949 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 60:142c6c6f5949 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 60:142c6c6f5949 13 * See the License for the specific language governing permissions and
mbed_official 60:142c6c6f5949 14 * limitations under the License.
mbed_official 60:142c6c6f5949 15 */
mbed_official 60:142c6c6f5949 16 #include "rtc_api.h"
mbed_official 60:142c6c6f5949 17
mbed_official 60:142c6c6f5949 18 static int rtc_inited = 0;
mbed_official 60:142c6c6f5949 19
mbed_official 60:142c6c6f5949 20 void rtc_init(void) {
mbed_official 60:142c6c6f5949 21 RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Enable PWR and Backup clock
mbed_official 60:142c6c6f5949 22
mbed_official 60:142c6c6f5949 23 PWR_BackupAccessCmd(ENABLE); // Allow access to Backup Domain
mbed_official 60:142c6c6f5949 24
mbed_official 60:142c6c6f5949 25 BKP_DeInit(); // Reset Backup Domain
mbed_official 60:142c6c6f5949 26
mbed_official 62:7731d679ae64 27 // Uncomment these lines if you use the LSE
mbed_official 60:142c6c6f5949 28 // Enable LSE and wait till it's ready
mbed_official 62:7731d679ae64 29 //RCC_LSEConfig(RCC_LSE_ON);
mbed_official 62:7731d679ae64 30 //while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {}
mbed_official 62:7731d679ae64 31 //RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); // Select LSE as RTC Clock Source
mbed_official 60:142c6c6f5949 32
mbed_official 62:7731d679ae64 33 // Uncomment these lines if you use the LSI
mbed_official 62:7731d679ae64 34 // Enable LSI and wait till it's ready
mbed_official 62:7731d679ae64 35 RCC_LSICmd(ENABLE);
mbed_official 62:7731d679ae64 36 while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {}
mbed_official 62:7731d679ae64 37 RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); // Select LSI as RTC Clock Source
mbed_official 62:7731d679ae64 38
mbed_official 60:142c6c6f5949 39 RCC_RTCCLKCmd(ENABLE); // Enable RTC Clock
mbed_official 60:142c6c6f5949 40
mbed_official 60:142c6c6f5949 41 RTC_WaitForSynchro(); // Wait for RTC registers synchronization
mbed_official 60:142c6c6f5949 42
mbed_official 60:142c6c6f5949 43 RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished
mbed_official 60:142c6c6f5949 44
mbed_official 60:142c6c6f5949 45 // Set RTC period to 1 sec
mbed_official 62:7731d679ae64 46 // For LSE: prescaler = RTCCLK/RTC period = 32768Hz/1Hz = 32768
mbed_official 62:7731d679ae64 47 // For LSI: prescaler = RTCCLK/RTC period = 40000Hz/1Hz = 40000
mbed_official 62:7731d679ae64 48 RTC_SetPrescaler(39999);
mbed_official 60:142c6c6f5949 49
mbed_official 60:142c6c6f5949 50 RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished
mbed_official 60:142c6c6f5949 51
mbed_official 60:142c6c6f5949 52 rtc_inited = 1;
mbed_official 60:142c6c6f5949 53 }
mbed_official 60:142c6c6f5949 54
mbed_official 60:142c6c6f5949 55 void rtc_free(void) {
mbed_official 60:142c6c6f5949 56 RCC_DeInit(); // Resets the RCC clock configuration to the default reset state
mbed_official 60:142c6c6f5949 57 rtc_inited = 0;
mbed_official 60:142c6c6f5949 58 }
mbed_official 60:142c6c6f5949 59
mbed_official 60:142c6c6f5949 60 int rtc_isenabled(void) {
mbed_official 60:142c6c6f5949 61 return rtc_inited;
mbed_official 60:142c6c6f5949 62 }
mbed_official 60:142c6c6f5949 63
mbed_official 60:142c6c6f5949 64 time_t rtc_read(void) {
mbed_official 60:142c6c6f5949 65 return (time_t)RTC_GetCounter();
mbed_official 60:142c6c6f5949 66 }
mbed_official 60:142c6c6f5949 67
mbed_official 60:142c6c6f5949 68 void rtc_write(time_t t) {
mbed_official 60:142c6c6f5949 69 RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished
mbed_official 60:142c6c6f5949 70 RTC_SetCounter(t); // Change the current time
mbed_official 60:142c6c6f5949 71 RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished
mbed_official 60:142c6c6f5949 72 }