Difference between revisions of "Serial ports usage on Linux"

From ArmadeusWiki
Jump to: navigation, search
(Generalities)
(Generalities)
 
(13 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
On Linux, all serial ports are driven the same way. Only their device nodes are changing to reflect the port type:
 
On Linux, all serial ports are driven the same way. Only their device nodes are changing to reflect the port type:
 
* i.MX processor internal ports:
 
* i.MX processor internal ports:
** on APF9328, APF27 & APF51: ''/dev/ttySMXN'' (kernels <= 2.6.29) or ''/dev/ttymxcN'' (kernels > 2.6.29)
+
** on [[APF9328]], [[APF27]], [[APF51]] & [[OPOS6UL]]: ''/dev/ttySMXN'' (with kernels <= 2.6.29) or ''/dev/ttymxcN'' (with kernels > 2.6.29)
** on APF28: ''/dev/ttySP[0-4]'' (general purpose serial ports) or ''/dev/ttyAMxx'' (debug serial ports)
+
** on [[APF28]]: ''/dev/ttySP[0-4]'' (general purpose serial ports) or ''/dev/ttyAMxx'' (debug serial ports)
 
* ''/dev/ttyUSBN'' for USB <-> serial converters
 
* ''/dev/ttyUSBN'' for USB <-> serial converters
 
* ''/dev/ttySnN'' for 16550 compatible FPGA's IP
 
* ''/dev/ttySnN'' for 16550 compatible FPGA's IP
Line 12: Line 12:
 
==Console port==
 
==Console port==
 
* Console port is the default serial port on which you can interact with the board (U-Boot and Linux):
 
* Console port is the default serial port on which you can interact with the board (U-Boot and Linux):
** it is serial port 0 (-> ''/dev/ttySMX0'' or ''/dev/ttymxc0) on [[APF9328]] & [[APF27]]
+
** it is serial port 0 (-> ''/dev/ttySMX0'' or ''/dev/ttymxc0) on [[APF9328]], [[APF27]] & [[OPOS6UL]]
 
** it is serial port 2 (-> ''/dev/ttymxc2'') on [[APF51]]
 
** it is serial port 2 (-> ''/dev/ttymxc2'') on [[APF51]]
 
** it is debug serial port 0 (-> ''/dev/ttyAM0'' (2.6.35 kernel) or ''/dev/ttyAMA0'' (3.x kernels)) on [[APF28]]
 
** it is debug serial port 0 (-> ''/dev/ttyAM0'' (2.6.35 kernel) or ''/dev/ttyAMA0'' (3.x kernels)) on [[APF28]]
 
* So, without software modifications, this port is not available to connect a MODEM or any other RS-232 device. If you want to use it as a normal serial port on Linux then:
 
* So, without software modifications, this port is not available to connect a MODEM or any other RS-232 device. If you want to use it as a normal serial port on Linux then:
 
** be sure that your device won't send data back in response of U-Boot boot's sequence
 
** be sure that your device won't send data back in response of U-Boot boot's sequence
** change U-Boot consoledev envt variable, to tell Linux to display console on the LCD (for example): ''BIOS> setenv consoledev tty0''
+
** change U-Boot ''consoledev'' envt variable, to tell Linux to display console on the LCD (for example): <pre class="apf> BIOS> setenv consoledev tty0</pre>
  
==Changing port parameters==
+
==Changing serial ports configuration==
* To get current parameters (change serial port device name depending on your board):
+
* To get current configuration (adapt serial port device name depending on your board, here ''ttymxc0''):
 
<pre class=apf>
 
<pre class=apf>
# stty -F /dev/ttySMX0
+
# stty -F /dev/ttymxc0
 
speed 115200 baud;
 
speed 115200 baud;
 
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ^J;
 
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ^J;
Line 32: Line 32:
 
* To only get actual speed:
 
* To only get actual speed:
 
<pre class=apf>
 
<pre class=apf>
# stty -F /dev/ttySMX0 speed
+
# stty -F /dev/ttymxc0 speed
 
115200
 
115200
 
</pre>
 
</pre>
* By default serial ports are configured as terminal emulator. If you want to use them as "raw" serial port you will have to do first (example for port 1):
+
* By default serial ports are configured as terminal emulator (canonical mode). If you want to use them as "raw" serial port you will have to do first (example for port 1):
 
<pre class=apf>
 
<pre class=apf>
# stty -F /dev/ttySMX1 raw
+
# stty -F /dev/ttymxc1 raw -echo -echoe -echok
# stty -F /dev/ttySMX1 -echo -echoe -echok
+
 
</pre>
 
</pre>
 
* To change baudrate of port 2 to 115200 :
 
* To change baudrate of port 2 to 115200 :
 
<pre class=apf>
 
<pre class=apf>
# stty -F /dev/ttySMX2 115200
+
# stty -F /dev/ttymxc2 115200
 
</pre>
 
</pre>
  
 
==Sending/Receiving data==
 
==Sending/Receiving data==
* It is simple as opening the device as a file and writing data to it:
+
 
 +
=== In Linux console ===
 +
* It is as simple as opening the device as a file and writing data to it:
 
<pre class=apf>
 
<pre class=apf>
# echo "HELLO" > /dev/ttySMX0
+
# echo "HELLO" > /dev/ttymxc0
 
</pre>
 
</pre>
 
* To receive data (ASCII in that case):
 
* To receive data (ASCII in that case):
 
<pre class=apf>
 
<pre class=apf>
# cat /dev/ttySMX0
+
# cat /dev/ttymxc0
 +
</pre>
 +
 
 +
=== With terminal (miniterm.py) ===
 +
 
 +
By default, a simple terminal named «miniterm.py» is installed in the BSP. To use it on [[OPOS6UL]], launch it with /dev port name and speed :
 +
<pre class="apf">
 +
$ miniterm.py /dev/ttymxc1 115200
 +
--- Miniterm on /dev/ttymxc1  115200,8,N,1 ---
 +
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
 +
Hello world !
 +
</pre>
 +
 
 +
On [[OPOS6UL_DEV]] if Rx/Tx are not in loop, nothing will be prompted on key input. To see something prompted the Rx/Tx must be plugged together with a jumper on [[OPOS6ULDev#Connectors |RaspberryPi connector]] (pin 8 and 10).
 +
 
 +
==Statistics==
 +
* To have some statistics on serial port usage:
 +
<pre class=apf>
 +
# cat /proc/tty/driver/<driver_name>      (for example ttyAPP on APF28, IMX-uart on OPOS6UL)
 +
 
 +
serinfo:1.0 driver revision:
 +
0: uart:8006a000.serial mmio:0x8006A000 irq:214 tx:0 rx:0 CTS
 +
1: uart:8006c000.serial mmio:0x8006C000 irq:215 tx:0 rx:0 CTS
 +
3: uart:80070000.serial mmio:0x80070000 irq:216 tx:875195 rx:4024187 CTS
 +
4: uart:80072000.serial mmio:0x80072000 irq:217 tx:0 rx:0 CTS
 
</pre>
 
</pre>
  
 
== Links ==
 
== Links ==
  
* [http://tldp.org/HOWTO/Serial-HOWTO.html Serial uart manual in Linux]
+
* [http://tldp.org/HOWTO/Serial-HOWTO.html Serial UART manual in Linux]
  
 
[[Category:Serial ports]]
 
[[Category:Serial ports]]

Latest revision as of 08:58, 26 July 2018

How to use the APF's serial ports on Linux.

Generalities

On Linux, all serial ports are driven the same way. Only their device nodes are changing to reflect the port type:

  • i.MX processor internal ports:
    • on APF9328, APF27, APF51 & OPOS6UL: /dev/ttySMXN (with kernels <= 2.6.29) or /dev/ttymxcN (with kernels > 2.6.29)
    • on APF28: /dev/ttySP[0-4] (general purpose serial ports) or /dev/ttyAMxx (debug serial ports)
  • /dev/ttyUSBN for USB <-> serial converters
  • /dev/ttySnN for 16550 compatible FPGA's IP

Console port

  • Console port is the default serial port on which you can interact with the board (U-Boot and Linux):
    • it is serial port 0 (-> /dev/ttySMX0 or /dev/ttymxc0) on APF9328, APF27 & OPOS6UL
    • it is serial port 2 (-> /dev/ttymxc2) on APF51
    • it is debug serial port 0 (-> /dev/ttyAM0 (2.6.35 kernel) or /dev/ttyAMA0 (3.x kernels)) on APF28
  • So, without software modifications, this port is not available to connect a MODEM or any other RS-232 device. If you want to use it as a normal serial port on Linux then:
    • be sure that your device won't send data back in response of U-Boot boot's sequence
    • change U-Boot consoledev envt variable, to tell Linux to display console on the LCD (for example):
       BIOS> setenv consoledev tty0

Changing serial ports configuration

  • To get current configuration (adapt serial port device name depending on your board, here ttymxc0):
# stty -F /dev/ttymxc0
speed 115200 baud;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ^J;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-brkint ixoff -imaxbel
-iexten -echoctl
  • To only get actual speed:
# stty -F /dev/ttymxc0 speed
115200
  • By default serial ports are configured as terminal emulator (canonical mode). If you want to use them as "raw" serial port you will have to do first (example for port 1):
# stty -F /dev/ttymxc1 raw -echo -echoe -echok
  • To change baudrate of port 2 to 115200 :
# stty -F /dev/ttymxc2 115200

Sending/Receiving data

In Linux console

  • It is as simple as opening the device as a file and writing data to it:
# echo "HELLO" > /dev/ttymxc0
  • To receive data (ASCII in that case):
# cat /dev/ttymxc0

With terminal (miniterm.py)

By default, a simple terminal named «miniterm.py» is installed in the BSP. To use it on OPOS6UL, launch it with /dev port name and speed :

$ miniterm.py /dev/ttymxc1 115200
--- Miniterm on /dev/ttymxc1  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Hello world !

On OPOS6UL_DEV if Rx/Tx are not in loop, nothing will be prompted on key input. To see something prompted the Rx/Tx must be plugged together with a jumper on RaspberryPi connector (pin 8 and 10).

Statistics

  • To have some statistics on serial port usage:
# cat /proc/tty/driver/<driver_name>       (for example ttyAPP on APF28, IMX-uart on OPOS6UL)

serinfo:1.0 driver revision:
0: uart:8006a000.serial mmio:0x8006A000 irq:214 tx:0 rx:0 CTS
1: uart:8006c000.serial mmio:0x8006C000 irq:215 tx:0 rx:0 CTS
3: uart:80070000.serial mmio:0x80070000 irq:216 tx:875195 rx:4024187 CTS
4: uart:80072000.serial mmio:0x80072000 irq:217 tx:0 rx:0 CTS

Links