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.


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

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

void isr_booped() {

int main() {
    while(1) {
        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