User avatar
Gavinmc42
Posts: 4196
Joined: Wed Aug 28, 2013 3:31 am

Re: New "gpio" config.txt command announcement

Mon Apr 02, 2018 12:08 pm

It's handled by start.elf and its variants
Thanks I was hoping for that ;)
Good way to get GPIO set quickly before any OS messes them up ;)
Are they set near the start of start.elf, ie quickly after booting <400ms?
Big difference between file sizes of start_cd and start_x
So quickest GPIO setting is done by reading start_cd from SD?

Hmm should be able to use two Pi's to test that now 8-)
One Pi has small OS that changes a pin state, the other Pi resets the first and can test how long start.elf takes to boot and change the pin and then how long the OS takes to change it back.

This simple Ultibo OS returns 3000C1EF, a simple GPIO status display.
Basically reading the GPIO as fast as I can to make a logic analyser.
I have set GPIO4 as GPCLK0 and I can see GPIO toggling between 3000C1EF and 3000C1FF.
By changing the clock speed it tests my capture rate, more useful when DMA/SMI reads gets going.

Some pins like the i2c have pullups, not much I can do about them ;)
But a Pi setup as a logic analyser does not need pins set as outputs on boot.

Code: Select all

  while True  do 
    Begin
     data:=GPIORead(BCM2835_GPLEV0);
     ConsoleWindowWriteLn(WindowHandle,'GPIO 0-31 = ' + IntToHex(data, 8));
    end;          
Should be able to do GPIO level interrupt timing ;)
Very weird thinking about using Pi's as test equipment :o
With the above code I have a build in logic level detector fast enough to capture i2c etc.
Pi's can have built in test equipment for self diagnostics, which is going to take some more thinking about.
Propeller is the only other one I know that can do this easily.

Hmm Digital Multimeter Hat, had not thought of that one before :lol:
Hmm logging Multimeter with bluetooth and wifi, now that could be really useful :shock:

Zero's must be the cheapest and most flexible pieces of kit I have these days.
And you guys just keep on improving them :D
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
TimG
Posts: 295
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: New "gpio" config.txt command announcement

Fri Apr 06, 2018 11:42 pm

jamesh wrote:
Fri Mar 23, 2018 10:57 am
Does anyone actually have anything useful to say on this cool new feature?
It seems to work well to enable pull-ups on overlays that don't otherwise support them (eg. the i2c-gpio overlay which provides extra bit-banged i2c ports). So, thanks for this cool new feature!

User avatar
Gavinmc42
Posts: 4196
Joined: Wed Aug 28, 2013 3:31 am

Re: New "gpio" config.txt command announcement

Sat Apr 07, 2018 2:06 am

Does anyone actually have anything useful to say on this cool new feature?
It is cool, this means other OS's and/or baremetal can use this to set initial GPIO state after boot.
Devicetree is for Linux and not everyone(0.0001%) uses Linux ;) some don't even use Raspbian :o

Since start.elf source code is not open we cannot give you a pat on the back for everything we don't know about.
The VCOS interface is documented and there are some examples but most apply only to Raspbian Linux.

This feature helps make Pi's a bit more useful for IoT apps.
Please stick it in the documentation and don't leave it buried in a few forum posts :D
Perhaps in bootmodes doc? It is very important info and feature.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

gwideman
Posts: 45
Joined: Tue Mar 01, 2016 8:18 pm

Re: New "gpio" config.txt command announcement

Mon Apr 09, 2018 6:32 am

dh - Driving high (for outputs)
dl - Driving low (for outputs)

Do these options set the default output level (logic 1 = high, logic 0 = low), or do they select between the two drive strength options (16mA = high, and 8mA = low)? Thanks.

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

Re: New "gpio" config.txt command announcement

Mon Apr 09, 2018 6:39 am

They set the logic levels - dh for 1, dl for 0.

Embring
Posts: 3
Joined: Thu May 17, 2018 5:34 pm

Re: New "gpio" config.txt command announcement

Thu May 17, 2018 6:05 pm

Is it possible to turn off the I2C drivers forced repeated starts in the new "gpio" config.txt?
It would be great! Really have problems with this issue. The old kernel doesn't work on my brand new 3B+

aBUGSworstnightmare
Posts: 1573
Joined: Tue Jun 30, 2015 1:35 pm

Re: New "gpio" config.txt command announcement

Thu Aug 23, 2018 9:38 am

Hi jamesh,

would like to try this new feature on my custom carrier board.
A custom dt-blob.bin is used atm to configure GPIO to correct function and required initial state. Think this only adds complexity and I'm looking for simpler way.

Question:
will this feature allow to configure PWM (GPIO40 + 41) pins, setting PWM frequency and initial duty cycle? If yes, how?

