8 years, 11 months ago.

set_time() problem after WakeUp interrupt

Can anyone explain why this code halts at line 8, when I try setting the RTC after a WakeUp interrupt?

I am using a Nucleo L152RE.

#include "mbed.h"
#include "WakeUp.h"

Serial pc(PC_10,PC_11);
DigitalOut myled(LED1);

void timeset(){
    set_time(1429689898); //The code halts at this line..
    wait_ms(1);
    }
int main() {
    
    set_time(1429689598);
    
    WakeUp::attach(timeset);
    WakeUp::set(5);
    
    while(1) {
        sleep();
    }
}

Just commenting here so you get an email

posted by Erik - 22 Apr 2015

1 Answer

8 years, 11 months ago.

How are you checking that it halts there? And in principle the WakeUp RTC code is assuming you do not set the time back (in practise this should give you an RTC interrupt every 5 seconds because you keep setting the time back).

Someting to try is in your interrupt handler first calling WakeUp::set(0) (this actually disables interrupts from being generated), then wait_ms(10), and then set your time to new value. (I have no idea if this will work, and also not if both are required, but it is something to try).

Alternatively try setting time in your while(1) loop after sleep. So it is not called from interrupt context.

Accepted Answer

Ok, I have tried all of the things u mentioned...and none of them works. I use printfs to check where the code halts, and it never gets beyond the set_time.

posted by Håkon Bryn 22 Apr 2015

I will see when I get around to testing it on my Nucleo device. But no guarantees.

posted by Erik - 22 Apr 2015

The problem has been solved. My code disabled the Backup Power domain after using it, and apparantly the mbed code does not re-enable it itself (anymore) when it requires this power domain. (The mbed code was changed, so maybe it used to work, but maybe I never tested this use case). This has been fixed now, possibly it is bit higher power consumption, but no idea :D.

Also just to prevent in your use case errors from being able to happen if you would set the clock a bit back, now it also disables the alarm after waking up.

Right click update on your WakeUp lib and you get the latest version.

posted by Erik - 22 Apr 2015

Thank you, it works now! :)

posted by Håkon Bryn 24 Apr 2015