727 views|1 replies

280

Posts

7

Resources
The OP
 

[The 3rd Xuantie Cup RISC-V Application Innovation Competition] LicheePi 4A+002 system software preparation [Copy link]

 This post was last edited by sipower on 2023-10-8 23:40

This article introduces the basic software preparation work. It mainly describes the following aspects: system image burning, SSH login, VNC remote desktop configuration, OpenCV installation, USB serial port usage.

1. System image burning

Since the LicheePi 4A development board is a beta version, the system that comes with it is not the latest. In order to better experience the development board, you need to re-burn the latest system. The following describes how to re-burn the system to the board.

1.1、Download the image

The official download link of Baidu Netdisk is provided:

链接已隐藏,如需查看请登录或者注册

1.2 Storage Directory

After downloading and unzipping, you need to modify the contents of burn_lpi4a.bat to adapt to your own file directory. The directory I stored and the modified files are shown in the figure below.

1.3、Programming process

The official document on burning the image is very detailed, just follow it. See the following link:

https://wiki.sipeed.com/hardware/zh/lichee/th1520/lpi4a/4_burn_image.html

I turned on the debug serial port monitoring, and I can compare the progress with the CMD burning window. This is what it looked like at the beginning.

The burning is completed like this:

After completion, restart manually and you can directly enter the new version of the system, and it will automatically log in to the sipeed account, which is easier to use than the default version.

2. SSH login

The new system enables SSH login by default, and basically no settings are required. Here I recommend a terminal tool software. MobaXterm is a toolbox for remote computing. As a Windows application, it has a large number of functions tailored for programmers, webmasters, IT administrators, and almost all users who need to handle remote work in a simpler way. MobaXterm provides all important remote network tools (SSH, X11, RDP, VNC, FTP, MOSH, ...) and Unix commands (bash, ls, cat, sed, grep, awk, rsync, ...). MobaXterm also has strong expansion capabilities and can integrate plug-ins to run Gcc, Perl, Curl, Tcl / Tk / Expect and other programs.

The specific download link is as follows. It is very useful to download the portable version.

Website:

https://mobaxterm.mobatek.net/download-home-edition.html

File Link:

https://download.mobatek.net/2332023092000531/MobaXterm_Portable_v23.3.zip

Log in using SSH, username sipeed, password licheepi. The login interface is as follows.

3. VNC Remote Desktop Configuration

3.1. Installation Dependencies

Install the required software packages and use the lightweight Xfce desktop environment for the remote desktop.

sudo apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils

sudo apt install tigervnc-standalone-server tigervnc-common

After installation, enter the vncserver command and configure the relevant password. The system will prompt you to configure the password. Set it according to your needs. The second password is for viewing-only users to log in:

3.2. Configure xstartup file

Kill the VNC instance you just created and do some configuration first. The xstartup file is a script that runs when the TigerVNC server starts. Create and edit the file ~/.vnc/xstartup:

  1. vi ~/.vnc/xstartup

Write the following content:

  1. #!/bin/sh
  2. unset SESSION_MANAGER
  3. unset DBUS_SESSION_BUS_ADDRESS
  4. exec startxfce4

And grant permissions

  1. chmod +x ~/.vnc/xstartup

3.3. Configure the config file

Add the startup parameters of the VNC server, create and edit the "~/.vnc/config" file, add the required startup parameters, for example, if you want to set the resolution and dpi at startup, you can write the following content:

  1. geometry=1280x720
  2. dpi=96

After completing the above two files, you can log in through SSH and see the following interface of mobaxterm.

If you cannot connect to VNC due to a firewall, you can use ufw to add allowed ports, such as using the display port 5901 of the VNC server.

  1. sudo apt-get install ufw #First time you need to install ufw
  2. sudo ufw allow 5901

Although there is an error, it does not seem to affect VNC login.

3.4. Configure VNC to start automatically

Open the startup settings through the Session and Startup menu in Applications->Setting:

Click the "Add" button at the bottom of the dialog box to add the auto-start program. Among them, it is most important to fill in the Command column correctly.

After doing this, since the system automatically logs in to the sipeed account desktop when it boots up, VNC can be started automatically at boot time.

4. OpenCV installation

Since my design is expected to use OpenCV, I installed and tested it according to the official guidance documents.

First install the dependencies and python3 environment

  1. sudo apt install python3 python3-pip
  2. sudo apt install python3-opencv
  3. sudo apt install libqt5gui5-gles

Then use the following program to read the camera and display it.

