1
1
/*!
2
2
Real time clock
3
-
4
- A continuously running clock that counts seconds. It is part of the backup domain which means
5
- that the counter is not affected by system resets or standby mode. If Vbat is connected, it is
6
- not reset even if the rest of the device is powered off. This allows it to be used to wake the
7
- CPU when it is in low power mode.
8
-
9
- Since it is part of the backup domain, write access to it must be enabled before the RTC can be
10
- used. See `backup_domain` for more details.
11
-
12
- See examples/rtc.rs and examples/blinky_rtc.rs for usage examples.
13
3
*/
14
-
15
4
use crate :: pac:: { RCC , RTC } ;
16
5
17
6
use crate :: backup_domain:: BackupDomain ;
@@ -23,8 +12,22 @@ use core::convert::Infallible;
23
12
const LSE_HERTZ : u32 = 32_768 ;
24
13
25
14
/**
26
- Interface to the real time clock
15
+ Real time clock
16
+
17
+ A continuously running clock that counts seconds¹. It is part of the backup domain which means
18
+ that the counter is not affected by system resets or standby mode. If Vbat is connected, it is
19
+ not reset even if the rest of the device is powered off. This allows it to be used to wake the
20
+ CPU when it is in low power mode.
21
+
22
+
23
+ See [examples/rtc.rs] and [examples/blinky_rtc.rs] for usage examples.
24
+
25
+ 1: Unless configured to another frequency using [select_frequency](struct.Rtc.html#method.select_frequency)
26
+
27
+ [examples/rtc.rs]: https://github.com/stm32-rs/stm32f1xx-hal/blob/v0.6.1/examples/rtc.rs
28
+ [examples/blinky_rtc.rs]: https://github.com/stm32-rs/stm32f1xx-hal/blob/v0.6.1/examples/blinky_rtc.rs
27
29
*/
30
+
28
31
pub struct Rtc {
29
32
regs : RTC ,
30
33
}
@@ -33,6 +36,12 @@ impl Rtc {
33
36
/**
34
37
Initialises the RTC. The `BackupDomain` struct is created by
35
38
`Rcc.bkp.constrain()`.
39
+
40
+ The frequency is set to 1 Hz.
41
+
42
+ Since the RTC is part of the backup domain, The RTC counter is not reset by normal resets or
43
+ power cycles where (VBAT) still has power. Use [set_time](#method.set_time) if you want to
44
+ reset the counter.
36
45
*/
37
46
pub fn rtc ( regs : RTC , bkp : & mut BackupDomain ) -> Self {
38
47
let mut result = Rtc { regs } ;
@@ -123,15 +132,17 @@ impl Rtc {
123
132
self . clear_alarm_flag ( ) ;
124
133
}
125
134
126
- /// Enables the RTCALARM interrupt
135
+ /// Enables the RTC interrupt to trigger when the counter reaches the alarm value. In addition,
136
+ /// if the EXTI controller has been set up correctly, this function also enables the RTCALARM
137
+ /// interrupt.
127
138
pub fn listen_alarm ( & mut self ) {
128
139
// Enable alarm interrupt
129
140
self . perform_write ( |s| {
130
141
s. regs . crh . modify ( |_, w| w. alrie ( ) . set_bit ( ) ) ;
131
142
} )
132
143
}
133
144
134
- /// Disables the RTCALARM interrupt
145
+ /// Stops the RTC alarm from triggering the RTC and RTCALARM interrupts
135
146
pub fn unlisten_alarm ( & mut self ) {
136
147
// Disable alarm interrupt
137
148
self . perform_write ( |s| {
@@ -147,7 +158,7 @@ impl Rtc {
147
158
self . regs . cnth . read ( ) . bits ( ) << 16 | self . regs . cntl . read ( ) . bits ( )
148
159
}
149
160
150
- /// Enables the RTC second interrupt
161
+ /// Enables triggering the RTC interrupt every time the RTC counter is increased
151
162
pub fn listen_seconds ( & mut self ) {
152
163
self . perform_write ( |s| s. regs . crh . modify ( |_, w| w. secie ( ) . set_bit ( ) ) )
153
164
}
0 commit comments