1

Say I'm making a thing which uses some GPIOs to launch a rocket. I wouldn't want to launch the rocket because there was a power outage and the Pi rebooted. As such, it's important to know the startup behavior of the GPIOs.

As an example of some undesirable behavior, I could trigger a launch when GPIO 14 goes high. GPIO 14 is perfectly usable, and can be controlled like any other pin. However, it goes high just for a bit when the Pi is booting. This would inadvertently launch the rocket whenever the Pi reboots.

So, which GPIOs have startup behavior I can rely on, and what is that behavior?

I should note this seems to be a common question, so I expect people will want to close it. So allow me to preemptively explain why the existing answers are insufficient.

A common answer is "GPIOs 0-8 pull high, and GPIOs 9-27 pull low.". This seems to come from the BCM2835 datasheet and is reinforced by the HAT design guide. This may be a correct answer for a BCM2835, but a Raspberry Pi is more than that. It may even be true for a Raspberry Pi with no software, however I think most people will understand "Raspberry Pi" to include an installation of Raspberry Pi OS, which if I had to guess, is what's responsible for the activity on GPIO 14.

6
  • If you really care about the state of a pin at all times then you should be concerned about what happens before the OS starts running. As the supply voltages are becoming stable almost anything can happen. I would never depend on an initial state of a pin for something critical. – Elliot Alderson Jan 12 at 19:48
  • @ElliotAlderson Yes that's true, and that particular problem is usually addressed with some kind of power sequencing IC, which is not specific to the Pi so I don't have to ask about it here. – Phil Frost Jan 12 at 20:05
  • Even with power sequencing you are only guaranteed that the system will be in a valid state at the end of the sequence. There's a big difference between a system that is eventually in a given state versus a system that is guaranteed to always be in a given state. – Elliot Alderson Jan 12 at 20:15
  • @ElliotAlderson right, which is why you configure your device to ignore inputs until the power supply sequencer indicates that all the power supplies have stabilized. Surely you must acknowledge that somehow people do manage to make devices that can be predictable when they are turned on. Again, not really specific to the Pi, and not what I'm asking about. What I need to know about is startup behavior that is specific to the Pi. – Phil Frost Jan 12 at 20:23
  • Yes, people can make devices with predictable behavior at startup, but that doesn't imply that all devices have predictable behavior at startup. Why should the designer worry about GPIO pins if 99.999% of users don't care how they wake up? If Broadcom doesn't guarantee behavior at startup I don't know what you expect to gain from anecdotal evidence on the internet. – Elliot Alderson Jan 12 at 20:28
3

GPIO 0-8 default to weak internal pull-high.

GPIO 9-27 default to weak internal pull-low.

In addition GPIO 2 and 3 on non-compute modules have hard-wired 1k8 pull-ups to 3V3.

All of this (apart from the hard-wired 1k8 pulls) can be overridden by Pi software as it boots.

Any overriding is completely under your control via entries you make in /boot/config.txt and the software you choose to launch.

That said I would avoid the UART GPIO (14/15) as they may be pulsed briefly even if you disable the serial link in /boot/config.txt.

Also avoid GPIO 0 and 1 which form I2C bus 0. This bus is probed at boot to see if a HAT is present (thanks to Phil Frost for pointing this out).

4
  • What about the probing for a HAT EEPROM on GPIO0 and 1? Is there anything else, including things that might be done by software started by Raspberry Pi OS? – Phil Frost Jan 12 at 19:46
  • @PhilFrost Quite right I forgot about HAT probes. I'll add that. You will have to lock down your OS though, there is no telling what OS updates may change in the future. – joan Jan 12 at 20:48
  • 1
    The future aside, I think there's value in an answer which can say something about what the current version of Raspberry Pi OS does today, since this is such a common software configuration. The Broadcom datasheet describes the CPU well enough (like you wrote, gpio 0-8 pull high, 9-27 pull low) but I've not found any complete documentation on what the rest of the Raspberry Pi, including the OS, may do on top of this behavior. – Phil Frost Jan 12 at 21:06
  • @PhilFrost: Agreed (and +1 from me for both Q & A). I've not seen this in the "official" documentation, but it ought to be in there! – Seamus Jan 13 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.