Setting Up Serial in GCC

Love Python, however I am a dyed-in-the-wool GCC C/C++ programmer for decades.My question has to do with GCC.

OK, I realized that I needed to configure the BBB R3 so that its P8 and P9 pins were set for UART (got that far myself). I kind of took an overkill approach.

What I did was I copied uEnv.txt from /boot to /boot/uboot (tell me if I did this right…does the supplied OS read uEnv.txt from there…everytime I tried modifying the original /boot/uEnv.txt it told me it was a read-only filesystem) ? Then in /boot/uboot/uEnv.txt I put the line in:


(I just thought I’d turn them all on…I have a big project I’m working on)

I was thinking that these would map over to ttyO1 thru ttyO5. Correct? Tell me if this doesn’t do this as my program isn’t working.

Then I came out with a shell script (that I call that has this in it:

config-pin overlay cape-universal
config-pin P9.21 uart
config-pin P9.22 uart
config-pin P9.24 uart
config-pin P9.26 uart

…made it executable and ran that. So I’m thinking my board is really UART-ized.

Now here’s the question. I have a C program that transmits over ttyO1 and receives on ttyO2, and I put a physical jumper between p9.22 (UART2 RX) and p9.24 (UART1 TX). However I can’t get it to work.

Here is some code snippets from the C source code.

I open the ports using code like this:

int fd1, fd2;

fd1 = open("/dev/ttyO1", O_RDWR | O_NOCTTY | O_NDELAY);

fd1 = open("/dev/ttyO2", O_RDWR | O_NOCTTY | O_NDELAY);

etc. etc.

and here is my main code:

int n;
char buf[255];
int res=0;

printf(“Ports /dev/ttyO1 and /dev/ttyO2 opened\n\n”);

fcntl(fd2, F_SETFL, 0); //set up receive for BLOCKING

n = write(fd1, “COMMAND STRING\n”, 4);
if (n < 0)
fputs(“write() of 4 bytes failed!\n”, stderr);
// fflush(NULL);

printf(“Receiving command…\n”);
printf(“Received Command: %s\n”,buf);


DOESN’T WORK. Ouchies. Any ideas…I’m all ears. Thanks in advance.