Skip to content

ylyamin/RT-Thread-on-Allwinner-D1H

 
 

Repository files navigation

Overview

This is an experimentation with the RT-Thread Operating System with the Allwinner D1H RISC-V SOC and a Collection of Bootloaders and Developer environment for programming and debugging.

Executed at hardware such as ClockworkPi DevTerm R01 and Sipeed Lichee RV + Dock.

The intention is to easily run peripherals in D1, exactly Display. RT-Thread OS was chosen because it looks like has the most extensive HAL layer for D1, similar to the Linux kernel but not so overcomplicated.

At the original repository RT-Thread the compilation is not streamlined for D1H 1. So was performed fork from v5.0.2 and introduced several changes to make it runnable in D1H. Added also bootloaders, compiler, debugger, build system.

Introduced code changes described in Code_changes document.

Current progress

RT-Thread could run in ClockworkPi DevTerm R01 and manage MIPI DSI LCD Display

devterm_lcd_mipi_work.jpg

Also could run in Sipeed Lichee RV and manage RGB LCD Display lichee_lcd_rgb_work

Installation

In repository exist pre-builded images for SD card in folder image, need to flash it to SD card and install to device.

Windows

Could use https://etcher.balena.io/#download-etcher for flash image to SD card.

Linux

Could use command

make sd_burn

Or

sudo dd if=image/sd_image_lichee.img of=/dev/sdb bs=512 seek=16 conv=sync

*where /dev/sdb - your SD card device

Run

Configure UART adapter to 115200 baud rate, 8N1. And connect to UART pins as shown in Hardware section.

Insert flashed SD card to device and power on, should see at the end of output like this:

 \ | /
- RT -     Thread Smart Operating System
 / | \     5.0.2 build Jun  9 2024 21:11:05
 2006 - 2022 Copyright by RT-Thread team
hal_sdc_create 0
card_detect insert
Initial card success. capacity :15200MB
sdmmc bytes_per_secotr:200, sector count:1db0000
not found partition of mbr, construct sd0 at offset 8M, size:0xffffffffb5800000
[D/FAL] (fal_flash_init:47) Flash device |                  sdcard0 | addr: 0x00000000 | len: 0xb6000000 | blk_size: 0x00000200 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name       | flash_dev |   offset   |    length  |
[I/FAL] -------------------------------------------------------------
[I/FAL] | download   | sdcard0   | 0x00800000 | 0x00800000 |
[I/FAL] | easyflash  | sdcard0   | 0x01000000 | 0x00100000 |
[I/FAL] | filesystem | sdcard0   | 0x01100000 | 0x00c00000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer initialize success.
Hello RISC-V
msh />Mount "sd0p0" on "/" fail

Repo structure

$tree -L 2

RT-Thread-on-Allwinner-D1H
    ├── bootloaders
    │   ├── opensbi
    │   ├── sun20i_d1_spl
    │   ├── u-boot (will be created by make !)
    │   └── xfel
    │   ├── opensbi_config
    ├── build
    │   ├── sd.bin
    │   ├── sun20i-d1-lichee-rv-dock.dtb
    │   ├── toc1_D1H.cfg
    │   └── .gdbinit
    ├── debugger (will be created by make !)
    │   ├── bl702_cklink_whole_img_v2.2.bin
    │   ├── blisp
    ├── documentation
    │   ├── Allwinner_D1H
    │   ├── ClockworkPi_DevTerm
    │   ├── RISC-V    
    │   └── Sipeed_Lichee_RV
    ├── image
    │   ├── sd_image_devterm.img
    │   └── sd_image_lichee.img
    ├── rt-thread
    │   ├── bsp/allwinner/d1s_d1h/
    │   ...
    ├── toolchain (will be created by make !)
    │   └── riscv64-linux-musleabi_for_x86_64-pc-linux-gnu
    │   └── riscv64-glibc-gcc-thead_20200702     
    │   └── T-HEAD_DebugServer
    ├── Makefile
    ├── environment.sh
    ├── LICENSE
    └── README.md

Environment

Tested on Ubuntu 22.04.3 64x. On machine need to be installed make environment:

sudo apt install git make build-essential scons libusb-1.0-0-dev libncurses5-dev

If needed to specify installation folders for toolchain and u-boot please modify environment.sh script to specify this variables

  • TOOLCHAIN_INSTALL_DIR - path for installation dir for toolchain ex.: $HOME/toolchain
  • U_BOOT_INSTALL_DIR - path for installation dir for u-boot bootloader ex.: $HOME/u-boot

