User avatar
jens.maus
Posts: 16
Joined: Sun Jan 01, 2017 10:53 am
Location: Dresden, Germany
Contact: Website

How to get udev ignoring GPIO states upon bootup?

Wed Jun 20, 2018 12:49 pm

Hello RaspberryPiers,

I am maintaining a project here where I use buildroot to be run on the RaspberryPi platform. During bootup udev is started to identify various devices, etc. I noticed that as soon as udev is started the first time (during bootup) it seems to resets all GPIO states (in/out) to their default values. That means, if I use e.g. the wiringpi to to set a certain pin (e.g. GPIO.28) to being an OUT pin using the following command:

Code: Select all

/usr/bin/gpio mode 28 out
Then as soon as udev is started for the first time it will reset this GPIO to the default "ALT0" state.

Now I wonder if there is a possibility that I can prevent this from happening so that e.g. udev does not reset the gpio pins to their default values but keep them untouched.

Any help would be appreciated.

Best Regards,
Jens

User avatar
DougieLawson
Posts: 34166
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to get udev ignoring GPIO states upon bootup?

Wed Jun 20, 2018 8:56 pm

Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
jens.maus
Posts: 16
Joined: Sun Jan 01, 2017 10:53 am
Location: Dresden, Germany
Contact: Website

Re: How to get udev ignoring GPIO states upon bootup?

Wed Jun 20, 2018 9:35 pm

Thanks for your reply and your suggestion. I, of course, know about the new 'gpio' command and this would indeed be a potential possibility to set a certain gpio to out right at the boot loader level. However, what I am searching for is a possibility that when starting udev it does not reset all gpio states to their default values because I might have already set them to something else right after boot and before starting udev.

User avatar
jens.maus
Posts: 16
Joined: Sun Jan 01, 2017 10:53 am
Location: Dresden, Germany
Contact: Website

Re: How to get udev ignoring GPIO states upon bootup?

Thu Jun 21, 2018 7:33 am

Just to illustrate the issue once more:

Here is the wiringpi output before udev started:

Code: Select all

| 36 | 0 | OUT  | GPIO.27 | 27  | 16  |
| 38 | 0 | OUT  | GPIO.28 | 28  | 20  |
| 40 | 0 | OUT  | GPIO.29 | 29  | 21  |
And here it is after udev was started:

Code: Select all

| 36 | 0 | OUT  | GPIO.27 | 27  | 16  |
| 38 | 0 | ALT0 | GPIO.28 | 28  | 20  |
| 40 | 0 | ALT0 | GPIO.29 | 29  | 21  |
And it also does not help if I use the 'gpio' command in 'config.txt' as pointed out above. 'udev' is always changing the GPIO.28 and GPIO.29 to ALT0. And please note, that this only happens for the first time udev is started. If I stop it and start it again it does not change GPIO modes again.
I can of course manually switch it back to OUT using wiringpi. But I still want to avoid that and I wonder what is actually triggering this pin mode change?

Any help appreciated!

User avatar
DougieLawson
Posts: 34166
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to get udev ignoring GPIO states upon bootup?

Thu Jun 21, 2018 8:28 am

GPIO28 and 29 are not externalised on any 40-pin Raspberry Pi. They're only available on a CM/CM3/CM3L and on the RPi1B with the P5 header https://elinux.org/RPi_Low-level_peripherals#P5_header.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
jens.maus
Posts: 16
Joined: Sun Jan 01, 2017 10:53 am
Location: Dresden, Germany
Contact: Website

Re: How to get udev ignoring GPIO states upon bootup?

Thu Jun 21, 2018 12:33 pm

Sorry, but I was of course using the wiringPi numbering für GPIOs (see wiringPi for more info on the unified numbering there). I was of course referencing to gpio16=pin36, gpio20=pin38 and gpio21=pin40.

So this is not the issue. The issue is really that udev is resetting IN/OUT modes of gpios once it is run for the very first time. And if I use the new 'gpio' command in config.txt it still does the same.

asavah
Posts: 347
Joined: Thu Aug 14, 2014 12:49 am

Re: How to get udev ignoring GPIO states upon bootup?

Thu Jun 21, 2018 8:52 pm

AFAIK udev does nothing to gpio pins unless explicitly told so.


Here is the output from my pi3 after udev has started:

Code: Select all

| 36 | 1 | IN   | GPIO.27 | 27  | 16  |
| 38 | 1 | IN   | GPIO.28 | 28  | 20  |
| 40 | 1 | IN   | GPIO.29 | 29  | 21  |
The pins you see in ALT0 are used for i2s ,
if i2s is enabled in config.txt (see dtparam=) the module will be loaded and the corresponding pins will be configured accordingly.

Paste your config.txt and read the fine documentation

hlev80
Posts: 4
Joined: Thu Oct 12, 2017 9:21 pm

Re: How to get udev ignoring GPIO states upon bootup?

Tue Jun 26, 2018 7:58 am

Have you checked your udev rules for a suspect both in /lib/udev/rules.d and /etc/udev/rules.d?

Return to “Advanced users”