juanma_cab
Posts: 27
Joined: Fri Mar 26, 2021 3:56 pm

Device Tree for switch on power on indicator

Tue May 11, 2021 6:51 am

Hi everyone, I'm using device tree to power on a led that indicates the Raspberry is on using this line on my config.txt:

dtoverlay=gpio-led,gpio=27,label=pwr_led,trigger=heartbeat

I'm using a button to switch on and switch off the Raspberry, but I realize that It takes a few seconds between the Rasp starts and the led is on. Is there any way to reduce this time at minimum?

I found this device trees on https://github.com/raspberrypi/firmware ... ays/README:

pwr_led_trigger
pwr_led_activelow
pwr_led_gpio

But there is not information available, maybe are they faster for switch on indicator?


Thank you so much!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Device Tree for switch on power on indicator

Tue May 11, 2021 7:28 am

You'll get a much quicker response using the "gpio=" directive in config.txt. On a Pi 4 (including the Pi 400 and CM4) this is executed by the boot EEPROM, and on other Pis its run by the firmware. To simply drive GPIO 20 high use:

Code: Select all

gpio=20=op=dh
The syntax is documented here: https://www.raspberrypi.org/documentati ... xt/gpio.md

juanma_cab
Posts: 27
Joined: Fri Mar 26, 2021 3:56 pm

Re: Device Tree for switch on power on indicator

Tue May 11, 2021 8:51 am

PhilE wrote:
Tue May 11, 2021 7:28 am
You'll get a much quicker response using the "gpio=" directive in config.txt. On a Pi 4 (including the Pi 400 and CM4) this is executed by the boot EEPROM, and on other Pis its run by the firmware. To simply drive GPIO 20 high use:

Code: Select all

gpio=20=op=dh
The syntax is documented here: https://www.raspberrypi.org/documentati ... xt/gpio.md
Thank you so much! I though than using tthe led-gpio triggers it will be much more faster. Thank you so much!

Another question, Is the lines config.txt order influence on the priority to execute the lines?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Device Tree for switch on power on indicator

Tue May 11, 2021 9:02 am

Yes and no. There are multiple phases of the config.txt parsing:
1. The boot EEPROM (on Pi 4s) looks at start_x, gpu_mem, gpio and a few other settings - in order.
2. The main firmware parsing for the majority of the settings (including gpio again) - in order.
3. Any dtoverlay and dtparam settings - again, in order.

juanma_cab
Posts: 27
Joined: Fri Mar 26, 2021 3:56 pm

Re: Device Tree for switch on power on indicator

Tue May 11, 2021 9:52 am

PhilE wrote:
Tue May 11, 2021 9:02 am
Yes and no. There are multiple phases of the config.txt parsing:
1. The boot EEPROM (on Pi 4s) looks at start_x, gpu_mem, gpio and a few other settings - in order.
2. The main firmware parsing for the majority of the settings (including gpio again) - in order.
3. Any dtoverlay and dtparam settings - again, in order.
I test your code on my Raspi 4B and yes, it is faster, but there is a 5-6 seconds delay between the raspi on and the led on, Is there no way to reduce this time at 1 second or this is imposible by software?

Thank you so much!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Device Tree for switch on power on indicator

Tue May 11, 2021 10:17 am

Training the SDRAM PHYs and running temperature calibration takes time - 5-6 seconds is the best you can do unless you choose a pin that is always high (e.g. one of the 3.3V pins) or pulls high by default (GPIOs 0-8).

cleverca22
Posts: 3752
Joined: Sat Aug 18, 2012 2:33 pm

Re: Device Tree for switch on power on indicator

Tue May 11, 2021 2:34 pm

PhilE wrote:
Tue May 11, 2021 10:17 am
Training the SDRAM PHYs and running temperature calibration takes time - 5-6 seconds is the best you can do unless you choose a pin that is always high (e.g. one of the 3.3V pins) or pulls high by default (GPIOs 0-8).

Code: Select all

OTP 67
0x80 enable bit 
0x40 first level
0x3f bitmask for pin#

the given pin is set to "first level", then 25ms later, the reverse
according to my notes, OTP67 allows driving a configured pin to a configured level for 25ms, then driving it in the reverse level
this occurs within the boot rom, before the boot EEPROM and dram training gets involved

its a much more permanent option, but it might be something that could be done

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Device Tree for switch on power on indicator

Tue May 11, 2021 2:47 pm

