Possible to repurpose i2c pins as a third uart? [edit: YES]

Post Reply
campbell
Posts: 387
Joined: Thu Sep 03, 2015 1:13 pm
languages_spoken: english
ODROIDs: N2, C2, C1+, XU4, XU3, Cloudshell, Smart Power
Has thanked: 1 time
Been thanked: 2 times
Contact:

Possible to repurpose i2c pins as a third uart? [edit: YES]

Unread post by campbell » Mon Jan 09, 2017 9:51 am

In the S905 datasheet, in table ii.7.3, it says that the GPIO_DV_24 and 25 pins have I2C_SDA_A and I2C_SCK_A as one of their functions and UART_TX_B and UART_RX_B as another of their possible functions. I REALLY need two uarts (not counting the debug port) without the extra power draw and complexity of a usb dongle, and I don't need i2c. Is it possible to change something in the device tree to repurpose these pins, and would the port then show up as /dev/ttySAC1?
Last edited by campbell on Tue Jan 10, 2017 5:28 am, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 32318
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 138 times
Been thanked: 315 times
Contact:

Re: Is it possible to repurpose the i2c pins as a third uart

Unread post by odroid » Mon Jan 09, 2017 12:02 pm

Please try this approach and let me know the result. It worked on C1+/S805.
http://odroid.com/dokuwiki/doku.php?id= ... pin_header

Consider that C2/S905 has slightly different pin map & pin mux.

campbell
Posts: 387
Joined: Thu Sep 03, 2015 1:13 pm
languages_spoken: english
ODROIDs: N2, C2, C1+, XU4, XU3, Cloudshell, Smart Power
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Is it possible to repurpose the i2c pins as a third uart

Unread post by campbell » Mon Jan 09, 2017 2:18 pm

The above guide doesn't seem to translate well to the c2. If I download the version of meson64_odroidc2.dts from https://github.com/hardkernel/linux/blo ... roidc2.dts, it has uart_A0 and uart_A sections similar to those in the C1 link above, but NOTHING in the pinmux section, even for the uarts enabled by default.

However if I run: dtc -I dtb meson64_odroidc2.dtb -O dts -o meson64_odroidc2.dts on my Odroid C2, I get a file (attached) that looks completely different, which includes (under pinmux) sections for a0_uart, a0_uart_b_uart, a_uart, b_uart, and c_uart. The a0_uart and a_uart sections are the only ones which have linux,phandle and phandle fields. All of them have amlogic,setmask and amlogic_pins fields. The b_uart one is the one that references GPIODV_24 and GPIODV_25 (which are also, as expected, used by a_i2c, which DOES have linux,phandle and phandle fields). Outside the pinmux section are two sections serial@c81004c0 and serial@c11084c0 (below), corresponding to the two active uarts, and referencing the corresponding phandles from the pinmux section. There is also an i2c@c1108500 section.

Code: Select all

	serial@c81004c0 {
		compatible = "amlogic, meson-uart";
		reg = <0x0 0xc81004c0 0x0 0x14>;
		interrupts = <0x0 0xc1 0x1>;
		status = "okay";
		clocks = <0xc 0x2>;
		clock-names = "clk_uart";
		fifosize = <0x40>;
		pinctrl-names = "default";
		pinctrl-0 = <0x2b>;
	};

	serial@c11084c0 {
		compatible = "amlogic, meson-uart";
		reg = <0x0 0xc11084c0 0x0 0x14>;
		interrupts = <0x0 0x1a 0x1>;
		status = "okay";
		clocks = <0xc 0x2>;
		clock-names = "clk_uart";
		fifosize = <0x80>;
		pinctrl-names = "default";
		pinctrl-0 = <0x2c>;
	};
So I think what I need to do is move the 0x10 phandle from the a_i2c section under pinmux to the b_uart section, REMOVE the i2c@c1108500 section, and ADD a new serial@something section that contains...what exactly? This is where I'm stuck. Clearly it needs to contain "pinctrl-0 = <0x10>" but beyond that I don't know.
Attachments
meson64_odroidc2_decompiled_dts.txt
(34.16 KiB) Downloaded 97 times

campbell
Posts: 387
Joined: Thu Sep 03, 2015 1:13 pm
languages_spoken: english
ODROIDs: N2, C2, C1+, XU4, XU3, Cloudshell, Smart Power
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Is it possible to repurpose the i2c pins as a third uart

Unread post by campbell » Mon Jan 09, 2017 3:05 pm

Here is where I've gotten to after consulting the S905 datasheet. The register offset is 0xc11084dc and it's a 64 byte fifo. The main thing I'm still unsure about is the "interrupts" field, but I've found .dts files for other Meson devices that have 0x1a for the c11084c0 UART and 0x4B for the c11084dc UART, so it's a reasonable guess that that's the correct value for this.

I haven't had a chance to test it yet - my only functional Odroid C2 is currently sealed in an aluminium enclosure, and the new one I ordered from Ameridroid showed up over the weekend all crunched up (thanks USPS) so it might be a few more days before I can test this.

Code: Select all

serial@c11084dc {
		compatible = "amlogic, meson-uart";
		reg = <0x0 0xc11084dc 0x0 0x14>;
		interrupts = <0x0 0x4b 0x1>;
		status = "okay";
		clocks = <0xc 0x2>;
		clock-names = "clk_uart";
		fifosize = <0x40>;
		pinctrl-names = "default";
		pinctrl-0 = <0x10>;
	};

campbell
Posts: 387
Joined: Thu Sep 03, 2015 1:13 pm
languages_spoken: english
ODROIDs: N2, C2, C1+, XU4, XU3, Cloudshell, Smart Power
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Is it possible to repurpose the i2c pins as a third uart

Unread post by campbell » Tue Jan 10, 2017 5:28 am

IT WORKS! I got impatient and ripped my c2 out of its enclosure and threw the heatsink back on so I could test this. The only additional change required was to add a "serial2" alias to the aliases section. Here's the total required changes to the decompiled dtb (full file attached).

First, decompile the .dtb (under /media/boot/ on Ubuntu, /boot/dtbs/ on Arch):

Code: Select all

mv meson64_odroidc2.dtb meson64_odroidc2.dtb_backup
dtc -I dtb meson64_odroidc2.dtb -O dts -o meson64_odroidc2.dts
Add/remove lines as specified in the following sections:

Code: Select all

  		a_uart {
  			amlogic,setmask = <0x4 0x3c00>;
  			amlogic,pins = "GPIOX_12", "GPIOX_13", "GPIOX_14", "GPIOX_15";
  			linux,phandle = <0x2c>;
  			phandle = <0x2c>;
  		};
  
  		b_uart {
  			amlogic,setmask = <0x2 0x30000000>;
  			amlogic,pins = "GPIODV_24", "GPIODV_25";
+ 			linux,phandle = <0x10>;
+ 			phandle = <0x10>;
  		};

Code: Select all

 
  		a_i2c {
  			amlogic,setmask = <0x7 0xc000000>;
  			amlogic,clrmask = <0x0 0x18c0 0x2 0x30000000 0x5 0x1800>;
  			amlogic,pins = "GPIODV_24", "GPIODV_25";
- 			linux,phandle = <0x10>;
- 			phandle = <0x10>;
  		};

Code: Select all

  	meson_clk_msr {
  		compatible = "amlogic, gxbb_measure";
  		reg = <0x0 0xc110875c 0x0 0x4 0x0 0xc1108764 0x0 0x4>;
  	};
  
