Skip to content

Commit d28415e

Browse files
committed
Added _configured flag, which is set to true after begin().
The read request code (used by every clock get method) would endlessly block if called before the RTC was configured.
1 parent be52db9 commit d28415e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/RTCZero.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727
voidFuncPtr RTC_callBack = NULL;
2828

29+
RTCZero::RTCZero()
30+
{
31+
_configured = false;
32+
}
33+
2934
void RTCZero::begin()
3035
{
3136
uint16_t tmp_reg = 0;
@@ -72,6 +77,8 @@ void RTCZero::begin()
7277

7378
RTCenable();
7479
RTCresetRemove();
80+
81+
_configured = true;
7582
}
7683

7784
void RTC_Handler(void)
@@ -369,9 +376,11 @@ void RTCZero::config32kOSC()
369376

370377
/* Synchronise the CLOCK register for reading*/
371378
inline void RTCZero::RTCreadRequest() {
372-
RTC->MODE2.READREQ.reg = RTC_READREQ_RREQ;
373-
while (RTCisSyncing())
374-
;
379+
if (_configured) {
380+
RTC->MODE2.READREQ.reg = RTC_READREQ_RREQ;
381+
while (RTCisSyncing())
382+
;
383+
}
375384
}
376385

377386
/* Wait for sync in write operations */

src/RTCZero.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RTCZero {
3838
MATCH_YYMMDDHHMMSS = RTC_MODE2_MASK_SEL_YYMMDDHHMMSS_Val // Once, on a specific date and a specific time
3939
};
4040

41-
RTCZero() {};
41+
RTCZero();
4242
void begin();
4343

4444
void enableAlarm(Alarm_Match match);
@@ -99,6 +99,8 @@ class RTCZero {
9999
void setY2kEpoch(uint32_t ts);
100100

101101
private:
102+
bool _configured;
103+
102104
void config32kOSC(void);
103105
void RTCreadRequest();
104106
bool RTCisSyncing(void);

0 commit comments

Comments
 (0)