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

Re: Serial ports -- using both

Fri Mar 13, 2015 11:19 am

I've been trying to get this running on a compute module but with little success.
I can get the module built and loaded see the new /dev/ttyS0 but every time I try to open the port with minicom or screen e Pi just freezes.
Has any one else got this working and what steps did you follow?
Here are are some of the steps I use to do all this.

Compute setup:-
Using another Pi and rip-boot flash raspbian-2015-02-17/2015-02-16-raspbian-wheezy.img
Once flashed reconnect the compute and update the bad firmware/kernel in the image

Code: Select all

$ sudo ROOT_PATH=/media/f24a4949-f4b2-4cad-a780-a138695079ec BOOT_PATH=/media/boot rpi-update
Boot the CM, connect to the wifi, and get everything updated correctly

Code: Select all

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo rpi-update
$ sudo reboot
Setting the port pins:
To get two gpio pins set to ALT5 I'm using the VC device tree
Grab the example file from http://www.raspberrypi.org/documentatio ... t-blob.dts
add the following two lines into the pins_cm/pin_config section

Code: Select all

pin@p32 { function = "uart1";  termination = "no_pulling"; }; // TX uart1
pin@p33 { function = "uart1";  termination = "pull_up"; }; // TX uart2
Compile, install and reboot

Code: Select all

$ sudo apt-get install device-tree-complier
$ sudo dtc -I dts -O dtb -o /boot/dt-blob.dtb dt-blob.dts
$ sudo reboot
Cross compile the kernel and module
For this I'm using a Ubuntu 12.04 VM
Following instructions from here http://www.raspberrypi.org/documentatio ... uilding.md

Code: Select all

$ git clone https://github.com/raspberrypi/tools
$ vi ~/.bashrc //added tools to the $PATH
$ git clone --depth=1 https://github.com/raspberrypi/linux
$ cd linux
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=~/modules modules
$ sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=~/modules modules_install
Compile the uart driver

Code: Select all

$ cd
$ wget http://brevera.in/blog/wp-content/uploads/2015/03/pi_mini_uart.zip
$ unzip pi_mini_uart.zip
$ cd pi_mini_uart
$ vi Makefile //edit the make file with arm-linux-gnueabihf- and /home/user/linux
$ make
Trying the driver
Sftp the bcm_mini_uart.ko over the to CM
Then on the CM load the module

Code: Select all

$ sudo insmod bcm_mini_uart.ko
$ ls /dev/tty*
$ minicom -D /dev/ttyS0 -o -b 115200
This shows the new tty in place but trying to open the port and it all just hangs

I've tried loading the module against both the kernel and modules as installed from rip-update and also my own cross compiled versions
wirelessthings.net
OpenMicros.org

Venkatesh
Posts: 12
Joined: Fri Jan 30, 2015 9:48 am
Location: Mangalore, India
Contact: Website

Re: Serial ports -- using both

Fri Mar 13, 2015 2:19 pm

I made it to work with 3.18.3+ kernel. I had built driver and loaded pi with the same kernel version.
www.brevera.in

cr_sh
Posts: 5
Joined: Thu Mar 05, 2015 3:03 pm

Re: Serial ports -- using both

Fri Mar 13, 2015 2:45 pm

Venkatesh wrote:I made it to work with 3.18.3+ kernel. I had built driver and loaded pi with the same kernel version.
can you put the compiled module online?

thanks!

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

Re: Serial ports -- using both

Fri Mar 13, 2015 5:05 pm

Well i just rolled back to commit
8bbf5eef164891b2ceb562978a01b3ff203bbcc7
Which is with in the 3.18.3+ point of the raspberry/linux github
compiled kernel, modules and uart and its still just crashing on port open

Venkatesh it would be really nice if you could post a zip of your working kernel, modules and bcm_mini_uart.ko
wirelessthings.net
OpenMicros.org

Venkatesh
Posts: 12
Joined: Fri Jan 30, 2015 9:48 am
Location: Mangalore, India
Contact: Website

Re: Serial ports -- using both

Sat Mar 14, 2015 6:28 am

