RTS for UART1 and UART2

Started by zharry, November 17, 2019, 05:24:44 PM

Previous topic - Next topic

zharry

Hi.
I've enabled the UART1 and 2 overlays by downloading dts files and adding them with the armbian-add-overlay. Then I edited /boot/armbianEnv.txt, where I found the line

user_overlays=sun50i-a64-uart2 sun50i-a64-uart1
and after it added lines

param_uart1_rtscts=1
param_uart2_rtscts=1

What I am getting, is working UART TX and RX pins, but I can not get the RTS to work for any of those pins. I checked the overlay data - pin names are correct. Is this a bug or am I missing something? If it is a bug, can anyone direct me to a solution? Sorry for noob question, first time working with overlays.

LubOlimex

Hey,

1) Where did you get the overlays exactly?

2) Can you paste the modified overlays that you used for UART1 and UART2 (with the RTS and CTS addition)?

3) Where exactly on the board do you access/measure UART1 and UART2 pins (RX1/2, TX1/2, RTS1/2, CTS1/2)?

Thanks.
Technical support and documentation manager at Olimex

selfbg

Try the following overlay:
/dts-v1/;
/plugin/;

/ {
 fragment@0 {
 target = <&uart1>;
 __overlay__ {
 pinctrl-names = "default";
 pinctrl-0 = <&uart1_pins>, <&uart1_rts_cts_pins>;
 status = "okay";
 };
 };

 fragment@1 {
 target = <&pio>;
 __overlay__ {
 uart2_rts_cts_pins: uart2_rts_cts {
 pins = "PA2", "PA3";
 function = "uart2";
 };
 };
 };

 fragment@2 {
 target = <&uart2>;
 __overlay__ {
 pinctrl-names = "default";
 pinctrl-0 = <&uart2_pins>, <&uart2_rts_cts_pins>;
 status = "okay";
 };
 };
};

Remove sun50i-a64-uart2 and sun50i-a64-uart1. Also remove the params.

zharry

Hi, thanks for replayes,

Quote from: LubOlimex on November 18, 2019, 11:45:32 AM1) Where did you get the overlays exactly?

From official armbian github repo:
https://github.com/armbian/sunxi-DT-overlays/tree/master/sun50i-a64

Quote from: LubOlimex on November 18, 2019, 11:45:32 AM2) Can you paste the modified overlays that you used for UART1 and UART2 (with the RTS and CTS addition)?

I did not modify them - they seem to already have the RTC and CTS enabled, or am I reading it wrong?
In this overlay:
https://github.com/armbian/sunxi-DT-overlays/blob/master/sun50i-a64/sun50i-a64-uart2.dts
They have defined:
uart2_rts_cts_pins: uart2_rts_cts_pins {
pins = "PB2", "PB3";
function = "uart2";
};
Which corresponds to A64 datasheet pins for RTS and CTS.

Quote from: LubOlimex on November 18, 2019, 11:45:32 AM3) Where exactly on the board do you access/measure UART1 and UART2 pins (RX1/2, TX1/2, RTS1/2, CTS1/2)?

And I have connected CP2012 USB serial for terminal monitoring and hooked Tek TDS2024 scope on pins 10, 12 and 14 of GPIO1 connector on the A64-OLinuXino-2Ge8G-IND board. Pins 10, 12 and 14 correspond to PB0, PB1 and PB2 which in turn correspond to TX, RX and RTS of UART2 judging by boards schematic and CPU datasheet.

For UART1 I used the same setup, soldered with coil winding wires to pins 42 through 44 of U11 Combo Module, which is not fitted in my board (Idustrial grade version).

For both ports I get RX and TX pins to function as expected, so I conclude that the pins, data pin part of Armbian provided overlays and general idea should be somewhat in the right direction.

Quote from: selfbg on November 18, 2019, 11:50:42 AMpins = "PA2", "PA3";
Regarding this overlay - are you sure about PA2 and PA3? There is no Port A available on the package, judging by both - board schematic and CPU datasheet.
Never the less I will try to use it and tell you what happened in one hour.

zharry

#4
Quote from: selfbg on November 18, 2019, 11:50:42 AMTry the following overlay:

Well... It killed both USBs, so I have no WiFi or keyboard anymore. I guess Poort A is used for something internally.

I do not have output on debug serial either, so I can't even test if TTY1 and 2 work, so will have to remove the overlay by editing the /boot on SDcard from another machine.

So question still stands.

EDIT: Tried the same suggested overlay with PB instead of PA - still kills USB.

LubOlimex

Quotepins = "PA2", "PA3";

This seems like a typo/mistake. Just use the pins from the datasheet - PB2, PB3 I believe for UART2.
Technical support and documentation manager at Olimex