- 	i2c@c1108500 {
- 		compatible = "amlogic, meson-i2c";
- 		dev_name = "i2c-A";
- 		status = "okay";
- 		reg = <0x0 0xc1108500 0x0 0x20>;
- 		device_id = <0x1>;
- 		pinctrl-names = "default";
- 		pinctrl-0 = <0x10>;
- 		#address-cells = <0x1>;
- 		#size-cells = <0x0>;
- 		use_pio = <0x0>;
- 		master_i2c_speed = <0x493e0>;
- 		clocks = <0xc 0xa>;
- 		clock-names = "clk_i2c";
- 		resets = <0xc 0x9>;
- 
- 		pcf8563@51 {
- 			status = "disabled";
- 			compatible = "nxp,pcf8563";
- 			reg = <0x51>;
- 			#clock-cells = <0x0>;
- 		};
- 	};
- 
  	i2c@c11087c0 {
  		compatible = "amlogic, meson-i2c";
  		dev_name = "i2c-B";

Code: Select all

  	aliases {
  		serial0 = "/serial@c81004c0";
  		serial1 = "/serial@c11084c0";
+ 		serial2 = "/serial@c11084dc";
  	};

Code: Select all

  	serial@c81004c0 {
  		compatible = "amlogic, meson-uart";
  		reg = <0x0 0xc81004c0 0x0 0x14>;
  		interrupts = <0x0 0xc1 0x1>;
  		status = "okay";
  		clocks = <0xc 0x2>;
  		clock-names = "clk_uart";
  		fifosize = <0x40>;
  		pinctrl-names = "default";
  		pinctrl-0 = <0x2b>;
  	};
  
  	serial@c11084c0 {
  		compatible = "amlogic, meson-uart";
  		reg = <0x0 0xc11084c0 0x0 0x14>;
  		interrupts = <0x0 0x1a 0x1>;
  		status = "okay";
  		clocks = <0xc 0x2>;
  		clock-names = "clk_uart";
  		fifosize = <0x80>;
  		pinctrl-names = "default";
  		pinctrl-0 = <0x2c>;
  	};
  
+ 	serial@c11084dc {
+ 		compatible = "amlogic, meson-uart";
+ 		reg = <0x0 0xc11084dc 0x0 0x14>;
+ 		interrupts = <0x0 0x4b 0x1>;
+ 		status = "okay";
+ 		clocks = <0xc 0x2>;
+ 		clock-names = "clk_uart";
+ 		fifosize = <0x40>;
+ 		pinctrl-names = "default";
+ 		pinctrl-0 = <0x10>;
+ 	};
+ 
+ 
Finally, recompile the dtb from your modified .dts:

Code: Select all

dtc -I dts meson64_odroidc2.dts -O dtb -o meson64_odroidc2.dtb
Attachments
meson64_odroidc2_decompiled_dts_modded.txt
(33.97 KiB) Downloaded 70 times
Last edited by campbell on Fri Jan 27, 2017 1:42 am, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 32318
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 138 times
Been thanked: 315 times
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by odroid » Tue Jan 10, 2017 10:12 am

Great! Thank you for the clear and helpful instruction.

Is it accessible via /dev/ttyS2 now?
40pin header Pin#3 is Rx and Pin#5 is Tx?
Sorry for many questions.
I just want to add this nice topic on our WiKi page.

campbell
Posts: 387
Joined: Thu Sep 03, 2015 1:13 pm
languages_spoken: english
ODROIDs: N2, C2, C1+, XU4, XU3, Cloudshell, Smart Power
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by campbell » Tue Jan 10, 2017 2:46 pm

Yes, to both. The SDA1 and SCL1 pins are TX and RX respectively for the /dev/ttyS2 device.

User avatar
odroid
Site Admin
Posts: 32318
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 138 times
Been thanked: 315 times
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by odroid » Tue Jan 10, 2017 4:45 pm

Ahh.. Pin#3 is Tx and Pin#5 is Rx.
Updated WiKi page. :D
http://odroid.com/dokuwiki/doku.php?id= ... pin_header

chdh
Posts: 9
Joined: Fri Dec 30, 2016 2:16 pm
languages_spoken: english
ODROIDs: C2
Location: Winterthur, Switzerland
Has thanked: 0
Been thanked: 0
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by chdh » Wed Jan 11, 2017 11:04 pm

@campbell

UART B has two disadvantages compared to UART C:

1. The two RX/TX pins of UART B are normally used for I2C.
2. The pins have hard-wired 1K pull-up resistors on the ODROID C2 board (see ODROID C2 Schematics, page 3, bottom right).

With UART C (RX = pin 26, TX = pin 32), this would not be the case.
Did you also try to get UART C working.
(I have tried it and encountered some problems: viewtopic.php?f=137&t=25373)

campbell
Posts: 387
Joined: Thu Sep 03, 2015 1:13 pm
languages_spoken: english
ODROIDs: N2, C2, C1+, XU4, XU3, Cloudshell, Smart Power
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by campbell » Fri Jan 13, 2017 5:42 am

I'm having a bit of trouble following that thread to its conclusion: is it the case that the uart is useful, but not if you also want to use a microsd card? If that's not the problem, what is?

I'm aware of the 1k resistors, but I've tested it with the Hardkernel usb-uart as well as a B&B 232LPTTL33 port powered level shifter (which is, unfortunately, more expensive than the entire Odroid, and bulky too) going into an FTDI dongle at standard RS232 levels and in both cases it works fine at 115200 baud.

campbell
Posts: 387
Joined: Thu Sep 03, 2015 1:13 pm
languages_spoken: english
ODROIDs: N2, C2, C1+, XU4, XU3, Cloudshell, Smart Power
Has thanked: 1 time
Been thanked: 2 times
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by campbell » Thu Jan 26, 2017 10:59 am

Addendum: if you want to also use the RTC shield with this, you will need to move the

Code: Select all

		pcf8563@51 {
			status = "okay";
			compatible = "nxp,pcf8563";
			reg = <0x51>;
			#clock-cells = <0x0>;
		};
section from i2c@c1108500 to i2c@c11087c0, and use pins 27 and 28 rather than pins 3 and 5 for the SDA and SCL functionality. You may also want to disable the sx865x@49 section under the latter i2c interface at the same time.

User avatar
Brian.K
Posts: 246
Joined: Tue Sep 15, 2015 7:30 pm
languages_spoken: English, Korean
ODROIDs: XU4, C1+, C2
Location: South Korea
Has thanked: 0
Been thanked: 0
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by Brian.K » Tue Jan 31, 2017 10:27 am

Note: As a result of contacting Amlogic, UART_C pins are wrong in S905 datasheet and kernel source.
  • GPIOY_11, UART_CTS_C function = register 1/bit 17
  • GPIOY_12, UART_RTS_C function = register 1/bit 16
  • GPIOY_13, UART_TX_C function = register 1/bit 19
  • GPIOY_14, UART_RX_C function = register 1/bit 18

Code: Select all

commit b22dbcc9173919eaa4bbdeb144abc062f2d5e0fd
Author: Brian Kim <brian.kim@hardkernel.com>
Date:   Fri Jan 20 14:06:58 2017 +0900

    pinctrl: meson-gxbb: fixed wrong pin multiplexing
    
    There is wrong UART_C pin function bits. This change fixes wrong UART_C
    pin multiplexing correctly as below:
    
    - GPIOY_11, UART_CTS_C function = register 1/bit 17
    - GPIOY_12, UART_RTS_C function = register 1/bit 16
    - GPIOY_13, UART_TX_C function = register 1/bit 19
    - GPIOY_14, UART_RX_C function = register 1/bit 18
    
    Change-Id: Ibbcbfd84946bca5ab64c1965e7f83b5e773c2ad0
    Signed-off-by: Brian Kim <brian.kim@hardkernel.com>

diff --git a/drivers/amlogic/pinctrl/pinctrl_gxbb.c b/drivers/amlogic/pinctrl/pinctrl_gxbb.c
index 20a8bdc..96e62c5 100644
--- a/drivers/amlogic/pinctrl/pinctrl_gxbb.c
+++ b/drivers/amlogic/pinctrl/pinctrl_gxbb.c
@@ -478,10 +478,10 @@ static unsigned int gpio_to_pin[][6] = {
        [PIN_GPIOY_8] = {PK(2, 16), PK(3, 5), PK(1, 5), NE, NE, NE,},
        [PIN_GPIOY_9] = {PK(2, 16), PK(3, 5), PK(1, 6), NE, NE, NE,},
        [PIN_GPIOY_10] = {PK(2, 16), PK(3, 5), PK(1, 7), NE, NE, NE,},
-       [PIN_GPIOY_11] = {PK(3, 3), PK(1, 19), PK(1, 8), NE, NE, NE,},
-       [PIN_GPIOY_12] = {PK(1, 18), PK(1, 9), NE, NE, NE, NE,},
-       [PIN_GPIOY_13] = {PK(1, 17), PK(1, 10), NE, NE, NE, NE,},
-       [PIN_GPIOY_14] = {PK(1, 16), PK(1, 11), NE, NE, NE, NE,},
+       [PIN_GPIOY_11] = {PK(3, 3), PK(1, 8), PK(1, 17), NE, NE, NE,},
+       [PIN_GPIOY_12] = {PK(1, 9), PK(1, 16), NE, NE, NE, NE,},
+       [PIN_GPIOY_13] = {PK(1, 10), PK(1, 19), NE, NE, NE, NE,},
+       [PIN_GPIOY_14] = {PK(1, 11), PK(1, 18), NE, NE, NE, NE,},
        [PIN_GPIOY_15] = {PK(2, 20), PK(1, 20), PK(1, 22), NE, NE, NE,},
        [PIN_GPIOY_16] = {PK(2, 21), PK(1, 21), NE, NE, NE, NE,},
        [PIN_GPIO_TEST_N] = {PK(AO, 19), PK(AO2, 2), NE, NE, NE, NE,},
This patch merged in our internal repo and will merge soon to the github repo.

KARL23
Posts: 15
Joined: Sun Jun 26, 2016 10:59 pm
languages_spoken: english
ODROIDs: c1, c2,xu4
Has thanked: 0
Been thanked: 0
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by KARL23 » Tue Jun 27, 2017 7:03 pm

Please find attached the fix of uart_c pinning for mainline kernel:

Code: Select all

--- linux-next-20170623/drivers/pinctrl/meson/pinctrl-meson-gxbb.c.orig 2017-06-23 11:30:35.072037057 +0200
+++ linux-next-20170623/drivers/pinctrl/meson/pinctrl-meson-gxbb.c      2017-06-26 12:31:27.161783467 +0200
@@ -202,8 +202,8 @@ static const unsigned int uart_rts_b_pin
 
 static const unsigned int uart_tx_c_pins[]     = { PIN(GPIOY_13, EE_OFF) };
 static const unsigned int uart_rx_c_pins[]     = { PIN(GPIOY_14, EE_OFF) };
-static const unsigned int uart_cts_c_pins[]    = { PIN(GPIOX_11, EE_OFF) };
-static const unsigned int uart_rts_c_pins[]    = { PIN(GPIOX_12, EE_OFF) };
+static const unsigned int uart_cts_c_pins[]    = { PIN(GPIOY_11, EE_OFF) };
+static const unsigned int uart_rts_c_pins[]    = { PIN(GPIOY_12, EE_OFF) };
 
 static const unsigned int i2c_sck_a_pins[]     = { PIN(GPIODV_25, EE_OFF) };
 static const unsigned int i2c_sda_a_pins[]     = { PIN(GPIODV_24, EE_OFF) };
@@ -444,10 +444,10 @@ static struct meson_pmx_group meson_gxbb
        GROUP(pwm_f_x,          3,      18),
 
        /* Bank Y */
-       GROUP(uart_cts_c,       1,      19),
-       GROUP(uart_rts_c,       1,      18),
-       GROUP(uart_tx_c,        1,      17),
-       GROUP(uart_rx_c,        1,      16),
+       GROUP(uart_cts_c,       1,      17),
+       GROUP(uart_rts_c,       1,      16),
+       GROUP(uart_tx_c,        1,      19),
+       GROUP(uart_rx_c,        1,      18),
        GROUP(pwm_a_y,          1,      21),
        GROUP(pwm_f_y,          1,      20),
        GROUP(i2s_out_ch23_y,   1,      5),
best regards

KARL23
Posts: 15
Joined: Sun Jun 26, 2016 10:59 pm
languages_spoken: english
ODROIDs: c1, c2,xu4
Has thanked: 0
Been thanked: 0
Contact:

Re: Possible to repurpose i2c pins as a third uart? [edit: Y

Unread post by KARL23 » Tue Jun 27, 2017 7:05 pm

Attached is a patch to enable UART_A and UART_C in mainline kernel for odroid-c2

Code: Select all

--- linux-next-20170627/arch/arm64/boot/dts/amlogic//meson-gxbb-odroidc2.dts.orig       2017-06-27 11:01:48.202939739 +0200
+++ linux-next-20170627/arch/arm64/boot/dts/amlogic//meson-gxbb-odroidc2.dts    2017-06-27 11:04:17.646108144 +0200
@@ -53,6 +53,8 @@
 
        aliases {
                serial0 = &uart_AO;
+               serial1 = &uart_A;
+               serial3 = &uart_C;
        };
 
        chosen {
@@ -293,6 +295,18 @@
        pinctrl-names = "default";
 };
 
+&uart_A {
+        status = "okay";
+        pinctrl-0 = <&uart_a_pins>;
+        pinctrl-names = "default";
+};
+
+&uart_C {
+        status = "okay";
+        pinctrl-0 = <&uart_c_pins &uart_c_cts_rts_pins>;
+        pinctrl-names = "default";
+};
+
 &usb0_phy {
        status = "okay";
        phy-supply = <&usb_otg_pwr>;
Regards

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 2 guests