Page 1 of 1

Maximum Baudrate of UART in Raspberry Pi 3

Posted: Mon Sep 04, 2017 10:26 am
by KyluAce
Hello every one, I saw a lot about this subject but still there are many understatements. Some people are giving us some numbers like 115200/921600 as maximum baudrate but all this is not true. I got 4000000 baudrate and still I'm thinking that RPi3 can do more. RPi3 have quite strong CPU. In CPU documentation we have something like that : http://imgur.com/a/IaT04 Image
So there is possibility to get 25Mbits/sec. To transfer files via uart I'm using PySerial lib in Python. There is support up to 4Mbits baud rate, but can we do more ? Inside this lib we got something like that :

Code: Select all

    baudrate_constants = {
        0:       0000000,  # hang up
        50:      0o000001,
        75:      0o000002,
        110:     0o000003,
        134:     0o000004,
        150:     0o000005,
        200:     0o000006,
        300:     0o000007,
        600:     0o000010,
        1200:    0o000011,
        1800:    0o000012,
        2400:    0o000013,
        4800:    0o000014,
        9600:    0o000015,
        19200:   0o000016,
        38400:   0o000017,
        57600:   0o010001,
        115200:  0o010002,
        230400:  0o010003,
        460800:  0o010004,
        500000:  0o010005,
        576000:  0o010006,
        921600:  0o010007,
        1000000: 0o010010,
        1152000: 0o010011,
        1500000: 0o010012,
        2000000: 0o010013,
        2500000: 0o010014,
        3000000: 0o010015,
        3500000: 0o010016,
        4000000: 0o010017
    }
I have no idea what are this numbers next to baudrate value and how to calculate it, but maybe we can overwrite this lib and add more values like 5Mbit/10Mbit and squeeze as much as RPi can. What do you think ?

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Mon Sep 04, 2017 5:36 pm
by karrika
The standard UART driver in the kernel can be made to write 250k. The stock QLC+ can use /dev/ttyAMA0 directly for output. Reading it back seems to fail unless there is gaps between the bytes. Trying to read in a block of 512 bytes with no breaks between bytes fails.

With pigpio and DMA you might get higher speeds but other functionality seems to suffer from it.

I believe there is some bare metal approach that can read 250k from DMX without errors. Arjan did publish some special code for this a year ago.

But imho higher speeds will not work reliably. Of course I can always be proven wrong :)

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Mon Sep 04, 2017 8:30 pm
by _sjonnie_
Note that the same manual you got the picture from also states (based on a 250MHz core clock):
"The UART itself has no throughput limitations in fact it can run up to 32 Mega baud. But doing so requires
significant CPU involvement as it has shallow FIFOs and no DMA support."
So although faster than uart0, this mini-uart1 has no DMA, which means your Python program has to empty the 8-symbols deep FIFO in time before it overflows. All in all seems like a nice challenge (even more if you consider overclocking the core clock...).

Regards,
Sjonnie

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Tue Sep 05, 2017 5:02 am
by KyluAce
_sjonnie_ wrote:
Mon Sep 04, 2017 8:30 pm
Note that the same manual you got the picture from also states (based on a 250MHz core clock)
So if RPi3 have 1200MHz core clock we can do even much more that this 25Mbits (almost 5x) or am I wrong ?

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Tue Sep 05, 2017 5:05 am
by rpdom
KyluAce wrote:
Tue Sep 05, 2017 5:02 am
So if RPi3 have 1200MHz core clock we can do even much more that this 25Mbits (almost 5x) or am I wrong ?
Wrong clock. The UART is based on the slower GPU core clock, not the CPU clock.

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Tue Sep 05, 2017 5:29 am
by KyluAce
Wrong clock. The UART is based on the slower GPU core clock, not the CPU clock.
Thanks I wasn't sure of that. Anyway this 250MHz can give us 25Mbits baud rate or not ? . Anyway Can someone know what can mean these values form first post "0o010017", "0o010016" etc. maybe If we know what it is I can manually add next positions in pyserial

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Tue Sep 05, 2017 5:46 am
by KyluAce
Additionally I'm curious what is this baudrate_reg from this http://imgur.com/a/IaT04 formula ?

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Tue Sep 05, 2017 5:54 am
by rpdom
KyluAce wrote:
Tue Sep 05, 2017 5:46 am
Additionally I'm curious what is this baudrate_reg from this http://imgur.com/a/IaT04 formula ?
Page 11 or so from https://www.raspberrypi.org/documentati ... herals.pdf The registers are described in there.

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Tue Sep 05, 2017 6:17 am
by KyluAce
rpdom wrote:
Tue Sep 05, 2017 5:54 am
KyluAce wrote:
Tue Sep 05, 2017 5:46 am
Additionally I'm curious what is this baudrate_reg from this http://imgur.com/a/IaT04 formula ?
Page 11 or so from https://www.raspberrypi.org/documentati ... herals.pdf The registers are described in there.

