1

I need to be able to enable uart4 on a Pi4 using dtoverlay, without adding it to /boot/config.txt, and have /dev/ttyAMA2 available immediately. The dtoverlay part is easy, sudo dtoverlay uart4, but /dev/ttyAMA2 does not show up.

Why? Because I am setting up automated configuration of a device and while I'm writing dtoverlay=uart4 to /boot/config.txt, I need to be able to immediately access that serial port without a reboot, in order to flash firmware to a device on that port.

dtoverlay -l shows the overlay. I just don't understand how to get /dev/ttyAMA2 to show up as a device.

enter image description here

Ricky
  • 111
  • 4

2 Answers2

1

When you add an overlay using the dtoverlay command, it only applies to the current running session. It does not persist across reboots, so it won't be available immediately after a reboot.

To make the overlay persistent, you need to add it to the /boot/config.txt file. However, if you don't want to modify that file, you can create a temporary overlay file that includes your desired overlay and then load it using the dtoverlay command. Here's how you can do it:

Create a new file with your overlay configuration. For example, you can create a file named uart4-overlay.dts with the following contents:

/dts-v1/;
/plugin/;

/ { fragment@0 { target = <&uart4>; overlay { status = "okay"; }; }; };

Compile the overlay file by running this command:

dtc -@ -I dts -O dtb -o uart4.dtbo uart4-overlay.dts

Load the overlay using the dtoverlay command: sudo dtoverlay uart4.dtbo After running these commands, /dev/ttyAMA2 should become available as a device.

jC61
  • 11
  • 2
  • 1
    Thank you. How is this different from the overlays that already exist, such as "uart4"? – Ricky May 16 '23 at 20:03
0

It is far from clear WHY you don't want to use config.txt.

You can enable a dtoverlay on the fly with the following command:-

sudo dtoverlay uart4

You will need to repeat this every time you boot.

The serial port will be assigned the next available /dev/ttyAMA This will normally be /dev/ttyAMA1

See https://raspberrypi.stackexchange.com/a/107780/8697

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • I explained why, despite its lack of relevance to the answer. The intent is for it to be tamporary. I also explained that when using sudo dtoverlay uart4, /dev/ttyAMA2 does not show up. – Ricky May 16 '23 at 18:31
  • When I tested this in 2020 it worked I tried on Raspberry Pi OS Bullseye and dtoverlay did not work. Something must have changed. – Milliways May 16 '23 at 22:35