1. Replace kernel.img on Pi
2. Copy contents of lib to /lib on Pi (Do NOT replace).

https://www.dropbox.com/s/30p99pteih4b8 ... d.zip?dl=0
www.brevera.in

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

Re: Serial ports -- using both

Wed Mar 18, 2015 10:56 am

Just an quick update I actually got this working.

Big issues seemed to be getting the pins configured to ALT5
Using dt-blob.dtb does not seem to be having any effect, not sure why yet
and using $ gpio from wiringPi to set pin 14&15 I had my numbering out by one

so doing the following currently works for me

Code: Select all

$ gpio mode 15 alt5
$ gpio mode 15 alt5
$ sudo insmod ./bcm_mini_uart.ko
$ minicom -D /dev/ttyS0 -b 115200
wirelessthings.net
OpenMicros.org

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1583
Joined: Sat Sep 10, 2011 11:43 am

Re: Serial ports -- using both

Thu Apr 02, 2015 3:34 pm

It's possibly because of the latest changes to add linux kernel device tree which seems to upset the use of the dt-blob

add

Code: Select all

device-tree=
To your config.txt and it should work

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

mseben
Posts: 1
Joined: Fri Mar 06, 2015 9:02 pm

Re: Serial ports -- using both

Sun Apr 12, 2015 6:36 am

Venkatesh wrote:1. Replace kernel.img on Pi
2. Copy contents of lib to /lib on Pi (Do NOT replace).

https://www.dropbox.com/s/30p99pteih4b8 ... d.zip?dl=0
I've made quick test using thes zip,
but I still have problems :

I connect uart1 and uart0 directly (gpio36 with gpio15 and gpio37 with gpio14)
so pins 36,37 are in alt2 mode and pins 14,15 are in alt5 (i am using this table http://elinux.org/RPi_BCM2835_GPIOs)
then I
insmod /lib/modules/bcm_mini_uart.ko
gpio mode 36 alt2
gpio mode 37 alt2
gpio mode 15 alt5
gpio mode 14 alt5

then
minicom -b 115200 -o -D /dev/ttyS0 in one terminal
minicom -b 115200 -o -D /dev/ttyAMA0 in second terminal
(I guess if I type somthing in one terminal now I should immediately see the same char on the second terminal an vice versa)
problem is that communication flows only from ttyAMA0 to ttyS0 but not in oposite directon

I am on 2015-02-16-raspbian-wheezy upgraded to jessie
kernel with modules downgraded to Venkatesh version from zip file to 3.18.3+


thanks for advice

aenbacka
Posts: 6
Joined: Tue Apr 28, 2015 8:03 am

Re: Serial ports -- using both

Thu Jun 04, 2015 11:52 am

I have been trying to get the UART1 (8250/16500) port working using Yocto project (the meta-raspberrypi layer), as well as with using the instructions in this thread for the raspbian image, however in all cases connecting to the port /dev/ttyS0 freezes the complete system.

Using Yocto, I enabled the 8250/16500 serial driver support in the kernel, and it seems to load the driver ok during bootup (observed by grepping the dmesg output). Also I have used wiringPi to put the appropriate pins (Broadcom pins 32/33 in my case) into alt5 mode. Has there been any more activity on this lately, e.g., has anyone been able to get the uart1 port properly working with the standard Linux 16550 driver?

Using raspbian I tried by replacing the kernel in the latest image (with 3.18.3+) and inserted the bcm_mini_uart.ko module. However seem freeze occurs when trying to connect using minicom.

The PL011 port (/dev/ttyAMA0) works without problems when disabling the console.

Any information would be greatly appreciated.

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

Re: Serial ports -- using both

Thu Jun 04, 2015 12:06 pm

If your setting pins with wiring pi make sure you use the -g switch so the pin numbers are the actually BCM pin numbering scheme

If your using the linux 8250 driver you need to add something to the BCM's kernel init file to enable the AUX peripheral
For me that looked something like this
arch/arm/mach-bcm2708/bcm2708.c

Code: Select all

@@ -323,6 +342,11 @@ static struct platform_device bcm2708_uart1_device = {
                },
 };
 
