Solved Serial Console between FreeBSD server and RPi

Dear all,

I'd like to ask you for a little help here. I'm running FreeBSD 10.2 on a headless homeserver (ASRock Q1900-ITX MB with Intel J1900 CPU).

I'm trying to build a Remote Access Card using a Raspberry Pi, which should act as a terminal server enabling me to connect to the homeserver using serial console in case the network adapter is down or if I need to debug the boot process.

The homeserver has the following uart hw:
uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
uart0: console (9600,n,8,1)
The RPi:
0.134703] Serial: AMBA PL011 UART driver
[    0.135007] 20201000.uart: ttyAMA0 at MMIO 0x20201000 (irq = 83, base_baud = 0) is a PL011 rev2
The RPi GPIO uart pins are connected to this module and then directly to a COM port bracket on the server.

Now I have tested the RPi connection with baud 115200 to a Mikrotik RouterBoard successfully.
Also, connecting my windows laptop to the ttyu0 port on the homeserver with baud 9600 works great, I can see all console output in putty.

The problem is when I connect the RPi to the FreeBSD server, I tried different baud rates but the text gets distorted all the time and also the serial connection is sending some characters to the console so it stops the boot process during the boot menu (I use minicom on the Raspbian distro).

example output:
25;0H     _   ____  ____|             |  _ \ / ____|  __ \

 | |___ _ __ ___  ___ | |_) | (___ | |  | |
 |  ___| '__/ _ \/ _ \|  _ < \___ \| |  | |
      0H | |  __/  __/| |_) |____) | |__| |
 | |   | | |    |    ||     |      |      |
 |_|   |_|  \___|\___||____/|_____/|_____/
                                             s` `.....---.......--.```   -/
^+============Welcome to FreeBSD===========+l+o   .--`         /y:`      +.
 |                                         |  yo`:.            :o      `+-
.|  1. Back to Main Menu [Backspace]
 |  2. Load System [D]efaults              |  .-                  ::/sy+:.
 |                                         |  /                     `--  /
 |  Boot Options:                          | `:                          :`
 |  3. n                                   | `:                          :`
]odeH.ode... off
in. off

0H25                                      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ |

õ;0H                    0H25;0H           5H
This is my /boot/loader.conf:
The /etc/ttys
$ cat /etc/ttys |grep ttyu0
ttyu0   "/usr/libexec/getty std.9600"   vt100   onifconsole secure
#ttyu0   "/usr/libexec/getty std.9600"   dialup  off secure
Appreciate any ideas as I mised the era of serial connections thus no much experience...

So, I did some troubleshooting taking your ideas into account.

The summary is - FreeBSD doesn't seem to be the problematic end. I found no working combination of configuration for using the raspberry Pi internal UART and my FreeBSD server.

The last step I did was connecting a USB to Serial adapter to the Raspberry Pi:
[404179.375842] usb 1-1.3: new full-speed USB device number 5 using dwc_otg
[404179.478210] usb 1-1.3: New USB device found, idVendor=067b, idProduct=2303
[404179.478249] usb 1-1.3: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[404179.539139] usbcore: registered new interface driver usbserial
[404179.539316] usbcore: registered new interface driver usbserial_generic
[404179.539474] usbserial: USB Serial support registered for generic
[404179.543708] usbcore: registered new interface driver pl2303
[404179.543886] usbserial: USB Serial support registered for pl2303
[404179.544029] pl2303 1-1.3:1.0: pl2303 converter detected
[404179.571090] usb 1-1.3: pl2303 converter now attached to ttyUSB0
root@raspberrypi:~# stty -a < /dev/ttyUSB0
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>;
start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
Which works like expected (the interconnection is done via a NULL Modem cable).

With the internal UART it seems like there are some characters beeing sent out of the serial port, which do interrupt the booting process several times (first is the BootLoader menu, I have to disconnect the serial connection and use a keyboard physically attached to the server to select the correct menu item and continue the boot process), then later during the boot process it hangs, until I disconnect the serial connection physically again.

Once I connect the serial port to a running system, I can see the login prompt but it's impossible to login because the user and password are filled with a lot of random characters automatically. Every key press on my end generates a new set of weird characters.

Nothing like this happens with the USB/Serial adapter.

Juha Nurmela yes, the gadget is connected to the 3v3 GPIO pin, as well as GND, TxD and RxD.

I doublechecked that the raspbian has turned off sending kernel messages to /dev/ttyAMA0.

Strange thing is, that if connecting the RPi to a router (Mikrotik RB433AH), everything works as expected out-of-the-box.
I use those RS232-to-TTL converters a lot for RPi and BeagleBone. I noticed that minicom(1) sometimes doesn't work properly. I have no explanation for that, since minicom(1) on the same computer works perfectly with other devices. I've ended up with using screen(1) instead:
screen /dev/ttyS0 115200
With the USB adapter, the 3.3V or 5V logic levels are used directly. The direct connection involves RS232 genuine levels of up to +/-12V. Has that level shifter board been tested elsewhere?
So, FreeBSD to RPi is mostly ok, and RPi to FreeBSD is mostly garbage ?

Some "old 5v" I2C chips (8574 etc) work just fine (in room temperature etc) on the RPi GPIO, but some are very flaky (TDA8444 for example). Feeding the converter 5v might help the charge pump (or burn the chip).

Maybe the Mikrotik has proper RS232 buffers, and the FreeBSD box does not. Or the other way around. Can you verify the +- voltage swing? Connected and/or unconnected. Sending a BREAK helps to catch the active voltage.

Juha Nurmela and wblock@ you put me on the correct track! Even that I didn't see any voltage drop but a steady 3.33V on the level shifter input pin, I tried switching it to the 5V branch of RPi GPIO (with confidence, because the datasheet of MAX3232 chip claims it can take anything between 3V3 and 5V as input) and it started working!

Thank you so much for your help, I appreciate it very much.