Skip to content

low-power: embassy-executor sets alarm with Instant::MAX #2381

Open
@chrenderle

Description

@chrenderle

I found a problem with the embassy-executor and the low-power feature in embassy-stm32. In my example the executor sets an alarm for Instant::MAX when I spawn my (only) task.

if driver::set_alarm(self.alarm, next_expiration.as_ticks()) {
The low-power executor then goes to sleep with the maximum rtc wakeup time, which is 32s because of the Instant::MAX alarm set. After this it checks the alarm again which isn't Instant::MAX anymore. From then on it behaves correctly. But because of this initial Instant::MAX alarm the MCU always sleeps 32s before executing the program correctly. I assume this is because it polls the raw executor once again where my task calls Timer::after, which then sets the alarm properly.

The question now is what is the best way to fix this. You could fix this by only calling set_alarm in the executor when the timestamp is not Instant::MAX. There might also be some other fix in the executor. But in any case I don't want to make any changes there since I don't know all requirements and don't want to break anything.

The other way to fix this would be to have the time driver discard any set_alarm calls which pass Instant::MAX as a timestamp.

In any case it would be good if someone more experienced in the executor and the time driver of stm32 could have a look into this.

I uploaded a fix to my embassy fork (chrenderle@7d6b7ea). It is only a demonstration how you could fix it in the executor. I tested it on my NUCLEO-L552ZE-Q. But this does currently not compile with STM32L5, because embassy-rs/stm32-data#325 is not yet merged. I worked around this by building stm32-metapac locally.

My fork also includes another minor change (chrenderle@96edbcc). Without it the low-power executor does not always suspend execution properly. This is later necessary for STOP suspension. Without this change the error I'm describing is also not active, since the low-power executor doesn't suspend properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions