6 6
7profy

[Orange Pi One] How to enable UART?

Recommended Posts

(edited)

I'm using Orange Pi One with ARMBIAN Debian GNU/Linux 8 (jessie) 3.4.112-sun8i.

To access to UART I'm using function serialOpen() of WiringPi library.

Default device name for Raspberry is '/dev/ttyAMA0'. But I can't open this device (No such file or directory).

 

How to enable ttyAMA0?

Edited by wildcat_paris
added board name in title

Share this post


Link to post
Share on other sites

And how to "tweak"? And what is "FEX"?

I'm trying to migrate from Rasperry to Orange. Almost all done.

I'm not powerful linux user.

Share this post


Link to post
Share on other sites

Depending of the version of your kernel, old ones called Legacy, it is using FEX to define GPIOs and Peripherals pins.

Wit Mainline Kernel, it is using DTS.

Maybe the settings currently are already Ok, did you have an /dev/ttyS3 ?

If not, then those settings need to be tweaked. What is the kernel version you are using ?

Do some search about UART FEX for Legacy.

For Mainline, I think my contribution to DTS is already in all Armbian images.

Share this post


Link to post
Share on other sites

About month ago I install from armbian.com this os.

root@orangepione ~ # uname -a
Linux orangepione 3.4.112-sun8i #8 SMP PREEMPT Tue May 31 19:00:17 CEST 2016 armv7l GNU/Linux

How to find out it using FEX or DTS?

 

I have the next device list:

root@orangepione ~ # ls /dev/
android_adb      input               ram1            tty18  tty45   uinput
apm_bios         ion                 ram2            tty19  tty46   urandom
autofs           kmsg                ram3            tty2   tty47   usb_accessory
block            lircd               ram4            tty20  tty48   usbdev1.1
btrfs-control    log                 ram5            tty21  tty49   usbdev2.1
bus              loop0               ram6            tty22  tty5    usbdev3.1
cachefiles       loop1               ram7            tty23  tty50   usbdev4.1
cedar_dev        loop2               random          tty24  tty51   usbdev5.1
char             loop3               rfkill          tty25  tty52   usbdev6.1
console          loop4               rtc             tty26  tty53   usbdev7.1
cpu_dma_latency  loop5               rtc0            tty27  tty54   usbdev8.1
cuse             loop6               shm             tty28  tty55   vcs
disk             loop7               snd             tty29  tty56   vcs1
disp             loop-control        spidev0.0       tty3   tty57   vcs2
ecryptfs         mapper              stderr          tty30  tty58   vcs3
fb0              mem                 stdin           tty31  tty59   vcs4
fb1              misc_fatfs          stdout          tty32  tty6    vcs5
fb2              mmcblk0             sunxi-reg       tty33  tty60   vcs6
fb3              mmcblk0p1           sunxi_soc_info  tty34  tty61   vcsa
fb4              mqueue              tty             tty35  tty62   vcsa1
fb5              mtp_usb             tty0            tty36  tty63   vcsa2
fb6              net                 tty1            tty37  tty7    vcsa3
fb7              network_latency     tty10           tty38  tty8    vcsa4
fd               network_throughput  tty11           tty39  tty9    vcsa5
full             null                tty12           tty4   ttyGS0  vcsa6
fuse             ppp                 tty13           tty40  ttyGS1  vmouse
hdmi             psaux               tty14           tty41  ttyGS2  watchdog
i2c-0            ptmx                tty15           tty42  ttyGS3  xconsole
i2c-1            pts                 tty16           tty43  ttyS0   zero
initctl          ram0                tty17           tty44  uhid

