GPIO.setup() doesn't check for pin number being valid
A Python module to control the GPIO on a Raspberry Pi
Brought to you by:
croston
Was setting up a push button as an input and accidentally used pin 34 instead of 24 (BCM numbering). Was using a VNC connection to the Pi, and running the code caused the connection to drop. Going non-headless revealed the Pi was still funciotning, but certain windows started freezing. Couldn't do a normal shutdown, so had to hard restart (pull power). Code was written in Jupyter Notebooks.
Can't say for certain, but it seems to me like GPIO.setup() doesn't actually check the value of the pin number to see if it's valid.
I'm afraid GPIO34 is a valid GPIO number ... it's just not a physical one. That may sound like splitting hairs but there's actually precedent for using non-physical GPIO numbers. For instance, on the v1 camera module the camera's LED was controlled by toggling GPIO 5 (on older Pi models this wasn't present on the header), or GPIO 32 (for newer Pi models - again a pin that isn't present on the header). There are also GPIO pins on certain Pi models that can be used to control the "ACT" LED on the board.
Off the top of my head, I'm not sure what GPIO34 controls by default but it's presumably something vaguely important if toggling it caused things to start freezing. Anyway - while RPi.GPIO could check whether the requested GPIO is non-physical it would be removing functionality if it actively rejected requests to control non-physical GPIOs.