Embedded Linux -- litchi school Zero--V3s--ST7789v

preface

  after several tortures, it was finally done well.

All three screens are ST7789v driver chips:

  • The 2.0-inch resolution is 240x320: GND, VCC, SCL, SDA, RES, DC, CS, BLK
  • 1.54 inch resolution is 240x240: GND, VCC, SCL, SDA, RES, DC, CS, BLK
  • The 1.3-inch resolution is 240x240: GND, VCC, SCL, SDA, RES, DC, BLK

The 1.3-inch screen is missing a CS pin and can't light up.

Blood lesson: you can't run without CS pin!

1, Schematic diagram

2, uboot

The steps are as follows:

  • (1) Clear: make clean
  • (2) Configuration compilation file: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_800x480LCD_defconfig
  • (3) Compile: time make arch = arm cross_ COMPILE=arm-linux-gnueabihf- 2>&1 | tee build.log

U-Boot compilation configuration file

Litchi pie has three compilation configuration files

  • LicheePi_Zero_480x272LCD_defconfig
  • LicheePi_Zero_800x480LCD_defconfig
  • LicheePi_Zero_defconfig

LicheePi_Zero_800x480LCD_defconfig

CONFIG_ARM=y
CONFIG_ARCH_SUNXI=y
# CONFIG_ARMV7_NONSEC is not set
CONFIG_MACH_SUN8I_V3S=y
CONFIG_DRAM_CLK=360
CONFIG_DRAM_ZQ=14779
CONFIG_VIDEO_LCD_MODE="x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0"
CONFIG_VIDEO_LCD_BL_PWM="PB4"
# CONFIG_VIDEO_LCD_BL_PWM_ACTIVE_LOW is not set
CONFIG_DEFAULT_DEVICE_TREE="sun8i-v3s-licheepi-zero"
# CONFIG_CONSOLE_MUX is not set
CONFIG_SPL=y
CONFIG_CMD_BOOTMENU=y
# CONFIG_CMD_IMLS is not set
CONFIG_CMD_MEMINFO=y
# CONFIG_CMD_FLASH is not set
CONFIG_CMD_SF=y
CONFIG_CMD_SPI=y
# CONFIG_CMD_FPGA is not set
CONFIG_DM_SPI_FLASH=y
CONFIG_SPI_FLASH=y
CONFIG_SPI_FLASH_WINBOND=y
CONFIG_SPL_SPI_SUNXI=y
# CONFIG_NETDEVICES is not set
CONFIG_DM_SPI=y
CONFIG_SUNXI_SPI=y
CONFIG_OF_LIBFDT_OVERLAY=y

Refer to LicheePi_Zero_800x480LCD_defconfig imitates its compiled configuration file. I also write one:
LicheePi_Zero_240x240TFT_defconfig

CONFIG_ARM=y
CONFIG_ARCH_SUNXI=y
# CONFIG_ARMV7_NONSEC is not set
CONFIG_MACH_SUN8I_V3S=y
CONFIG_DRAM_CLK=360
CONFIG_DRAM_ZQ=14779
CONFIG_VIDEO_LCD_MODE="x:240,y:240,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0"
CONFIG_VIDEO_LCD_BL_PWM="PB4"
# CONFIG_VIDEO_LCD_BL_PWM_ACTIVE_LOW is not set
CONFIG_DEFAULT_DEVICE_TREE="sun8i-v3s-licheepi-zero"
# CONFIG_CONSOLE_MUX is not set
CONFIG_SPL=y
CONFIG_CMD_BOOTMENU=y
# CONFIG_CMD_IMLS is not set
CONFIG_CMD_MEMINFO=y
# CONFIG_CMD_FLASH is not set
CONFIG_CMD_SF=y
CONFIG_CMD_SPI=y
# CONFIG_CMD_FPGA is not set
CONFIG_DM_SPI_FLASH=y
CONFIG_SPI_FLASH=y
CONFIG_SPI_FLASH_WINBOND=y
CONFIG_SPL_SPI_SUNXI=y
# CONFIG_NETDEVICES is not set
CONFIG_DM_SPI=y
CONFIG_SUNXI_SPI=y
CONFIG_OF_LIBFDT_OVERLAY=y

Compile uboot

The steps are as follows:

  • (1) Clear: make clean
  • (2) Configuration compilation file: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_240x240TFT_defconfig
  • (3) Compile: time make arch = arm cross_ COMPILE=arm-linux-gnueabihf- 2>&1 | tee build.log

3, Linux Kernel

  • First, enter the directory and configure the compilation option file: make CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm licheepi_zero_defconfig

  • Configure the driver you need, such as network card driver or small screen display driver: make ARCH=arm menuconfig

Device Drivers  --->
     [*] Staging drivers  --->
              <*>   Support for small TFT LCD display modules  --->
                        <*>   FB driver for the ST7789V LCD Controller
  • Compile kernel: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16

