您尚未登录。

#1 全志 SOC » Allwinner D1H library for small OS » 2025-02-04 20:20:38

ylyamin
回复: 1

Hi all,

I created bare-metal library for R-01 (for Allwinner D1H RISC-V SOC).
Tested in ClockworkPi DevTerm R-01 and  Sipeed lichee RV.
Everything actually is based on @robots allwinner_t113 and @ua1arn hftrx projects, these guys are genius.

Is minimal low-level library could be used to run own OS, or Doom or whatever.

Now is have:

  • Bootloader, could run from SD card.

  • USB keyboard working well

  • TWI (I2C) supported AXP228 Power management chip for Display backlight and USB power.

  • UART, GPIO

To run need configure UART adapter to 115200 baud rate.
Insert flashed SD card to device should see output like this:

[INF]:  \ | /
[INF]:  - Allwinner D1 HAL [ver: 0.0.1-5-gd69c9f1]
[INF]:  / | \
[INF]:  SoC: D1H
[INF]:  Platform: ClockworkPi Devterm R-01
[DBG]:irq_init
[DBG]:twi_init

With Display I have a big problem is work with external board with LCD RGB(ST7701S SPI) but with ClockworkPi LCD MIPI not work.
My dream to have just one C file to init LCD and framebuffer, but LCD driver stack is very complicated.

I found drivers in Linux and RT-Thread OS but is very big and I could not extract from it what should be set.
Tried configure registers the same as in Linux but is still not work.

Perhaps someone would enjoy diving deep into the LCD world to solve this riddle. Ready for issue reports and pull requests to bare-metal library for R-01!

Also I accumulated many knowledge and write articles when run RT-Thread OS in DevTerm/uConsole R-01, in this OS LCD and USB work well.

#2 Re: 全志 SOC » RT-Thread on Allwinner D1H. LCD work, USB in progress. » 2024-11-16 04:46:17

UPD: 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
!

#3 Re: 全志 SOC » RT-Thread on Allwinner D1H. LCD work, USB in progress. » 2024-11-04 18:52:51

Hi all,

User @zoenggit found this discussion isuue 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);

2. 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);
}

3. 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 ?

#4 Re: 全志 SOC » RT-Thread on Allwinner D1H. LCD work, USB in progress. » 2024-10-26 00:05:48

642242855 说:

USB部分可以看下CherryUSB,好像CherryUSB支持F133,按道理应该是可以用

Hi, thanks for your involvement,

Actually I was port CherryUSB already in folder rt-thread/bsp/allwinner/d1s_d1h/packages/CherryUSB/.
Cherry USB do switch from EHCI to OHCI companion controller when I connect USB device but in Cherry USB - OHCI transfer functions is not implemented.

Because of that I switch to TinyUSB in folder rt-thread/bsp/allwinner/d1s_d1h/packages/TinyUSB/
However, it did not reach the point when OHCI started to work in TinyUSB.
More info at D1-6. USB Keyboard

#5 Re: 全志 SOC » RT-Thread on Allwinner D1H. LCD work, USB in progress. » 2024-10-22 17:30:13

UPD:
@jusentari made Clockworkpi uConsole R-01 display work in RTT (experimental display parameters, use with caution).

uconsole

#6 全志 SOC » RT-Thread on Allwinner D1H. LCD work, USB in progress. » 2024-10-17 21:43:28

ylyamin
回复: 6

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.

Intention was to make RT-Thread portable terminal with a 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.
Should say: it's not truly low-level bare-metal from ground as RT-Thread operates with threads and events and the HAL level is quite complex. But it is easier to manage compared to working within the Linux kernel - at least for me, as I'm not an expert in Linux. RT-Thread has great potential, as it supports many packages for GUI, audio, Ethernet, and more.

Ready images for SD card:

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:

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 Devterm R-01:
Devterm

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn