UART flow control with WP7608

Hi jyijyi

Got it!
It works as follows.

—Write operation

root@swi-mdm9x28-wp:~# echo 101 > /sys/class/gpio/export
root@swi-mdm9x28-wp:~# echo out > /sys/class/gpio/gpio101/direction

root@swi-mdm9x28-wp:~# echo 1 > /sys/class/gpio/gpio101/value
=> Measured #11 pin of CN600 then it was 1.8V

root@swi-mdm9x28-wp:~# echo 0 > /sys/class/gpio/gpio101/value
=> Measured #11 pin of CN600 then it was 0V

—Read Operaiton
root@swi-mdm9x28-wp:~# echo in > /sys/class/gpio/gpio101/direction
root@swi-mdm9x28-wp:~# cat /sys/class/gpio/gpio101/value
1

=>Connect #11 pin to GND(There is on CN1500)
root@swi-mdm9x28-wp:~# cat /sys/class/gpio/gpio101/value
0

Thank you.

–TAK

Hi, ijyijy

What about following?

In order to check UART on mangOH green, which interface in /dev should I set? >Currently, I set “ttyHS0” but it seems not to work.

In some case, the customer needs to use ioctl so I’d like to know it.

Thank you.

–TAK

does customer accept to use GPIO as workaround?
I tried ioctl() to read the status of DTR/DSR/DCD, it is not working either.

Goto-san (@TAK_G )

I need “Read procedure” and “Write Procedure” of UART pins.

My goal is to check hardware check on our board with loopback wiring.

In summary, (using as DCE)
Read pin : RTS, DTR, DCD, RI, TxD
Write pin : CTS, DSR, RxD

BR,
Tanoue

Hi jyijyi,

First of all,I’d like to ask simple question.

Is it possible that they can read these pin state with your suggested ways(GPIO) while they use UART as 8-wire UART(such as enabling Hardware flow control) ?
In this case, the customer will not control RTS,CTS,DSR and DTR manually as GPIO by “echo/cat”.

Thank you.

–TAK

To set RI pin as input pin:

  1. you need to first send an AT command: AT!RIOWNER=1
  2. after that you can control the RI in linux console:
    echo RI > /sys/class/gpio/export
    echo in > /sys/class/gpio/gpioRI/direction
    cat /sys/class/gpio/gpioRI/value

In addition, I found that you can read the RTS pin status by AT command:
AT!entercnd=“A710”
AT!bsgpio?6

For setting the CTS pin, you can use ioctl():

	 int arg;
	 if (ioctl(fd1, TIOCMGET, &arg) == -1)
	 {
	 	LE_DEBUG("ERROR: %s", strerror(errno));
	 }

	 if (level)
		  arg |= TIOCM_RTS;
	   else
	   	  arg &= ~TIOCM_RTS;

	  if (ioctl(fd1, TIOCMSET, &arg) == -1) {
	    		LE_DEBUG("ERROR: %s", strerror(errno));
	      }

Hi jyijyi,

Since I’m a little bit confusing, please provide your answer for my question first.

Is it possible that they can read these pin state with your suggested ways(GPIO) while they use UART as 8-wire UART(such as enabling Hardware flow control) ? In this case, the customer will not control RTS,CTS,DSR and DTR manually as GPIO by “echo/cat”. >In addition, I found that you can read the RTS pin status by AT command: >AT!entercnd=“A710” >AT!bsgpio?6

The customer needs to read UART pins via Linux, not external host.
So, AT commands is not useful.

For setting the CTS pin, you can use ioctl():
I copied you suggestion in my source code as follows.
test_helloComponent.c (1.6 KB)

Then, following error was happened.

/root/legato/workspace/test_hello/test_helloComponent/test_helloComponent.c:30:18: error: ‘fd1’ undeclared (first use in this function)

You did not call open(fd,) with serial port dev name so it did not work.

Thank you.

–TAK

For your code, Of course you need to call open() before ioctl().

For entering AT command in legato application, you can send AT command through /dev/ttyAT port inside the application to get the result.

For the first question, I have tried controlling dtr dsr dcd ri via console (gpio) during uart communication with hardware flow control.

Hi jyijyi

When you enabled hardware flow control, you need to check “RTS” and “CTS” not “DTR” or others.
If we set unique GPIO numbers with each UART pins then we can use specified function of these pins by UART block, not GPIO control(echo) , I think this solution should be acceptable for the customer.

BTW, regarding to GPIO numbers of each pins,such as DTR is #17, how can I find this HW connection information >
I can not find such information in any document.
I think it is necessary for the customer.

