# Using GPIO instead of RTS

**URL:** <https://forum.legato.io/t/using-gpio-instead-of-rts/6108>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [February 13, 2022, 10:32am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108 "2022-02-13T10:32:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [February 13, 2022, 10:32am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/1 "2022-02-13T10:32:53Z")

</div>

Hi,

On a custom board we have a GPIO7 for controlling RS485 on UART2, when using libmodbus the RTS pin is used to control the DE pin of RS485 transceiver.

Can someone provide info on how can we modify the DTS to use use GPIO7 as RTS pin for UART2?

Thanks,

Pankaj Sant

---

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [February 13, 2022, 10:55am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/2 "2022-02-13T10:55:25Z")

</div>

Hi,

From mdm9607-wp76xx.dtsi would like to configure the UART2 CTS GPIO:

blsp1\_uart2\_active: blsp1\_uart2\_active {  
mux {  
pins = “gpio4”, “gpio5”, “gpio6”, “gpio7”;  
function = “blsp\_uart2”;  
};

```
		config {
			pins = "gpio4", "gpio5", "gpio6", "gpio7";
			drive-strength = <2>;
			bias-disable;
		};
	};

	blsp1_uart2_sleep: blsp1_uart2_sleep {
		mux {
			pins = "gpio4", "gpio5", "gpio6", "gpio7";
			function = "gpio";
		};

		config {
			pins = "gpio4", "gpio5", "gpio6", "gpio7";
			drive-strength = <2>;
			bias-disable;
		};
	};

```

Would like to know the GPIO4,gpio5,gpio6 and gpio7 pin functions.

Thanks,

Pankaj Sant

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 14, 2022, 1:19am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/3 "2022-02-14T01:19:44Z")

</div>

“gpio4”, “gpio5”, “gpio6”, “gpio7” are for internal qualcomm chipeset.  
They are used for UART1 of WP modules, not UART2…

BTW, why don’t you directly use RTS pin of UAR2 to control RS485?

Changing GPIO7 to RTS of UART2 actually is violating the PTS of WP76xx.  
Also no validation has been done on this situation.

---

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [February 14, 2022, 5:27am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/4 "2022-02-14T05:27:26Z")

</div>

@jyijyi ,

I understand it is PTS violation and no validation is done. In the given scenario the hardware is already done and therefore it is required to get the RTS changed to GPIO7.

I have been able to change the GPIO and verify the change in the new DTB. I request for the information on the Internal Qualcomm GPIO numbers for RTS and CTS. Preferred is if for both the UARTS the information is shared.

I understand that the change will be done at my risk but would like to change it and get the board working.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 14, 2022, 5:33am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/5 "2022-02-14T05:33:18Z")

</div>

but why don’t you directly control it in GPIO?

e.g.  
echo 7 \> /sys/class/gpio/export  
echo out \> /sys/class/gpio/gpio7/direction

---

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [February 14, 2022, 6:40am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/6 "2022-02-14T06:40:42Z")

</div>

@jyijyi,

We can use it for RAW data transfer over UART and it works fine. But in the end application libmodbus is used which handles the DE signal using RTS for read and write over the serial port. you can have a look at the modus rtu code in modbus-rtu.c line 254 here:

#if HAVE\_DECL\_TIOCM\_RTS  
static void \_modbus\_rtu\_ioctl\_rts(modbus\_t \*ctx, int on)  
{  
int fd = ctx-\>s;  
int flags;

```
ioctl(fd, TIOCMGET, &flags);
if (on) {
    flags |= TIOCM_RTS;
} else {
    flags &= ~TIOCM_RTS;
}
ioctl(fd, TIOCMSET, &flags);

```

}  
#endif

Hence to get the compatibility would like to change the RTS to GPIO7.

Thanks,

Pankaj Sant

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 14, 2022, 6:44am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/7 "2022-02-14T06:44:43Z")

</div>

do you mean you cannot recompile modbus-rtu.c to change the ioctl to GPIO access ???

---

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [February 14, 2022, 6:52am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/8 "2022-02-14T06:52:34Z")

</div>

@jyijyi,

What do you recommend Changing the modbus-rtu.c or the DTS?

If the modbus-rtu.c has to be changed can you let me know how it can be done for GPIO7 as generally the GPIO7 would be available from Legato Application with LE\_GPIO services.

so do we need to connect to legato services from libmodbus?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 14, 2022, 6:55am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/9 "2022-02-14T06:55:53Z")

</div>

Is modbus-rtu.c a kernel driver or application layer?  
If it is in application layer, you can simply call

system(“echo 1 \> /sys/class/gpio/gpio7/value”)

---

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [February 14, 2022, 6:58am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/10 "2022-02-14T06:58:28Z")

</div>

@jyijyi ,

OKay I will try this way as well. but for the interest to try and use GPIO7 as RTS or in Sierra Case CTS signal can you let me know the exact GPIO number to UART 2 RTS and CTS

Thanks,

Pankaj Sant

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 14, 2022, 6:59am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/11 "2022-02-14T06:59:25Z")

</div>

BTW, if it is kernel driver, you can go to here to see (priority\_test.rar) on how to control GPIO in kernel driver

> [@MCP2515 CAN Data loss](https://forum.legato.io/t/mcp2515-can-data-loss/4928/7):
>
> Seems you did not change the task priority… Attached “priority\_test.rar” is my testing code. In low\_priority\_helloworld.c, I have set the task priority to be 51. In high\_priority\_helloworld.c, I have set the task priority to be 50 which is having lower priority than the other one. If you run the two kernel drivers together, you can check by: root@fx30:~# ps -eo pid,pri,rtprio,cmd | grep LED 4755 91 51 [LED\_flash\_threa] 4786 90 50 [LED\_flash\_threa] 5613 19 - grep LED I …

According to gpiolib-sysfs.c in WP76 FW R13.3 yocto source, GPIO7 of WP76 module is connecting to GPIO\_16 of qualcomm chipset internally.  
So in case you use this in kernel driver layer, you need to use this number instead of GPIO7.

---

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [February 14, 2022, 7:02am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/12 "2022-02-14T07:02:31Z")

</div>

This is a user space so your suggestion to use sysfs may work. also as an alternate way can you let me know GPIO number for CTS/RTS signal for UART2 to verify if replacing the GPIO7 in the DTS works correctly ?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [February 14, 2022, 7:08am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/13 "2022-02-14T07:08:11Z")

</div>

please let me know if the system() call (application layer) or the priority\_test.rar (kernel driver layer) working on your side first.  
As changing the DTS might have side effect or potential issue, this should be the last step

---

<div class="post-metadata">

**Author:** ![Pankaj](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/pankaj/32/1317_2.png) [@Pankaj](https://forum.legato.io/u/Pankaj)\
**Post date:** [February 14, 2022, 7:45am UTC](https://forum.legato.io/t/using-gpio-instead-of-rts/6108/14 "2022-02-14T07:45:36Z")

</div>

@jyijyi,

Will check this out and let you know.

Thanks & Regards,

Pankaj Sant