Then execute due each session:

 source ./environment.sh

Or add to ~/.bashrc

Environment setup with virtual machine

In my case I was use Windows 10 64x as a host with IDE VSCode and Ubuntu 22.04.3 64x virtual machine as a guest for compilation.
Repo was downloaded to a shared folder in Windows mounted in Ubuntu, /etc/fstab example

.host:/ /mnt/hgfs       fuse.vmhgfs-fuse    defaults,allow_other    0    0

Notice: in a virtual machine with a mounted shared folder, it isn't possible to create hard links.
So as toolchain and u-boot use hard links it is impossible to extract toolchain and u-boot files to this mounted folder. Need to use internal filesystem in a virtual machine.
For this was provided installation folders in environment.sh script described above.

Build toolchain

Installing toolchain

make toolchain

* T-HEAD_DebugServer will request specify installation dir: 'Set full installing path:'
  Could be seted as $HOME/toolchain or RT-Thread-on-Allwinner-D1H/toolchain folder

Will be installed:

  • riscv64-linux-musleabi_for_x86_64-pc-linux-gnu (Used by RT-Thread compilation)
  • riscv64-glibc-gcc-thead_20200702 (Need for using GDB)
  • T-HEAD_DebugServer (Need for using JTAG connection)

Build bootloaders

To compile bootloaders use command

make bootloaders

Will be installed:

  • sun20i_d1_spl (first bootloader after BROM, used for init DRAM and load TOC image from MMC)
  • u-boot (could used to load Linux image but now just tool to create TOC image)
  • opensbi (Supervisor Binary Interface for platform in M mode)
  • xfel (used for debug when platform in FEL mode)

Build RT-Thread

For configure RT-Thread:

make rt-conf

In menuconfig chooses "General Drivers Configuration" -> "Choose Board" and then choose "ClockworkPi DevTerm R01 board" or "Sipeed Lichee RV board" depend what board do you use.

To compile RT-Thread use command:

make rt

For clean:

make rt-clean

Build SD card image

To create SD card image in image folder:

make sd

For flash to SD card:

make sd_burn

Debugging

For debugging used Sipeed RV-Debugger Plus with T-Head CKLink firmware.
To connect debugger to board need use MicroSD breakout board because in D1H JTAG pins mapped to SD Card pins as shown in Hardware section.

For flash firmware to Sipeed RV-Debugger Plus - Press and hold the boot pin then plug the usb in the computer to go to the boot mode. And execute command:

make debug-burn

To start GDB session need to use FEL button but surprisingly this works even without it somehow just after power up. Anyway in device that have FEL button (Sipeed Lichee RV) - press and hold the FEL button then press RESET button to go to the FEL mode, then execute command or just execute command (for Clockwork Devterm):

make debug

Should see at the output the like this:

+---                                                    ---+
|  T-Head Debugger Server (Build: Oct 21 2022)             |
   User   Layer Version : 5.16.05
   Target Layer version : 2.0
|  Copyright (C) 2022 T-HEAD Semiconductor Co.,Ltd.        |
+---                                                    ---+

...

GDB connection command for CPUs(CPU0):
        target remote 127.0.0.1:1025

...

0x000000000000a22a in ?? ()
Restoring binary file bootloaders/opensbi/build/platform/generic/firmware/fw_dynamic.bin into memory (0x40000000 to 0x40042790)
Restoring binary file build/sun20i-d1-lichee-rv-dock.dtb into memory (0x40200000 to 0x40207b23)
Restoring binary file rt-thread/bsp/allwinner/d1s_d1h/rtthread.bin into memory (0x40400000 to 0x404f0840)

Hardware

ClockworkPi DevTerm R01 assembly

Devterm_R01_assembly

I figure out that integrated UART work very unstable. According discussion "The problem is that the CH340C provides 5 V logic levels, whereas the D1 only supports 3.3 V I/O...A better solution would be to solder wires to pins 2 and 3 of the CH340C and use a different USB-UART adapter that runs at the correct voltage." So I do this: Devterm_R01_uart

Sipeed Lichee RV assembly

Lichee_RV_assembly

Links

TODO

  • Keyboard, trackball
  • Build env and RTT gui

Footnotes

  1. At time when I'm tried to compile was issue 9063 after it was solved by PR in Master.

About

Experimentation with the RT-Thread Operating System with the Allwinner D1H

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • C 95.7%
  • Python 2.0%
  • Shell 1.1%
  • Makefile 0.5%
  • CMake 0.3%
  • C++ 0.2%
  • Other 0.2%