GPIO:

 +-----+-----+----------+------+---+--OrangePiPC--+---+------+---------+-----+--+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 |     |     |     3.3v |      |   |  1 || 2  |   |      | 5v       |     |     |
 |   2 |   8 |    SDA.0 | ALT5 | 0 |  3 || 4  |   |      | 5V       |     |     |
 |   3 |   9 |    SCL.0 | ALT5 | 0 |  5 || 6  |   |      | 0v       |     |     |
 |   4 |   7 |   GPIO.7 | ALT3 | 0 |  7 || 8  | 0 | ALT3 | TxD3     | 15  | 14  |
 |     |     |       0v |      |   |  9 || 10 | 0 | ALT3 | RxD3     | 16  | 15  |
 |  17 |   0 |     RxD2 | ALT3 | 0 | 11 || 12 | 0 | OUT  | GPIO.1   | 1   | 18  |
 |  27 |   2 |     TxD2 | ALT3 | 0 | 13 || 14 |   |      | 0v       |     |     |
 |  22 |   3 |     CTS2 | ALT3 | 0 | 15 || 16 | 0 | ALT3 | GPIO.4   | 4   | 23  |
 |     |     |     3.3v |      |   | 17 || 18 | 0 | ALT3 | GPIO.5   | 5   | 24  |
 |  10 |  12 |     MOSI | ALT4 | 0 | 19 || 20 |   |      | 0v       |     |     |
 |   9 |  13 |     MISO | ALT4 | 0 | 21 || 22 | 0 | ALT3 | RTS2     | 6   | 25  |
 |  11 |  14 |     SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0      | 10  | 8   |
 |     |     |       0v |      |   | 25 || 26 | 0 | ALT3 | GPIO.11  | 11  | 7   |
 |   0 |  30 |    SDA.1 | ALT4 | 0 | 27 || 28 | 0 | ALT4 | SCL.1    | 31  | 1   |
 |   5 |  21 |  GPIO.21 | ALT3 | 0 | 29 || 30 |   |      | 0v       |     |     |
 |   6 |  22 |  GPIO.22 | ALT3 | 0 | 31 || 32 | 1 | OUT  | RTS1     | 26  | 12  |
 |  13 |  23 |  GPIO.23 | ALT3 | 0 | 33 || 34 |   |      | 0v       |     |     |
 |  19 |  24 |  GPIO.24 |  OUT | 1 | 35 || 36 | 1 | OUT  | CTS1     | 27  | 16  |
 |  26 |  25 |  GPIO.25 | ALT3 | 0 | 37 || 38 | 1 | OUT  | TxD1     | 28  | 20  |
 |     |     |       0v |      |   | 39 || 40 | 1 | OUT  | RxD1     | 29  | 21  |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+--OrangePIPC--+------+----------+-----+-----+

Although GPIO allows to change pins values ALTx, but actually they are not changed.

 

What I have to do?

 

Share this post


Link to post
Share on other sites
(edited)

SOLVED!

 

Here is solution (for H3):

 

1. Convert script.bin to FEX:

cd /boot
bin2fex script.bin script.fex

2. Edit script.fex to enable UART3:

sudo nano script.fex

Find section [uart0] and set the next to disable uart0-2 and enable uart3 only with 2-pin mode on pin 8/10:

[uart0]
uart_used       = 0
uart_port       = 0
uart_type       = 2
uart_tx         = port:PA04<2><1><default><default>
uart_rx         = port:PA05<2><1><default><default>

[uart1]
uart_used       = 0
uart_port       = 1
uart_type       = 4
uart_tx         = port:PG06<2><1><default><default>
uart_rx         = port:PG07<2><1><default><default>
uart_rts        = port:PG08<2><1><default><default>
uart_cts        = port:PG09<2><1><default><default>

[uart2]
uart_used       = 0
uart_port       = 2
uart_type       = 4
uart_tx         = port:PA00<2><1><default><default>
uart_rx         = port:PA01<2><1><default><default>
uart_rts        = port:PA02<2><1><default><default>
uart_cts        = port:PA03<2><1><default><default>

[uart3]
uart_used       = 1
uart_port       = 3
uart_type       = 2
uart_tx         = port:PA13<2><1><default><default>
uart_rx         = port:PA14<2><1><default><default>
;uart_rts        = port:PA15<3><1><default><default>
;uart_cts        = port:PA16<3><1><default><default>

Remark: I don't find description for value <2> in PA13<2> but it works as expected.

 

3. Save changes.

 

4. Convert FEX to bin

fex2bin script.fex script.bin

5. Reboot.

 

6. Device name is ttyS3. Default speed = 57600. To test it type "echo TEST > /dev/ttyS3"

 

 

PS. Some times after 

apt-get upgrade

script.bin replaces to default values, so it need to repeat all steps.

Edited by 7profy

Share this post


Link to post
Share on other sites

I use Orange PI PC Plus with Debian 8. Need disable GPIO in fex file, for work ttyS3. 

 

[gpio_para]
gpio_used = 0
gpio_num = 19
gpio_pin_1 = port:PA06<1><default><default><0>
gpio_pin_2 = port:PA13<1><default><default><0>
gpio_pin_3 = port:PA14<1><default><default><0>
gpio_pin_4 = port:PA01<1><default><default><0>
gpio_pin_5 = port:PD14<1><default><default><0>
gpio_pin_6 = port:PA00<1><default><default><0>
gpio_pin_7 = port:PA03<1><default><default><0>
gpio_pin_8 = port:PC04<1><default><default><0>
gpio_pin_9 = port:PC07<1><default><default><0>
gpio_pin_10 = port:PA02<1><default><default><0>
gpio_pin_11 = port:PA21<1><default><default><0>
gpio_pin_12 = port:PA07<1><default><default><0>
gpio_pin_13 = port:PA08<1><default><default><0>
gpio_pin_14 = port:PG08<1><default><default><0>
gpio_pin_15 = port:PA09<1><default><default><0>
gpio_pin_16 = port:PA10<1><default><default><0>
gpio_pin_17 = port:PG09<1><default><default><0>
gpio_pin_18 = port:PG06<1><default><default><0>
gpio_pin_19 = port:PG07<1><default><default><0>

 

How can rewrite it to work well the GPIO, and also ttyS3?

 

Thank You

 

Share this post


Link to post
Share on other sites

I rewrite this

 

[gpio_para]
gpio_used = 1
gpio_num = 19
gpio_pin_1 = port:PA06<1><default><default><0>
gpio_pin_2 = port:PA15<1><default><default><0>
gpio_pin_3 = port:PA16<1><default><default><0>
 

And working fine. Without RTS and CTS.

[uart3]
    uart_used = 1
    uart_port = 3
    uart_type = 2
    uart_tx = port:PA13<3><1><default><default>
    uart_rx = port:PA14<3><1><default><default>
    ;uart_rts = port:PA15<3><1><default><default>
    ;uart_cts = port:PA16<3><1><default><default>

Share this post


Link to post
Share on other sites

I need to use the serial port in the 26-pin header of an Orange Pi Zero. For what I have read, I assume that it is /dev/ttyS3. Is that right?

 

I have followed the instructions of 7profy, and now ttyS3 shows in /dev/, but I can't get the port to work. But when I hook a serial-to-USB adapter to pins 6, 8 and 10, and try to communicate with it using minicom, nothing happens. I have double-checked the communications settings (both minicom and PuTTY are set to 9600,8,n,1) and the connections, and I have tested /dev/ttyS2 and /dev/ttyS1 just in case, but I have got no reply at all.

 

How can I verify the serial port is enabled and working? Are there any extra steps to enable /dev/ttyS3 on the Orange Pi Zero?

 

uname -a outputs the following:

Linux orangepizero 3.4.113-sun8i #10 SMP PREEMPT Thu Feb 23 19:55:00 CET 2017 armv7l GNU/Linux

 

Share this post


Link to post
Share on other sites

To isolate the issue, maybe you should try to do a simple loopback test first, a jumper between 8 and 10, and use minicom or picocom to get local echo.

 

BTW, in the case of Mainline, without having other uart enabled other than debug uart0, when I load overlay for uart2, it comes up as /dev/ttyS1, since debug is on /dev/ttyS0.

 

Share this post


Link to post
Share on other sites

Orange Pi Zero working fine for me (ttyS1 on pin 8, pin 10) with this settings in script.fex:

 

[uart1]
uart_used = 1
uart_port = 1
uart_type = 2
uart_tx = port:PG06<2><1><default><default>
uart_rx = port:PG07<2><1><default><default>
 

There is no [gpio_para] section.

Share this post


Link to post
Share on other sites

for mainline kernel

```

Linux version 4.11.5-sun8i (root@devel) (gcc version 7.1.1 20170510 (Linaro GCC 7.1-2017.05) ) #11 SMP Fri Jun 23 20:03:23 CEST 2017

 

user@orangepipcplus:/boot/dtb$ ls -al /dev/ttyS*
crw--w---- 1 root tty     4, 64 Jun 25 12:07 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Jun 25 12:07 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 Jun 25 12:07 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Jun 25 12:07 /dev/ttyS3
crw-rw---- 1 root dialout 4, 68 Jun 25 12:07 /dev/ttyS4
crw-rw---- 1 root dialout 4, 69 Jun 25 12:07 /dev/ttyS5
crw-rw---- 1 root dialout 4, 70 Jun 25 12:07 /dev/ttyS6
crw-rw---- 1 root dialout 4, 71 Jun 25 12:07 /dev/ttyS7

```

Even connected pin 38 and 40, no characters are shown in local echo. Any steps (kernel or user layout) required to enable ttyS1.

Share this post


Link to post
Share on other sites

for mainline kernel

```

Linux version 4.11.5-sun8i (root@devel) (gcc version 7.1.1 20170510 (Linaro GCC 7.1-2017.05) ) #11 SMP Fri Jun 23 20:03:23 CEST 2017

 

user@orangepipcplus:/boot/dtb$ dtc -I dtb sun8i-h3-orangepi-pc-plus.dtb -O dts |less

                       uart1 {
                                pins = "PG6", "PG7";
                                function = "uart1";
                                linux,phandle = <0x19>;
                                phandle = <0x19>;
                        };

                        uart1_rts_cts {
                                pins = "PG8", "PG9";
                                function = "uart1";
                                linux,phandle = <0x48>;
                                phandle = <0x48>;
                        };
 

user@orangepipcplus:/boot/dtb$ ls -al /dev/ttyS*
crw--w---- 1 root tty     4, 64 Jun 25 12:07 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Jun 25 12:07 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 Jun 25 12:07 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Jun 25 12:07 /dev/ttyS3
crw-rw---- 1 root dialout 4, 68 Jun 25 12:07 /dev/ttyS4
crw-rw---- 1 root dialout 4, 69 Jun 25 12:07 /dev/ttyS5
crw-rw---- 1 root dialout 4, 70 Jun 25 12:07 /dev/ttyS6
crw-rw---- 1 root dialout 4, 71 Jun 25 12:07 /dev/ttyS7

 

minicom with hardware flow disabled and software flow enabled

    │ A -    Serial Device      : /dev/ttyS1                                │

    │ B - Lockfile Location     : /var/lock                                 │
    │ C -   Callin Program      :                                           │
    │ D -  Callout Program      :                                           │
    │ E -    Bps/Par/Bits       : 9600 8N1                                  │
    │ F - Hardware Flow Control : No                                        │
    │ G - Software Flow Control : Yes                                       │
    │                                                                       │
    │    Change which setting?    

```

Even connected pin 38 and 40, no characters are shown in local echo. Any steps (kernel or user layout) required to enable ttyS1.

Share this post


Link to post
Share on other sites
18 minutes ago, martinayotte said:

You need to add "overlays=uart1" in armbienEnv.txt and reboot

 

It works perfect. This forum is far better than many worldwide software company Thanks for your prompt reply.

Share this post


Link to post
Share on other sites

Hi 

I tried to swap pin tx and rx on uart1 

[uart1] uart_used = 0

uart_port = 1

uart_type = 4

uart_tx = port:PG07<2><1><default><default>

uart_rx = port:PG06<2><1><default><default>

physical pin on 38 and 40

but still, no change

is it fixed pin mapping for PG07 and 06 with physical pin or there is another conf at fex file?

 

Thanks 

Share this post


Link to post
Share on other sites

Hi

 

I am having following kernal

Linux orangepi 3.4.39 #41 SMP PREEMPT Sun Jun 21 13:09:26 HKT 2015 armv7l armv7l armv7l GNU/Linux

 

and in my boot directory there is no script.bin file.

how can i enable my serial ports 2 and 3. also my serial port 1 seems to be used for console is there any way that i can disable console output and use the same port for my custom application

Share this post


Link to post
Share on other sites
27 minutes ago, tush.jambhekar said:

I am having following kernal

Linux orangepi 3.4.39 #41 SMP PREEMPT Sun Jun 21 13:09:26 HKT 2015 armv7l armv7l armv7l GNU/Linux

 

and in my boot directory there is no script.bin file.

how can i enable my serial ports 2 and 3. also my serial port 1 seems to be used for console is there any way that i can disable console output and use the same port for my custom application


That kernel is supported by no one and the process of changing parameters is not as simple as in armbian.

Share this post


Link to post
Share on other sites
On 7/9/2017 at 11:18 PM, martinayotte said:

You need to add "overlays=uart1" in armbienEnv.txt and reboot

 

OHHHHHH Sh!t......it works!!!

I sign up an account just to thank martinayotte !!! You are like god for me now !

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
6 6