arisw
Posts: 7
Joined: Tue Aug 11, 2015 5:13 am

Re: Serial ports -- using both

Tue Aug 11, 2015 5:34 am

Hi,

for a project I'm going to use both serial ports with the compute module.

I installed the uart1 overlay but the system freeze when I try to init the 2nd serial port.

Below some info, if you need more just ask:

/boot/config.txt

Code: Select all

# At the bottom I added this
dtoverlay=uart1,txd1_pin=40,rxd1_pin=41
dmesg

Code: Select all

[    0.132217] bcm2708.uart_clock = 3000000
[    0.136566] bcm2708: Mini UART enabled
[    0.137420] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers.
[    0.137494] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.137715] Serial: AMBA PL011 UART driver
[    0.138129] 20201000.uart: ttyAMA0 at MMIO 0x20201000 (irq = 83, base_baud = 0) is a PL011 rev2
[    0.526098] console [ttyAMA0] enabled


[    0.943095] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.953482] 20215040.uart: ttyS0 at MMIO 0x20215040 (irq = 29, base_baud = 31250000) is a 16550

Code: Select all

$ uname -a
Linux raspberrypi 4.1.4+ #808 PREEMPT Thu Aug 6 15:51:03 BST 2015 armv6l GNU/Linux
Doing this freeze the system:

Code: Select all

stty -F /dev/ttyS0 9600
p.s.
I did a rpi-update

dpslwk
Posts: 20
Joined: Sun Feb 19, 2012 2:08 pm

Re: Serial ports -- using both

Thu Aug 13, 2015 8:07 am

You need to make sure you have a device connected to the serial port before opening it with something like minicom
wirelessthings.net
OpenMicros.org

arisw
Posts: 7
Joined: Tue Aug 11, 2015 5:13 am

Re: Serial ports -- using both

Thu Aug 13, 2015 8:17 pm

I connected the two serials and it works. Thank you very much.

nixy82
Posts: 51
Joined: Sat Sep 12, 2015 9:19 am

Re: Serial ports -- using both

Sat Sep 12, 2015 10:01 am

Hi

Apologies up front if this is a stupid question, but I'm having real problems in making this work

I'm trying to create a new dts/dtb blob that enables all 4 UART1 serial lines, RX1/TX1/RTS1/CTS1

I'm working on the compute dev board, and have a plug in USB-2-LAN adapter to make things easier

I'm getting some success, in so far as raspi-gpio appears to show it working, but the raspbian Linux OS doesn't show any active 16550 ports nor are has it assigned ttyS0 - unsurprising I guess if it can't find any active.

I'm clearly missing something (probably the core concept :P )

So here's what I've done so far

I've updated both the OS and the kernel/pi firmware via

Code: Select all

apt-get update
apt-get upgrade
rpi-update
So I'm running :

Code: Select all

# uname -a
Linux raspberrypi 4.1.6+ #812 PREEMPT Thu Sep 10 11:27:23 BST 2015 armv6l GNU/Linux
Using the default uart1 overlay by adding the below to the bottom of config.txt:

Code: Select all

dtoverlay=uart1
This is the result :
dmesg :

Code: Select all

[    0.356034] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
raspi-gpio get :

Code: Select all

 GPIO 14: level=1 fsel=2 alt=5 func=TXD1
 GPIO 15: level=0 fsel=2 alt=5 func=RXD1
And I find a ttyS0 nicely appears in /dev so all good so far :)

Using a different overlay syntax instead (i.e. removed the previous line from config.txt and added this one instead) I've moved the RX/TX pins, as I expected this ignores the RTS/CTS assignments.

Code: Select all

dtoverlay=uart1,txd1_pin=32,rxd1_pin=33,cts1_pin=30,rts1_pin=31
dmesg :

Code: Select all

[    0.355913] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.359721] 20215040.uart: ttyS0 at MMIO 0x20215040 (irq = 29, base_baud = 31250000) is a 16550
raspi-gpio get :

Code: Select all

  GPIO 30: level=0 fsel=0 alt=  func=INPUT
  GPIO 31: level=0 fsel=0 alt=  func=INPUT
  GPIO 32: level=1 fsel=2 alt=5 func=TXD1
  GPIO 33: level=0 fsel=2 alt=5 func=RXD1
So I looked at the example of a dts blob from an earlier post

viewtopic.php?p=779867#p779867

I've modified it to the below - not 100% on what fragment@1 part does, still getting to grips with this :

Code: Select all

   /dts-v1/;
    /plugin/;

    / {
        compatible = "brcm,bcm2708";

        fragment@0 {
            target = <&gpio>;
            __overlay__ {
                uart1_pins: uart1 {
                    brcm,pins = <30 31 32 33>; /* UART1: CTS1 RTS1 TX1 RX1 */
                    brcm,function = <2>; /* alt 5 */
                    brcm,pull = <0 0 0 2>; /* 2:up 1:down 0:none */
                };
            };
        };

        fragment@1 {
            target = <&uart1>;
            __overlay__ {
                pinctrl-names = "default";
                pinctrl-0 = <&uart1_pins>;
                status = "okay";
            };
        };

       __overrides__ {

        };

    };
Compiled it with :

Code: Select all

dtc -@ -I dts -O dtb -o uart1-full-overlay.dtb uart1-full-overlay.dts
cp uart1-full-overlay.dtb /boot/overlays/uart1-full-overlay.dtb
Added it to the bottom of the config.txt (removing all the others)

Code: Select all

dtoverlay=uart1-full
On boot I find

Code: Select all

dmesg | grep 16550
[    0.355953] Serial: 8250/16550 driver, 0 ports, IRQ sharing disabled
however raspi-gpio shows

Code: Select all

  GPIO 30: level=0 fsel=2 alt=5 func=CTS1
  GPIO 31: level=1 fsel=2 alt=5 func=RTS1
  GPIO 32: level=1 fsel=2 alt=5 func=TXD1
  GPIO 33: level=0 fsel=2 alt=5 func=RXD1
Clearly I'm missing something here, so I backed off to the original only using pins 32/33 instead of 14/15, recompiled that and put that in instead (I'll skip the steps for brevity, but it's essentially the same)

This was the result:

Code: Select all

dmesg | grep 16550
[    0.355965] Serial: 8250/16550 driver, 0 ports, IRQ sharing disabled
raspi-gpio shows

Code: Select all

  GPIO 30: level=0 fsel=0 alt=  func=INPUT
  GPIO 31: level=0 fsel=0 alt=  func=INPUT
  GPIO 32: level=1 fsel=2 alt=5 func=TXD1
  GPIO 33: level=0 fsel=2 alt=5 func=RXD1
Can anyone point me as to what I'm missing here?

I feel like there's some kind of "activation" step that I'm not doing maybe?

Can I get a peak at the dts file(s) that are being used to generate the boot/overlay files, as I can't find that on the git trunk anywhere, to maybe crib from to see if I can find my error.

Once I've conquered this I'll move on to more exotic things like a custom GPIO setup blob ;)

nixy82
Posts: 51
Joined: Sat Sep 12, 2015 9:19 am

Re: Serial ports -- using both

Sat Sep 12, 2015 10:21 am

The below debug gives a bit more of a clue :

Code: Select all

root@raspberrypi:~# dtc -@ -I dts -O dtb -o uart1-full-overlay.dtb uart1-full-overlay.dts
root@raspberrypi:~# cp uart1-full-overlay.dtb /boot/overlays/uart1-full-overlay.dtb
root@raspberrypi:~# reboot

root@raspberrypi:~# dmesg | grep -C3 16550
[    0.345538] BCM2708FB: allocated DMA memory 5bc00000
[    0.345685] BCM2708FB: allocated DMA channel 0 @ f2007000
[    0.350730] Console: switching to colour frame buffer device 82x26

[    0.355928] Serial: 8250/16550 driver, 0 ports, IRQ sharing disabled
[    0.359704] of_serial: probe of 20215040.uart failed with error -28

[    0.362730] vc-cma: Videocore CMA driver
[    0.364522] vc-cma: vc_cma_base      = 0x00000000

root@raspberrypi:~# raspi-gpio get
<snip>
  GPIO 30: level=0 fsel=2 alt=5 func=CTS1
  GPIO 31: level=1 fsel=2 alt=5 func=RTS1
  GPIO 32: level=1 fsel=2 alt=5 func=TXD1
  GPIO 33: level=0 fsel=2 alt=5 func=RXD1
<snip>
 
So it's failing in some manner when trying to probe the UART

nixy82
Posts: 51
Joined: Sat Sep 12, 2015 9:19 am

Re: Serial ports -- using both

Sat Sep 12, 2015 3:53 pm

OK, I've now found the dts sources, and have got a little further here in my quest :)

Taking the existing file uart1 file :
https://github.com/raspberrypi/linux/tr ... s/overlays

and modifying it thus :

Code: Select all

/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2708";

	fragment@0 {
		target = <&uart1>;
		__overlay__ {
			pinctrl-names = "default";
			pinctrl-0 = <&uart1_pins>;
			status = "okay";
		};
	};

	fragment@1 {
		target = <&gpio>;
		__overlay__ {
			uart1_pins: uart1_pins {
				//brcm,pins = <14 15>;
				brcm,pins = <30 31 32 33>; /* UART1: 30=CTS1 31=RTS1 32=TX1 33=RX1 */
				brcm,function = <2>; /* alt5 */
				brcm,pull = <0 0 0 2>;
			};
		};
	};

	fragment@2 {
		target-path = "/chosen";
		__overlay__ {
			bootargs = "8250.nr_uarts=1";
		};
	};

	__overrides__ {
		txd1_pin = <&uart1_pins>,"brcm,pins:0";
		rxd1_pin = <&uart1_pins>,"brcm,pins:4";
	};
};
This works :D

Code: Select all

# dmesg | grep -C1 16550
[    0.350904] Console: switching to colour frame buffer device 82x26
[    0.356077] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.360519] 20215040.uart: ttyS0 at MMIO 0x20215040 (irq = 29, base_baud = 31250000) is a 16550
[    0.365948] vc-cma: Videocore CMA driver

Code: Select all

raspi-gpio get
  GPIO 30: level=0 fsel=2 alt=5 func=CTS1
  GPIO 31: level=1 fsel=2 alt=5 func=RTS1
  GPIO 32: level=1 fsel=2 alt=5 func=TXD1
  GPIO 33: level=0 fsel=2 alt=5 func=RXD1
What I don't quite understand is why the lines below have a 0 or 4 at the end though, as these don't appear marry up to any TX1/RX1 pin, and I'm assuming this is a default of some sort?

Code: Select all

txd1_pin = <&uart1_pins>,"brcm,pins:0";
rxd1_pin = <&uart1_pins>,"brcm,pins:4";
Would be nice to be able to add the final options to allow you to configure the RTS/CTS lines as well, does it matter what numbers are placed here?

tiagojcp
Posts: 4
Joined: Tue Nov 24, 2015 2:10 pm

Re: Serial ports -- using both

Tue Nov 24, 2015 2:17 pm

Hi all,

I've also been capable of enabling ttyS0. However, in my case, using pins 40 and 41 for RX/TX, if nothing is connected to RX pin, the system will hang and a reboot is required. For what I can see and test, using a scope, the RX pin, while booting, appears to be HIGH. After a while it goes LOW and stays that way.

Question, is it possible to force the pin to stay HIGH, without an external pull-up resistor? I've tried to do that in the overlay without success. It seems that something else is forcing the pin to LOW.

Offcourse, if I connect something to the other end of the serial port, then everything works fine, because the RX line gets forced to HIGH from the other end.

Thank you guys. Keep up the good work!

Tiago

Blix
Posts: 6
Joined: Fri Dec 11, 2015 12:05 pm

Re: Serial ports -- using both

Wed Dec 16, 2015 3:41 pm

I'm trying to setup a RPi using UART1. Googling around it seems as if people have tried this before. However it seems a bit unclear to me, if anyone have done this successfully?

I have some questions:

1. On the RPi, is UART0 the only currently working and supported in the RPi-kernel?
2. UART0 is a "mini-uart", it is not full-fledged and has some limitations?
3. If i want another uart besides UART0, i need to use an USB device?

nixy82
Posts: 51
Joined: Sat Sep 12, 2015 9:19 am

Re: Serial ports -- using both

Wed Dec 16, 2015 4:08 pm

Hi

The mini uart (uart0) is /dev/ttyAMA0 - this is not fully 16550 compliant, if you google around you'll find out the differences and whether this will do the job you want. I gather the port was originally only intended for a console port, so again you'll need to check if the supported settings work for your app

The main on board 16550 compatible serial port (uart1) is /dev/ttyS0

