mbed library sources. Supersedes mbed-src. Fixed broken STM32F1xx RTC on rtc_api.c
Dependents: Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay
Fork of mbed-dev by
Revision 177:619788de047e, committed 2017-11-07
- Comitter:
- maxxir
- Date:
- Tue Nov 07 16:46:29 2017 +0000
- Parent:
- 176:447f873cad2f
- Commit message:
- To fix broken RTC on Nucleo_F103RB / STM32F103 BluePill etc..; Used direct RTC register manipulation for STM32F1xx; rtc_read() && rtc_write() (native rtc_init() - works good); also added stub for non-working on STM32F1xx rtc_read_subseconds().
Changed in this revision
targets/TARGET_STM/rtc_api.c | Show annotated file Show diff for this revision Revisions of this file |
--- a/targets/TARGET_STM/rtc_api.c Wed Oct 25 14:53:38 2017 +0100 +++ b/targets/TARGET_STM/rtc_api.c Tue Nov 07 16:46:29 2017 +0000 @@ -218,6 +218,11 @@ time_t rtc_read(void) { +#if (TARGET_STM32F1) + time_t seconds; + seconds = ((uint32_t)RTC->CNTH << 16) | RTC->CNTL; + return seconds; +#else RTC_DateTypeDef dateStruct = {0}; RTC_TimeTypeDef timeStruct = {0}; struct tm timeinfo; @@ -244,10 +249,18 @@ time_t t = _rtc_mktime(&timeinfo); return t; +#endif } void rtc_write(time_t t) { +#if (TARGET_STM32F1) + /* Change the current time */ + RTC->CRL |= RTC_CRL_CNF;// заходим в режим конфигурации + RTC->CNTH = t>>16; + RTC->CNTL = t; + RTC->CRL &= ~RTC_CRL_CNF; // выходим из режима конфигурации} +#else RTC_DateTypeDef dateStruct = {0}; RTC_TimeTypeDef timeStruct = {0}; @@ -281,6 +294,7 @@ // Change the RTC current date/time HAL_RTC_SetDate(&RtcHandle, &dateStruct, RTC_FORMAT_BIN); HAL_RTC_SetTime(&RtcHandle, &timeStruct, RTC_FORMAT_BIN); +#endif } int rtc_isenabled(void) @@ -311,7 +325,11 @@ uint32_t rtc_read_subseconds(void) { +#if (TARGET_STM32F1) + return 0; //Not exists on STM32F1 +#else return 1000000.f * ((double)(RTC_SYNCH_PREDIV - RTC->SSR) / (RTC_SYNCH_PREDIV + 1)); +#endif } void rtc_set_wake_up_timer(uint32_t delta)