Mbed sleep does not work?

21 Mar 2019

I'm attempting to make a simple program that sleeps until woken by a button press, and will blink some LEDs. However, I'm finding that I cannot make the sleep() or deepsleep() functions to work in either mbed-os or mbed classic. The code simply executes the LED loop all the time, never even entering sleep mode.

The mbed-os has no documentation on the use of indefinite sleep, it only discusses the use of Thread::wait. Mbed classic describes examples very close to this, suggesting it should work. Does anyone know why this is failing on both frameworks? Platform is STM32F103RB.

code

#include "mbed.h"
#include "PinDetect.h"

DigitalOut led(PA_3);
PinDetect btn(PA_1);

void isr_booped() {
    
}

int main() {
    btn.attach_deasserted(&isr_booped);
    btn.setSampleFrequency();
    while(1) {
        sleep();
        for(int i=0;i<5;i++) {  
            led = 1; // LED is ON
            wait(0.5); // 200 ms
            led = 0; // LED is OFF
            wait(0.5); // 1 sec
        }
    }
}