Have a look at this overlay post using the below dts file contents, so you how to enable it :

viewtopic.php?p=814661#p814661

I've generated something similar to bring up the RTS/CTS lines all onto pins 30-33 (so you can have both active if you really want) :

Code: Select all

/dts-v1/;
/plugin/;

/{
        compatible = "brcm,bcm2708";

        fragment@0 {
                target = <&uart1>;
                __overlay__ {
                        pinctrl-names = "default";
                        pinctrl-0 = <&uart1_pins>;
                        status = "okay";
                };
        };

        fragment@1 {
                target = <&gpio>;
                __overlay__ {
                        uart1_pins: uart1_pins {
                                //brcm,pins = <14 15>;
                                brcm,pins = <30 31 32 33>; /* UART1: CTS1 RTS1 TX1 RX1 */
                                brcm,function = <2>; /* alt5 */
                                brcm,pull = <0 0 0 2>;
                        };
                };
        };

        fragment@2 {
                target-path = "/chosen";
                __overlay__ {
                        bootargs = "8250.nr_uarts=1";
                };
        };

        __overrides__ {
                txd1_pin = <&uart1_pins>,"brcm,pins:0";
                rxd1_pin = <&uart1_pins>,"brcm,pins:4";
//              cts1_pin = <&uart1_pins>,"brcm,pins:0";
//              rts1_pin = <&uart1_pins>,"brcm,pins:4";
        };
};

tiagojcp
Posts: 4
Joined: Tue Nov 24, 2015 2:10 pm

Re: Serial ports -- using both

Wed Dec 16, 2015 5:05 pm

Hello all,

I've been able to get ttyS0 working. Nevertheless I think there is still a issue. Here are my findings:

OS : Raspbian wheezy
Kernel: 4.1.13+
HW: Compute Module (CM)
GPIO's used: 40 (TX) and 41 (RX), but tested also with 32,33

Issue:
The baud rate calculations seem to be incorrect. I found this out while trying to communicate from my PC to the CM. I was getting many communication errors and getting half the bytes I was expecting in the receiver. After many days of banging my head and getting desperate, I decreased the baud rate in my PC to half it was configured in the CM. Surprisingly it started working, although with some errors.

Last test I've executed, trying to find out if I had any coding mistake, I changed the CM console from ttyAMA0 to ttyS0. Also here I could not get anything clear in my PC, while booting the CM, just garbage. I decreased the baud rate in "screen" to half it was configured in CM and it started working, also with some errors (invalid characters).

So, by now, I'm guessing there is an issue somewhere with this port. Anyone has gone through this issue also?

Thank you all!

Cheers.

tiagojcp
Posts: 4
Joined: Tue Nov 24, 2015 2:10 pm

Re: Serial ports -- using both

Wed Dec 16, 2015 5:05 pm

Hello all,

I've been able to get ttyS0 working. Nevertheless I think there is still a issue. Here are my findings:

OS : Raspbian wheezy
Kernel: 4.1.13+
HW: Compute Module (CM)
GPIO's used: 40 (TX) and 41 (RX), but tested also with 32,33

Issue:
The baud rate calculations seem to be incorrect. I found this out while trying to communicate from my PC to the CM. I was getting many communication errors and getting half the bytes I was expecting in the receiver. After many days of banging my head and getting desperate, I decreased the baud rate in my PC to half it was configured in the CM. Surprisingly it started working, although with some errors.

Last test I've executed, trying to find out if I had any coding mistake, I changed the CM console from ttyAMA0 to ttyS0. Also here I could not get anything clear in my PC, while booting the CM, just garbage. I decreased the baud rate in "screen" to half it was configured in CM and it started working, also with some errors (invalid characters).

So, by now, I'm guessing there is an issue somewhere with this port. Anyone has gone through this issue also?

Thank you all!

Cheers.

tiagojcp
Posts: 4
Joined: Tue Nov 24, 2015 2:10 pm

Re: Serial ports -- using both

Thu Dec 17, 2015 1:51 pm

Finally I could make it work.

For anyone who gets into the same problem, make sure you are working at 700 MHz and 250 MHz clock.

I got to this, after reading this post:

viewtopic.php?f=44&t=17559

It seems the baud rate formula is affected (only for ttyS0, not for ttyAMA0, i've tested it) by this configurations.

T

Return to “Compute Module”