Skip to main content

Taming The Serial Console

USB Debug port

Embedded Linux boards usually can be controlled through a serial port driven directly by a UART block of the SoC (System-On-Chip) at the heart of the board. Without hardware flow control, this interface uses only 2 pins (RX and TX) and the clock itself (baud rate) is generated independantly at both ends. Where such a port was usually exposed through a D-sub connector on older boards, modern boards use a USB-to-serial converter and expose the port on a regular USB micro plug. It is still a serial port, so this post applies to it equally well.

Once the boot-up sequence successfully reaches Linux shell, problems sometimes occur when the command line is very long and the terminal emulator window is larger or smaller than the standard 80 columns by 24 lines. In such situations, the display gets messed up and it is basically impossible to tell what command will be executed on pressing enter. Using ssh to login to a remote board, all of these problems will not even show up - so if you can use ssh you will circumvent the problems described in this post.

On a desktop Linux one usually fixes the problem of a mismatch between the internal representation of the terminal window size and the actual size like this:

dzu@krikkit:~$ eval `resize`

Unfortunatly, the resize program belongs to the xterm package and is thus usually not available on ressource limited embedded boards.

I pushed a small Python tool to which fixes the problem when you have Python3 available on the board.

The file also explains what is happening under the hood to make the program work without calling it under eval:

user@ls1012afrwy:~$ resize-term
Terminal is now set to 35 rows, 110 cols

Looking for this solution I was explicitly interested to keep the program as small and understandable as possible. As Python should be available nowadays even on embedded platforms, I then found a program by Akkana Peck, modified it to my taste and finally pushed it into its own codeberg repository to ease using it.

If you just want to use it as quickly as possible, I suggest something along the following lines:

user@ls1012afrwy:~$ wget
--2021-03-20 10:39:53--
Resolving (, 2a03:4000:4c:e24:85e:10ff:fef8:a405
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1384 (1.4K) [text/plain]
Saving to: 'resize-term'

resize-term                 100%[=========================================>]   1.35K  --.-KB/s    in 0s

2021-03-20 10:39:54 (57.9 MB/s) - 'resize-term' saved [1384/1384]

user@ls1012afrwy:~$ chmod a+x resize-term
user@ls1012afrwy:~$ sudo mv resize-term /usr/local/bin
[sudo] password for user:

If /usr/local/bin is on your PATH, it should then be possible to call resize-term as shown in the previous example.


Comments powered by Disqus