Skip to content

Latest commit

 

History

History
396 lines (232 loc) · 23.3 KB

RPi4bSleep.md

File metadata and controls

396 lines (232 loc) · 23.3 KB

Minimize Raspberry Pi 4B Power Consumption After halt... or shutdown... or poweroff

N.B. If you are using - or have plans to use - the dtoverlay=gpio-poweroff in /boot/config.txt, please review the UPDATES before you proceed here.


Who cares about minimizing power consumption?

For those considering the RPi 4B for a role in an off-grid project, a mobile application, or anyone else who needs to power the RPi 4B from a battery for more than a few minutes, this recipe may be of interest. Or, perhaps, anyone who simply doesn't wish to see energy wasted - that is to say converted to heat, without anything useful being accomplished in the expenditure.

Unfortunately, no RPi has yet been been designed or produced with a "sleep mode". And no RPi has been produced that complies with the "One Watt Initiative" - which has actually been the one-half watt initiative since 2013! Perhaps the folk pimping Pis in the name of charitable education in Cambridge, UK are ignorant of the "One Watt Initiative"? With well over 30 million RPi units manufactured and sold to date, and volumes now in the range of 10 million units per year, an outsider may wonder why this has been ignored. It's been opined by some that the RPi does not incorporate energy saving features because they would add to the cost...?! Think on that one for a moment, but it's time to end the rant, and get on with the subject at hand.

Some background

This all started when I read a post made by a "Raspberry Pi Engineer" in the Raspberry Pi Organization's forum. In this post, dated June 24, 2019 it was claimed:

"sudo poweroff" will shut down the PMIC [Power Management Integrated Circuit - a RPi hardware component that controls power distribution] at the conclusion of the shutdown sequence. This reduces power consumption to about 3mA but requires pulling GLOBAL_EN low (or cycling input power) to wake the PMIC up.

There's user-modifiable EEPROM setting to change this behaviour (halt instead of poweroff, allows GPIO pin wake) but these are currently deliberately undocumented until we have a reliable, scripted way to change these.

More than two years and several firmware revisions later, this claim remains unrealized, although giving full credit, it seems there have been some improvements. Following are the results of measurements made on my RPi 4B since this recipe was initially published:

  • While up and running:

    • The Apr 29 2021 version of the bootloader: approx 2.0 Watts; 400mA
    • The Jun 15, 2020 version of the bootloader: approx 2.5 Watts; 500mA
  • Following shutdown, halt or poweroff with default bootloader configuration:

    • The Apr 29 2021 version of the bootloader: approx 1.35 Watts; 270mA
    • The Jun 15, 2020 version of the bootloader: approx 1.85 Watts; 370mA
  • Following shutdown, halt or poweroff with Low Power Mode bootloader configuration:

    • Tue Jan 25 2022 version of the bootloader: approx 0.2 Watts; 40mA
    • The Apr 29 2021 version of the bootloader: approx 0.15 Watts; 35mA
    • The Jun 15, 2020 version of the bootloader: approx 0.2 Watts; 40mA

    NOTE 1: busterOS, Lite distro for RPi, no monitor, quiescent/idle compute load, CPU governor: ondemand

    NOTE 2: No differences in power consumption noted between halt, shutdown poweroff

What is "Low Power Mode" (LPM) - Is it a "Sleep Mode"?

No... the Raspberry Pi has no Sleep mode; it does not have a complete set of any of the states considered to constitute "Sleep mode". It only has the ability to reduce its power consumption following a halt, shutdown, or poweroff command. Consequently, "Low Power Mode" (LPM) is simply a state of reduced power consumption after all processing has been terminated - it does not save state, and offers no way to restore or resume processing. Restoring the RPi to an operational mode may only be accomplished by a reboot. A reboot is triggered by removing and re-installing power ("pulling the plug"), or by using an external switch to trigger a reboot; for example the RUN or GLOBAL_EN terminals on the board.

How to configure LPM for the RPi 4B:

The RPi 4B represents a break from previous models in that bootloader code is stored in EEPROM - the boot code is now resident in the hardware instead of in the /boot/bootcode.bin file on the SD card. With this change came a new set of configuration parameters, and new software tools to assist managing the bootloader. Most of the "official documentation" on the EEPROM-based bootloader is in two locations:

The "Low Power Mode (LPM)" is not the default bootloader configuration. However, reviewing the referenced documents above tells us what we need know to re-configure the system. As you see below, making this configuration change is very simple now:

NOTE: Review the "official" documentation to confirm these instructions remain valid.

1. Open the bootloader configuration file for editing:
  ```bash
  $ sudo -E rpi-eeprom-config --edit 
  [all]
  BOOT_UART=0
  WAKE_ON_GPIO=1
  POWER_OFF_ON_HALT=0
  DHCP_TIMEOUT=45000
  DHCP_REQ_TIMEOUT=4000
  TFTP_FILE_TIMEOUT=30000
  ENABLE_SELF_UPDATE=1
  DISABLE_HDMI=0
  BOOT_ORDER=0xf41
  ```
2. Change two (2) parameters (WAKE_ON_GPIO and POWER_OFF_ON_HALT) in the editor as follows:
  ```bash
  # WAKE_ON_GPIO:       CHANGE FROM: 1  TO: 0
  # POWER_OFF_ON_HALT:  CHANGE FROM: 0  TO: 1
  ```
3. Save changes & re-boot
  ```bash
  # Save the changes, and exit the editor. 
  # After the editor closes, you'll be prompted to reboot into the new configuration
  
  $ sudo reboot
  ```

Configured in this way, you will see a marked reduction in power consumption (and current draw) the next time you issue a halt, shutdown, or poweroff command - or shut down your system using the desktop.

4. Test the change:

The EEPROM firmware has now been modified, and the system has booted with the modified firmware. How did these modifications affect power consumption? See the measured results in the table below:

NOTE: All measurements made with Ethernet cable connecting RPi 4 to Ethernet Switch.

BEFORE BOOTLOADER MODIFICATION AFTER BOOTLOADER MODIFICATION
critical/pieeprom-2020-04-16.bin stable/pieeprom-2020-06-15.bin
WAKE_ON_GPIO=1 WAKE_ON_GPIO=0
POWER_OFF_ON_HALT=0 POWER_OFF_ON_HALT=1
Measured current while running: 0.51A Measured current while running: 0.50A
Measured current after halt/poweroff: 0.37A Measured current after halt/poweroff: 0.04A
5. Summary

That's a 90% reduction in power consumption in halt/poweroff mode. It's certainly an improvement, but given the initial claim, a bit disappointing. Not only is the power consumption in "Low Power Mode" an order of magnitude greater than claimed by "Raspberry Pi Engineer", it's not low enough to permit battery-powered operation in many remote-sensor applications.

Is there a downside to LPM?

If you are using the "One Button Startup/Shutdown" feature enabled by the gpio-shutdown dtoverlay REF, you will find this no longer works. As The Foundation currently has things jiggered, the only way (other than "pulling the plug") to reboot the RPi is to pull down & release the GLOBAL_EN node (see figure below). For now, this will require adding a separate switch/button tied to GLOBAL_EN, or some additional hardware - as in this example.

global_en_location


OTHER REFERENCES:

  1. Raspberry Pi 4 boot EEPROM - The "official" documentation on administration of the EEPROM bootloader code.
  2. Raspberry Pi 4 bootloader configuration - The "official" documentation on the configuration parameters
  3. Raspberry Pi 4 Bootloader Firmware Updating / Recovery Guide from James Chambers' Legendary Technology Blog
  4. The Foundation's GitHub page for device tree overlays - everything you wanted to know, but ...
  5. An RPi Forum post with some insights on the raison d'etre for the device tree
  6. While contemplating absence of sleep mode in RPI, review man logind.conf, and man sleep.conf

UPDATES:

2021/04/24: For reasons that are not entirely clear, the "low power configuration" outlined here cannot be used with the dtoverlay=gpio-poweroff in /boot/config.txt. IOW: You may use the "low power configuration" described here, OR the gpio-poweroff overlay BUT NOT BOTH.

2021/04/30: This seems to be resolved now. It was classified by the RPi maintainers as not a bug, but eventually the team made some changes in the gpio-poweroff kernel code to remediate the issue. I've not gotten around to testing the it yet. Will post again when I have.