As you see link which I give is from this document :) But mostly I'm interested what value here I should use :) because later there is no "baudrate_reg"

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Tue Sep 05, 2017 7:31 pm
by _sjonnie_
KyluAce wrote:
Tue Sep 05, 2017 6:17 am
rpdom wrote:
Tue Sep 05, 2017 5:54 am
KyluAce wrote:
Tue Sep 05, 2017 5:46 am
Additionally I'm curious what is this baudrate_reg from this http://imgur.com/a/IaT04 formula ?
Page 11 or so from https://www.raspberrypi.org/documentati ... herals.pdf The registers are described in there.

As you see link which I give is from this document :) But mostly I'm interested what value here I should use :) because later there is no "baudrate_reg"
AUX_MU_IO_REG Register (0x7E21 5040) for the least significant 8 bits
AUX_MU_IIR_REG Register (0x7E21 5044) for the most significant 8 bits
So both together will give you the 16-bit baudrate_reg.

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Wed Sep 06, 2017 5:19 am
by KyluAce
_sjonnie_ wrote:
Tue Sep 05, 2017 7:31 pm
KyluAce wrote:
Tue Sep 05, 2017 6:17 am
rpdom wrote:
Tue Sep 05, 2017 5:54 am


Page 11 or so from https://www.raspberrypi.org/documentati ... herals.pdf The registers are described in there.

As you see link which I give is from this document :) But mostly I'm interested what value here I should use :) because later there is no "baudrate_reg"
AUX_MU_IO_REG Register (0x7E21 5040) for the least significant 8 bits
AUX_MU_IIR_REG Register (0x7E21 5044) for the most significant 8 bits
So both together will give you the 16-bit baudrate_reg.
Can so it means that baud rate = 250MHz / 8*(16+1) ?

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Wed Sep 06, 2017 8:19 am
by karrika
I suppose that the UART and SPI speed have similar restrictions. From the manual:

If the system clock is 250 MHz and the speed field is zero the SPI clock frequency is 125 MHz. The practical SPI clock will be lower as the I/O pads can not transmit or receive signals at such high speed

The question is really of how fast can you send/receive stuff reliably. For my programmer HAT I stopped at 16 MHz because it provided reliable two way communication with fairly long wires.

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Wed Sep 06, 2017 8:47 am
by RaTTuS
FYI
from this thread viewtopic.php?f=44&t=51633 the best I could do is 1Mbps , 16000000 on the uart I never did try with 33ohm resistors

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Wed Sep 06, 2017 9:04 am
by KyluAce
RaTTuS wrote:
Wed Sep 06, 2017 8:47 am
FYI
from this thread viewtopic.php?f=44&t=51633 the best I could do is 1Mbps , 16000000 on the uart I never did try with 33ohm resistors
According to this : http://wormfood.net/avrbaudcalc.php?bit ... databits=8
with core about 250MHz we can use baud rate <=15.625Mbps it means that we can set baud rate up to 15625000, and still we can overclock gpu core up to 588MHz so after that we can get even more speed. As you see there is 0% error at this value. Maybe I'm missing something and I'm not understand this whole subject if yes please explain it to me as simply as you can but here we got real numbers.

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Wed Sep 06, 2017 11:20 am
by joan
You will learn more if you try communicating between two devices at such a high baud rate. The problems will soon become apparent.

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Wed Jun 19, 2019 8:33 am
by KyluAce
joan wrote:
Wed Sep 06, 2017 11:20 am
You will learn more if you try communicating between two devices at such a high baud rate. The problems will soon become apparent.
There was a lot of problems but it can be done. I know that it took a lot of time but I created comunnication beetwen RPi and other side devices (parallel connection) using baudrate = 10500000 (10,5Mb). (Ofc I cannot do this using python and serial lib but when we send to the registry proper value we get it) I'm coping gigabytes of data from RPi to this devices and it works good. Ofc I was needed to create a lot of communication security like adding checksum and repeating single packet sending. Now transfer 2GB of data takes about 1 hour (sometimes less/more all it depends on number of connected devices on other side, more devices more repeting single packet => little bit longer etc)

Re: Maximum Baudrate of UART in Raspberry Pi 3

Posted: Mon Oct 28, 2019 8:37 am
by janis-ax
KyluAce wrote:
Wed Jun 19, 2019 8:33 am
joan wrote:
Wed Sep 06, 2017 11:20 am
You will learn more if you try communicating between two devices at such a high baud rate. The problems will soon become apparent.
There was a lot of problems but it can be done. I know that it took a lot of time but I created comunnication beetwen RPi and other side devices (parallel connection) using baudrate = 10500000 (10,5Mb). (Ofc I cannot do this using python and serial lib but when we send to the registry proper value we get it) I'm coping gigabytes of data from RPi to this devices and it works good. Ofc I was needed to create a lot of communication security like adding checksum and repeating single packet sending. Now transfer 2GB of data takes about 1 hour (sometimes less/more all it depends on number of connected devices on other side, more devices more repeting single packet => little bit longer etc)
Can you explain how you done this?