carlo.antinarella
Posts: 4
Joined: Mon Jan 29, 2018 7:25 am

Setting GPIO alternate functions by modifying the device tree

Mon Jan 29, 2018 8:02 am

Hi everyone,
I'm new to Raspberry. I have a CM3, and I would like to switch to alternate function number 3 (I'm referring to the official datasheet) for GPIO pins 31 and 32. It is my necessity to have these pins operating that way from the boot on, so I decided to modify the device tree source adding the following code to the root node:

Code: Select all

videocore {
		pins_cm3 { // Pi 3 CM3
			pin_config {
				[email protected] {
					polarity = "active_high";
					termination = "pull_down";
					startup_state = "inactive";
					function = "input";
				}; // pin
				[email protected] { function = "uart0"; termination = "no_pulling"; drive_strength_mA = < 8 >; }; // TX uart0
				[email protected] { function = "uart0"; termination = "pull_up"; drive_strength_mA = < 8 >; };
			}; // pin_config
		}; // pins
	};
after compiling with

Code: Select all

sudo dtc -I dts -O dtb -o /boot/dt-blob.dtc
I couldn't see any changes in the GPIO alternate functions using

Code: Select all

sudo raspi-gpio get
Maybe I'm missing something, but I can't figure out why this is not working.

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

Re: Setting GPIO alternate functions by modifying the device tree

Mon Jan 29, 2018 9:57 am

The file needs to be /boot/dt-blob.bin, not .dtc.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

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

Re: Setting GPIO alternate functions by modifying the device tree

Mon Jan 29, 2018 9:58 am

The dt-blob (it's not really Device Tree) file must be called "dt-blob.bin" and copied into the root of the SD card (/boot) alongside the other boot files. Also, pin 31 isn't TXD0 - it's RTS0. I think you want 32 and 33.

There is now an easier way to achieve the same effect, and that is to use the new "uart0" overlay, but that requires a very recent firmware.

Return to “Compute Module”

Who is online

Users browsing this forum: No registered users and 8 guests