UART0 (ttyAMA0) Comms Quirk In Raspbian Firmware 4.9+

The Raspberry Pi 3 board features on board Bluetooth and WiFi adapters, in order to get the on-board Bluetooth module to work correctly the Raspberry Pi dev team found they needed to use the primary comms port ttyAMA0 rather than ttyS0 and as a result made some changes to the OS configuration. These changes involved swapping internal serial port alias ids as well as moving the IO pins UART0 (ttyAMA0) and UART1 (ttyS0) were assigned to. If you spend some time Googling the subject you'll find this caused quite a stir at the time as the removal of ttyAMA0 from the IO conector impacted a lot of setups.

Whilst the Compute Module 3 doesn't have these Pi3 features integrated we do still need to take notice of the changes made to the firmware to accomodate them on the standard Pi3 board, and effectively reverse them so the internal aliases once again match the UARTs we are using as standard.

This step has already been performed on the stock image available for download, however customers running kernel 4.4.x should perform the below patch to assure compatibility going foward.

To do this we first need to create a device tree overlay file called uart_swap.dts (see /root/device-tree for this file) containing the below :

/dts-v1/;
/plugin/;
/{
        compatible = "brcm,bcm2708";

        fragment@0 {
                target-path = "/aliases";
                __overlay__ {
                        serial0 = "/soc/serial@7e215040";
                        serial1 = "/soc/serial@7e201000";
                };
        };
};

Then compile it and copy to the overlays folder in /boot/

# dtc -@ -I dts -O dtb -o uart_swap.dtb uart_swap.dts 
# cp uart_swap.dtb /boot/overlays/uart_swap.dtbo

 

Add that add the overlay in after the serial port assignments in /boot/config.txt


### UART0 ###
# MODE 1 : Enable ttyAMA0 TX/RX to pins 32/33
dtoverlay=mypi-uart0,txd0_pin=32,rxd0_pin=33

# MODE 2 : Enable ttyAMA0 CTS/RTS/TX/RX to pins 30/31/32/33
#dtoverlay=uart0-full


### UART1 ###
# Console Port (Alter cmdline.txt to disable)
# Enable ttyS0 TX/RX to pins 14/15
# Note : set 'core_freq=250' below to avoid baud rate issues
dtoverlay=uart1,txd1_pin=14,rxd1_pin=15

# Required to correct firmware serial port assignments from their Pi3 defaults
dtoverlay=uart_swap
enable_uart=1

Lastly we need to amend the kernel cmdline console assignment:to match the correct serial port by editing the file /boot/cmdline.txt

console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

 

This set of steps ensures the serial ports work correctly.

Contact us now to discuss your project

Ready to order, contact us today for pricing or samples

Contact Us