In order to call open(), we need to set device name in dev.
What is the device name of UART1?

Thank you.

–TAK

If you don’t want echo/cat to control gpio, you can use legato goio api.
For the gpio number document, i don’t have either, but i think now you have all the information to control dtr dcd dsr.
The device name for uart1 is /dev/ttyHS0 after setting AT! mapuart=17,1 and reboot.

Hi jyijyi,

The customer original question is follows.

We don’t know GPIO number of “CTS” and “RTS”.

@Tanoue

Your original comment is follows so we should focus for it.

Thank you.

–TAK

As said before, you can use ioctl() to write CTS pin and use AT command to read RTS pin.

Hi, TAK_G

I realized that WP76 could do UART communication with RTS/CTS hardware flow control with ioctl().
And I realized that WP76 could not read DTR, DCD, RI, DSR with ioctl()

To summarize discussion, I think how to check them the following.

image

Is it correct?

I think the best way to check all 8-wire UART’s pins with just one command.
It means I want to avoid mixing some type commands(echo/) on a program, if possible.

Which command is the best way?
Then, how should I write program?

Could you provide information about legato gpio api?
I hope it is a simple solution because I didn’t know it in detail

BR,
Tanoue

The easiest way is to access the gpio path directly inside your legato application:

 #define INPUT_GPIO  101
 char temp_Str[256];
	  int fd;
	  char  value[10];


 memset(temp_Str,0,sizeof(temp_Str));
	  sprintf(temp_Str,"/sys/class/gpio/gpio%d/direction",INPUT_GPIO);
	   fd = open(temp_Str, O_WRONLY);
	   if (fd < 0)
	   {
	      LE_DEBUG("Failed to open gpio%d direction\n",INPUT_GPIO);
	      return;
	   }
	   else
	   {
	      LE_DEBUG("gpio%d direction opened\n",INPUT_GPIO);
	   }
	   write(fd, "in",2);
	   close(fd);

	   memset(temp_Str,0,sizeof(temp_Str));
	   sprintf(temp_Str,"/sys/class/gpio/gpio%d/value",INPUT_GPIO);
	   fd = open(temp_Str, O_RDONLY);
	   	   if (fd < 0)
	   	   {
	   	      LE_DEBUG("Failed to open gpio%d value\n",INPUT_GPIO);
	   	      return;
	   	   }
	   	   else
	   	   {
	   	      LE_DEBUG("gpio%d value opened\n",INPUT_GPIO);
	   	   }
	   	   read(fd, value,sizeof(value));
	   	   close(fd);

Hi jyijyi,@jyijyi

Please answer Tanoue-san’s questions.

Thank you.

–TAK

didn’t i already answer?

Hi jyijyi,

Sorry for missing read since my browse still not be updated.

I think your answer is only for “how to read GPIO pins from Legato API”.
And also, you suggestion is based on adding GPIO by the modification of “yocto/kernel/driver/gpio/gpiolib.c.”

Is my understanding correct?

If so , the customer needs to know all GPIO numbers of following pins.

RTS, DTR, DCD, RI, TxD , CTS, DSR, RxD

We know only DCD,DTR and DSR.

And, if you provide above information, I think we can read them by “cat” commands.

Thank you.

–TAK

Hi Tanoue-san,

I think the best way to check all 8-wire UART’s pins with just one command.
It means I want to avoid mixing some type commands(echo/) on a program, if possible.

If we can provide GPIO numbers, I think you can read it by “cat” that I and jyijyi mentioned before.
If you’d like to read it on command, you should make C source or shell like usual Linux application.

Thank you.

–TAK

I don’t recommend your suggestion.
Here I have tried to put RTS/CTS/TXD/RXD inside “yocto/kernel/driver/gpio/gpiolib.c", after that if you turn them into GPIO, later you cannot use it to communicate as UART in legato application.
That is why i suggest another way for accessing RTS (i.e. using AT comnand) and CTS (i.e. ioctl())pins.

Hi @jyijyi

Here I have tried to put RTS/CTS/TXD/RXD inside “yocto/kernel/driver/gpio/gpiolib.c",
after that if you turn them into GPIO, later you cannot use it to communicate as UART in legato application.
That is why i suggest another way for RTS and CTS pins.

I wait this information !!!
I understand why you suggested AT command to read RTS/CTS.

Hmm, is there any ways else to read RTS and CTS?
There is no description of your suggested command in the latest AT command manual.
So, we are not sure which parameter of return is read value.

Thank you.

–TAK