1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/sam0_common: rtt: enable COUNTSYNC in CTRLA

From the data sheet:

> The COUNT register requires synchronization when reading.
> Disabling the synchronization will prevent reading valid
> values from the COUNT register.

Without this bit enabled, rtt_get_counter() will always return 0.
This commit is contained in:
Benjamin Valentin 2019-11-08 15:19:58 +01:00 committed by Benjamin Valentin
parent a78bdaa85a
commit 89b987494e

View File

@ -27,6 +27,14 @@
#define ENABLE_DEBUG 0
#include "debug.h"
/*
* Bit introduced by SAML21xxxB, setting it on SAML21xxxxA too has no ill
* effects, but simplifies the code. (This bit is always set on SAML21xxxxA)
*/
#ifndef RTC_MODE0_CTRLA_COUNTSYNC
#define RTC_MODE0_CTRLA_COUNTSYNC BIT15
#endif
static rtt_cb_t _overflow_cb;
static void* _overflow_arg;
@ -91,7 +99,7 @@ void rtt_init(void)
/* set 32bit counting mode & enable the RTC */
#ifdef REG_RTC_MODE0_CTRLA
RTC->MODE0.CTRLA.reg = RTC_MODE0_CTRLA_MODE(0) | RTC_MODE0_CTRLA_ENABLE;
RTC->MODE0.CTRLA.reg = RTC_MODE0_CTRLA_MODE(0) | RTC_MODE0_CTRLA_ENABLE | RTC_MODE0_CTRLA_COUNTSYNC;
#else
RTC->MODE0.CTRL.reg = RTC_MODE0_CTRL_MODE(0) | RTC_MODE0_CTRL_ENABLE;
#endif