So far, the kernel configuration is OK. Next, you need to change the device tree.

4, Device tree

Step 1: comment out the video output

vim arch/arm/boot/dts/sun8i-v3s.dtsi

sun8i-v3s.dtsi

...
    chosen {
        #address-cells = <1>;
        #size-cells = <1>;
        ranges;

//      simplefb_lcd: framebuffer@0 {
//          compatible = "allwinner,simple-framebuffer",
//                   "simple-framebuffer";
//          allwinner,pipeline = "de0-lcd0";
//          clocks = <&ccu CLK_BUS_TCON0>, <&ccu CLK_BUS_DE>,
//               <&ccu CLK_DE>, <&ccu CLK_TCON0>;
//          status = "disabled";
//      };
    };
...

Step 2: add screen driver node

vim arch/arm/boot/dts/sun8i-v3s-licheepi-zero-dock.dts

sun8i-v3s-licheepi-zero-dock.dts

&spi0{
    status = "okay";
    st7789v: st7789v@0{
        compatible = "sitronix,st7789v";
        reg = <0>;
        status = "okay";
        spi-max-frequency = <36000000>;
        spi-cpol;
        spi-cpha;
        rotate = <0>;
        fps = <60>;
        buswidth = <8>;
        rgb;
        dc-gpios    = <&pio 1 5 GPIO_ACTIVE_HIGH>;  // PB5 
        reset-gpios = <&pio 1 6 GPIO_ACTIVE_HIGH>;  // PB6
        led-gpios   = <&pio 1 7 GPIO_ACTIVE_LOW>;   // PB7
        width = <240>;
        height= <320>;
        debug = <0>;
    };
};

Update device tree:

vim arch/arm/boot/dts/sun8i-v3s-licheepi-zero-dock.dts

Compile the device tree separately:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs

5, Burn

  here, the simplest SD card is used to start, and the above will be burned into the SD card.

How did litchi pie start

  the first step of startup is the on-chip 32KB boot ROM (Bloom). In order to avoid the user's external NOR Flash, most ARM processors usually integrate such a bloom on chip. BROM attempts to read programs from external storage devices (first SD/MMC, then SPI NOR, and finally SPI NAND). This program is called boot0 by Quanzhi. Here is SPL. If BROM does not load this program successfully, it will enter USB startup mode.

  the second step is SPL. SPL is actually a simplified version of u-boot, which can only perform some specific tasks. SPL will be loaded into the internal SRAM of V3s, and then SPL will perform the following operations:

  • Initialize clock, serial port, DRAM and boot device (SD/MMC/SPI Flash)
  • Copy the complete u-boot from the boot device to the DRAM
  • Jump to full u-boot

  the third step is u-boot. U-boot is responsible for loading the kernel. In general, u-boot will try to read from the first partition of the SD card and execute the "boot. SCR" script. Generally speaking, boot.scr includes three instructions: load the kernel into SDRAM, load the device tree binary into SDRAM, and (extract and) run the kernel.

What do I need on the TF card

The following is a typical bootable TF card structure:


Basically, to create a bootable TF card, you need partition table (through fdisk), u-boot with SPL, startup script, device tree binary, kernel and root file system image.

Actual burning

  for a TF card that has never been used, first format it with SD Formatter software on Windows platform.
If you want to burn an all-in-one image of a formatted TF Card:

  • Burning with Win32DiskImager software in Windows Environment
  • In Ubuntu environment: not used

It is the formatted TF card. Use GParted partition editor software to partition the TF card under Ubuntu: it is mainly divided into two areas, as shown in the figure above. When partitioning, free up the space of the first 1MByte for U-Boot, that is, the BOOT area is after the 1MByte address. The previous 1MByte is actually a RAW data area without file system format.

  • BOOT area: the file system format is FAT16, which is used to store device tree files and Kernel files
  • rootfs area: the file system format is EXT4, which is used to store the root file system

In Ubuntu environment, files are generally separated:

  • U-Boot file: u-boot-sunxi-with-spl.bin
  • Linux Kernel image file: zImage
  • Device tree binary: sun8i-v3s-licheepi-zero-dock.dtb
  • Root file system: rootfs

6, Connect

SPI screenlichee pi zero
GNDGND
VCC3v3
SCLSCL(PC1)
SDAMOSI(PC3)
RESSCK(PB6)
DCPWM1(PB5)
CSCS(PC2)
BLKSDA(PB7)
  • Wires that must be connected: MOSI, CLK, CS, DC, VCC, GND.
  • BLK can be connected to 3v3 without dimming
  • RES does not need to be connected to GND

7, Testing

Snowflakes appear when you enter a command on the command line:

cat /dev/urandom > /dev/fb0
/opt/qt5.12.9-arm/examples/widgets/widgets/analogclock

Tags: Linux

Posted on Wed, 01 Sep 2021 14:34:54 -0400 by serbestgezer