0

I'm trying to run communication with my hardware using RPi built-in UART ports. I need to use 3 UART ports at 4M baud rate. I added to /boot/config.txt following lines at the end:

dtoverlay=uart5
dtoverlay=uart2

And switched off serial console from raspi-config

When I try to configure /dev/ttyAMA1 or /dev/ttyAMA2 I get following error:

Exception: Command 'stty -F /dev/ttyAMA1 4000000' returned non-zero exit status 1.
stty: /dev/ttyAMA1: unable to perform all requested operations

Maximum what is possible to set is 2000000. I checked that echo works fine, but I didn't verify if it's really 2M with oscilloscope.

I found some answers related to UART clock speed but they seems to be obsolete - they are all about RPI2 or RPI3 and only UART0.

Question: How to set baud rate to 4000000 for any 3 ports of RPi?

2

You must change init_uart_clock to at least 64000000 in order to get 4Mbps baudrate.

And I wouldn't be surprised if setting the baudrate to 2Mbps without any changes actually results in 1.5Mbps effective baudrate: baudrates typically are integer divisions of the maximum, which is 3Mbps by default.

It is also possible that the change will result in standard baudrates such as 115200 becoming unstable: 4Mbps/35 is 114286, which about 0.8% error from 115200. The critical error value is about 1-2% for most UART implementations. For comparison, 3Mbps/26 yields 115385, which is is only 0.16% error.

2
  • 1
    Thanks! It works, however - this works only for the PL011 UART - not miniUart, which is available at the default. I had to disable BT module by adding dtoverlay=disable-bt additionally. More info here: raspberrypi.org/documentation/configuration/uart.md – Mazi Dec 4 '20 at 13:23
  • Yeah, the mini-uart clock is tied to the GPU clock, so it's more difficult to use it. – Dmitry Grigoryev Dec 4 '20 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.