aBUGSworstnightmare
Posts: 1573
Joined: Tue Jun 30, 2015 1:35 pm

Re: New "gpio" config.txt command announcement

Thu Sep 06, 2018 5:16 pm

aBUGSworstnightmare wrote:
Thu Aug 23, 2018 9:38 am
Question:
will this feature allow to configure PWM (GPIO40 + 41) pins, setting PWM frequency and initial duty cycle? If yes, how?
maybe last post went unnoticed, so let me ask again if PWM can be initialized as well.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7708
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: New "gpio" config.txt command announcement

Thu Sep 06, 2018 5:59 pm

aBUGSworstnightmare wrote:
Thu Sep 06, 2018 5:16 pm
aBUGSworstnightmare wrote:
Thu Aug 23, 2018 9:38 am
Question:
will this feature allow to configure PWM (GPIO40 + 41) pins, setting PWM frequency and initial duty cycle? If yes, how?
maybe last post went unnoticed, so let me ask again if PWM can be initialized as well.
Afaik no. It only allows setting pin muxing and pulls, same as the raspi-gpio command can.
I'd expect that any settings that did get set in there would get overwritten as soon as the Linux kernel driver starts up anyway.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Gord_Fi
Posts: 6
Joined: Wed Feb 27, 2019 8:21 am

Re: New "gpio" config.txt command announcement

Thu Feb 28, 2019 4:12 am

I tried the commands in terminal and most work, but I have an issue the I hope can be explained. Terminal mode write pin 18 works for 1 and 0 but I have an led connected between that and the 3.5 v supply via 470 ohm resistor. What happens is, when I write to pin 18, the readall command reports changes on that pin, but it doesn't happen in real life. Maybe I have to use a transistor driver instead so the sink current isn't to high? When I use the C program from wiki using pigpio.h, the led flashes as it is supposed to. Only issue I have with that is, the terminal screen is locked out when the program is running, ie. when I put printf commands in that timing loop, it's buffered until I Ctrl-C exit the program.. Than all the printf data is dumped. Also, what is the flashing green led indicating? SD IO or WiFi IO?

Any way I can have printf work with the timer, or is there another hardware "tick" I can use instead? I find it difficult to work with the hardware when software isn't cooperating. And the documentation for this is all over the place depending on where you look.

Thanks for any suggestions...

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7708
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: New "gpio" config.txt command announcement

Thu Feb 28, 2019 7:32 am

The gpio command (and the majority of others) work using the chip gpio number, and not the pin number on the header. Pigpio is the exception in often using the header pin number.
Pin 18 is gpio 24. See https://pinout.xyz for a complete mapping.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: New "gpio" config.txt command announcement

Mon Jul 22, 2019 3:52 am

I hope no one minds me bringing this back from the dead but I have a question about the implementation:

Doe the order of the commands reflect the order they are executed?

IE, If I do

Code: Select all

gpio mode 16 output
then the pin will go LOW into output mode (which in my case triggers a relay to the 'on' state), THEN I can do

Code: Select all

gpio write 16 1
and it will switch.

BUT .... If i do

Code: Select all

 gpio write 16 1
then

Code: Select all

gpio mode 16 output
it will go HI into output mode.

Does

Code: Select all

gpio=16=op, dh
go LOW then HIGH like above?

And does

Code: Select all

gpio=16=dh,op
go directly to HIGH without the detour to LOW?

walterwoj
Posts: 28
Joined: Fri Mar 15, 2019 10:46 pm

Re: New "gpio" config.txt command announcement

Fri Jul 26, 2019 12:28 am

I have been testing this out and it would appear this does not apply to all pins. I put this in my config file:

Code: Select all

# Set GPIO Default Positions
# Set to Pull Up Output
gpio=22,23,24,25,26,27,28,29=pu,dh,op
# Set To Pull Up Input
gpio=1,4,5,6,10,11,12,13,14,15,16,=pu,ip
And MOST of the pins change, but not all. In my case the pins 13, 23, 24, 28 and 19 are still 'floating' and the pull up resistor is not engaged. I can engage it manually from the command line and the pins respond but not through the config file. I have even tried the commands individually and those pins do not obey the config file. I have watched them during boot and they do not flicker or change then change back so I don't think there is another file conflicting with it.. I have also only modified the one file for this purpose, so any conflicts would be from stock raspbian.

Any thoughts or guidance?

User avatar
neilgl
Posts: 1252
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: New "gpio" config.txt command announcement

Sat Jul 27, 2019 1:33 pm

Please see the other replies to this in the Beginners section. @walterwoj

User avatar
RDK
Posts: 271
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: New "gpio" config.txt command announcement

Mon Dec 23, 2019 1:06 pm