Ignoring all the potential dangers of encouraging somebody to write to OTP (don't go there), 25ms is a bit short for a user LED. Using the default pull that is later reversed/replaced with an output is a much better option.

cleverca22
Posts: 3752
Joined: Sat Aug 18, 2012 2:33 pm

Re: Device Tree for switch on power on indicator

Tue May 11, 2021 3:00 pm

PhilE wrote:
Tue May 11, 2021 2:47 pm
Ignoring all the potential dangers of encouraging somebody to write to OTP (don't go there), 25ms is a bit short for a user LED. Using the default pull that is later reversed/replaced with an output is a much better option.
but if you program it backwards, it will turn it off for 25ms, then turn it back on, i think it left it in output after reversing it

as for the dangers of writing to OTP, adding a config.txt flag like the old pi3 enable-usb-boot flag, would make it safer, if engineers choose to expose that officially

juanma_cab
Posts: 27
Joined: Fri Mar 26, 2021 3:56 pm

Re: Device Tree for switch on power on indicator

Wed May 12, 2021 2:32 pm

cleverca22 wrote:
Tue May 11, 2021 2:34 pm
PhilE wrote:
Tue May 11, 2021 10:17 am
Training the SDRAM PHYs and running temperature calibration takes time - 5-6 seconds is the best you can do unless you choose a pin that is always high (e.g. one of the 3.3V pins) or pulls high by default (GPIOs 0-8).

Code: Select all

OTP 67
0x80 enable bit 
0x40 first level
0x3f bitmask for pin#

the given pin is set to "first level", then 25ms later, the reverse
according to my notes, OTP67 allows driving a configured pin to a configured level for 25ms, then driving it in the reverse level
this occurs within the boot rom, before the boot EEPROM and dram training gets involved

its a much more permanent option, but it might be something that could be done
I don't know if i understand it well, the solution you are talking about, could it switch on a led 25 ms from start of the raspberry and after switch off or reverse? Could the system take the control of that gpio later?

juanma_cab
Posts: 27
Joined: Fri Mar 26, 2021 3:56 pm

Re: Device Tree for switch on power on indicator

Wed May 12, 2021 2:34 pm

PhilE wrote:
Tue May 11, 2021 2:47 pm
Ignoring all the potential dangers of encouraging somebody to write to OTP (don't go there), 25ms is a bit short for a user LED. Using the default pull that is later reversed/replaced with an output is a much better option.
Yes, but that way doesn't allow to use the led as a power on indicator, does it?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Device Tree for switch on power on indicator

Wed May 12, 2021 2:35 pm

The intention was that it would switch a GPIO/LED off then on again 25ms later, leaving it on - but don't go down that route.

juanma_cab
Posts: 27
Joined: Fri Mar 26, 2021 3:56 pm

Re: Device Tree for switch on power on indicator

Thu May 13, 2021 6:13 am

PhilE wrote:
Wed May 12, 2021 2:35 pm
The intention was that it would switch a GPIO/LED off then on again 25ms later, leaving it on - but don't go down that route.
Understood, other way I have searched is using a MCU to govern the led as the same time as a button I'm using for switch on, is the best option, isn't it?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Device Tree for switch on power on indicator

Thu May 13, 2021 7:42 am

If you have an MCU in the design then getting it to manage the LED for you is the most flexible, but you probably want to make it controllable from Linux which adds complexity.

I still think that using a GPIO that naturally pulls high (GPIO0 to GPIO8) as the LED control signal is the best way to go. Once Linux boots it can take over that GPIO and drive the LED in the usual way.

juanma_cab
Posts: 27
Joined: Fri Mar 26, 2021 3:56 pm

Re: Device Tree for switch on power on indicator

Thu May 13, 2021 8:36 am

PhilE wrote:
Thu May 13, 2021 7:42 am
If you have an MCU in the design then getting it to manage the LED for you is the most flexible, but you probably want to make it controllable from Linux which adds complexity.

I still think that using a GPIO that naturally pulls high (GPIO0 to GPIO8) as the LED control signal is the best way to go. Once Linux boots it can take over that GPIO and drive the LED in the usual way.
But the led won't switch down when Raspberry is off if I use a naturally pull high GPIO, will it? I have though about use a GPIO as as input for the MCU, that way that GPIO will be able to take the control of the LED too (by mcu, obviusly).

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3881
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Device Tree for switch on power on indicator

Thu May 13, 2021 9:51 am

True - if you aren't going to actually switch off the power then the reset associated with a shutdown will re-enable the LED. It sounds like the MCU is the way to go.

juanma_cab
Posts: 27
Joined: Fri Mar 26, 2021 3:56 pm

Re: Device Tree for switch on power on indicator

Fri May 14, 2021 6:40 am

PhilE wrote:
Thu May 13, 2021 9:51 am
True - if you aren't going to actually switch off the device then the reset associated with a shutdown will re-enable the LED. It sounds like the MCU is the way to go.
Thank you so much for your answers PhilE! You have helped me a lot!

Return to “Device Tree”