Changes

How to use UARTs

335 bytes removed, 11:41, 12 November 2014
no edit summary
= Overview=<brsection begin=overview /> =This How-To is meant to be a starting point for people to learn use UART for IGEP devices as quickly and easily as possible. In this How-To, we use [http://labs.isee.biz/index.php/Pre-installed_software_on_IGEP_Processor_Boards IGEP Firmware] and a program that use UART peripherals. This How-To was tested in: *[[IGEP firmware Yocto|IGEP firmware Yocto]] and [[Linux_Kernel_2.6.37.y|Kernel 2.6.37.y]] with IGEPv2.
This How-To Example program has a debug option using GPIOs to debug via oscilloscope, this method is meant to be a starting point for people useful to learn use UART for IGEP v2 devices as quickly and easily as possibleabout the Kernel latencies. In this how-Debug has set to, we use [http://releases.linaro.org/platform/linaro-m/headless/final/linaro-m-headless-tar-20101108-2"write" and "select" functions.tar.gz Linaro Headless] with [[Linux Kernel 2.6.35.yPeripherals Summary#UART|Kernel 2.6.35.yMore information]] and UART test program. This program is executed twice, at the same time inside the same IGEP. Its function is get a number via UART, increase it and send result to other UART, the result will be a infinite loop between 2 UARTs. '''(upload source code)''' <section end=overview />
More information about = Preparing IGEP =IGEP Uart devices have the following names in Kernel [http[Linux Kernel 2.6.35.y|2.6.35.y]]:*UART1: /dev/ttyS0*UART2: /dev/ttyS1*UART3:/dev/enttyS2*UART4: /dev/ttyS3IGEP Uart devices have the following names in Kernel [[Linux Kernel 2.6.37.y|2.6.wikipedia37.orgy]]:*UART1: /dev/ttyO0*UART2: /dev/ttyO1*UART3: /dev/wikittyO2*UART4: /UART UART]. dev/ttyO3
'''Note''': This program have a debug option using GPIOs to debug via oscilloscope, this option is useful to learnt about the Kernel latencies. Debug has set to "write" and "select" functions.
= Feedback == Configure UART1 and Contributing UART3 in IGEP with RS232 levels on J960 connector ===
At any point, if you see a mistake you can contribute to this How-To==== Edit igep. ini file ====
= Preparing IGEP =To test UARTs we use UART1 (dev/ttyO0) and UART3 (dev/ttyO2) via J960 connector using RS232 standard.
*UART1 can used by RS485 driver, we need to disable it, edit igep.ini file: <br> <pre>board.ei485=yes</pre> *UART1 is configured in RS232 driver, when igep line is replaced by (or type in -Maybe you don't found this line-):<br> <pre>board.ei485=no</pre> *By default, UART3 is used by Kernel serial console, we need to disable it, go to igep.ini file, comment next line: <br> <pre>;console=ttyO2,115200n8;console=ttyO</pre>==== Edit inittab file = Configure IGEP ===Getty program uses /dev/ttyO2 in IGEP Firmware, disable it modifying /etc/inittab file:*Comment next line:<pre> #S:2345:respawn:/sbin/getty 115200 ttyO2</pre>
To test UARTs we use UART1 (dev/ttyS0) and UART3 (dev/ttyS2) via J960 connector using RS232 standard.
 
NOTE: Make sure that you installed open SSH server. If you don't have it go [[How to forge a local file system server with IGEP0020 board#Installing_Open_SSH_Server|here]].
 
By default, UART1 is used by RS485 driver, we need to disable it, edit igep.ini file: <br>
<pre>board.ei485= yes
</pre>
Maybe you don't found this line, replaced by or type this:<br>
<pre>board.ei485= no
</pre>
By default, UART3 is used by Kernel serial console, we need to disable it, go to igep.ini file, comment next line: <br>
<pre>console=ttyS2,115200n8</pre>
=== Check UARTs devices ===
<pre>dmesg | grep tty</pre>
The result will be similar at that:
<pre>root@localhostigep00x0:~/PROGRAM# dmesg | grep tty
[ 0.000000] console [tty0] enabled
[ 0.598999485198] serial8250omap_uart.0: ttyS0 ttyO0 at MMIO 0x4806a000 (irq = 72) is a ST16654OMAP UART0[ 0.784057485565] serial8250omap_uart.1: ttyS1 ttyO1 at MMIO 0x4806c000 (irq = 73) is a ST16654OMAP UART1[ 0.969085485931] serial8250omap_uart.2: ttyS2 ttyO2 at MMIO 0x49020000 (irq = 74) is a ST16654OMAP UART2[ 10.153503486267] serial8250omap_uart.3: ttyS3 ttyO3 at MMIO 0x49042000 (irq = 80) is a ST16654root@localhost:~/PROGRAM# </pre> Get information about UARTs, type: <pre>setserial -g /dev/ttyS[0123]</pre> The result will be similar at that: <pre>root@localhost:~/PROGRAM# setserial -g /dev/ttyS[0123]/dev/ttyS0, UART: 16654, Port: 0x0000, IRQ: 72/dev/ttyS1, UART: 16654, Port: 0x0000, IRQ: 73/dev/ttyS2, UART: 16654, Port: 0x0000, IRQ: 74/dev/ttyS3, UART: 16654, Port: 0x0000, IRQ: 80OMAP UART3root@localhostigep00x0:~/PROGRAM# </pre> If you don't have setserial installed type: <pre>apt-get install setserial</pre>
=== Connect peripherals ===
Connect IGEPv2 board using J960 connector like this:
<pre> J960
------
(Not used) x---| 1 2 |---o (Connect to 8)
(Connect to 9) o---| 3 4 |---x (Not used)
(Not used)x---| 7 8 |---o (Connect to 2)
(Connect to 3) o---| 9 10 |---x (Not used)
------
</pre>
=== Send some data ===
Use minicom microcom to prove it, open two terminals via SSH&nbsp;and log with root user:
Terminal 1:
<pre>minicom -D microcom /dev/ttyS0ttyO0</pre>
Terminal 2:
<pre>minicom -D microcom /dev/ttyS2 ttyO2 </pre> Type something in one terminal.  {| cellspacing="1" cellpadding="1" border="1" align="center" width="200"|-| style="text-align: left;" | [[Image:Minicom screenshot.png|640x400px]]|}
= Schematics =
=== RS232 Schematic Igep V2 ===
{| cellspacing="1" cellpadding="1" border="1" align="center"
|-
| [[Image:uartRS232 Schematic Igep V2.png|800x531px]]
|}
<br>
=== Uart Schematic Igep Module === {| cellspacing="1" cellpadding="1" width="200" border="1" align="center"|-| [[Image:Uart Schematic Igep Module.png|581x600px]]|}
= Compile and run program =
As explained above, the program uses GPIO for debug option via oscilloscope, it is necessary install userDownload [http://labs.isee.biz/index.php/File:Uart-test-gpio2-drvbeta1.tar.ko driver inside Linux Kernel, more information [[How to use GPIOs|here]bz2 program source] and extract it.  There Before compiling the program, there are some interesting things to configure, before compiling the program. Open it, program and seek next lines:
<pre>//Define Array char size
#define SIZE 30
 
//Define Debug mode:0==Disable
#define DEBUG 0
//Set GPIO Debugger port
//Be sure that mux is correctly configured and GPIOs are not used
#define GPIO1 136158#define GPIO2 137 162</pre> Constant SIZE: it determines the max number of char than chars sended. Constant DEBUG: it can be sent<br> break program infinite loop part, useful to debug errors: 0 (infinite loop) or positive number determines loop max entrances.
Constant DEBUGWAIT: it can break program infinite loop part, it can be useful to debug some errors, 0 (infinite loop) or positive number determine loop configures select max entrances time in seconds.
Constant WAITConstants GPIO1 and GPIO2: it configurea select max timethey configure GPIOs used for debug via oscilloscope. By default, 158 and 162 values are not used in IGEPv2. Configure [[Mux configuration|mux]] properly if you use other GPIOs.
Constants GPIO1 and GPIO2Compile source code using a [[How to setup a cross compiler|cross compiler]] for example IGEP SDK: they configure GPIOs used for debug via oscilloscope<pre>arm-poky-linux-gnueabi-gcc uart-test-2-beta1. Take care to configure mux and don't use them for other purposesc -o uart-test-beta1 <br/pre>
Once you have installed module. Compile program using your Cross Compiler, I used arm-linux-gnueabi-:
<pre>arm-linux-gnueabi-gcc uart-test-beta1.c -o uart-test-beta1 </pre>
= Testing UART =
Decoded with [http://www.asciitable.com/ ASCII table].
{| cellspacing="1" cellpadding="1" width="200" border="1" align="center" width="200"
|-
| [[Image:Uart decode1withlf.JPG|350x230px]]
Program sends information via UART1 but don't receive response via UART3, because only a process is executed. This problem is repeated every 5 seconds (constant WAIT=5) until other process sends information via UART3 at the same speed. If "select" hasn't been implemented, process would have stayed blocked.<br>
{| cellspacing="1" cellpadding="1" width="200" border="1" align="center" width="200"
|-
| [[Image:Uart select timeout9.JPG|350x230px]]
More information [http://en.wikipedia.org/wiki/RS-232#Standard_details here].
{| cellspacing="1" cellpadding="1" width="200" border="1" align="center" width="200"
|-
| [[Image:Uart voltageparams8.JPG|350x230px]]
Note that wave is degraded when speed is higher
{| cellspacing="1" cellpadding="1" width="200" border="1" align="center" width="200"
|-
| [[Image:Uart 300 o.JPG|260x172px]]
You can see that RS232 have some lag between transmisions. This caused mainly by kernel process management. UART peripheral is controlled by Linux and It isn't a [http://en.wikipedia.org/wiki/Real-time_operating_system real-time operating system].&nbsp;
{| cellspacing="1" cellpadding="1" width="200" border="1" align="center" width="200"
|-
| [[Image:Uart lag left6.JPG|350x230px]]
This program have three I/O functions that connect to UART driver via ioctl: (read(), write() and select()). But select() and write() change process stat to sleep mode until system don't receive or transmit all information via UART. "select" function is used to prevent that read function can be blocked when data aren't available. <br>The next images (program with debug_gpio enabled and 300 bauds speed) show when process is executed or is waiting. Blue=UART1, Violet="write" and Green="select". When GPIO has HIGH value, process is blocked.<br>
{| cellspacing="1" cellpadding="1" width="200" border="1" align="center" width="200"
|-
| [[Image:Uart select5.JPG|260x172px]]
Every full process the number is increased twice. Program checks that this condicion is true, if it isn't accomplished, process will be finish.
{| cellspacing="1" cellpadding="1" width="200" border="1" align="center" width="200"
|-
| [[Image:Uart error test2.png|640x400px]]
<br>
[[Category:Communications]] [[Category:How_to_forge]] [[Category:TutorialsUART]]
0
edits