Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Rockpi4/dev/serial-console

< Rockpi4‎ | dev
    ROCK Pi 4 >  Development >  Serial Console

ROCK Pi 4 exports a dedicated uart(UART2) for serial console on GPIO PIN 6/8/10, which can access the low level debug message. If you want to use UART2 as application uart, check this guide.

Requirement

  • ROCK Pi 4
  • USB Type-C power adapter and USB Type-C charging data cable
  • Host PC with Windows or Linux
  • USB to TTL serial cable
    • The definition of each pin of USB to TTL cable is showing like this:

Usb2ttl-cable-definition.jpeg

Note

  • The default baudrate of ROCK Pi 4 is 1500000(1.5Mbps), please check if your USB to TTL cable support 1.5Mbps baudrate. Some model of CP210X and PL2303x have baudrate limitation, please check the specified model. We also tested that some cheap PL2303x based cable does not work well. Make sure choose a high quality one. The instructions below use a FT232RL based cable.
  • It seems that the serial tool on macOS platform can not support custom baudrate such as 1.5Mbps due to driver restriction. If you know how to set custom baudrate on macOS, please add an item here to show your findings.

Connection

Connect the USB to TTL serial cable as below. Don't connect the red wire.

ROCK Pi 4 <---> USB to TTL cable
RX(pin 10) <---> Green wire
TX(pin 8) <---> White wire
GND(pin 6) <---> Black wire

Serial-connection.jpeg

Serial setting on host PC

The default serial setting for ROCK Pi 4 u-boot and kernel console is:

   baudrate: 1500000
   data bit: 8
   stop bit: 1
   parity  : none
   flow control: none

Linux

Minicom is the serial tool that supports wide range baud rate.

Install minicom:

   sudo apt-get update
   sudo apt-get install minicom

Plug in the USB to TTL cable, kernel `dmesg | tail` should show the following device:

   [1036835.654076] usb 1-6.4.3: new full-speed USB device number 103 using xhci_hcd
   [1036835.755730] usb 1-6.4.3: New USB device found, idVendor=0403, idProduct=6001
   [1036835.755732] usb 1-6.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
   [1036835.755733] usb 1-6.4.3: Product: USB <-> Serial
   [1036835.755734] usb 1-6.4.3: Manufacturer: FTDI
   [1036835.756728] ftdi_sio 1-6.4.3:1.0: FTDI USB Serial Device converter detected
   [1036835.756750] usb 1-6.4.3: Detected FT232BM
   [1036835.757195] usb 1-6.4.3: FTDI USB Serial Device converter now attached to ttyUSB0

/dev/ttyUSB0 is our device here.

Setup minicom

First add current user to plugdev group to use minicom without sudo or root.

   sudo usermod -a -G plugdev $USER

Edit your ~/.bashrc and add the following line with some default parameter

   alias minicom='minicom -w -t xterm -l -R UTF-8'

Login to a new terminal to take effect.

Create and edit file ~/.minirc.rockpi4, add the following content:

   pu port             /dev/ttyUSB0
   pu baudrate         1500000
   pu bits             8
   pu parity           N
   pu stopbits         1
   pu rtscts           No

Now run minicom rockpi4 to use the config above and connects to the ROCK Pi 4 serial console.

Windows

Putty is also great serial tool that supports wide range baud rate.

Plug in the USB to TTL cable to you windows PC. Viewing the device manager you can find the COM number. Here it is COM3.

Launch the application Putty on your windows PC. And do the setting as follows:

For category Session, set serial line as COM3, speed ad 1500000, connection type as Serial.

Write rockpi4 in the Saved Sessions column and press Save.

Putty-setting-session.jpg

For category Connection---Serial, do the setting:

Putty-setting-serial.jpg

Once finish the setting, press Open button to start.

macOS

  • Download and install the PL2303 Mac OS X Driver(Universal Binary Driver)
  • Install CoolTerm(Universal Binary)
  • Click the Option menu and set the following:
    • Port: select usbserial-xxx
    • Baud rate: choose custom and input 1500000
    • No flow control nor DTR/RTS

Coolterm serialport setting.png

  • Click save icon to save the configuration as rockpi4 and click connect icon
  • Boot your ROCK Pi 4 and you will see the serial console ouput

Coolterm output.png

Reduce serial port baudrate

Some of the USB-to-UART cable cannot work at such high speed 1500000. (For example, Sillicon Labs CP2102). The symptom is minicom prints out garbage/binary texts.

To fix that we need to

  • Download the corresponding BSP
  • Apply the following patches
  • recompile the u-boot and kernel with a default baudrate set to 115200
  • Modify the minicom config file, reduce the baudrate to 115200


Patch for baudrate reduction in u-boot

   Subject: [PATCH 1/1] Reduce baudrate to 115200 for compatibility
   
   ---
    configs/rk3399_defconfig | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
   
   diff --git a/configs/rk3399_defconfig b/configs/rk3399_defconfig
   index ae4d35572b..25b60d2692 100755
   --- a/configs/rk3399_defconfig
   +++ b/configs/rk3399_defconfig
   @@ -96,7 +96,7 @@ CONFIG_SDRAM_COMMON_CAP_DETECT=y
    CONFIG_SDRAM_COMMON_OSREG=y
    CONFIG_SDRAM_COMMON_MSCH_RK3399=y
    CONFIG_DM_RESET=y
   -CONFIG_BAUDRATE=1500000
   +CONFIG_BAUDRATE=115200
    CONFIG_DEBUG_UART_BASE=0xFF1A0000
    CONFIG_DEBUG_UART_CLOCK=24000000
    CONFIG_DEBUG_UART_SHIFT=2
   -- 


Apply the following patch to reduce baudrate in kernel

   Subject: [PATCH 1/1] Reduce serial port baudrate to 115200
   
   ---
    arch/arm64/boot/dts/rockchip/rk3399-android.dtsi | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
   
   diff --git a/arch/arm64/boot/dts/rockchip/rk3399-android.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-android.dtsi
   index 95942d278058..243fdfa49e0d 100644
   --- a/arch/arm64/boot/dts/rockchip/rk3399-android.dtsi
   +++ b/arch/arm64/boot/dts/rockchip/rk3399-android.dtsi
   @@ -76,7 +76,7 @@
           rockchip,serial-id = <2>;
           rockchip,wake-irq = <0>;
           rockchip,irq-mode-enable = <0>;  /* If enable uart uses irq instead of fiq */
   -       rockchip,baudrate = <1500000>;  /* Only 115200 and 1500000 */
   +       rockchip,baudrate = <115200>;  /* Only 115200 and 1500000 */
           pinctrl-names = "default";
           pinctrl-0 = <&uart2c_xfer>;
           interrupts = <GIC_SPI 150 IRQ_TYPE_LEVEL_HIGH 0>;
   -- 


FAQs

1.While using debug console, there is system startup information on the screen, but the keyboard cannot be used to input text?

One of the reason would be the wrong setting of the serial tool, such as the Hardware Flow Control, etc. Here we should disable the Hardware Flow Control.

Troubleshooting