Open matthijskooijman opened 3 years ago
Wrt to stop mode and peripherals:
STM32L0_SYSTEM_LOCK_STOP
prevents stop mode from being entered at all. This lock is taken by USB (when attached/enabled) ADC (during conversion), DAC (when enabled), EEPROM/Flash (while writing), I²C (during a transaction), SDSPI (?), SPI (during transactions), UART (when wakup is enabled and maybe also during RX)STM32L0_SYSTEM_LOCK_REGULATOR
prevents the regulator from going into low-power mode. This lock is taken by UART (when wakup enabled and baud > 19200).STM32L0_SYSTEM_LOCK_VREFINT
prevents the voltage reference from being disabled. This lock is taken by the HSI48 clock (while enabled), which is enabled by the random generator (while generating a number), MCO (clock output, when enabled) and USB (when enabled).SPI.end()
or Serial1.end()
probably helps to lower power usage further.Serial.end()
, though, since that just seems to disable the CDC serial part, not the USB core. Attach/detach seems to be possible using USBDevice.attach()
/ USBDevice.detach()
, but there is no way to de-initialize, it seems.All this is with the 0.0.10 core version. It seems that git master has seen significant changes in how this locking and powersaving works, see also https://github.com/GrumpyOldPizza/ArduinoCore-stm32l0/issues/125. The overall approach is still the same, except that now the USB stack completely shuts down when VBUS is not present (which won't help for us), but also when USBDevice.detach()
is called, which is ideal.
It seems we could even try using USB suspend mode to keep the USB device enumerated during stop.
For MJS2020, I now implemented basic powersaving based on the STM32 "Stop" mode, resulting in about 3.6mA while sleeping. This mode stops all core clocks and some peripherals, puts the internal regulator in a low-power mode and is the lowest-power mode that preserves memory contents ("Standby mode" is even lower power, but greatly complicates programming because memory contents is lost, and the gain is limited - 0.45μA for stop, 0.29μA for standby).
There are still more things that can be done to improve power usage, both to improve the sleep power usage, as well as improve the overall power usage.
STM32L0_GPIO_PARK_HIZ
, but it seems the defaultpinMode
does not support this. However, it can be done explicitly before/after sleep too usingpinMode(pin, HIGHZ)
.