Using GPIO instead of RTS

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

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

“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.

@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.

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

@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

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

@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?

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”)

@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

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

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.

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 ?

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

@jyijyi,

Will check this out and let you know.

Thanks & Regards,

Pankaj Sant