diff options
| author | boa <[email protected]> | 2026-11-17 11:19:03 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-11-17 11:19:03 +0800 |
| commit | 9ddb0249c0bf022f8d5efc9ff20d407247e5602d (patch) | |
| tree | 55309f895ff923f4cfa86f98346d5df4f6c66c05 | |
| parent | 0dffe47813444cc8b0d26a10b019e1a629a40a96 (diff) | |
[bsp][artinchip] Add initial D213ECV-DEMO-V4-0 support (#12058)
* [bsp][artinchip] Add basic D213ECV-DEMO-V4-0 support
* [bsp][artinchip] Register D213 BSP in board index and CI
* [bsp][artinchip] Fix UART TX timeout and UTest registration
30 files changed, 1783 insertions, 0 deletions
diff --git a/.github/ALL_BSP_COMPILE.json b/.github/ALL_BSP_COMPILE.json index c7ab65a00b..4e2bcaf30b 100644 --- a/.github/ALL_BSP_COMPILE.json +++ b/.github/ALL_BSP_COMPILE.json @@ -438,6 +438,7 @@ "RTT_BSP": "riscv64-unknown", "RTT_TOOL_CHAIN": "sourcery-riscv64-unknown-elf", "SUB_RTT_BSP": [ + "artinchip/d213ecv-demo-v4-0", "bluetrum/ab32vg1-ab-prougen", "qemu-virt64-riscv", "ultrarisc/ur_dp1000_evb" diff --git a/bsp/README.md b/bsp/README.md index 221ac20468..0d20c2c0ff 100644 --- a/bsp/README.md +++ b/bsp/README.md @@ -886,6 +886,12 @@ This document is based on the RT-Thread mainline repository and categorizes the | [ri5cy](rv32m1_vega/ri5cy) | ✅ | ✅ | - | - | - | - | | [rv32m1_sdk_riscv](rv32m1_vega/rv32m1_sdk_riscv) | ✅ | ✅ | - | - | - | - | +#### ⚪ ArtInChip + +| BSP Name | GPIO | UART | ADC | I2C | SPI | WDT | +|----------|------|------|-----|-----|-----|-----| +| [d213ecv-demo-v4-0](artinchip/d213ecv-demo-v4-0) | - | ✅ | - | - | - | - | + --- ### AVR Architecture Series diff --git a/bsp/artinchip/README.md b/bsp/artinchip/README.md new file mode 100644 index 0000000000..820b0bf174 --- /dev/null +++ b/bsp/artinchip/README.md @@ -0,0 +1,30 @@ +# ArtInChip BSPs + +[English](README.md) | [中文](README_zh.md) + +This directory provides RT-Thread board support for ArtInChip SoCs. + +| Board | SoC / CPU | Support | +|-------|-----------|-----------------| +| [D213ECV-DEMO-V4-0](d213ecv-demo-v4-0/README.md) | D213ECV / T-Head C906, RV64GC | M-mode base kernel, UART0 console | + +## Source organization + +```text +artinchip/ +├── d213ecv-demo-v4-0/ Board configuration and build entry +│ ├── applications/ Startup application +│ └── board/ Board wiring and initialization sequence +└── libraries/ + ├── include/ UART register definitions + └── soc/d21x/ + ├── include/ SoC addresses and MMIO accessors + ├── drivers/ D213 UART0 serial adapter + └── port/ CPU, clock, PLIC and timer platform hooks +``` + +Board wiring and memory layout are configured in the board directory. Shared D21x register definitions, drivers and platform initialization are in `libraries/soc/d21x`. + +The BSP uses the RT-Thread RISC-V common port for startup, context switching, FPU state, interrupts and system ticks. It provides UART0 with the required clock, reset and pin configuration. The bootloader initializes DDR, PLLs and memory/cache attributes before starting RT-Thread. + +See the [board README](d213ecv-demo-v4-0/README.md) for build instructions, configuration, bootloader requirements and UART usage. diff --git a/bsp/artinchip/README_zh.md b/bsp/artinchip/README_zh.md new file mode 100644 index 0000000000..fa31861006 --- /dev/null +++ b/bsp/artinchip/README_zh.md @@ -0,0 +1,30 @@ +# ArtInChip 板级支持包 + +[English](README.md) | [中文](README_zh.md) + +本目录提供 ArtInChip SoC 的 RT-Thread 板级支持。 + +| 开发板 | SoC / CPU | 支持功能 | +|--------|-----------|----------| +| [D213ECV-DEMO-V4-0](d213ecv-demo-v4-0/README_zh.md) | D213ECV / T-Head C906,RV64GC | M-mode 基础内核、UART0 控制台 | + +## 源码结构 + +```text +artinchip/ +├── d213ecv-demo-v4-0/ 板级配置与构建入口 +│ ├── applications/ 启动应用 +│ └── board/ 板级接线与初始化编排 +└── libraries/ + ├── include/ UART 寄存器定义 + └── soc/d21x/ + ├── include/ SoC 地址与 MMIO 访问接口 + ├── drivers/ D213 UART0 串口适配 + └── port/ CPU、时钟、PLIC 和定时器平台接口 +``` + +板级目录用于配置开发板接线和内存布局,`libraries/soc/d21x` 存放 D21x 共用的寄存器定义、驱动和平台初始化代码。 + +BSP 使用 RT-Thread RISC-V common port 完成启动、上下文切换、FPU 状态保存、中断处理和系统定时,提供 UART0 及所需的时钟、复位和引脚配置。Bootloader 在启动 RT-Thread 前完成 DDR、PLL 和内存/Cache 属性初始化。 + +构建方法、配置、Bootloader 要求和 UART 使用方法见 [开发板说明](d213ecv-demo-v4-0/README_zh.md)。 diff --git a/bsp/artinchip/d213ecv-demo-v4-0/.config b/bsp/artinchip/d213ecv-demo-v4-0/.config new file mode 100644 index 0000000000..4a3c21aa22 --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/.config @@ -0,0 +1,403 @@ + +# +# RT-Thread Kernel +# + +# +# klibc options +# + +# +# rt_vsnprintf options +# +# CONFIG_RT_KLIBC_USING_LIBC_VSNPRINTF is not set +CONFIG_RT_KLIBC_USING_VSNPRINTF_LONGLONG=y +CONFIG_RT_KLIBC_USING_VSNPRINTF_STANDARD=y +CONFIG_RT_KLIBC_USING_VSNPRINTF_DECIMAL_SPECIFIERS=y +CONFIG_RT_KLIBC_USING_VSNPRINTF_EXPONENTIAL_SPECIFIERS=y +CONFIG_RT_KLIBC_USING_VSNPRINTF_WRITEBACK_SPECIFIER=y +CONFIG_RT_KLIBC_USING_VSNPRINTF_CHECK_NUL_IN_FORMAT_SPECIFIER=y +# CONFIG_RT_KLIBC_USING_VSNPRINTF_MSVC_STYLE_INTEGER_SPECIFIERS is not set +CONFIG_RT_KLIBC_USING_VSNPRINTF_INTEGER_BUFFER_SIZE=32 +CONFIG_RT_KLIBC_USING_VSNPRINTF_DECIMAL_BUFFER_SIZE=32 +CONFIG_RT_KLIBC_USING_VSNPRINTF_FLOAT_PRECISION=6 +CONFIG_RT_KLIBC_USING_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL=9 +CONFIG_RT_KLIBC_USING_VSNPRINTF_LOG10_TAYLOR_TERMS=4 +# end of rt_vsnprintf options + +# +# rt_vsscanf options +# +# CONFIG_RT_KLIBC_USING_LIBC_VSSCANF is not set +# end of rt_vsscanf options + +# +# rt_memset options +# +# CONFIG_RT_KLIBC_USING_USER_MEMSET is not set +# CONFIG_RT_KLIBC_USING_LIBC_MEMSET is not set +# CONFIG_RT_KLIBC_USING_TINY_MEMSET is not set +# end of rt_memset options + +# +# rt_memcpy options +# +# CONFIG_RT_KLIBC_USING_USER_MEMCPY is not set +# CONFIG_RT_KLIBC_USING_LIBC_MEMCPY is not set +# CONFIG_RT_KLIBC_USING_TINY_MEMCPY is not set +# end of rt_memcpy options + +# +# rt_memmove options +# +# CONFIG_RT_KLIBC_USING_USER_MEMMOVE is not set +# CONFIG_RT_KLIBC_USING_LIBC_MEMMOVE is not set +# end of rt_memmove options + +# +# rt_memcmp options +# +# CONFIG_RT_KLIBC_USING_USER_MEMCMP is not set +# CONFIG_RT_KLIBC_USING_LIBC_MEMCMP is not set +# end of rt_memcmp options + +# +# rt_strstr options +# +# CONFIG_RT_KLIBC_USING_USER_STRSTR is not set +# CONFIG_RT_KLIBC_USING_LIBC_STRSTR is not set +# end of rt_strstr options + +# +# rt_strcasecmp options +# +# CONFIG_RT_KLIBC_USING_USER_STRCASECMP is not set +# end of rt_strcasecmp options + +# +# rt_strncpy options +# +# CONFIG_RT_KLIBC_USING_USER_STRNCPY is not set +# CONFIG_RT_KLIBC_USING_LIBC_STRNCPY is not set +# end of rt_strncpy options + +# +# rt_strcpy options +# +# CONFIG_RT_KLIBC_USING_USER_STRCPY is not set +# CONFIG_RT_KLIBC_USING_LIBC_STRCPY is not set +# end of rt_strcpy options + +# +# rt_strncmp options +# +# CONFIG_RT_KLIBC_USING_USER_STRNCMP is not set +# CONFIG_RT_KLIBC_USING_LIBC_STRNCMP is not set +# end of rt_strncmp options + +# +# rt_strcmp options +# +# CONFIG_RT_KLIBC_USING_USER_STRCMP is not set +# CONFIG_RT_KLIBC_USING_LIBC_STRCMP is not set +# end of rt_strcmp options + +# +# rt_strlen options +# +# CONFIG_RT_KLIBC_USING_USER_STRLEN is not set +# CONFIG_RT_KLIBC_USING_LIBC_STRLEN is not set +# end of rt_strlen options + +# +# rt_strnlen options +# +# CONFIG_RT_KLIBC_USING_USER_STRNLEN is not set +# end of rt_strnlen options +# end of klibc options + +CONFIG_RT_NAME_MAX=16 +# CONFIG_RT_USING_ARCH_DATA_TYPE is not set +# CONFIG_RT_USING_NANO is not set +# CONFIG_RT_USING_SMART is not set +# CONFIG_RT_USING_AMP is not set +# CONFIG_RT_USING_SMP is not set +CONFIG_RT_CPUS_NR=1 +CONFIG_RT_ALIGN_SIZE=8 +# CONFIG_RT_THREAD_PRIORITY_8 is not set +CONFIG_RT_THREAD_PRIORITY_32=y +# CONFIG_RT_THREAD_PRIORITY_256 is not set +CONFIG_RT_THREAD_PRIORITY_MAX=32 +CONFIG_RT_TICK_PER_SECOND=1000 +CONFIG_RT_USING_OVERFLOW_CHECK=y +# CONFIG_RT_USING_HOOK is not set +# CONFIG_RT_USING_HOOKLIST is not set +# CONFIG_RT_USING_IDLE_HOOK is not set +CONFIG_IDLE_THREAD_STACK_SIZE=2048 +# CONFIG_RT_USING_TIMER_SOFT is not set +# CONFIG_RT_USING_CPU_USAGE_TRACER is not set + +# +# kservice options +# +# CONFIG_RT_USING_TINY_FFS is not set +# end of kservice options + +CONFIG_RT_USING_DEBUG=y +CONFIG_RT_DEBUGING_ASSERT=y +# CONFIG_RT_DEBUGING_COLOR is not set +# CONFIG_RT_DEBUGING_CONTEXT is not set +# CONFIG_RT_DEBUGING_AUTO_INIT is not set +# CONFIG_RT_USING_CI_ACTION is not set + +# +# Inter-Thread communication +# +CONFIG_RT_USING_SEMAPHORE=y +CONFIG_RT_USING_MUTEX=y +CONFIG_RT_USING_EVENT=y +CONFIG_RT_USING_MAILBOX=y +CONFIG_RT_USING_MESSAGEQUEUE=y +# CONFIG_RT_USING_MESSAGEQUEUE_PRIORITY is not set +# CONFIG_RT_USING_SIGNALS is not set +# end of Inter-Thread communication + +# +# Memory Management +# +# CONFIG_RT_USING_MEMPOOL is not set +CONFIG_RT_USING_SMALL_MEM=y +# CONFIG_RT_USING_SLAB is not set +# CONFIG_RT_USING_MEMHEAP is not set +CONFIG_RT_USING_SMALL_MEM_AS_HEAP=y +# CONFIG_RT_USING_MEMHEAP_AS_HEAP is not set +# CONFIG_RT_USING_SLAB_AS_HEAP is not set +# CONFIG_RT_USING_USERHEAP is not set +# CONFIG_RT_USING_NOHEAP is not set +# CONFIG_RT_USING_MEMTRACE is not set +# CONFIG_RT_USING_HEAP_ISR is not set +CONFIG_RT_USING_HEAP=y +# end of Memory Management + +CONFIG_RT_USING_DEVICE=y +CONFIG_RT_USING_DEVICE_OPS=y +# CONFIG_RT_USING_INTERRUPT_INFO is not set +# CONFIG_RT_USING_THREADSAFE_PRINTF is not set +CONFIG_RT_USING_CONSOLE=y +CONFIG_RT_CONSOLEBUF_SIZE=128 +CONFIG_RT_CONSOLE_DEVICE_NAME="uart0" +# CONFIG_RT_USING_CONSOLE_OUTPUT_CTL is not set +CONFIG_RT_VER_NUM=0x50400 +# CONFIG_RT_USING_STDC_ATOMIC is not set +CONFIG_RT_BACKTRACE_LEVEL_MAX_NR=32 +# end of RT-Thread Kernel + +CONFIG_ARCH_TEXT_OFFSET=0x200000 +CONFIG_ARCH_RAM_OFFSET=0 +CONFIG_ARCH_CPU_64BIT=y +CONFIG_RT_USING_CPU_FFS=y +CONFIG_ARCH_RISCV=y +CONFIG_ARCH_RISCV_FPU=y +CONFIG_ARCH_RISCV_FPU_D=y +CONFIG_ARCH_RISCV64=y + +# +# RISC-V Architecture Configuration +# +CONFIG_RT_USING_RISCV_NEW_COMMON=y +CONFIG_ARCH_RISCV_M_MODE=y +CONFIG_ARCH_RISCV_USING_IRQ_STACK=y +CONFIG_ARCH_RISCV_IRQ_STACK_SIZE=4096 +# CONFIG_RT_USING_USERSPACE_32BIT_LIMIT is not set +# end of RISC-V Architecture Configuration + +CONFIG_ARCH_USING_NEW_CTX_SWITCH=y + +# +# RT-Thread Components +# +CONFIG_RT_USING_COMPONENTS_INIT=y +CONFIG_RT_USING_USER_MAIN=y +CONFIG_RT_MAIN_THREAD_STACK_SIZE=4096 +CONFIG_RT_MAIN_THREAD_PRIORITY=10 +# CONFIG_RT_USING_LEGACY is not set +CONFIG_RT_USING_MSH=y +CONFIG_RT_USING_FINSH=y +CONFIG_FINSH_USING_MSH=y +CONFIG_FINSH_THREAD_NAME="tshell" +CONFIG_FINSH_THREAD_PRIORITY=20 +CONFIG_FINSH_THREAD_STACK_SIZE=4096 +CONFIG_FINSH_USING_HISTORY=y +CONFIG_FINSH_HISTORY_LINES=5 +# CONFIG_FINSH_USING_WORD_OPERATION is not set +# CONFIG_FINSH_USING_FUNC_EXT is not set +CONFIG_FINSH_USING_SYMTAB=y +CONFIG_FINSH_CMD_SIZE=80 +CONFIG_MSH_USING_BUILT_IN_COMMANDS=y +CONFIG_FINSH_USING_DESCRIPTION=y +# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set +# CONFIG_FINSH_USING_AUTH is not set +CONFIG_FINSH_ARG_MAX=10 +CONFIG_FINSH_USING_OPTION_COMPLETION=y + +# +# DFS: device virtual file system +# +# CONFIG_RT_USING_DFS is not set +# end of DFS: device virtual file system + +# CONFIG_RT_USING_FAL is not set + +# +# Device Drivers +# +# CONFIG_RT_USING_DM is not set +# CONFIG_RT_USING_DEV_BUS is not set +CONFIG_RT_USING_DEVICE_IPC=y +CONFIG_RT_UNAMED_PIPE_NUMBER=64 +# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set +CONFIG_RT_USING_SERIAL=y +CONFIG_RT_USING_SERIAL_V1=y +# CONFIG_RT_USING_SERIAL_V2 is not set +# CONFIG_RT_SERIAL_USING_DMA is not set +CONFIG_RT_SERIAL_RB_BUFSZ=512 +# CONFIG_RT_USING_SERIAL_BYPASS is not set +# CONFIG_RT_USING_CAN is not set +# CONFIG_RT_USING_ADC is not set +# CONFIG_RT_USING_CLOCK_TIME is not set +# CONFIG_RT_USING_I2C is not set +# CONFIG_RT_USING_PHY is not set +# CONFIG_RT_USING_PHY_V2 is not set +# CONFIG_RT_USING_DAC is not set +# CONFIG_RT_USING_NULL is not set +# CONFIG_RT_USING_ZERO is not set +# CONFIG_RT_USING_RANDOM is not set +# CONFIG_RT_USING_PWM is not set +# CONFIG_RT_USING_PULSE_ENCODER is not set +# CONFIG_RT_USING_INPUT_CAPTURE is not set +# CONFIG_RT_USING_MTD_NOR is not set +# CONFIG_RT_USING_MTD_NAND is not set +# CONFIG_RT_USING_PM is not set +# CONFIG_RT_USING_RTC is not set +# CONFIG_RT_USING_SDIO is not set +# CONFIG_RT_USING_SPI is not set +# CONFIG_RT_USING_WDT is not set +# CONFIG_RT_USING_AUDIO is not set +# CONFIG_RT_USING_SENSOR is not set +# CONFIG_RT_USING_TOUCH is not set +# CONFIG_RT_USING_LCD is not set +# CONFIG_RT_USING_HWCRYPTO is not set +# CONFIG_RT_USING_WIFI is not set +# CONFIG_RT_USING_RPMSG is not set +# CONFIG_RT_USING_BLK is not set +# CONFIG_RT_USING_REGULATOR is not set +# CONFIG_RT_USING_POWER_SUPPLY is not set +# CONFIG_RT_USING_PIN is not set +# CONFIG_RT_USING_CHERRYUSB is not set +# end of Device Drivers + +# +# C/C++ and POSIX layer +# + +# +# ISO-ANSI C layer +# + +# +# Timezone and Daylight Saving Time +# +# CONFIG_RT_LIBC_USING_FULL_TZ_DST is not set +CONFIG_RT_LIBC_USING_LIGHT_TZ_DST=y +CONFIG_RT_LIBC_TZ_DEFAULT_HOUR=8 +CONFIG_RT_LIBC_TZ_DEFAULT_MIN=0 +CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0 +# end of Timezone and Daylight Saving Time +# end of ISO-ANSI C layer + +# +# POSIX (Portable Operating System Interface) layer +# +# CONFIG_RT_USING_POSIX_FS is not set +# CONFIG_RT_USING_POSIX_DELAY is not set +# CONFIG_RT_USING_POSIX_CLOCK is not set +# CONFIG_RT_USING_POSIX_TIMER is not set +# CONFIG_RT_USING_PTHREADS is not set +# CONFIG_RT_USING_MODULE is not set + +# +# Interprocess Communication (IPC) +# +# CONFIG_RT_USING_POSIX_PIPE is not set +# CONFIG_RT_USING_POSIX_MESSAGE_QUEUE is not set +# CONFIG_RT_USING_POSIX_MESSAGE_SEMAPHORE is not set + +# +# Socket is in the 'Network' category +# +# end of Interprocess Communication (IPC) +# end of POSIX (Portable Operating System Interface) layer + +# CONFIG_RT_USING_CPLUSPLUS is not set +# end of C/C++ and POSIX layer + +# +# Network +# +# CONFIG_RT_USING_SAL is not set +# CONFIG_RT_USING_NETDEV is not set +# CONFIG_RT_USING_LWIP is not set +# CONFIG_RT_USING_AT is not set +# end of Network + +# +# Memory protection +# +# CONFIG_RT_USING_MEM_PROTECTION is not set +# CONFIG_RT_USING_HW_STACK_GUARD is not set +# end of Memory protection + +# +# Utilities +# +# CONFIG_RT_USING_RYM is not set +# CONFIG_RT_USING_ULOG is not set +# CONFIG_RT_USING_UTEST is not set +# CONFIG_RT_USING_VAR_EXPORT is not set +# CONFIG_RT_USING_RESOURCE_ID is not set +CONFIG_RT_USING_ADT=y +# CONFIG_RT_USING_ADT_AVL is not set +CONFIG_RT_USING_ADT_BITMAP=y +# CONFIG_RT_USING_ADT_HASHMAP is not set +# CONFIG_RT_USING_ADT_REF is not set +# CONFIG_RT_USING_RT_LINK is not set +# end of Utilities + +# +# Using USB legacy version +# +# CONFIG_RT_USING_USB_HOST is not set +# CONFIG_RT_USING_USB_DEVICE is not set +# end of Using USB legacy version + +# CONFIG_RT_USING_FDT is not set +# CONFIG_RT_USING_LEGACY_VIRTIO is not set +# CONFIG_RT_USING_RUST is not set +# end of RT-Thread Components + +# +# RT-Thread Utestcases +# +# CONFIG_RT_USING_UTESTCASES is not set +# end of RT-Thread Utestcases + +CONFIG_AIC_SOC_D21X=y +CONFIG_SOC_D213=y + +# +# Board options +# +CONFIG_BSP_USING_UART0=y +CONFIG_BSP_UART_CLK_FREQ=48000000 +CONFIG_BSP_CLINT_FREQ=4000000 +# end of Board options diff --git a/bsp/artinchip/d213ecv-demo-v4-0/.gitignore b/bsp/artinchip/d213ecv-demo-v4-0/.gitignore new file mode 100644 index 0000000000..376664dab2 --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/.gitignore @@ -0,0 +1,10 @@ +build/ +dist/ +.sconsign.dblite +__pycache__/ +rtthread.elf +rtthread.bin +rtthread.map +rtthread.asm +.cconfig.h +.config.old diff --git a/bsp/artinchip/d213ecv-demo-v4-0/Kconfig b/bsp/artinchip/d213ecv-demo-v4-0/Kconfig new file mode 100644 index 0000000000..92b9778ae4 --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/Kconfig @@ -0,0 +1,11 @@ +mainmenu "RT-Thread Project Configuration" + +BSP_DIR := . +RTT_DIR := ../../.. +PKGS_DIR := packages + +source "$(RTT_DIR)/Kconfig" +osource "$(PKGS_DIR)/Kconfig" +orsource "libraries/Kconfig" +orsource "../libraries/Kconfig" +rsource "board/Kconfig" diff --git a/bsp/artinchip/d213ecv-demo-v4-0/README.md b/bsp/artinchip/d213ecv-demo-v4-0/README.md new file mode 100644 index 0000000000..c92ea2aca3 --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/README.md @@ -0,0 +1,111 @@ +# D213ECV-DEMO-V4-0 + +[English](README.md) | [中文](README_zh.md) + +## Overview + +This BSP supports the ArtInChip D213ECV-DEMO-V4-0 development board with RT-Thread running in M-mode on a single T-Head C906 core. + +| Item | Description | +|------|-------------| +| SoC | ArtInChip D213ECV | +| CPU | T-Head C906, RV64GC | +| Memory | 128 MiB DDR3 at `0x40000000` | +| Console | UART0, PA.0 (TX) / PA.1 (RX), 115200 baud, 8N1, no flow control | + +See the [official board documentation](https://aicdoc.artinchip.com/topics/product/d213ecV4.html) for hardware details. + +## Supported features + +| Feature | Description | +|---------|-------------| +| Kernel port | RT-Thread RISC-V common port, including double-precision FPU context switching | +| System tick | CLINT timer, 1000 Hz tick by default | +| Interrupt controller | PLIC | +| UART0 | Serial-v1, polling TX and thread-based polling RX | +| FinSH/MSH | Enabled by default | +| Heap and device framework | Enabled by default | + +UART0 is intended for an interactive console. Sustained input or long scheduling delays may cause data loss. UART hardware interrupts, DMA and flow control are not supported. The BSP provides the clock, reset and pin configuration required by UART0; DDR and PLL initialization are handled by the bootloader. + +## Build and configuration + +Install Python 3, SCons, kconfiglib and a GNU bare-metal RISC-V toolchain supporting RV64GC and the `lp64d` ABI. GCC 10.2.0 is recommended. + +From the repository root: + +```sh +python -m pip install scons kconfiglib +cd bsp/artinchip/d213ecv-demo-v4-0 +export RTT_EXEC_PATH=/path/to/riscv-toolchain/bin +scons --pyconfig-silent +scons -j8 +``` + +On PowerShell, use `$env:RTT_EXEC_PATH = 'C:/path/to/riscv-toolchain/bin'` to set the toolchain path. The default compiler prefix is `riscv64-unknown-elf-`; set `RTT_CC_PREFIX` if your toolchain uses a different prefix. The compiler can also be located through PATH. + +The build produces `rtthread.elf`, `rtthread.bin` and `rtthread.map`. + +To change the configuration, run: + +```sh +scons --menuconfig +scons --pyconfig-silent +scons -j8 +``` + +Generate `rtconfig.h` with the configuration tools rather than editing it directly. + +| Board option | Default | Description | +|--------------|---------|-------------| +| `BSP_USING_UART0` | Enabled | UART0 console; requires Serial-v1 | +| `BSP_UART_CLK_FREQ` | 48000000 | UART0 input clock in Hz | +| `BSP_CLINT_FREQ` | 4000000 | CLINT timebase in Hz | + +The clock settings must match the bootloader configuration; they do not change hardware clock dividers. Serial-v2 is not supported by the UART0 driver. + +UTest is disabled by default. To use it, enable `RT_USING_UTESTCASES` and select the required test cases in menuconfig, then regenerate the configuration and rebuild. + +To export a standalone project, run `scons --dist`. Extract `dist/project.zip`, unset `RTT_ROOT` if it is set, and run the same configuration and build commands in the extracted `project/` directory. + +## Download and run + +This BSP requires an external ArtInChip-compatible bootloader. Package `rtthread.bin` in the FIT or firmware format expected by that bootloader, using a matching partition layout. + +| Region | Address range | +|--------|---------------| +| RT-Thread, including heap | `0x40000000`–`0x477fffff` (120 MiB) | +| Bootloader reservation | `0x47800000`–`0x47ffffff` (8 MiB) | +| Binary load address and ELF entry | `0x40000000` | + +Before entering RT-Thread, the bootloader must: + +1. Initialize DDR, PLLs, bus clocks and CPU memory/cache attributes, with MMIO mapped as non-cacheable. +2. Provide the UART0 input clock and CLINT timebase specified in the BSP configuration. +3. Load the image at `0x40000000`, clean the loaded data from the data cache and synchronize the instruction cache if caches are enabled. +4. Enter the image on hart 0 in M-mode with interrupts disabled, no active DMA and no outstanding claimed PLIC interrupts. + +Connect a serial terminal to UART0 using 115200 baud, 8 data bits, no parity, 1 stop bit and no flow control. After boot, the console displays: + +```text +RT-Thread Operating System +D213ECV-DEMO-V4-0 +msh > +``` + +Use `help` to list shell commands, `ps` to view threads, `free` to view heap usage, and `list device` to view registered devices. The default configuration registers `uart0`. + +## UART usage + +UART0 is enabled by default. To change its format, use `RT_DEVICE_CTRL_CONFIG` with `struct serial_configure` before opening the device. Supported formats are 5–8 data bits, no/odd/even parity, and one or two stop bits, except for 5 data bits with two stop bits. The available baud rates depend on the configured input clock and the hardware divisor range of 1–65535. + +Open with `RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX` for buffered reception and receive callbacks. In this driver, `INT_RX` uses a polling thread rather than hardware interrupts. Polling reads are available when opened without `INT_RX`. + +Stop traffic before reconfiguring the device because configuration clears the hardware FIFOs. Transmit waits have a timeout; check the returned byte count for short writes. RS-485 direction control is not supported. + +## References and license + +- [ArtInChip board documentation](https://aicdoc.artinchip.com/topics/product/d213ecV4.html) +- [ArtInChip Luban-Lite SDK](https://gitee.com/artinchip/luban-lite), the source of the SoC definitions and hardware initialization sequences used by this BSP. + +The BSP is licensed under Apache-2.0. Copyright and license notices are retained in the source files. diff --git a/bsp/artinchip/d213ecv-demo-v4-0/README_zh.md b/bsp/artinchip/d213ecv-demo-v4-0/README_zh.md new file mode 100644 index 0000000000..b71ef5491a --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/README_zh.md @@ -0,0 +1,111 @@ +# D213ECV-DEMO-V4-0 + +[English](README.md) | [中文](README_zh.md) + +## 简介 + +本 BSP 支持 ArtInChip D213ECV-DEMO-V4-0 开发板,RT-Thread 在单核 T-Head C906 上以 M-mode 运行。 + +| 项目 | 说明 | +|------|------| +| SoC | ArtInChip D213ECV | +| CPU | T-Head C906,RV64GC | +| 内存 | 128 MiB DDR3,起始地址 `0x40000000` | +| 控制台 | UART0,PA.0(TX)/ PA.1(RX),115200 波特率,8N1,无流控 | + +硬件信息请参阅[官方开发板文档](https://aicdoc.artinchip.com/topics/product/d213ecV4.html)。 + +## 支持功能 + +| 功能 | 说明 | +|------|------| +| 内核移植 | RT-Thread RISC-V common port,包含双精度 FPU 上下文切换 | +| 系统时钟 | CLINT 定时器,默认系统 Tick 为 1000 Hz | +| 中断控制器 | PLIC | +| UART0 | Serial-v1,轮询发送,线程轮询接收 | +| FinSH/MSH | 默认启用 | +| 堆与设备框架 | 默认启用 | + +UART0 面向交互式控制台,持续输入或调度长时间延迟可能导致数据丢失。不支持 UART 硬件中断、DMA 和流控。BSP 提供 UART0 所需的时钟、复位和引脚配置,DDR 与 PLL 由 Bootloader 初始化。 + +## 构建与配置 + +安装 Python 3、SCons、kconfiglib,以及支持 RV64GC 和 `lp64d` ABI 的 GNU 裸机 RISC-V 工具链。推荐使用 GCC 10.2.0。 + +在仓库根目录执行: + +```sh +python -m pip install scons kconfiglib +cd bsp/artinchip/d213ecv-demo-v4-0 +export RTT_EXEC_PATH=/path/to/riscv-toolchain/bin +scons --pyconfig-silent +scons -j8 +``` + +PowerShell 中使用 `$env:RTT_EXEC_PATH = 'C:/path/to/riscv-toolchain/bin'` 设置工具链路径。默认编译器前缀为 `riscv64-unknown-elf-`,使用其他前缀时设置 `RTT_CC_PREFIX`。也可通过 PATH 查找编译器。 + +构建产物为 `rtthread.elf`、`rtthread.bin` 和 `rtthread.map`。 + +修改配置时执行: + +```sh +scons --menuconfig +scons --pyconfig-silent +scons -j8 +``` + +请通过配置工具生成 `rtconfig.h`,不要直接编辑该文件。 + +| 板级选项 | 默认值 | 说明 | +|----------|--------|------| +| `BSP_USING_UART0` | 启用 | UART0 控制台,依赖 Serial-v1 | +| `BSP_UART_CLK_FREQ` | 48000000 | UART0 输入时钟,单位 Hz | +| `BSP_CLINT_FREQ` | 4000000 | CLINT 时基,单位 Hz | + +时钟设置必须与 Bootloader 配置一致,这些选项不会改变硬件时钟分频器。UART0 驱动不支持 Serial-v2。 + +UTest 默认关闭。如需使用,在 menuconfig 中启用 `RT_USING_UTESTCASES` 并选择所需测试用例,然后重新生成配置并构建。 + +使用 `scons --dist` 导出独立工程。解压 `dist/project.zip`,清除已设置的 `RTT_ROOT` 环境变量,在解压后的 `project/` 目录运行相同的配置与构建命令。 + +## 下载与运行 + +本 BSP 需要外部 ArtInChip 兼容 Bootloader。请按 Bootloader 要求将 `rtthread.bin` 打包为 FIT 或烧录镜像,并使用匹配的分区布局。 + +| 区域 | 地址范围 | +|------|----------| +| RT-Thread,包含堆 | `0x40000000`–`0x477fffff`(120 MiB)| +| Bootloader 保留区 | `0x47800000`–`0x47ffffff`(8 MiB)| +| BIN 加载地址与 ELF 入口 | `0x40000000` | + +进入 RT-Thread 前,Bootloader 必须: + +1. 初始化 DDR、PLL、总线时钟及 CPU 内存/Cache 属性,将 MMIO 区域设为不可缓存。 +2. 提供与 BSP 配置一致的 UART0 输入时钟和 CLINT 时基。 +3. 将镜像加载到 `0x40000000`;Cache 开启时,将已加载数据从数据 Cache 写回,并同步指令 Cache。 +4. 在 hart 0、M-mode 下进入镜像,进入时关闭中断,无活动 DMA,也无尚未完成的已 claim PLIC 中断。 + +将串口终端连接至 UART0,设置为 115200 波特率、8 位数据、无校验、1 位停止位、无流控。启动后控制台显示: + +```text +RT-Thread Operating System +D213ECV-DEMO-V4-0 +msh > +``` + +使用 `help` 查看 shell 命令,`ps` 查看线程,`free` 查看堆使用情况,`list device` 查看注册设备。默认配置注册 `uart0`。 + +## UART 使用 + +UART0 默认启用。修改串口格式时,在打开设备前通过 `RT_DEVICE_CTRL_CONFIG` 和 `struct serial_configure` 配置。支持 5–8 位数据、无/奇/偶校验、1 或 2 位停止位,但不支持 5 位数据加 2 位停止位。可用波特率取决于配置的输入时钟和 1–65535 的硬件分频范围。 + +使用 `RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX` 打开设备可启用缓冲接收与接收回调。本驱动的 `INT_RX` 通过轮询线程实现,不使用硬件中断。不带 `INT_RX` 打开时可轮询读取。 + +重新配置会清空硬件 FIFO,请先停止收发。发送等待有超时限制,应检查返回的实际写入字节数。不支持 RS-485 方向控制。 + +## 参考资料与许可证 + +- [ArtInChip 开发板文档](https://aicdoc.artinchip.com/topics/product/d213ecV4.html) +- [ArtInChip Luban-Lite SDK](https://gitee.com/artinchip/luban-lite),本 BSP 使用的 SoC 定义与硬件初始化时序来源。 + +BSP 使用 Apache-2.0 许可证,源码文件保留相应版权与许可证声明。 diff --git a/bsp/artinchip/d213ecv-demo-v4-0/SConscript b/bsp/artinchip/d213ecv-demo-v4-0/SConscript new file mode 100644 index 0000000000..07fb08dced --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/SConscript @@ -0,0 +1,5 @@ +from building import * + +objs = SConscript('board/SConscript') +objs += SConscript('applications/SConscript') +Return('objs') diff --git a/bsp/artinchip/d213ecv-demo-v4-0/SConstruct b/bsp/artinchip/d213ecv-demo-v4-0/SConstruct new file mode 100644 index 0000000000..3e09818a7b --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/SConstruct @@ -0,0 +1,28 @@ +import os +import sys +import rtconfig + +RTT_ROOT = os.getenv('RTT_ROOT') or os.path.join(os.getcwd(), '..', '..', '..') +sys.path.append(os.path.join(RTT_ROOT, 'tools')) +from building import * + +TARGET = 'rtthread.' + rtconfig.TARGET_EXT + +DefaultEnvironment(tools=[]) +env = Environment(tools=['mingw'], + AS=rtconfig.AS, ASFLAGS=rtconfig.AFLAGS, + CC=rtconfig.CC, CCFLAGS=rtconfig.CFLAGS, + CXX=rtconfig.CXX, CXXFLAGS=rtconfig.CXXFLAGS, + AR=rtconfig.AR, ARFLAGS='-rc', + LINK=rtconfig.LINK, LINKFLAGS=rtconfig.LFLAGS) +env.PrependENVPath('PATH', rtconfig.EXEC_PATH) +env['ASCOM'] = env['ASPPCOM'] + +Export('RTT_ROOT', 'rtconfig') +objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) + +# The dist project carries the shared SoC sources inside its own root. +libraries = 'libraries' if os.path.isdir('libraries') else '../libraries' +objs += SConscript(os.path.join(libraries, 'SConscript'), + variant_dir='build/libraries', duplicate=0) +DoBuilding(TARGET, objs) diff --git a/bsp/artinchip/d213ecv-demo-v4-0/applications/SConscript b/bsp/artinchip/d213ecv-demo-v4-0/applications/SConscript new file mode 100644 index 0000000000..bf8f3af7ca --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/applications/SConscript @@ -0,0 +1,4 @@ +from building import * + +group = DefineGroup('Applications', ['main.c'], depend=['']) +Return('group') diff --git a/bsp/artinchip/d213ecv-demo-v4-0/applications/main.c b/bsp/artinchip/d213ecv-demo-v4-0/applications/main.c new file mode 100644 index 0000000000..0e2616c928 --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/applications/main.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include <rtthread.h> + +int main(void) +{ + rt_kprintf("D213ECV-DEMO-V4-0\n"); + return 0; +} diff --git a/bsp/artinchip/d213ecv-demo-v4-0/board/Kconfig b/bsp/artinchip/d213ecv-demo-v4-0/board/Kconfig new file mode 100644 index 0000000000..b1a36044c8 --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/board/Kconfig @@ -0,0 +1,38 @@ +config SOC_D213 + bool + default y + select AIC_SOC_D21X + select ARCH_CPU_64BIT + select ARCH_RISCV + select ARCH_RISCV64 + select ARCH_RISCV_FPU + select ARCH_RISCV_FPU_D + select ARCH_RISCV_M_MODE + select RT_USING_RISCV_NEW_COMMON + select RT_USING_ADT + select RT_USING_ADT_BITMAP + select RT_USING_COMPONENTS_INIT + select RT_USING_USER_MAIN + +menu "Board options" + +config BSP_USING_UART0 + bool "Enable UART0 console" + depends on RT_USING_SERIAL_V1 + default y + help + UART0 on PA.0/PA.1. Transmit is polled; a polling thread supplies + the serial-v1 receive FIFO. UART hardware interrupts and DMA are + not supported in this initial BSP. + +config BSP_UART_CLK_FREQ + int "Bootloader-configured UART0 input clock (Hz)" + range 1843200 200000000 + default 48000000 + +config BSP_CLINT_FREQ + int "Bootloader-configured CLINT timebase (Hz)" + range 1000000 100000000 + default 4000000 + +endmenu diff --git a/bsp/artinchip/d213ecv-demo-v4-0/board/SConscript b/bsp/artinchip/d213ecv-demo-v4-0/board/SConscript new file mode 100644 index 0000000000..9bb16647dd --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/board/SConscript @@ -0,0 +1,5 @@ +from building import * + +group = DefineGroup('Board', ['board.c'], depend=[''], + CPPPATH=[GetCurrentDir()]) +Return('group') diff --git a/bsp/artinchip/d213ecv-demo-v4-0/board/board.c b/bsp/artinchip/d213ecv-demo-v4-0/board/board.c new file mode 100644 index 0000000000..532d9d22df --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/board/board.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022-2026, ArtInChip Technology Co., Ltd + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include <rthw.h> +#include <rtdevice.h> +#include <isa_ext.h> +#include <riscv_timer.h> +#include "board.h" + +extern char __heap_start[], __heap_end[]; +extern int rt_hw_tick_init(void); + +void rt_hw_board_init(void) +{ + riscv_isa_ext_set(I); + riscv_isa_ext_set(M); + riscv_isa_ext_set(A); + riscv_isa_ext_set(F); + riscv_isa_ext_set(D); + riscv_isa_ext_set(C); + + riscv_timer_set_frequency(BSP_CLINT_FREQ); + aic_soc_init(); + aic_interrupt_init(); + aic_clock_init(); + +#ifdef BSP_USING_UART0 + /* D213ECV-DEMO-V4-0: PA.0 TX / PA.1 RX, function 5, drive 3. */ + aic_write32(AIC_GPIO_BASE + 0x80, 0x35); + aic_write32(AIC_GPIO_BASE + 0x84, 0x335); +#endif + +#ifdef RT_USING_HEAP + rt_system_heap_init(__heap_start, __heap_end); +#endif + + rt_hw_interrupt_init(); + rt_hw_tick_init(); + +#ifdef BSP_USING_UART0 + rt_hw_serial_init(); +#endif + +#ifdef RT_USING_COMPONENTS_INIT + rt_components_board_init(); +#endif + +#if defined(RT_USING_CONSOLE) && defined(BSP_USING_UART0) + rt_console_set_device(RT_CONSOLE_DEVICE_NAME); +#endif +} diff --git a/bsp/artinchip/d213ecv-demo-v4-0/board/board.h b/bsp/artinchip/d213ecv-demo-v4-0/board/board.h new file mode 100644 index 0000000000..0918d6b64b --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/board/board.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __BOARD_H__ +#define __BOARD_H__ + +#include <rtthread.h> +#include <interrupt.h> +#include "aic_soc.h" + +#define MAX_HANDLERS 128 +#define INTC_TYPE INTC_TYPE_RISCV + +void rt_hw_serial_init(void); + +#endif /* __BOARD_H__ */ diff --git a/bsp/artinchip/d213ecv-demo-v4-0/link.lds b/bsp/artinchip/d213ecv-demo-v4-0/link.lds new file mode 100644 index 0000000000..40cdfda2f9 --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/link.lds @@ -0,0 +1,131 @@ +/* D213ECV-DEMO-V4-0: 128 MiB DDR, loader-owned upper 8 MiB. + * SPDX-License-Identifier: Apache-2.0 + */ +OUTPUT_ARCH("riscv") +ENTRY(_start) + +MEMORY +{ + DRAM (rwx) : ORIGIN = 0x40000000, LENGTH = 0x07800000 /* top 8 MiB reserved for the loader */ +} + +SECTIONS +{ + . = ORIGIN(DRAM); + + .text : { + PROVIDE(__text_start = .); + KEEP(*(.start)) + KEEP(*(.text.start)) + KEEP(*(.text.entry)) + *(.text) + *(.text.*) + *(.gnu.linkonce.t*) + . = ALIGN(8); + + . = ALIGN(8); + __fsymtab_start = .; + KEEP(*(FSymTab)) + __fsymtab_end = .; + . = ALIGN(8); + __vsymtab_start = .; + KEEP(*(VSymTab)) + __vsymtab_end = .; + . = ALIGN(8); + __rtmsymtab_start = .; + KEEP(*(RTMSymTab)) + __rtmsymtab_end = .; + . = ALIGN(8); + __rt_init_start = .; + KEEP(*(SORT(.rti_fn*))) + __rt_init_end = .; + + . = ALIGN(8); + __rt_utest_tc_tab_start = .; + KEEP(*(UtestTcTab)) + __rt_utest_tc_tab_end = .; + + . = ALIGN(8); + __etext = .; + } > DRAM + + .rodata : { + . = ALIGN(8); + __srodata = .; + *(.rodata) + *(.rodata.*) + *(.srodata) + *(.srodata.*) + *(.rdata) + *(.rdata.*) + . = ALIGN(8); + __ctors_start__ = .; + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + __ctors_end__ = .; + __dtors_start__ = .; + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + __dtors_end__ = .; + . = ALIGN(8); + __rodata_end__ = .; + } > DRAM + + .data : { + . = ALIGN(8); + __data_start__ = .; + __global_pointer$ = . + 0x800; + *(.data) + *(.data.*) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.d*) + . = ALIGN(8); + __data_end__ = .; + } > DRAM + + .bss (NOLOAD) : { + . = ALIGN(8); + __bss_noclean_start = .; + *(.bss.noclean.*) + __bss_noclean_end = .; + . = ALIGN(8); + __bss_start = .; + *(.bss) + *(.bss.*) + *(.sbss) + *(.sbss.*) + *(COMMON) + . = ALIGN(8); + __bss_end = .; + } > DRAM + + .percpu (NOLOAD) : { + . = ALIGN(16); + __percpu_start = .; + *(.percpu) + __percpu_end = .; + __percpu_real_end = .; + } > DRAM + + _end = .; + __bss_start__ = __bss_start; + __bss_end__ = __bss_end; + + . = ALIGN(16); + __heap_start = .; + + __heap_end = ORIGIN(DRAM) + LENGTH(DRAM); + + /DISCARD/ : { + *(.eh_frame) + *(.eh_frame_hdr) + *(.comment) + } +} + +ASSERT(__data_end__ <= __bss_start__, "data overlaps bss") +ASSERT(__bss_end__ <= __heap_start, "bss overlaps heap") +ASSERT(__percpu_start <= __percpu_end, "percpu section is invalid") +ASSERT(__heap_start < __heap_end, "heap is empty") +ASSERT((__percpu_end & 15) == 0, "early stack is not ABI aligned") diff --git a/bsp/artinchip/d213ecv-demo-v4-0/rtconfig.h b/bsp/artinchip/d213ecv-demo-v4-0/rtconfig.h new file mode 100644 index 0000000000..ab49bfcb5f --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/rtconfig.h @@ -0,0 +1,222 @@ +#ifndef RT_CONFIG_H__ +#define RT_CONFIG_H__ + +/* RT-Thread Kernel */ + +/* klibc options */ + +/* rt_vsnprintf options */ + +#define RT_KLIBC_USING_VSNPRINTF_LONGLONG +#define RT_KLIBC_USING_VSNPRINTF_STANDARD +#define RT_KLIBC_USING_VSNPRINTF_DECIMAL_SPECIFIERS +#define RT_KLIBC_USING_VSNPRINTF_EXPONENTIAL_SPECIFIERS +#define RT_KLIBC_USING_VSNPRINTF_WRITEBACK_SPECIFIER +#define RT_KLIBC_USING_VSNPRINTF_CHECK_NUL_IN_FORMAT_SPECIFIER +#define RT_KLIBC_USING_VSNPRINTF_INTEGER_BUFFER_SIZE 32 +#define RT_KLIBC_USING_VSNPRINTF_DECIMAL_BUFFER_SIZE 32 +#define RT_KLIBC_USING_VSNPRINTF_FLOAT_PRECISION 6 +#define RT_KLIBC_USING_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL 9 +#define RT_KLIBC_USING_VSNPRINTF_LOG10_TAYLOR_TERMS 4 +/* end of rt_vsnprintf options */ + +/* rt_vsscanf options */ + +/* end of rt_vsscanf options */ + +/* rt_memset options */ + +/* end of rt_memset options */ + +/* rt_memcpy options */ + +/* end of rt_memcpy options */ + +/* rt_memmove options */ + +/* end of rt_memmove options */ + +/* rt_memcmp options */ + +/* end of rt_memcmp options */ + +/* rt_strstr options */ + +/* end of rt_strstr options */ + +/* rt_strcasecmp options */ + +/* end of rt_strcasecmp options */ + +/* rt_strncpy options */ + +/* end of rt_strncpy options */ + +/* rt_strcpy options */ + +/* end of rt_strcpy options */ + +/* rt_strncmp options */ + +/* end of rt_strncmp options */ + +/* rt_strcmp options */ + +/* end of rt_strcmp options */ + +/* rt_strlen options */ + +/* end of rt_strlen options */ + +/* rt_strnlen options */ + +/* end of rt_strnlen options */ +/* end of klibc options */ +#define RT_NAME_MAX 16 +#define RT_CPUS_NR 1 +#define RT_ALIGN_SIZE 8 +#define RT_THREAD_PRIORITY_32 +#define RT_THREAD_PRIORITY_MAX 32 +#define RT_TICK_PER_SECOND 1000 +#define RT_USING_OVERFLOW_CHECK +#define IDLE_THREAD_STACK_SIZE 2048 + +/* kservice options */ + +/* end of kservice options */ +#define RT_USING_DEBUG +#define RT_DEBUGING_ASSERT + +/* Inter-Thread communication */ + +#define RT_USING_SEMAPHORE +#define RT_USING_MUTEX +#define RT_USING_EVENT +#define RT_USING_MAILBOX +#define RT_USING_MESSAGEQUEUE +/* end of Inter-Thread communication */ + +/* Memory Management */ + +#define RT_USING_SMALL_MEM +#define RT_USING_SMALL_MEM_AS_HEAP +#define RT_USING_HEAP +/* end of Memory Management */ +#define RT_USING_DEVICE +#define RT_USING_DEVICE_OPS +#define RT_USING_CONSOLE +#define RT_CONSOLEBUF_SIZE 128 +#define RT_CONSOLE_DEVICE_NAME "uart0" +#define RT_VER_NUM 0x50400 +#define RT_BACKTRACE_LEVEL_MAX_NR 32 +/* end of RT-Thread Kernel */ +#define ARCH_TEXT_OFFSET 0x200000 +#define ARCH_RAM_OFFSET 0 +#define ARCH_CPU_64BIT +#define RT_USING_CPU_FFS +#define ARCH_RISCV +#define ARCH_RISCV_FPU +#define ARCH_RISCV_FPU_D +#define ARCH_RISCV64 + +/* RISC-V Architecture Configuration */ + +#define RT_USING_RISCV_NEW_COMMON +#define ARCH_RISCV_M_MODE +#define ARCH_RISCV_USING_IRQ_STACK +#define ARCH_RISCV_IRQ_STACK_SIZE 4096 +/* end of RISC-V Architecture Configuration */ +#define ARCH_USING_NEW_CTX_SWITCH + +/* RT-Thread Components */ + +#define RT_USING_COMPONENTS_INIT +#define RT_USING_USER_MAIN +#define RT_MAIN_THREAD_STACK_SIZE 4096 +#define RT_MAIN_THREAD_PRIORITY 10 +#define RT_USING_MSH +#define RT_USING_FINSH +#define FINSH_USING_MSH +#define FINSH_THREAD_NAME "tshell" +#define FINSH_THREAD_PRIORITY 20 +#define FINSH_THREAD_STACK_SIZE 4096 +#define FINSH_USING_HISTORY +#define FINSH_HISTORY_LINES 5 +#define FINSH_USING_SYMTAB +#define FINSH_CMD_SIZE 80 +#define MSH_USING_BUILT_IN_COMMANDS +#define FINSH_USING_DESCRIPTION +#define FINSH_ARG_MAX 10 +#define FINSH_USING_OPTION_COMPLETION + +/* DFS: device virtual file system */ + +/* end of DFS: device virtual file system */ + +/* Device Drivers */ + +#define RT_USING_DEVICE_IPC +#define RT_UNAMED_PIPE_NUMBER 64 +#define RT_USING_SERIAL +#define RT_USING_SERIAL_V1 +#define RT_SERIAL_RB_BUFSZ 512 +/* end of Device Drivers */ + +/* C/C++ and POSIX layer */ + +/* ISO-ANSI C layer */ + +/* Timezone and Daylight Saving Time */ + +#define RT_LIBC_USING_LIGHT_TZ_DST +#define RT_LIBC_TZ_DEFAULT_HOUR 8 +#define RT_LIBC_TZ_DEFAULT_MIN 0 +#define RT_LIBC_TZ_DEFAULT_SEC 0 +/* end of Timezone and Daylight Saving Time */ +/* end of ISO-ANSI C layer */ + +/* POSIX (Portable Operating System Interface) layer */ + + +/* Interprocess Communication (IPC) */ + + +/* Socket is in the 'Network' category */ + +/* end of Interprocess Communication (IPC) */ +/* end of POSIX (Portable Operating System Interface) layer */ +/* end of C/C++ and POSIX layer */ + +/* Network */ + +/* end of Network */ + +/* Memory protection */ + +/* end of Memory protection */ + +/* Utilities */ + +#define RT_USING_ADT +#define RT_USING_ADT_BITMAP +/* end of Utilities */ + +/* Using USB legacy version */ + +/* end of Using USB legacy version */ +/* end of RT-Thread Components */ + +/* RT-Thread Utestcases */ + +/* end of RT-Thread Utestcases */ +#define AIC_SOC_D21X +#define SOC_D213 + +/* Board options */ + +#define BSP_USING_UART0 +#define BSP_UART_CLK_FREQ 48000000 +#define BSP_CLINT_FREQ 4000000 +/* end of Board options */ + +#endif diff --git a/bsp/artinchip/d213ecv-demo-v4-0/rtconfig.py b/bsp/artinchip/d213ecv-demo-v4-0/rtconfig.py new file mode 100644 index 0000000000..7986697b7c --- /dev/null +++ b/bsp/artinchip/d213ecv-demo-v4-0/rtconfig.py @@ -0,0 +1,49 @@ +import os +import shutil +import subprocess + +ARCH = 'risc-v' +CPU = 'c906' +CROSS_TOOL = 'gcc' +PLATFORM = 'gcc' +EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '' +PREFIX = os.getenv('RTT_CC_PREFIX') or 'riscv64-unknown-elf-' + +CC = PREFIX + 'gcc' +CXX = PREFIX + 'g++' +AS = CC +AR = PREFIX + 'ar' +LINK = CC +SIZE = PREFIX + 'size' +OBJCPY = PREFIX + 'objcopy' +OBJDUMP = PREFIX + 'objdump' +TARGET_EXT = 'elf' + +# Accept both the CI GCC 10 ISA spelling and newer GNU assemblers. +compiler = os.path.join(EXEC_PATH, CC) if EXEC_PATH else shutil.which(CC) +if compiler and os.name == 'nt' and not compiler.lower().endswith('.exe'): + compiler += '.exe' +isa = 'rv64imafdc' +if compiler and os.path.isfile(compiler): + version = subprocess.check_output([compiler, '-dumpversion']).decode() + if int(version.split('.')[0]) >= 12: + isa += '_zicsr_zifencei' +if not EXEC_PATH and compiler: + EXEC_PATH = os.path.dirname(compiler) + +DEVICE = ' -march=' + isa + ' -mabi=lp64d -mcmodel=medany' +CFLAGS = DEVICE + ' -O2 -g -Wall -ffunction-sections -fdata-sections -fno-common' +CXXFLAGS = CFLAGS +AFLAGS = DEVICE + ' -c -g -x assembler-with-cpp -D__ASSEMBLY__' +LFLAGS = DEVICE + ' -nostartfiles -Wl,--gc-sections -Wl,-Map=rtthread.map -T link.lds' +CPATH = '' +LPATH = '' +POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET\n' + + +def dist_handle(BSP_ROOT, dist_dir): + from mkdist import do_copy_folder + libraries = os.path.join(BSP_ROOT, 'libraries') + if not os.path.isdir(libraries): + libraries = os.path.join(BSP_ROOT, '..', 'libraries') + do_copy_folder(libraries, os.path.join(dist_dir, 'libraries')) diff --git a/bsp/artinchip/libraries/Kconfig b/bsp/artinchip/libraries/Kconfig new file mode 100644 index 0000000000..1dd9be6fd0 --- /dev/null +++ b/bsp/artinchip/libraries/Kconfig @@ -0,0 +1,6 @@ +config AIC_SOC_D21X + bool + default n + help + Selects the ArtInChip D21x SoC layer. This initial port supports + D213 only; other family members require separate validation. diff --git a/bsp/artinchip/libraries/SConscript b/bsp/artinchip/libraries/SConscript new file mode 100644 index 0000000000..7615e47f63 --- /dev/null +++ b/bsp/artinchip/libraries/SConscript @@ -0,0 +1,4 @@ +from building import * + +group = SConscript('soc/d21x/SConscript') +Return('group') diff --git a/bsp/artinchip/libraries/include/aic_uart_reg.h b/bsp/artinchip/libraries/include/aic_uart_reg.h new file mode 100644 index 0000000000..7d4383ccee --- /dev/null +++ b/bsp/artinchip/libraries/include/aic_uart_reg.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021-2026, ArtInChip Technology Co., Ltd + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * ArtInChip UART register layout. + * + * Register offsets and fields used by the D213 UART controllers. + * + * Derived from the ArtInChip Luban-Lite HAL + * (bsp/artinchip/hal/uart/aic_hal_uart.c, Apache-2.0). + */ + +#ifndef __AIC_UART_REG_H__ +#define __AIC_UART_REG_H__ + +/* Register offsets */ +#define UART_RBR 0x00 +#define UART_THR 0x00 +#define UART_DLL 0x00 +#define UART_DLH 0x04 +#define UART_IER 0x04 +#define UART_FCR 0x08 +#define UART_LCR 0x0C +#define UART_MCR 0x10 +#define UART_LSR 0x14 +#define UART_USR 0x7C + +/* Line status register */ +#define UART_LSR_DR 0x01 +#define UART_LSR_THRE 0x20 + +/* UART status register */ +#define UART_USR_BUSY 0x01 +#define UART_USR_TFNF 0x02 + +/* Line control register */ +#define UART_LCR_DLAB 0x80 +#define UART_LCR_8N1 0x03 +#define UART_LCR_STOP 0x04 +#define UART_LCR_PARITY 0x08 +#define UART_LCR_EVEN 0x10 + +/* FIFO control register */ +#define UART_FCR_ENABLE 0x01 +#define UART_FCR_RX_RESET 0x02 +#define UART_FCR_TX_RESET 0x04 + +/* Vendor non-DMA FIFO thresholds: TX level 3, RX level 2. */ +#define UART_FCR_TX_TRIGGER (3U << 4) +#define UART_FCR_RX_TRIGGER (2U << 6) + +#endif /* __AIC_UART_REG_H__ */ diff --git a/bsp/artinchip/libraries/soc/d21x/SConscript b/bsp/artinchip/libraries/soc/d21x/SConscript new file mode 100644 index 0000000000..70124d6aeb --- /dev/null +++ b/bsp/artinchip/libraries/soc/d21x/SConscript @@ -0,0 +1,10 @@ +from building import * + +cwd = GetCurrentDir() +src = ['port/system.c', 'port/clock.c', 'port/interrupt.c', 'port/timer.c'] +if GetDepend('BSP_USING_UART0'): + src += ['drivers/drv_uart.c'] + +group = DefineGroup('D21x', src, depend=['AIC_SOC_D21X'], + CPPPATH=[cwd + '/include', cwd + '/../../include']) +Return('group') diff --git a/bsp/artinchip/libraries/soc/d21x/drivers/drv_uart.c b/bsp/artinchip/libraries/soc/d21x/drivers/drv_uart.c new file mode 100644 index 0000000000..c04a91bac4 --- /dev/null +++ b/bsp/artinchip/libraries/soc/d21x/drivers/drv_uart.c @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2021-2026, ArtInChip Technology Co., Ltd + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * D213 serial-v1 adapter. Register sequence adapted from Luban-Lite + * bsp/artinchip/hal/uart/aic_hal_uart.c. No vendor OSAL or DMA dependency. + */ + +#include <rthw.h> +#include <rtdevice.h> +#include <interrupt.h> +#include <riscv_timer.h> +#include "aic_soc.h" +#include "aic_uart_reg.h" + +struct aic_uart +{ + struct rt_serial_device serial; + rt_ubase_t base; + rt_ubase_t clock_reg; + int irq; + const char *name; + rt_bool_t rx_enabled; + rt_uint64_t tx_timeout_ticks; +}; + +static struct aic_uart uart0 = { + .base = AIC_UART0_BASE, + .clock_reg = AIC_CMU_UART0, + .irq = AIC_UART0_IRQ, + .name = "uart0", + .tx_timeout_ticks = BSP_CLINT_FREQ / 10, +}; +static struct rt_thread rx_thread; +rt_align(RT_ALIGN_SIZE) static rt_uint8_t rx_stack[1024]; + +static rt_err_t aic_uart_configure(struct rt_serial_device *serial, + struct serial_configure *cfg) +{ + struct aic_uart *uart = serial->parent.user_data; + rt_uint32_t divisor, lcr, old_lcr, frame_bits; + rt_uint64_t deadline, tx_timeout; + rt_err_t ret = -RT_EIO; + rt_base_t level; + + if (!cfg->baud_rate || cfg->data_bits < DATA_BITS_5 || + cfg->data_bits > DATA_BITS_8 || + (cfg->stop_bits != STOP_BITS_1 && cfg->stop_bits != STOP_BITS_2) || + (cfg->data_bits == DATA_BITS_5 && cfg->stop_bits == STOP_BITS_2) || + (cfg->parity != PARITY_NONE && cfg->parity != PARITY_ODD && + cfg->parity != PARITY_EVEN) || + cfg->bit_order != BIT_ORDER_LSB || cfg->invert != NRZ_NORMAL || + cfg->flowcontrol != RT_SERIAL_FLOWCONTROL_NONE) + { + /* With five data bits the hardware STOP bit means 1.5 stop bits, + * which serial-v1 cannot represent. Reject a request for two. */ + return -RT_EINVAL; + } + lcr = cfg->data_bits - DATA_BITS_5; + if (cfg->stop_bits == STOP_BITS_2) + { + lcr |= UART_LCR_STOP; + } + if (cfg->parity != PARITY_NONE) + { + lcr |= UART_LCR_PARITY; + if (cfg->parity == PARITY_EVEN) + { + lcr |= UART_LCR_EVEN; + } + } + divisor = ((rt_uint64_t)BSP_UART_CLK_FREQ + cfg->baud_rate * 8ULL) / + (cfg->baud_rate * 16ULL); + if (!divisor || divisor > 0xffff) + { + return -RT_EINVAL; + } + + /* TFNF needs one FIFO slot, not an empty FIFO. Allow two actual frame + * times, rounded up, with the existing 100 ms minimum for fast rates. */ + frame_bits = 1 + cfg->data_bits + (cfg->parity != PARITY_NONE) + + (cfg->stop_bits == STOP_BITS_2 ? 2 : 1); + tx_timeout = (16ULL * divisor * frame_bits * BSP_CLINT_FREQ + BSP_UART_CLK_FREQ - 1) / + BSP_UART_CLK_FREQ; + tx_timeout *= 2; + if (tx_timeout < BSP_CLINT_FREQ / 10) + { + tx_timeout = BSP_CLINT_FREQ / 10; + } + + deadline = riscv_timer_rdtime() + BSP_CLINT_FREQ / 10; + for (;;) + { + level = rt_hw_interrupt_disable(); + /* Like the vendor HAL, reset FIFOs before waiting for idle. + * A busy controller can ignore LCR writes; DLL then aliases THR. */ + aic_write32(uart->base + UART_FCR, + UART_FCR_ENABLE | UART_FCR_RX_RESET | UART_FCR_TX_RESET | + UART_FCR_TX_TRIGGER | UART_FCR_RX_TRIGGER); + if (!(aic_read32(uart->base + UART_USR) & UART_USR_BUSY)) + { + break; + } + rt_hw_interrupt_enable(level); + if (riscv_timer_rdtime() >= deadline) + { + return -RT_ETIMEOUT; + } + } + /* IER aliases DLH while DLAB is set, including on loader handoff. */ + old_lcr = aic_read32(uart->base + UART_LCR) & ~UART_LCR_DLAB; + aic_write32(uart->base + UART_LCR, old_lcr); + if (aic_read32(uart->base + UART_LCR) & UART_LCR_DLAB) + { + goto restore_lcr; + } + aic_write32(uart->base + UART_IER, 0); + aic_write32(uart->base + UART_LCR, lcr | UART_LCR_DLAB); + if ((aic_read32(uart->base + UART_LCR) & 0xff) != (lcr | UART_LCR_DLAB)) + { + goto restore_lcr; + } + aic_write32(uart->base + UART_DLL, divisor & 0xff); + aic_write32(uart->base + UART_DLH, divisor >> 8); + aic_write32(uart->base + UART_LCR, lcr); + if ((aic_read32(uart->base + UART_LCR) & 0xff) != lcr) + { + goto restore_lcr; + } + aic_write32(uart->base + UART_MCR, 0); + uart->tx_timeout_ticks = tx_timeout; + ret = RT_EOK; + goto out; + +restore_lcr: + aic_write32(uart->base + UART_LCR, old_lcr); +out: + rt_hw_interrupt_enable(level); + return ret; +} + +static rt_err_t aic_uart_control(struct rt_serial_device *serial, int cmd, void *arg) +{ + struct aic_uart *uart = serial->parent.user_data; + rt_base_t level; + + switch (cmd) + { + case RT_DEVICE_CTRL_SET_INT: + case RT_DEVICE_CTRL_CLR_INT: + level = rt_hw_interrupt_disable(); + uart->rx_enabled = (cmd == RT_DEVICE_CTRL_SET_INT); + rt_hw_interrupt_enable(level); + return RT_EOK; + default: + return -RT_ENOSYS; + } +} + +static int aic_uart_putc(struct rt_serial_device *serial, char c) +{ + struct aic_uart *uart = serial->parent.user_data; + + /* Bound a stalled transmitter without depending on scheduler state. */ + rt_uint64_t start = riscv_timer_rdtime(); + + /* Like the vendor hal_usart_putchar, wait for room in the TX FIFO. + * LSR.THRE reports the TX threshold, not whether a byte can be queued. */ + while (!(aic_read32(uart->base + UART_USR) & UART_USR_TFNF)) + { + if (riscv_timer_rdtime() - start >= uart->tx_timeout_ticks) + { + return -1; + } + } + aic_write32(uart->base + UART_THR, (rt_uint8_t)c); + return 1; +} + +static int aic_uart_getc(struct rt_serial_device *serial) +{ + struct aic_uart *uart = serial->parent.user_data; + + if (aic_read32(uart->base + UART_LSR) & UART_LSR_DR) + { + return aic_read32(uart->base + UART_RBR) & 0xff; + } + return -1; +} + +static const struct rt_uart_ops aic_uart_ops = { + .configure = aic_uart_configure, + .control = aic_uart_control, + .putc = aic_uart_putc, + .getc = aic_uart_getc, +}; + +static void aic_uart_rx_poll(void *parameter) +{ + for (;;) + { + rt_base_t level = rt_hw_interrupt_disable(); + + /* Serial-v1 owns the FIFO. Serialize with close/reconfigure + * so the single-core poller cannot access a freed FIFO. */ + if (uart0.rx_enabled && uart0.serial.serial_rx != RT_NULL && + (aic_read32(uart0.base + UART_LSR) & UART_LSR_DR)) + { + rt_hw_serial_isr(&uart0.serial, RT_SERIAL_EVENT_RX_IND); + } + rt_hw_interrupt_enable(level); + rt_thread_mdelay(1); + } +} + +static int aic_uart_poll_init(void) +{ + rt_err_t ret; + int priority = RT_THREAD_PRIORITY_MAX / 2; + +#ifdef RT_USING_FINSH + /* Poll RX even while the shell is busy transmitting console output. */ + priority = FINSH_THREAD_PRIORITY > 0 ? FINSH_THREAD_PRIORITY - 1 : 0; +#endif + + ret = rt_thread_init(&rx_thread, "uart0rx", aic_uart_rx_poll, RT_NULL, + rx_stack, sizeof(rx_stack), priority, 10); + if (ret != RT_EOK) + { + return ret; + } + return rt_thread_startup(&rx_thread); +} +INIT_DEVICE_EXPORT(aic_uart_poll_init); + +void rt_hw_serial_init(void) +{ + struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; + rt_err_t ret; + + rt_uint32_t value = aic_read32(uart0.clock_reg); + + /* Drop loader state while retaining the divider and gate bits. */ + aic_write32(uart0.clock_reg, value & ~(1U << 13)); + rt_hw_us_delay(30); + aic_write32(uart0.clock_reg, value | (1U << 13)); + rt_hw_us_delay(30); + + uart0.serial.ops = &aic_uart_ops; + uart0.serial.config = config; + rt_hw_interrupt_mask(IRQ_PLIC(uart0.irq)); + ret = rt_hw_serial_register(&uart0.serial, uart0.name, + RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, &uart0); + RT_ASSERT(ret == RT_EOK); +} diff --git a/bsp/artinchip/libraries/soc/d21x/include/aic_soc.h b/bsp/artinchip/libraries/soc/d21x/include/aic_soc.h new file mode 100644 index 0000000000..0832b6fddd --- /dev/null +++ b/bsp/artinchip/libraries/soc/d21x/include/aic_soc.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022, ArtInChip Technology Co., Ltd + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * D213 register addresses from Luban-Lite bsp/artinchip/sys/d21x. + */ + +#ifndef __AIC_SOC_H__ +#define __AIC_SOC_H__ + +#include <rtthread.h> + +#define AIC_CMU_BASE 0x18020000UL +#define AIC_GPIO_BASE 0x18700000UL +#define AIC_UART0_BASE 0x18710000UL +#define AIC_PLIC_BASE 0x20000000UL +#define AIC_CLINT_BASE 0x24000000UL +#define AIC_UART0_IRQ 76 +#define AIC_CMU_UART0 (AIC_CMU_BASE + 0x840) + +/* Order device accesses. The loader must leave MMIO non-cacheable. */ +rt_inline rt_uint32_t aic_read32(rt_ubase_t addr) +{ + rt_uint32_t value; + + __asm__ volatile("fence iorw, iorw" ::: "memory"); + value = *(volatile rt_uint32_t *)addr; + __asm__ volatile("fence iorw, iorw" ::: "memory"); + return value; +} + +rt_inline void aic_write32(rt_ubase_t addr, rt_uint32_t value) +{ + __asm__ volatile("fence iorw, iorw" ::: "memory"); + *(volatile rt_uint32_t *)addr = value; + __asm__ volatile("fence iorw, iorw" ::: "memory"); +} + +void aic_soc_init(void); +void aic_clock_init(void); +void aic_interrupt_init(void); + +#endif /* __AIC_SOC_H__ */ diff --git a/bsp/artinchip/libraries/soc/d21x/port/clock.c b/bsp/artinchip/libraries/soc/d21x/port/clock.c new file mode 100644 index 0000000000..cf3da03be7 --- /dev/null +++ b/bsp/artinchip/libraries/soc/d21x/port/clock.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022-2026, ArtInChip Technology Co., Ltd + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Gate/reset sequencing adapted from Luban-Lite bsp/artinchip/hal/cmu. + * DDR, PLLs and the bus clock tree belong to the loader. + */ + +#include <rthw.h> +#include "aic_soc.h" + +#define CMU_BUS_GATE (1U << 12) +#define CMU_RESET_N (1U << 13) +#define CMU_MODULE_GATE (1U << 8) + +static void aic_clock_enable(rt_ubase_t reg, rt_uint32_t gates) +{ + aic_write32(reg, aic_read32(reg) | gates); + rt_hw_us_delay(30); + aic_write32(reg, aic_read32(reg) | CMU_RESET_N); + rt_hw_us_delay(30); +} + +void aic_clock_init(void) +{ +#ifdef BSP_USING_UART0 + aic_clock_enable(AIC_CMU_UART0, CMU_BUS_GATE | CMU_MODULE_GATE); +#endif + aic_clock_enable(AIC_CMU_BASE + 0x83c, CMU_BUS_GATE); /* GPIO */ +} diff --git a/bsp/artinchip/libraries/soc/d21x/port/interrupt.c b/bsp/artinchip/libraries/soc/d21x/port/interrupt.c new file mode 100644 index 0000000000..f3b9dfaf0c --- /dev/null +++ b/bsp/artinchip/libraries/soc/d21x/port/interrupt.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022-2026, ArtInChip Technology Co., Ltd + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * PLIC setup adapted from Luban-Lite bsp/artinchip/sys/d21x/system.c. + */ + +#include "aic_soc.h" + +void aic_interrupt_init(void) +{ + /* Mask loader-owned sources before the common PLIC driver starts. + * Pending bits are read-only. Never complete an unclaimed source. */ + for (int i = 0; i < 32; i++) + { + aic_write32(AIC_PLIC_BASE + 0x2000 + i * 4, 0); + aic_write32(AIC_PLIC_BASE + 0x2080 + i * 4, 0); + } + /* C906 PLIC priority enable, not part of the standard PLIC block. */ + aic_write32(AIC_PLIC_BASE + 0x1ffffc, 1); +} + +rt_ubase_t platform_get_plic_base(void) +{ + return AIC_PLIC_BASE; +} + +rt_size_t platform_get_plic_size(void) +{ + return 0x210000; +} diff --git a/bsp/artinchip/libraries/soc/d21x/port/system.c b/bsp/artinchip/libraries/soc/d21x/port/system.c new file mode 100644 index 0000000000..a136a9d43c --- /dev/null +++ b/bsp/artinchip/libraries/soc/d21x/port/system.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022-2026, ArtInChip Technology Co., Ltd + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * C906 setup adapted from Luban-Lite bsp/artinchip/sys/d21x/system.c. + */ + +#include <rthw.h> +#include "aic_soc.h" + +void aic_soc_init(void) +{ + rt_ubase_t value; + + /* C906 THEADISAEE and misaligned access, as in vendor SystemInit. */ + __asm__ volatile("csrr %0, 0x7c0" : "=r"(value)); + value |= (1UL << 22) | (1UL << 15); + __asm__ volatile("csrw 0x7c0, %0" ::"r"(value) : "memory"); + + __asm__ volatile("csrr %0, mstatus" : "=r"(value)); + value = (value & ~(3UL << 13)) | (1UL << 13); + __asm__ volatile("csrw mstatus, %0" ::"r"(value) : "memory"); +} diff --git a/bsp/artinchip/libraries/soc/d21x/port/timer.c b/bsp/artinchip/libraries/soc/d21x/port/timer.c new file mode 100644 index 0000000000..c25953fe8b --- /dev/null +++ b/bsp/artinchip/libraries/soc/d21x/port/timer.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022-2026, ArtInChip Technology Co., Ltd + * Copyright (c) 2026, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * D213 timer access adapted from the ArtInChip D21x RT-Thread port. + */ + +#include <riscv_timer.h> +#include "aic_soc.h" + +/* D213 keeps mtime in the time CSR; mtimecmp uses two 32-bit stores. */ +rt_uint64_t riscv_timer_rdtime(void) +{ + rt_uint64_t value; + + __asm__ volatile("rdtime %0" : "=r"(value)); + return value; +} + +void riscv_timer_set_compare(rt_uint64_t value) +{ + rt_ubase_t cmp = AIC_CLINT_BASE + 0x4000; + + /* Prevent a transient expired value while updating the low word. */ + aic_write32(cmp + 4, RT_UINT32_MAX); + aic_write32(cmp, (rt_uint32_t)value); + aic_write32(cmp + 4, (rt_uint32_t)(value >> 32)); +} + +rt_uint64_t rt_hw_get_clock_timer_freq(void) +{ + return BSP_CLINT_FREQ; +} |
