Riot OS - Problem with pm_layered API

Hi,

I’m trying to use pm_layered API with Bluepill board (STM32F103). I’ve wrote a simple code, creating a thread and executing it every minute. The thread just toggle the embedded LED.

I want the MCU to be in sleep mode when not in used (after changing the LED state, and during a minute). I tried using pm_set_lowest(), but there’s no difference : the MCU consumes about 12mA.

I’m a firmware beginner, so I surely do something wrong. Do you have any simple example of how to use pm_layered API (preferably with STM32 core) ?

Thank you for your help, Thibaud.

Hi Thibaud,

Welcome and thanks for your interest in RIOT! I also apologize for replying so late.

STOP and STANDBY low-power modes are supported on STM32F1 so you should be able to make it work.

I guess you already read the very minimal pm_layered module documentation [1].

Calling "pm_set_lowest" won't switch to deep sleep modes because they are all blocked by default [2]. The simplest way is to directly call "pm_set" from your application code to force the switch to STOP (1) or STANDBY (0) low-power modes. The other (preferred) way is to globally unblock one (or more) mode by setting CFLAGS += '-DPM_BLOCKER_INITIAL={ .val_u32 = 0x01010001 }' (here it unblocks STOP mode) and to "let" RIOT switch to low-power mode when it switches to the idle thread.

You also need to think of a way to wakeup the CPU: either via an interrupt, this will work with STOP mode and STANDBY mode (if a wakeup pin is enabled [3]), or using an RTC alarm (not yet supported on F1, but there's a PR for this [4]).

Do you have any simple example of how to use pm_layered API (preferably with STM32 core) ?

You can have a look at [5] where the updated "examples/lorawan" application plays with "pm_unblock"/"pm_block" functions to automatically switch to low-power modes: you'll have to remove the lorawan related parts and integrate the PR adding RTC to make it work on stm32f1.

Let us know if you still have any problems and we'll try to help.

Regards,

Alex

[1] Layered PM Infrastructure [2] RIOT/sys/pm_layered/pm.c at master · RIOT-OS/RIOT · GitHub [3] https://github.com/RIOT-OS/RIOT/blob/master/cpu/stm32_common/include/periph_cpu_common.h#L98 [4] cpu: RTC implementation for STM32F1 by Former · Pull Request #11258 · RIOT-OS/RIOT · GitHub [5] pkg/semtech-loramac: provide basic persistence for MAC state by aabadie · Pull Request #11552 · RIOT-OS/RIOT · GitHub