aurelia
Posts: 1
Joined: Mon Jan 15, 2018 2:34 pm

how do i activate my GPIO at boot with DT overlay?

Mon Jan 15, 2018 3:39 pm

Hello i've got a board connected to my raspberry pi 3 and according to the pin set on boot of the raspberry this shield reboot which is problematic. I need to be able to reset the board and control the pin. I cannot add an EEPROM to use the Raspberry shield system, so i tried to add an overlay to the DT to activate the gpio to an high output at boot but it doesn't work.
My overlay:

Code: Select all

// Definitions for gpio module 
/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target-path = "/";
		__overlay__ {
			test_board: test_board {
				compatible = "brcm,bcm2835";
				pinctrl-names = "default";
				pinctrl-0 = <&test_board_pin>;
				gpio-controller;
				gpios = <&gpio 27 0>;//GPIO active high is 0
				default-state = "keep";
				non-removable;
				#gpio-cells = <2>;
				status = "okay";
			};
		};
	};
	fragment@1 {
		target = <&gpio>;
		__overlay__ {
			test_board_pin: test_board_pin {
				status = "okay";
				brcm,pins = <27>;
				brcm,pull = <1>;//pull-down
				brcm,function = <1>; // out 
				output-hight;
			};
		};
	};
};
I compile it:

Code: Select all

dtc -W no-unit_address_vs_reg -@ -I dts -O dtb -o test_board.dtbo gpio-test-overlay.dts 
I add it to the overlay:

Code: Select all

sudo cp test_board.dtbo /boot/overlays
I activate it:

Code: Select all

dtoverlay=test_board
I reboot.
I check that it wok:

Code: Select all

dtc -I fs /proc/device-tree > look1.txt

Code: Select all

		gpio@7e200000 {
			compatible = "brcm,bcm2835-gpio";
			gpio-controller;
			#interrupt-cells = <0x2>;
			interrupts = <0x2 0x11 0x2 0x12>;
			phandle = <0xc>;
			reg = <0x7e200000 0xb4>;
			#gpio-cells = <0x2>;
			interrupt-controller;

			i2c1 {
				brcm,pins = <0x2 0x3>;
				phandle = <0x13>;
				brcm,function = <0x4>;
			};

			test_board_pin {
				brcm,pins = <0x1b>;
				status = "okay";
				phandle = <0x4b>;
				brcm,pull = <0x1>;
				brcm,function = <0x1>;
				linux,phandle = <0x4b>;
				output-hight;
			};

			spi0_pins {
				brcm,pins = <0x9 0xa 0xb>;
				phandle = <0xd>;
				brcm,function = <0x4>;
			};

			sdhost_pins {
				brcm,pins = <0x30 0x31 0x32 0x33 0x34 0x35>;
				phandle = <0x17>;
				brcm,function = <0x4>;
			};

			uart1_pins {
				brcm,pins;
				phandle = <0x11>;
				brcm,pull;
				brcm,function;
			};

			i2s {
				brcm,pins = <0x12 0x13 0x14 0x15>;
				phandle = <0xb>;
				brcm,function = <0x4>;
			};
	aliases {
		intc = "/soc/interrupt-controller@7e00b200";
		spi2 = "/soc/spi@7e2150c0";
		i2c1 = "/soc/i2c@7e804000";
		i2c_vc = "/soc/i2c@7e205000";
		spi0 = "/soc/spi@7e204000";
		thermal = "/soc/thermal";
		vchiq = "/soc/vchiq";
		sdhost = "/soc/sdhost@7e202000";
		aux = "/soc/aux@0x7e215000";
		gpio = "/soc/gpio@7e200000";
		audio = "/soc/audio";
		dma = "/soc/dma@7e007000";
		soc = "/soc";
		leds = "/leds";
		mmc = "/soc/mmc@7e300000";
		serial1 = "/soc/serial@7e201000";
		i2c_arm = "/soc/i2c@7e804000";
		ethernet = "/soc/usb@7e980000/usb1@1/usbether@1";
		uart0 = "/soc/serial@7e201000";
		fb = "/soc/fb";
		i2c2 = "/soc/i2c@7e805000";
		i2s = "/soc/i2s@7e203000";
		spi1 = "/soc/spi@7e215080";
		usb = "/soc/usb@7e980000";
		i2c0 = "/soc/i2c@7e205000";
		watchdog = "/soc/watchdog@7e100000";
		sound = "/soc/sound";
		mailbox = "/soc/mailbox@7e00b880";
		uart1 = "/soc/serial@7e215040";
		random = "/soc/rng@7e104000";
		i2c = "/soc/i2c@7e804000";
		serial0 = "/soc/serial@7e215040";
	};
.......................
	chosen {
		bootargs = "8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=436d5485-02 rootfstype=e
xt4 elevator=deadline fsck.repair=yes rootwait";
		kaslr-seed = <0x895630ca 0x6a72a22f>;
	};

	test_board {
		gpios = <0xc 0x1b 0x0>;
		compatible = "brcm,bcm2835";
		gpio-controller;
		status = "okay";
		phandle = <0x4c>;
		#gpio-cells = <0x2>;
		pinctrl-0 = <0x4b>;
		default-state = "keep";
		linux,phandle = <0x4c>;
		non-removable;
		pinctrl-names = "default";
	};
		
So the code is well integrated in the DT but the gpio is not exported, and when i export it, i can see that it's not set to output but input.

Can you help me to activate my GPIO?

thanks

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 11 guests