+void __init bcm2708_init_8250(void)
+{
+    writel(1,__io_address(UART1_BASE + 0x4));
+}
+
 static struct resource bcm2708_usb_resources[] = {
        [0] = {
               .start = USB_BASE,
@@ -876,6 +900,9 @@ void __init bcm2708_init(void)
        bcm_register_device(&bcm2708_usb_device);
        bcm_register_device(&bcm2708_uart1_device);
        bcm_register_device(&bcm2708_powerman_device);
+#if defined(CONFIG_SERIAL_8250)
+       bcm2708_init_8250();
+#endif
 
 #ifdef CONFIG_MMC_BCM2835
        bcm_register_device(&bcm2835_emmc_device);
wirelessthings.net
OpenMicros.org

aenbacka
Posts: 6
Joined: Tue Apr 28, 2015 8:03 am

Re: Serial ports -- using both

Thu Jun 04, 2015 12:12 pm

Thanks a lot for the reply,

I will look into modifying the kernel init. The pins given to wiringPi should be correct as I observed the mode change using oscilloscope.
dpslwk wrote:If your setting pins with wiring pi make sure you use the -g switch so the pin numbers are the actually BCM pin numbering scheme

If your using the linux 8250 driver you need to add something to the BCM's kernel init file to enable the AUX peripheral
For me that looked something like this
arch/arm/mach-bcm2708/bcm2708.c

Code: Select all

@@ -323,6 +342,11 @@ static struct platform_device bcm2708_uart1_device = {
                },
 };
 
+void __init bcm2708_init_8250(void)
+{
+    writel(1,__io_address(UART1_BASE + 0x4));
+}
+
 static struct resource bcm2708_usb_resources[] = {
        [0] = {
               .start = USB_BASE,
@@ -876,6 +900,9 @@ void __init bcm2708_init(void)
        bcm_register_device(&bcm2708_usb_device);
        bcm_register_device(&bcm2708_uart1_device);
        bcm_register_device(&bcm2708_powerman_device);
+#if defined(CONFIG_SERIAL_8250)
+       bcm2708_init_8250();
+#endif
 
 #ifdef CONFIG_MMC_BCM2835
        bcm_register_device(&bcm2835_emmc_device);

aenbacka
Posts: 6
Joined: Tue Apr 28, 2015 8:03 am

Re: Serial ports -- using both

Mon Jun 08, 2015 12:11 pm

Hello,

Now I tried to modify the kernel init according to your example, and compiled the 8250 driver as a kernel module (using Yocto). Then I used wiringPi to set BCM pins 32 and 33 to alt5 mode, and after this I did insmod of the 8250 module. Grepping the dmesg output shows that the 8250/16550 driver has been loaded (output same as before). However, connecting mincom to the port /dev/ttyS0 and trying to disable flow control (as it should not be in use) still freezes the system. Also opening minicom (minicom -D /dev/ttyS0 -b 115200) and the quitting directly using X freezes the system.

Is there still anything else that could be wrong with the configuration?

Edit: What output do you recieve on dmesg related to 8250 after successfully enabling the 8250 driver? And have you also used pins 32/33 in alt5 mode?
dpslwk wrote:If your setting pins with wiring pi make sure you use the -g switch so the pin numbers are the actually BCM pin numbering scheme

If your using the linux 8250 driver you need to add something to the BCM's kernel init file to enable the AUX peripheral
For me that looked something like this
arch/arm/mach-bcm2708/bcm2708.c

Code: Select all

@@ -323,6 +342,11 @@ static struct platform_device bcm2708_uart1_device = {
                },
 };
 
+void __init bcm2708_init_8250(void)
+{
+    writel(1,__io_address(UART1_BASE + 0x4));
+}
+
 static struct resource bcm2708_usb_resources[] = {
        [0] = {
               .start = USB_BASE,
@@ -876,6 +900,9 @@ void __init bcm2708_init(void)
        bcm_register_device(&bcm2708_usb_device);
        bcm_register_device(&bcm2708_uart1_device);
        bcm_register_device(&bcm2708_powerman_device);
+#if defined(CONFIG_SERIAL_8250)
+       bcm2708_init_8250();
+#endif
 
 #ifdef CONFIG_MMC_BCM2835
        bcm_register_device(&bcm2835_emmc_device);

kuba_moo
Posts: 5
Joined: Tue Mar 17, 2015 12:47 pm

Re: Serial ports -- using both

Mon Jun 15, 2015 1:43 pm

@aenbacka My users connect the auxiliary serial to some external modules and they reported to me that using those modules would sometimes freeze the device. According to my tests this behaviour will appear when I connect the RX pin to GND. Aux UART does not have framing checks so dropping RX pin low causes a huge IRQ storm and device is completely blocked. We are still investigating this because apparently it doesn't even happen on with all CM modules... I'll share my findings with you once we find the solution.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Serial ports -- using both

Mon Jun 15, 2015 2:49 pm

My two cents worth:
In the 'user manual' of the second UART I put a dire warning:
It is is strongly recommended that the user FIRST switches the I/O port to 'receive' and only then enables the UART
as the "input might be flooded with receive-null" bytes especially if the baudrate generator is still set to zero.
(This behaviour showed up in my Verilog simulations. )
I have never anticipated somebody to connect an RX pin which is permanently low.
As such I would change the recommendation to:
FIRST make sure the baud rate generator is set to some not too low value. Then enable the receiver...

kuba_moo
Posts: 5
Joined: Tue Mar 17, 2015 12:47 pm

Re: Serial ports -- using both

Mon Jun 15, 2015 3:04 pm

Gert, thanks for your two cents ;) Manual was what hinted me at the "RX kept low" diagnosis. However, it seem to me when I tested connecting RX to GND that the IRQ storm is way bigger than if it was only caused by receiving null-bytes with configured baudrate. My system was still (somehow) responsive when I received random characters at 115k from another box, however pulling RX down caused total lockup and the number of IRQs as measured by /proc/interrupts sky rocketed. Is it possible that pulling the pin down will cause chars to arrive more often than baudrate would suggest?

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Serial ports -- using both

Mon Jun 15, 2015 8:18 pm

Is it possible that pulling the pin down will cause chars to arrive more often than baudrate would suggest?
I don't think so but to be sure I have to look again at the Verilog code, which I can't do as I no longer have access to that.

aenbacka
Posts: 6
Joined: Tue Apr 28, 2015 8:03 am

Re: Serial ports -- using both

Tue Jun 16, 2015 6:13 am

Thanks a lot for all the feedback. I have still not had any success with UART1. Does it not mean that when I have set the GPIO pins 32 and 33 into alt5 mode, and after this inserting the serial8250 driver, the port I/O mode should be set to receive as suggested in the Broadcom bcm2835 aux specification?

When I grepping the dmesg output after inserting the driver I find the following lines

[ 1.010958] Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled

[ 1.013920] serial8250.0: ttyS0 at MMIO 0x20215040 (irq = 29, base_baud = 7812500) is a 8250

Does e.g., base address and other parameters seem correct?

Connecting using minicom (baud 115200) cause the system to freeze when e.g., trying to disable flow control in serial port settings or resetting the terminal.

kuba_moo
Posts: 5
Joined: Tue Mar 17, 2015 12:47 pm

Re: Serial ports -- using both

Tue Jun 16, 2015 9:33 am

Your init message is different than mine:

Code: Select all

[    0.797242] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.798193] serial8250.0: ttyS0 at MMIO 0x20215040 (irq = 29, base_baud = 31250000) is a 16550
Do you have my patch applied? Wrong parameters should not cause the system to freeze anyway, though. I would guess it's either that RX pin is low or that the code which enables AUX port is wrong. Can you try reading /dev/mem to see if 0x20215004 is indeed set to 1?

aenbacka
Posts: 6
Joined: Tue Apr 28, 2015 8:03 am

Re: Serial ports -- using both

Tue Jun 16, 2015 12:19 pm

kuba_moo wrote:Your init message is different than mine:

Code: Select all

[    0.797242] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.798193] serial8250.0: ttyS0 at MMIO 0x20215040 (irq = 29, base_baud = 31250000) is a 16550
Do you have my patch applied? Wrong parameters should not cause the system to freeze anyway, though. I would guess it's either that RX pin is low or that the code which enables AUX port is wrong. Can you try reading /dev/mem to see if 0x20215004 is indeed set to 1?
I applied your patch, still same result. I will check /dev/mem still (in the kernel init I do set the enable bit in AUX_ENABLES register).

MrBool
Posts: 111
Joined: Sat Jul 05, 2014 9:51 am

Re: Serial ports -- using both

Tue Jun 23, 2015 3:21 pm

In the new kernel device tree (version 4) file are two uarts. I did not test it but it looks promising.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3303
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Serial ports -- using both

Tue Jun 23, 2015 3:28 pm

Unfortunately the standard kernel configurations have only just been updated to include the 8250 driver, so any current release won't allow access to UART1 (see here). But the next firmware build (which may be as early as this evening for rpi-update) will include this driver.

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Serial ports -- using both

Wed Jun 24, 2015 4:14 pm

Hi all,

I am also very interested in getting the second UART to work and following this discussion. Now I tried the latest firmware and after updating to Kernel 4.0.6 I see indeed the device /dev/ttyS0 on my compute module.
However I am still not able to access it. I have set GPIO14,15 to ALT5 function and created a console getty for ttyS0:

Code: Select all

  GPIO 14: level=1 fsel=2 alt=ALT5 func=TXD1
  GPIO 15: level=1 fsel=2 alt=ALT5 func=RXD1

Code: Select all

root      2219     1  0 18:06 ?        00:00:00 /sbin/getty -L ttyS0 115200 vt100
I have the serial line attached to a PC but the console does not work. Selecting ALT0 function and ttyAMA0 as console instead works fine.

Also writing to ttyS0 throws an error:

Code: Select all

# echo qwerty > /dev/ttyS0
-bash: echo: write error: Input/output error
Am I doing something wrong or is this still buggy?

Ondrej
The Telegea.org project: https://www.telegea.org

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

Re: Serial ports -- using both

Thu Jun 25, 2015 9:36 am

Its working a treat for me by using the following overlay and testing via minicom, i've not tried it with getty

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";

    fragment@0 {
        target = <&gpio>;
        __overlay__ {
            uart1_pins: uart1 {
                brcm,pins = <40 41>;
                brcm,function = <2>; /* alt 5 */
                brcm,pull = <0 2>;
            };
        };
    };

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

	__overrides__ {

    };

};
(note you can change the pin numbers as needed, I'm using <40 41> other pairs could be <14 15> and <32 31>

save the above to a file, say uart1-overlay.dts
then complier with dtc

Code: Select all

$ dtc -@ -I dts -O dtb -o uart1-overlay.dtb uart1-overlay.dts 
(note the -overlay.dtb part of the name is important)
copy to boot/overlays

Code: Select all

$ sudo cp uart1-overlay.dtb /boot/overlays
and append the following to the bottom of /boot/config.txt

Code: Select all

dtoverlay=uart1
and reboot

test with

Code: Select all

$ minicom -D /dev/ttyS0 -b 9600
wirelessthings.net
OpenMicros.org

ondrej1024
Posts: 171
Joined: Thu Dec 05, 2013 3:09 pm
Contact: Website

Re: Serial ports -- using both

Thu Jun 25, 2015 10:08 am

Thank you dpslwk for your detailed instructions. You are right, of course. I missed the overlay part. Now it is working great here as well.
And thank you all who contributed to providing the UART1 support in the stock RPi kernel.
Ondrej
The Telegea.org project: https://www.telegea.org

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

Re: Serial ports -- using both

Thu Jun 25, 2015 10:12 am

ondrej1024 wrote:Thank you dpslwk for your detailed instructions. You are right, of course. I missed the overlay part. Now it is working great here as well.
And thank you all who contributed to providing the UART1 support in the stock RPi kernel.
Ondrej
With the overlay you do not need to do any pin changes in the os with wiringpi or other such utilities
wirelessthings.net
OpenMicros.org

Return to “Compute Module”