Code 1, camtest.py

import cv2

# 打开摄像头
cap = cv2.VideoCapture(0)

# 检查是否成功打开摄像头
if not cap.isOpened():
    print("无法打开摄像头")
    exit()

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

# 循环读取摄像头的每一帧图像
while True:
    # 从摄像头中获取一帧图像
    ret, frame = cap.read()

    # 检查是否读取成功
    if not ret:
        print("无法获取图像")
        break

    # 显示图像
    cv2.imshow("USB Camera", frame)

    # 等待按下 ESC 键退出
    if cv2.waitKey(1) == 27:
        break

# 释放摄像头并关闭所有窗口
cap.release()
cv2.destroyAllWindows()

The installation is successful and the running effect is as shown below.

5. USB to serial port use

My design is expected to use USB to serial port, and the small board on hand is CP2102 chip. After inserting the adapter cable into the LicheePi 4A development board, you can see the following information from the debug serial port.

It can be seen that this version of the operating system of the development board has a built-in CP210X driver, and after the device is connected, it is automatically loaded to /dev/ttyUSB0.

We plan to use the serial port to connect to Arduino peripherals in Python programs, so we need to install the Python serial port library.

  1. apt install python3-serial

Write test code for simple sending and receiving. The code is as follows.

Code 2, test_com.py

# 导入模块
import threading
import time
import serial
import serial.tools.list_ports

# 自定义变量
port = "/dev/ttyUSB0"  # 端口号,根据自己实际情况输入,可以在设备管理器查看
bps = 115200     # 串口波特率,根据自己实际情况输入
timeout = 5       # 超时时间,None:永远等待操作,0为立即返回请求结果,其他值为等待超时时间(单位为秒)
rxdata = ''    # 接收的数据

# 扫描端口
def check_uart_port():
    port_list = list(serial.tools.list_ports.comports())
    # print(port_list)
    if len(port_list) == 0:
        print('can not fine uart port')
        return False
    else:
        for i in range(0,len(port_list)):
            print(port_list[i])
    return True

# 打开串口
def open_uart(port, bps, timeout):
    try:
        # 打开串口,并返回串口对象
        uart = serial.Serial(port, bps, timeout=timeout)
        return uart
    except Exception as result:
        print("can not open uart")
        print(result)
        return False

# 发送数据
def uart_send_data(uart, txbuf):
    len = uart.write(txbuf.encode('utf-8'))  # 写数据
    return len

# 接收数据
def uart_receive_data(uart):
    if uart.in_waiting:
        rxdata = uart.read(uart.in_waiting).decode("utf-8")   # 以字符串接收
        # rxdata = uart.read().hex()  # 以16进制(hex)接收
        print(rxdata)  # 打印数据

# 关闭串口
def close_uart(uart):
    uart.close()

# 创建一个线程用来等待串口接收数据
class myThread (threading.Thread):   # 继承父类threading.Thread
    def __init__(self, uart):
        threading.Thread.__init__(self)
        self.uart = uart
    def run(self):                   # 把要执行的代码写到run函数里面 线程在创建后会直接运行run函数
        while True:
            # print("thread_uart_receive")
            uart_receive_data(self.uart)  # 接收数据
            time.sleep(0.01)

# 主函数
def main():
    # 扫描端口
    result = check_uart_port()
    if(result == False):
        return

    # 打开串口
    result = open_uart(port, bps, timeout)
    if (result == False):
        return
    else:
        uart1 = result

    # 创建一个线程用来接收串口数据
    thread_uart = myThread(uart1)
    thread_uart.start()

    while True:
        # 定时发送数据
        txbuf = "hello world\r\n"
        len = uart_send_data(uart1, txbuf)
        print("send len: ", len)
        time.sleep(3)

# 启动主函数
main()

I used two CP2102 boards for this test, one connected to the development board and the other connected to the PC, with the serial ports cross-connected. Run the test program.

  1. sudo python3 test_com.py

The test result is as shown in the figure below. The development board sends "hello world" every 3 seconds, which can be received on the PC. The PC sends some random characters, which can also be received by the development board. The serial port test passes.

6. Summary

Through the above operations, the system's commonly used tools and hardware peripherals are basically prepared. After a simple test, they can all work normally, laying a good foundation for the next task.

Latest reply

It is quite convenient to use VNC. I will learn it when I go back.   Details Published on 2023-10-9 10:39
 
 

6830

Posts

11

Resources
2
 

It is quite convenient to use VNC. I will learn it when I go back.

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list