导航

    全志在线开发者论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 在线文档
    • 社区主页

    RT-Thread on D1H. LCD work, USB in progress.

    MR Series
    4
    6
    1567
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Y
      ylyamin LV 4 最后由 ylyamin 编辑

      Hi all,

      I successfully build and ran RT-Thread (a small embedded OS) on the RISC-V Allwinner D1H SoC.

      Experimenting on ClockworkPi DevTerm R-01 device and Sipeed Lichee RV board.
      Also @jusentari made ClockworkPi uConsole R-01 display work in RTT (experimental parameters, use with caution).

      Intention was to make RT-Thread portable terminal with working display and keyboard.

      I manage to:

      • Create a working LCD MIPI DSI Display driver with frame buffer.
      • Create a working LCD RGB Display driver with frame buffer.
      • Make some progress on a USB keyboard driver.
      • Boot from SD card and communicate via UART
      • Debugging with GDB

      The code is available at: https://github.com/ylyamin/RT-Thread-on-Allwinner-D1H
      If you enjoy brainteaser and some low-level stuff, you’re welcome.

      Ready images for SD card:

      • DevTerm R01: sd_image_devterm.img
      • uConsole R01: sd_image_uconsole.img (experimental display parameters, use with caution)
      • Sipeed Lichee RV: sd_image_lichee.img

      Please note: The DevTerm/uConsole battery charging/discharging controller is not yet configured in the driver, so I’m unsure how it affects the battery. I suggest not using the battery with RT-Thread and powering it via USB instead.

      I’m writing a series of articles covering the knowledge and experience I’ve gained:

      • D1-1. Introduction - Motivation and intention.
      • D1-2. Boot process - Existing Allwinner D1H bootloaders best practice in example with booting Linux and RT-Thread, also JTAG and GDB.
      • D1-3. RT-Thread overview and Build - Overview of RT-Thread structure and libraries. Compile RT-Thread for Allwinner D1H platform.
      • D1-4. Makefile and Hardware changes - My repository structure, Makefile and Hardware changes was needed to be done.
      • D1-5. LCD Display driver - Display driver for DevTerm R-01, uConsole R-01 and Sipeed Lichee RV.
      • D1-6. USB Keyboard - USB Keyboard driver for ClockworkPi DevTerm, still not working.

      Finally, I dare to ask for help from the community, please:

      I’m really stuck with the USB driver. It can detect device connections, but communication has not started.<br>
      Perhaps someone would enjoy diving deep into the USB driver to solve this riddle. Ready for issue reports and pull requests.

      Picture of LCD Display test in RT-Thread running on uConsole R-01:

      uconsole_lcd_mipi_work.jpg

      Picture of LCD Display test in RT-Thread running on Devterm R-01:

      devterm_lcd_mipi_work.jpg

      B Y 3 条回复 最后回复 回复 引用 分享 3
      • Z
        zoengjay LV 5 最后由 编辑

        @ylyamin 在 RT-Thread on D1H. LCD work, USB in progress. 中说:

        I’m really stuck with the USB driver. It can detect device connections, but communication has not started.<br>
        Perhaps someone would enjoy diving deep into the USB driver to solve this riddle. Ready for issue reports and pull requests.
        Picture of LCD Display test in RT-Thread running on uConsole R-01:

        nice work!
        I'd like to help, and just bought a Sipeed Lichee RV board.

        Y 1 条回复 最后回复 回复 引用 分享 1
        • Y
          ylyamin LV 4 @zoenggit 最后由 编辑

          @zoenggit Thank you for your enthusiasm and support !

          1 条回复 最后回复 回复 引用 分享 1
          • B
            bigfly LV 5 @ylyamin 最后由 编辑

            @ylyamin 在 RT-Thread on D1H. LCD work, USB in progress. 中说:

            I’m writing a series of articles covering the knowledge and experience I’ve gained:

            D1-1. Introduction - Motivation and intention.
            D1-2. Boot process - Existing Allwinner D1H bootloaders best practice in example with booting Linux and RT-Thread, also JTAG and GDB.
            D1-3. RT-Thread overview and Build - Overview of RT-Thread structure and libraries. Compile RT-Thread for Allwinner D1H platform.
            D1-4. Makefile and Hardware changes - My repository structure, Makefile and Hardware changes was needed to be done.
            D1-5. LCD Display driver - Display driver for DevTerm R-01, uConsole R-01 and Sipeed Lichee RV.
            D1-6. USB Keyboard - USB Keyboard driver for ClockworkPi DevTerm, still not working.

            Detailed article,nice

            1 条回复 最后回复 回复 引用 分享 1
            • Y
              ylyamin LV 4 @ylyamin 最后由 编辑

              Hi

              @zoenggit found this discussion issue in TinyUSB. Where user @robots created repo for Allwinner T113 chip. Is ARM core but peripherals looks absolutely the same as D1H RISC-V.

              Is repo is bare metal experiments with T113 and FreeRTOS also contains Doom. So author decide to deactivate USB EHCI and use only OHCI. Also for USB descriptors used memory section with direct mapping.

              I try to do the same:

              1. Deactivate EHCI:

              rt-thread/bsp/allwinner/d1s_d1h/packages/TinyUSB/rt-thread/bsp/sunxi_D1/drv_tinyusb.c

              	volatile uint32_t *portsc  = (uint32_t * ) (EHCI1_BASE + 0x054);  //E_PORTSC
              	*portsc |= BV(13);
              
              1. Add few places to clear/invalidate caches, in rt-thread/bsp/allwinner/d1s_d1h/packages/TinyUSB/src/portable/ohci/ohci.c:
              static void gtd_init(ohci_gtd_t* p_td, uint8_t* data_ptr, uint16_t total_bytes)
              {
              ...
              rt_hw_cpu_dcache_clean_and_invalidate_local(data_ptr, total_bytes);
              }
              
              
              1. Define DMA memory section:
                rt-thread/bsp/allwinner/d1s_d1h/link.lds
              MEMORY
              {
                  SRAM : ORIGIN = 0x40300000, LENGTH = 4M
                  DMA :  ORIGIN = 0x40700000, LENGTH = 16M
                  HEAP : ORIGIN = 0x41700000, LENGTH = 16M
              }
              
              SECTIONS
              {
                  .usb :
                  {
                      . = ALIGN(4);   
                  } > DMA
              

              Init MMU with different sections in rt-thread/bsp/allwinner/d1s_d1h/board/board.c:

              struct mem_desc platform_mem_desc[] = {
                  {KERNEL_VADDR_START, 0x40700000 - 1, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},       //KERNEL
                  {0x1000, 0x3ffff000 - 1, (rt_size_t)ARCH_MAP_FAILED, DEVICE_MEM},                   //IO
                  {0x40700000, 0x40700000 + 0x1000000 - 1, (rt_size_t)ARCH_MAP_FAILED, DEVICE_MEM},   //DMA
                  {0x41700000, 0x40700000 + 0x4000000 - 1, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},   //HEAP + HW PAGE
              };
              

              rt-thread/bsp/allwinner/d1s_d1h/packages/TinyUSB/src/portable/ohci/ohci.c

              CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static ohci_data_t ohci_data;
              

              Run board.
              Looks like USB device start to do something new, but all data transfers did not produce any results, all of it STALLED or FAULT:

              [0:0] Open EP0 with Size = 8
              Get 8 byte of Device Descriptor
              [0:0] Get Descriptor: 80 06 00 01 00 00 08 00
              on EP 00 with 8 bytes
              on EP 80 with 8 bytes
              [0:0] Control STALLED, xferred_bytes = 8
              
              [0:0] Get Descriptor: 80 06 00 03 D0 03 08 00 
              on EP 00 with 8 bytes
              on EP 80 with 8 bytes
              [0:0] Control STALLED, xferred_bytes = 8
              
              [0:0] Get Descriptor: 80 06 00 02 18 08 08 00 
              on EP 00 with 8 bytes
              on EP 80 with 8 bytes
              [0:0] Control STALLED, xferred_bytes = 8
              
              [0:0] Get Descriptor: 80 06 00 02 58 0C 08 00 
              on EP 00 with 8 bytes
              on EP 00 with 4294964828 bytes
              
              Set Address = 1
              [0:0] Set Address: 00 05 01 00 00 00 00 00
              on EP 00 with 0 bytes
              [0:0] Control STALLED, xferred_bytes = 0
              
              [0:0] Set Address: 00 05 01 02 00 00 00 00 
              on EP 00 with 0 bytes
              on EP 00 with 2088 bytes
              
              [0:0] Get Descriptor: 80 06 00 01 00 00 12 00 
              on EP 00 with 8 bytes
              [0:1] Control FAILED, xferred_bytes = 8
              

              So did not lead to success with USB again.
              Need to dive deeper into EHCI/OHCI, maybe some one can advice please ?

              • DevTerm R01 image image/sd_image_devterm.img
              • uConsole R01 image image/sd_image_uconsole.img
              • Sipeed Lichee image image/sd_image_lichee.img
              1 条回复 最后回复 回复 引用 分享 0
              • Y
                ylyamin LV 4 @ylyamin 最后由 编辑

                I managed to do USB working.
                Thanks, user @zoenggit for the tip.
                Found a hand-made ham radio transceiver project from one guru guy, it has a proper implementation of EHCI/OHCI stack for Allwinner D1/T113 hftrx_tinyusb. I just changed it a little to support RT-Thread.

                Now USB keyboard sends a key press to the system.

                HID device address = 2, instance = 0 is mounted
                HID Interface Protocol = None
                HID has 4 reports
                msh />
                H
                e
                l
                l
                o
                !
                
                1 条回复 最后回复 回复 引用 分享 0
                • 1 / 1
                • First post
                  Last post

                Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

                行为准则 | 用户协议 | 隐私权政策