stm32-rs / stm32l0xx-hal

A hardware abstraction layer (HAL) for the STM32L0 series microcontrollers written in Rust
BSD Zero Clause License
96 stars 60 forks source link

Disable regulator when entering Stop on STM32l0x1 #222

Closed jcard0na closed 1 year ago

jcard0na commented 1 year ago

Only category 1 devices of the STM32l0x1 family have a lpds bit on the power configuration register. Categories 2 and above use the lpsdsr bit instead. On STM32l0x2 and STM32l0x3, these two bits are aliased in the stm32l0 crate, so cr.lpds() and cr.lpsdsr() will modify the same bit.

Tested by compiling the pwr.rs example and running it on a STM32L051C8Tx. With the fix, the stop current is reduced by 13.4 uA.

cargo build --release --example pwr --features mcu-STM32L051C8Tx

The problem could not be measured in the pwr.rs example because in it the device is put into low-power sleep mode before entering stop. That code accidentally left the lpsdsr bit set which would then affect the stop mode that followed. Fix this by properly exiting low power sleep.

jamwaffles commented 1 year ago

I just merged #223 which should fix this branch too if you rebase from master.

jamwaffles commented 1 year ago

Thanks!