How to deep sleep with STM32F103C8T6 (Blue Pill)

After a year of being elsewhere I’m back in mbed world. Mbed Studio looks promising and anything is cool. I’m on mbed-os 6.13.0 now :slight_smile:

Now for at little “test things out” I’m trying to get my Blue Pill board (STM32F103C8T6) doing deep sleep.
In the past I had a good dialogue over here: How to deep sleep? - #11 by kenjiArai , and I think I have tried following what I learned back then. but well, it does not work out quite well.

Then I tried to manually putting it a sleep using the RTC. inspired from this one: GitHub - tsaarni/stm32f103-low-power-mbed: How to enable standby mode on STM32F1
It works really good, 3.2uA.

So question is how to let mbed handle the the deep sleep when possible and not having to do it manually, also rebooting the program on every iteration is not ideal.

Anyway, hints and pointers on how to progress are most welcome :slight_smile:

Hello Morten,

The Mbed OS Documentation says:

In most cases, you don’t need to call sleep() directly. Mbed OS enters sleep mode automatically any time the system is idle. That is when all your threads are in a waiting state, for example waiting for an event or a timeout.

For more info have a look at Power management (sleep).

yes, thats what I expected too. It works fine with my STM32L152 based nucleo board, but on the F103 it keeps consuming several mA when thread is waiting.
So I think question is more related to the specific chip on the bluepill and less on mbed-os in general.

You are right. Some MCU’s consume less power than others. Such targets usually utilize the tickless feature of the Mbed RTOS and are equipped with low power tickers/timers. When the system has nothing to do, based on the system status (taking into account scheduled tasks to be executed in the future) the RTOS calculates how mutch time it can spend in deep sleep state to save power and falls into deep sleep. Once the calculated time has elapsed, the system wakes up and performs the task scheduled as next. But there is a price for such feature. The program becomes less responsive. For example as in this case. You can try to enable the tickless feature for the STM32F103 for example by using the following mbed_app.json:

{
    "target_overrides": {
        "*": {
            "target.macros_add": ["MBED_TICKLESS"]
        }
    }
}

But, I’m not sure whether it will help (I have never tried that for the Blue Pill).

I have tried adding MBED_TICKLESS but it does not lower the current draw when board is supposed to be idling.

While googling around I came across STM32F103C8 Mbed Support - #5 by maxgerhardt - Development Platforms - PlatformIO Community where maxgerhardt wrote

The bluepill has no LPTIM but it has several TIMs, so low-power ticker is not possible

I can not say I know much about the internals of an STM32 device, but it could be an explanation why I do not see a significant current drop when blinky has led in off state.

I just figured that info on the Tickless mode - Porting , along with the requirements to be met, is available in the Mbed OS documentation.