Modification of mbed-src library only for STM32F030F4, very cheap microcontroller in 20-Pin TSSOP package, with 16Kbytes of Flash and 4Kbytes of Ram. **Target for online compilator must be Nucleo 32F030R8.**

Dependents:   STM32F031_blink_LED_2

Issue: Can't get sleep mode to work (Closed: Fixed)

I cannot seem to get the sleep modes to work. The following piece of code should send the device to sleep after 5 seconds. It should then re awaken via external interrupt when the button on PA_6 is pressed. However, the device does not appear to ever enter sleep mode as the LED continues flashing indefinitely.

I don't know enough about the hardware abstraction layer to know where to go in the code to fix this.

  1. include "mbed.h" DigitalIn mybutton(PA_6); InterruptIn event(PA_6); attach interrupts for use in sleep mode DigitalOut myled(PA_9);

Timer timer;

void pressed() { empty function to awaken the device on interrupt }

int main() { event.fall(&pressed);

while (1) { timer.start();

if(timer.read_ms()>5000) { timer.stop(); timer.reset(); sleep(); deepsleep(); } myled = !myled; wait(.5);

} }

4 comments:

12 Aug 2015

Ok, I believe I have identified what may or may not be a problem, but it at least requires a work around.

1) if using ST-LINK/V2 to program your chip then you must disconnect the ST-LINK/V2 from your chip in order to enter sleep mode (fair enough since the ST-LINK/V2 is probably triggering interrupts by communicating with the chip). However in addition to disconnecting the ST-LINK/V2 from my chip I also had to reset my chip before the chip would enter sleep mode.

2) a second issue that caused me problems is that the function disable_irq() appears to disable interrupts perfectly well however enable_irq() doesn't appear to re-enable them. Again I'm not sure if this is to do with the software or if it is a hardware issue. when I look at the comments in the code they say it depends on hardware implementation.

/ Enable IRQ. This method depends on hw implementation, might enable one

  • port interrupts. For further information, check gpio_irq_enable().
  • /
12 Aug 2015

Yes, there is a problem. My attempts with the same program had the same result. Deepsleep looks OK, but Sleep is not working. The program goes through Sleep every time. Since my library is based on the mbed-src v89 (little old), I was looking for further modifications Sleep function at a low level, in newer versions. But I have not found anything interesting. Then I tested the normal Nucleo F030R8 for comparison. And surprise. I imported the original demo of STM: https://developer.mbed.org/teams/ST/code/Nucleo_sleep/, and Sleep worked perfectly. But the demo was accompanied by an very old version of mbed libraries. When I upgrade it to the new version, the program was not working. When I downloaded version intermediate between that which worked well, and the latest ... Sleep function had become "transparent" in the same way as in the library 030F4.

So I think it's not a problem with this particular type of chip, and it worked fine once before, but someone broke. I'm searching now old sources of library mbed-src, for changes have caused this error.

13 Aug 2015

Interrupt of hardware timer that supports e.g wait(), Timer class, resulted in an immediate exit from the sleep state. Corrected. I have tested corrected version, and now it looks good.

22 Feb 2019

hi I'm new to mbed I can not get to sleep STM32F030F4 you can give an example of how to get to sleep and Wake up