Out of the box the serial transmit pin (TX) on the Onion Omega is configured to output the boot messages during startup and will print kernel debugging messages. The receive pin (RX) will also accept input at boot time.
Because of this configuration you are not able to fully use the serial port in C/C++ code and trying to do so will cause undefined behavior in your programs.
This pro tip will show you how to reconfigure your Omega in less than 5 minutes so you will have full access to the serial port from your code.
Note: If you want to use the serial port in it's factory configuration the default baud rate is 115200. The path is /dev/ttyATH0Disable Boot Serial Console
As I said above the default boot behavior of the Omega is to output messages via the serial port and also prompt for input.
Disabling this behavior is very simple.
1. SSH Into the Omega. All of the configuration will be done from the command line.
2. Install Nano. This is a very lightweight text editor that we will use to modify files.
opkg install nano
3. Open /etc/inittab. This is the file that contains the boot setting that ties up the serial port.
nano /etc/inittab
4. Comment out the askconsole line.
To comment out a line you simply place a # at the start of the line. Your inittab
file should look something like this when you are done.
::sysinit:/etc/init.d/rcS S boot
: :shutdown:/etc/init.d/rcS K shutdown
#: :askconsole:/bin/ash --login
(The actual file doesn't have spaces between the colons. The hackster.io editor breaks when I don't have the spaces between the colons above. )
You could also remove the line but I prefer to comment it out in case I want to enable it again in the future. That way I don't have to remember the syntax, I can just remove the #.
5. Save the file and exit. In Nano this is accomplished with Ctrl-O which will prompt you if you want to overwrite the existing file by saying "File Name to Write: /etc/inittab". Just hit Enter. Then you use Ctrl-X to exit Nano back to the shell prompt.
Disable Kernel Message OutputThe other default behavior of the Omega that uses the serial port is kernel debug messaging. By default if a kernel message log level is above the system console_loglevel
it will output it on the serial port. You can see this in action if you have a serial lcd hooked up or a logic analyzer by running the following.
echo "Hello from the kernel" > /dev/kmsg
That command will cause "Hello from the kernel" to output on the serial port TX pin.
Disabling this behavior simply requires that we set the default console_loglevel
high enough that no kernel messages will be output on the serial port.
1. Open sysctl.conf.
This file will allow us to set the console log level at bootup.
nano /etc/sysctl.conf
2. Add the kernel.printk line.
Add the following line to the top of your sysctl.conf
file.
kernel.printk=0 4 1 7
3. Save the file and exit.
This is done the same as above with inittab
. Ctrl-O, Enter, Ctrl-X.
4. Reboot your Omega.
This allows all of the changes to take affect.
Enjoy Your Serial PortYou are now ready to access the serial port in your C/C++ code using the termios functions.
Resourceshttps://wiki.openwrt.org/doc/recipes/terminate.console.on.serial - Terminate console on UART
http://elinux.org/Debugging_by_printing - Kernel debug output settings
Comments