[riot-notifications] [RIOT-OS/RIOT] cpu: RTC implementation for STM32F1 (#11258)

Marian Buschsieweke notifications at github.com
Tue Apr 9 08:29:47 CEST 2019


maribu requested changes on this pull request.



> +
+    /* turn on LSE crystal */
+    RCC->BDCR |= RCC_BDCR_LSEON;
+    while ((RCC->BDCR & RCC_BDCR_LSEON) != RCC_BDCR_LSEON) {}
+
+    /* calibration clock from 0 to 0x7F */
+    BKP->RTCCR |= 0;
+
+    /* second interrupt is disabled. */
+    RTC->CRH &= ~RTC_CRH_SECIE;
+
+    _rtc_enter_config_mode();
+
+    /* if the input clock frequency (fRTCCLK) is 32.768 kHz, write 7FFFh in this register to get a signal period of 1 second. */
+    RTC->PRLH = 0;
+    RTC->PRLL = 0x7FFF;

Btw: `0x8000` is 32.768. With 32.768 kHz clock frequency, it should be indeed `0x8000` here, shouldn't it? The comment above should then be fixed as well.

> +static time_t _rtc_get_time(void)
+{
+    return (RTC->CNTH << 16) | RTC->CNTL;
+}
+
+static void _rtc_set_time(time_t counter_val)
+{
+    _rtc_enter_config_mode();
+    RTC->CNTH = (counter_val & 0xffff0000) >> 16;
+    RTC->CNTL = counter_val & 0x0000ffff;
+    _rtc_exit_config_mode();
+}
+
+void rtc_init(void)
+{
+    /* save current time if RTC already works */

`rtc_init()` will be called from `periph_init()` implemented in `drivers/periph_common/init.c`. I don't see any reason why it would get called more than once during startup. Therefore, I would suggest to skip the check if the RTC is already running and just configure it here

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11258#pullrequestreview-224206477
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190408/a3974187/attachment.html>


More information about the notifications mailing list