Raspberry Pi 4b ubuntu system open serial port

How to open the serial port after installing ubuntu server18 on Raspberry Pi 4b?

The pin diagram of Raspberry Pi 4b is as follows:

Among them, GPIO14 and GPIO15 are hardware serial ports.

Because I am not installing a Raspian system, I cannot use raspi-config to open the serial port.

It is also explained in the /boot/firmware/config.txt of the ubuntu server raspi system that enable_uart=1 enables this serial port by default. The name in Linux is /ttyAMA0, but the default is when the serial port console is used (/boot/firmware/nobtcmd. txt also wrote console = /ttyAMA 921600)

And this hardware serial port is also connected with Bluetooth. If you want to use this serial port for other peripherals, you must disable the serial port console and Bluetooth.

method:

1. Delete console = /ttyAMA 921600 in /boot/firmware/nobtcmd.txt to disable the serial console. This txt file can also be found in system-boot by inserting the SD card into the windows system with a card reader.

2. Set enable_uart=1 in /boot/firmware/config.txt (the default is). If =0, the minicom serial port is enabled instead of the hardware serial port.

3. Add a line dtoverlay=disable-bt to /boot/firmware/config.txt to disable Bluetooth.

4. sudo systemctl disable bluetooth...... Disable the startup items related to Bluetooth. Until the desktop no longer displays the Bluetooth logo, but there is still /ttyAMA0.

In this way, after booting to connect the serial peripherals, the serial communication can be normal by using /ttyAMA0.

It is recommended to read the official Raspberry Pi documentation:

https://www.raspberrypi.org/documentation/configuration/uart.md

There are also linux documents:

https://elinux.org/RPi_Serial_Connection

 

But there is still a problem. If you connect peripherals before booting, the serial data sent by the serial peripherals will interfere with ubuntu booting, because u-boot (similar to bootloader) will wait for the serial port data for 2s before entering autoboot to open when ubuntu starts. System, during this period, once there is serial port data, it will enter u-boot (similar to computer boot and press F2 to enter BIOS). This will cause the system to fail to open, and the screen will always display garbled characters sent by the serial device.

The solution is to cancel the 2s waiting time of the u-boot and directly enter the system (but this will also cause u-boot to be unable to enter in the future)

Mainly refer to this answer found with bing, askubuntu.com is really a good website:

https://askubuntu.com/questions/1215848/how-to-disable-ttyama0-console-on-boot-raspberry-pi

There are two ways to cancel the waiting time:

Method 1: Recompile the modified u-boot on your computer, and replace the original rasp4.bin with the .bin file (in /boot/firmware)

Method 2: Use the serial port to enter u-boot when booting, and type the command to cancel the boot waiting

I have tried both methods, but method one does not seem to work. It may be that raspi4 is not mature enough to replace the .bin file compiled by myself.

Method two was successful. details as follows:

The description of u-boot environment variables can be seen https://www.denx.de/wiki/view/DULG/UBootEnvVariables

Here is how to enter u-boot through the serial port. Use a serial port to USB to connect the Raspberry Pi to your computer, and then use the serial port debugging assistant on your computer to send instructions.

Power on and press any key to enter u-boot, then enter

setenv bootdelay -2
saveenv

Thereby setting the environment variable to cancel the waiting time and save it.

Note that a carriage return must be added after each line of input.

The display on the Raspberry Pi's screen is as follows:

Get it done!

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/benchuspx/article/details/112571880