I've been reading about the GPIO facilities and uses. I had begun to think I was understanding it until I arrived at this GPIO config.txt discussion!

Can someone please detail which pin numbering system is to be used in the config.txt file? WiringPi, BCM or BOARD?

In the rc.local the answer is WiringPi, in Python (RPi.GPIO) one can choose: BOARD or BCM. I do not see where this is defined for the config.txt file.

Thanks....RDK

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

Re: New "gpio" config.txt command announcement

Mon Dec 23, 2019 1:12 pm

BCM numbering only.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
RDK
Posts: 271
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: New "gpio" config.txt command announcement

Mon Dec 23, 2019 3:03 pm

Thanks. I'll give config.txt a try....RDK

User avatar
RDK
Posts: 271
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: New "gpio" config.txt command announcement

Mon Dec 23, 2019 4:18 pm

OK, it works for me. Before I had this code in the rc.local to initialize the pins being used in my application:

Code: Select all

	# BCM pin 12 is the same as wPi pin 26 or physical pin 32
	# BCM pin 16 is the same as wPi pin 27 or physical pin 36
	# BCM pin 20 is the same as wPi pin 28 or physical pin 38
	# BCM pin 21 is the same as wPi pin 29 or physical pin 40

	sudo /usr/bin/gpio write 26 1
	sudo /usr/bin/gpio mode 26 out
	sudo /usr/bin/gpio write 27 1
	sudo /usr/bin/gpio mode 27 out
	sudo /usr/bin/gpio write 28 1
	sudo /usr/bin/gpio mode 28 out
	sudo /usr/bin/gpio write 29 1
	sudo /usr/bin/gpio mode 29 out
It worked but the rc.local is run at the end of the boot process which could have mixed results for my application.

To try this new function with the config.txt, I added this to the [all] section of the /boot/config.txt, using BCM pin codes

Code: Select all

[all]
gpio=12,16,20,21=dh,op
I did not use either the "pu" or "pd" options as I'm not really sure what they do. Regardless this resulted in the pins being set almost immediataely when the Pi was booting up. My application worked.

Thanks....RDK

User avatar
rpdom
Posts: 15868
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: New "gpio" config.txt command announcement

Mon Dec 23, 2019 5:14 pm

Code in rc.local does not need sudo. It is already running as root.

I prefer to use the BCM numbers for everything. If I were to use the WiringPi "gpio" command I would code it like this:

Code: Select all

# BCM pin 12 is the same as wPi pin 26 or physical pin 32
# BCM pin 16 is the same as wPi pin 27 or physical pin 36
# BCM pin 20 is the same as wPi pin 28 or physical pin 38
# BCM pin 21 is the same as wPi pin 29 or physical pin 40

/usr/bin/gpio -g write 12 1
/usr/bin/gpio -g mode 12 out
/usr/bin/gpio -g write 16 1
/usr/bin/gpio -g mode 16 out
/usr/bin/gpio -g write 20 1
/usr/bin/gpio -g mode 20 out
/usr/bin/gpio -g write 21 1
/usr/bin/gpio -g mode 21 out
or use the new raspi-gpio command like this

Code: Select all

# BCM pin 12 is the same as wPi pin 26 or physical pin 32
# BCM pin 16 is the same as wPi pin 27 or physical pin 36
# BCM pin 20 is the same as wPi pin 28 or physical pin 38
# BCM pin 21 is the same as wPi pin 29 or physical pin 40

/usr/bin/raspi-gpio set 12,16,20,21 op dh

User avatar
RDK
Posts: 271
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: New "gpio" config.txt command announcement

Tue Dec 24, 2019 5:56 am

Thanks. Yes, I would prefer to use only one numbering system. Where did you find the documentation for the use of BCM numbering in the rc.local? I did some searching without success.

Can I assume that this use of the config.txt to set the gpio pins is only available in Buster?

Thanks again...RDK

Milliways
Posts: 495
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: New "gpio" config.txt command announcement

Tue Dec 24, 2019 6:29 am

RDK wrote:
Mon Dec 23, 2019 1:06 pm
In the rc.local the answer is WiringPi, in Python (RPi.GPIO) one can choose: BOARD or BCM. I do not see where this is defined for the config.txt file.
The only thing that uses the WiringPi numbering is WiringPi - and it is deprecated!

User avatar
rpdom
Posts: 15868
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: New "gpio" config.txt command announcement

Tue Dec 24, 2019 8:14 am

RDK wrote:
Tue Dec 24, 2019 5:56 am
Can I assume that this use of the config.txt to set the gpio pins is only available in Buster?
It was available in Stretch, I believe.

Return to “Interfacing (DSI, CSI, I2C, etc.)”