1 MBaud rate on uarts

I setup my serial ports on the BBB to have a 1Mbaud rate. However, when I look at the output on the logic analyzer, I see the baud rate is more like 1.214 MBaud. This of course is too much deviation for my serial transmission to sync up. I tried setting a custom baud rate, and that just fails completely. I wanted to use all four uarts. If I need to, I could bit bang it from the PRU (but then limit myself to two versus four). Is there a way to setup a more accurate baud rate on the BBB?

I’m unsure how close to the hardware you’re working, but it looks like the UART baud rate generator is using 13x oversampling when you were expecting 16x oversampling. This is controlled by MODESELECT field in the UART’s MDR1 register.

So long as you’re using the standard internal clock rates, the UARTs take a 48MHz clock as input, divide that down by the divisor you provide (UART registers DLH and DLL), then use the resulting clock to oversample each pixel period by either 13x or 16x. Since you are trying to get 1Mbaud, a divisor of 3 with 16x oversampling would get you there. It appears as if you have a divisor of 3 with 13x oversampling producing approximately 1.23Mbaud.

One small change and you may be good to go.

So where do I change this? In the device tree overlay?
I am just not comfortable on linux. Use to direct control coding a PIC.

What did you do to set the baud rate? There are many ways to set the baud rate and it is hard to tell if you are using “stty”, writing your own software, or doing something else. It is also unclear which operating system version you are using.

Have you found anything helpful in the numerous forum threads related to UARTs? (see https://groups.google.com/forum/embed/?place=forum/beagleboard#!categories/beagleboard/uart).

I am using Debian. I was using terms and the following in my C++ program
cfsetispeed(t, B1000000);
cfsetospee(t, B1000000);

to set the baud rate.
I have downloaded Robert nelsons kernel (based on his wiki) and have found the drivers/tty/serial/omap-serial.c file. However, it appears to have routines to set the 16 versus 13. So I am unclear why the 1MB is so far off.