UART from C on Beagle Bone Black

Beagleboard Gurus,

I desperately need help getting a BeagleBone Black rev-c UART to work from a C program.

The code that I am attempting to use is listed below. The code came from Chapter 8 of Derek Molloy’s “Beaglebone” book.

The code runs and writes data to the UART4 pin P9.13 as it is supposed to if I issue the following command from the console prior to running the program.

config-pin –a P9.13 uart

I must issue this command every time after a reboot for the program to work.
I have two questions?
(1) How can perform the equivalent of “config-pin –a P9.13 uart” inside the C-program?
(2) Is there a way to modify the uEnv.txt file to effectively issue the “config-pin –a P9.13 uart” command during the boot process. If so, how?

I modified the uEnv.txt to contain the following


After rebooting and using “config-pin –q P9.13” I get the following response:

“P9_13 pinmux file not found!
Cannot read pinmux file: /sys/devices/platform/ocp/ocp*P9_13_pinmux/state”

           What does this mean and how do I correct the problem?

More information:
I am not certain what version of Debian that I am using. I monitored the “header” output from J1 during booting with a terminal program on my PC and found this:
Debian GNU/Linux 9 ebb ttyS0 Debian Image 2019-08-03

Also, I found this:
Machine ID: 229f313330aab6c19873bdc15d4645c7
Boot ID: b74381516ae64aefa37415709164f0e4
Operating System: Debian GNU/Linux 9 (stretch)
Kernel: Linux 4.14.108-ti-r113
Architecture: arm

Any help will be greatly appreciated.

/* Simple send message example for communicating with the

* UART that is connected to a desktop PC. */


int main(int argc, char *argv){
int file, count;
printf(“Please pass a message string to send, exiting!\n”);
return -2;
if ((file = open(“/dev/ttyO4”, O_RDWR | O_NOCTTY | O_NDELAY))<0){
perror(“UART: Failed to open the device.\n”);
return -1;
struct termios options;
tcgetattr(file, &options);
options.c_cflag = B115200 | CS8 | CREAD | CLOCAL;
options.c_iflag = IGNPAR | ICRNL;
tcflush(file, TCIFLUSH);
tcsetattr(file, TCSANOW, &options);

// send the string plus the null character
if ((count = write(file, argv[1], strlen(argv[1])+1))<0){
perror(“UART: Failed to write to the output.\n”);
return -1;
printf(“Finished sending the message, exiting.\n”);
return 0;

Since you told u-boot to load BB-UART4-00A0.dtbo you do NOT need to use config-pin –q P9.13 as it’s already configured…



You are right! The C-program writes to P9.13 just fine.
I assumed since the query
config-pin -q P9.13
did not return “uart” that something was wrong. I never thought to try running the C-program.

I cannot thank you enough!