zharry

#6
Quote from: LubOlimex on November 18, 2019, 03:48:58 PMJust use the pins from the datasheet - PB2, PB3 I believe for UART2.

I did. With same overlay it kills USB, so I lose Ethernet and keyboard.

Anyway - I went back to original overlay and checked the register values:


root@olinuxino:/home/harry# busybox devmem 0x01c28810
0x0000002B
root@olinuxino:/home/harry# busybox devmem 0x01c28808
0x000000C1
root@olinuxino:/home/harry# busybox devmem 0x01c20824
0x77772222


So AutoFlow is on, FIFO is enabled and Port B pins 0 through 3 are muxed to UART. Still nothing on the RTS pin. It just stays in perpetual 0. Even went as far as to add an external pullup - still nothing. Out of ideas here.

EDIT:
Just to double check for stupid mistakes I turned off the AutoFlow bit and cleared the RTS bit:
root@olinuxino:/home/harry# busybox devmem 0x01c28810 w 0x0B
root@olinuxino:/home/harry# busybox devmem 0x01c28810 w 0x09
And the RTS pin went hihg, as expectd.

So is this a silicon bug of A64? Has anyone ever seen the RTS pin actually working in auto flow control mode?

Perhaps anyone has tried using software controlled 485 DE/RE toggling in UART driver, like the em485 patch or something similar? Any help at this point would be appreciated, I really would not wish to add external USB serial ports just to handle a stupid direction change pin :(

martinayotte

Quote from: zharry on November 18, 2019, 06:00:05 PMPerhaps anyone has tried using software controlled 485 DE/RE toggling in UART driver, like the em485 patch or something similar?

Right ! You absolutely need to use em485 patch, otherwise the dw-apb-uart driver (aka 8250_dw.c) won't support RS485 direction control.

HarrisonCreates

Quote from: LubOlimex on November 18, 2019, 03:48:58 PM
Quotepins = "PA2", "PA3";

This seems like a typo/mistake. Just use the pins from the datasheet - PB2, PB3 I believe for UART2.

Where is the datasheet exactly? I can't find it anywhere (not even on the product page) and it would help me out a bunch with my own question...

LubOlimex

The A64's datasheet. Just search for "Allwinner A64 Datasheet".
Technical support and documentation manager at Olimex

zharry

Quote from: HarrisonCreates on November 18, 2019, 11:55:23 PMWhere is the datasheet exactly?

Datasheet effectively has only the pinout of package, I got confused a bit too.

But if you go to LINUX-SUNXI community wiki, under Documentation you will see the Datasheet v1.1 and User Manual v1.0 - If you want the memory map, register maps and descriptions and so on - you want the User Manual not Datasheet.

zharry

Quote from: martinayotte on November 18, 2019, 10:00:03 PMYou absolutely need to use em485 patch,

I'm looking at https://docs.armbian.com/Developer-Guide_Build-Preparation/
I've got as far as to the kernel configuration. It does not use 8250_dw.c by default, it uses uart.c (which is some very simple character put and get thing) from  sun50iw1p1/drivers/uart

Is the method described in armbian docs even right for compiling kernel for Olimex A64 boad?

Should I apply some patches from Olimex before running build.sh?

This is all so confusing, is there a known working tutorial / howto / guide / anything on building custom kernel for olinuxino64?

zharry



Quote from: zharry on November 19, 2019, 03:41:21 PMThis is all so confusing, is there a known working tutorial / howto / guide / anything on building custom kernel for olinuxino64?

Let me rephrase it - is there a guide on how exactly was this image:

ftp://staging.olimex.com/Allwinner_Images/a64-olinuxino/linux/1.latest_images/bionic/images/

built?

martinayotte

Quote from: zharry on November 19, 2019, 03:41:21 PMIt does not use 8250_dw.c by default, it uses uart.c
Where this statement comes from ? There is no such uart.c file in Mainline kernel ...
All the SoC from AllWinner is using the driver from drivers/tty/serial/8250/8250_dw.c

zharry

Quote from: martinayotte on November 19, 2019, 04:05:17 PMWhere this statement comes from ?

Well, when compiling kernel with default settings while following the Armbian guide, using the configuration for lime64 (I guess that's how they call olinuxino64, as there there was nothing else similar) the 8250 driver is not selected. The SUNXI-UART Controller is though.

Sorry, it's sunxi-uart.c not uart.c

It's located in:
build/cache/sources/linux-pine64/my-hacks-1.2/drivers/tty/serial$

Or am I getting it wrong?

And while we are at it, is there a way to build just that one driver as kernel module to be inserted by modprobe or does one absolutely must compile and change whole kernel + uboot?