summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-10-08 12:41:12 +0100
committerDamien George <damien.p.george@gmail.com>2015-10-08 12:41:12 +0100
commit2a8d7ee0f89b43fb2e65452343891897837f8231 (patch)
treea5a0c6d5b12e8187845dad69aca1b001b22e94ba
parentfd38799049b9f1fac9258f202cf9ecfccecb5372 (diff)
downloadmicropython-2a8d7ee0f89b43fb2e65452343891897837f8231.tar.gz
micropython-2a8d7ee0f89b43fb2e65452343891897837f8231.zip
stmhal: Fix RTC.wakeup so it correctly calculates WUT for large periods.
Thanks to Peter Hinch. Addresses issue #1488.
-rw-r--r--stmhal/rtc.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/stmhal/rtc.c b/stmhal/rtc.c
index 91dae0d6eb..1be0b6e62b 100644
--- a/stmhal/rtc.c
+++ b/stmhal/rtc.c
@@ -419,17 +419,23 @@ mp_obj_t pyb_rtc_wakeup(mp_uint_t n_args, const mp_obj_t *args) {
if (div <= 16) {
wut = 32768 / div * ms / 1000;
} else {
+ // use 1Hz clock
wucksel = 4;
wut = ms / 1000;
- if (ms > 0x10000) {
- wucksel = 5;
- ms -= 0x10000;
- if (ms > 0x10000) {
+ if (wut > 0x10000) {
+ // wut too large for 16-bit register, try to offset by 0x10000
+ wucksel = 6;
+ wut -= 0x10000;
+ if (wut > 0x10000) {
+ // wut still too large
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "wakeup value too large"));
}
}
}
- wut -= 1;
+ // wut register should be 1 less than desired value, but guard against wut=0
+ if (wut > 0) {
+ wut -= 1;
+ }
enable = true;
}
if (n_args == 3) {