From d81744214853d24ec303113283a2df60ebf357c5 Mon Sep 17 00:00:00 2001 From: Stephan Zhdanov Date: Wed, 1 Jan 2025 16:21:58 +0300 Subject: [PATCH 1/2] Disable UART0 output log section --- .../en/lichee/RV_Nano/5_peripheral.md | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/docs/hardware/en/lichee/RV_Nano/5_peripheral.md b/docs/hardware/en/lichee/RV_Nano/5_peripheral.md index 8551ad8f47..b2416af139 100644 --- a/docs/hardware/en/lichee/RV_Nano/5_peripheral.md +++ b/docs/hardware/en/lichee/RV_Nano/5_peripheral.md @@ -13,12 +13,64 @@ keywords: riscv, licheerv,nano ### UART0 -Connect the UART port to the board at: - -A17 A16 GND +Connect the UART serial port to the GND, `A16 (TX)`, and `A17 (RX)` of the board Then use terminal software to connect to the serial port, with a baud rate of 115200. +UART0 is also brought out on SBU1/2 on the USB interface. You can use the USB TypeC adapter to bring out RX0 and TX0. + +#### Disable UART0 output log + +First, transfer the output of the user space to another tty device: + +``` +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + int fd; + if (argc < 2) { + fprintf(stderr, "usage: %s /dev/ttyX\n", argv[0]); + exit(EXIT_FAILURE); + } + fd = open(argv[1], O_RDWR); + if (fd < 0) { + perror("open"); + exit(EXIT_FAILURE); + } + ioctl(fd, TIOCCONS); + close(fd); + exit(EXIT_SUCCESS); +} +``` + +``` +riscv64-unknown-linux-gcc tioccons.c -o tioccons +./tioccons /dev/tty2 # Transfer /dev/console to tty2 +``` + +Then set the kernel log level: + +``` +echo 0 > /proc/sys/kernel/printk +``` + +Test method: + +``` +echo userspace > /dev/console +echo kernel > /dev/kmsg +``` + +Another way is to add the following content to /boot/uEnv.txt to switch the console to another tty: + +``` +consoledev=/dev/ttyX +``` + + ### USB CDC ACM Serial Port When the board's USB Type-C port is connected to a computer, it will provide a USB CDC ACM serial port device (provided by Linux gadget). From a924f03bbab05e01fd7abbf0aa33080285d07733 Mon Sep 17 00:00:00 2001 From: Stephan Zhdanov Date: Wed, 1 Jan 2025 16:26:21 +0300 Subject: [PATCH 2/2] UART1 UART2 UART3 section --- .../en/lichee/RV_Nano/5_peripheral.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/docs/hardware/en/lichee/RV_Nano/5_peripheral.md b/docs/hardware/en/lichee/RV_Nano/5_peripheral.md index b2416af139..33506ad047 100644 --- a/docs/hardware/en/lichee/RV_Nano/5_peripheral.md +++ b/docs/hardware/en/lichee/RV_Nano/5_peripheral.md @@ -70,6 +70,74 @@ Another way is to add the following content to /boot/uEnv.txt to switch the cons consoledev=/dev/ttyX ``` +### UART1 UART2 UART3 + +By default, the pins of UART1 and 2 are used to connect to the UART Bluetooth chip: + +``` +mmio_write_32(0x03001070, 0x1); // GPIOA 28 UART1 TX +mmio_write_32(0x03001074, 0x1); // GPIOA 29 UART1 RX +mmio_write_32(0x03001068, 0x4); // GPIOA 18 UART1 CTS +mmio_write_32(0x03001064, 0x4); // GPIOA 19 UART1 RTS +``` + +If you only want to use UART1, you don't need to change PINMUX, just connect GPIOA28 GPIOA29. + +If you want to use the functions of UART1 and UART2 at the same time, you need to write to the register to set the PINMUX of the pin: + +In Linux user space, you can use the `devmem` tool to write registers. + +shell: + +``` +devmem 0x03001070 32 0x2 # GPIOA 28 UART2 TX +devmem 0x03001074 32 0x2 # GPIOA 29 UART2 RX +devmem 0x03001068 32 0x6 # GPIOA 18 UART1 RX +devmem 0x03001064 32 0x6 # GPIOA 19 UART1 TX +``` + +The UART3 pins are multiplexed as SDIO by default: + +``` +mmio_write_32(0x030010D0, 0x0); // D3 +mmio_write_32(0x030010D4, 0x0); // D2 +mmio_write_32(0x030010D8, 0x0); // D1 +mmio_write_32(0x030010DC, 0x0); // D0 +mmio_write_32(0x030010E0, 0x0); // CMD +mmio_write_32(0x030010E4, 0x0); // CLK +``` + +If you want to use the UART3 function, you need to write to the register to set the PINMUX of the pin: + +In Linux user space, you can use the `devmem` tool to write registers. + +shell: + +``` +devmem 0x030010D0 32 0x5 # GPIOP 18 UART3 CTS +devmem 0x030010D4 32 0x5 # GPIOP 19 UART3 TX +devmem 0x030010D8 32 0x5 # GPIOP 20 UART3 RX +devmem 0x030010DC 32 0x5 # GPIOP 21 UART3 RTS +``` + +Serial port usage in Linux system: + +C: + +``` +/* TODO */ +``` + + +shell: + +``` +stty -F /dev/ttyS1 115200 # Set the UART1 baud rate to 115200 +stty -F /dev/ttyS1 raw # Set tty to RAW mode +echo -n UUU > /dev/ttyS1 # Send UUU(0x55 0x55 0x55) +hexdump -C /dev/ttyS1 # Display the received data in HEX format +``` + ### USB CDC ACM Serial Port