Skip to content

Conversation

Ironside-Zhang
Copy link

本次提交为对 SpacemiT KeyStone K1的初步支持。K1芯片采用双集群(2x4核)架构,搭载X60核心,支持RVA22标准和RVV 1.0向量扩展。

本次移植遵循RT-Thread现代BSP的最佳实践,采用了libcpu分层架构和模块化驱动设计
libcpu 专用层:
在 libcpu/risc-v/spacemit/k1/ 目录下创建了K1的专用CPU适配层。(完善中)
BSP 板级支持包 (bsp/spacemit_k1/):
board 目录: 提供了针对MUSE-Pi-Pro开发板的精确硬件定义,包括内存布局(mem_layout.h)、外设基地址(board.h)和中断号(irq_num.h)。所有信息均从官方Linux SDK的DTS文件中提取,保证了准确性。
drivers 目录:
实现了pinctrl和sysctl_clk驱动框架,用于管理引脚复用和时钟。其实现逻辑同样基于对Linux DTS和驱动源码的分析。
实现了一个功能完整的drv_uart.c驱动,该驱动兼容16550A标准,并能在rt_hw_board_init中正确调用pinctrl和sysctl完成初始化,最终作为FinSH控制台。
link.lds: 编写了链接脚本,将内核加载到U-Boot期望的0x80200000地址。
Kconfig: 提供了清晰的、集中式的配置选项,允许用户方便地使能BSP和相关驱动。

Copy link

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:spacemit/k1
  • 设置PR number为 \ Set the PR number to:10817
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 spacemit/k1 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the spacemit/k1 branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions bot added the BSP label Oct 15, 2025
@Rbb666 Rbb666 requested a review from Copilot October 15, 2025 09:44
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces initial support for the SpacemiT KeyStone K1 processor in RT-Thread. The K1 is a dual-cluster (2x4 core) RISC-V processor featuring X60 cores with RVA22 standard and RVV 1.0 vector extensions support. The implementation follows RT-Thread's modern BSP best practices with a layered libcpu architecture and modular driver design.

Key changes include:

  • Creation of K1-specific BSP with board definitions for MUSE-Pi-Pro development board
  • Implementation of UART driver with 16550A compatibility and proper pin control/clock management
  • Development of pinctrl and system clock control framework drivers

Reviewed Changes

Copilot reviewed 31 out of 32 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
bsp/spacemit/k1/rtconfig.py Build configuration with SpacemiT X60 toolchain settings
bsp/spacemit/k1/rtconfig.h RT-Thread kernel and component configuration header
bsp/spacemit/k1/link.lds Linker script targeting U-Boot's 0x80200000 load address
bsp/spacemit/k1/board/ Board-specific hardware definitions and initialization
bsp/spacemit/k1/drivers/ Modular driver implementation for UART, pinctrl, and clock control
bsp/spacemit/k1/applications/ Basic application entry point
bsp/spacemit/k1/Kconfig Configuration options for BSP and drivers


if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '/opt/gcc-riscv/spacemit-toolchain-elf-newlib-x86_64-v1.1.2/bin'
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maintainability/可维护性: The hardcoded toolchain path may not exist on all development systems. Consider using a more generic path or providing better fallback mechanisms.

English: The hardcoded toolchain path /opt/gcc-riscv/spacemit-toolchain-elf-newlib-x86_64-v1.1.2/bin assumes a specific installation location that may not be available on all development machines. This could cause build failures for developers who install the toolchain in different locations.

中文:硬编码的工具链路径 /opt/gcc-riscv/spacemit-toolchain-elf-newlib-x86_64-v1.1.2/bin 假设了特定的安装位置,但在所有开发机器上可能都不可用。这可能导致将工具链安装在不同位置的开发者构建失败。

Copilot uses AI. Check for mistakes.

OBJCPY = PREFIX + 'objcopy'

# --- Core Config---
#DEVICE = ' -mcpu=spacemit-x60 -march=rv64gcv_zba_zbb_zbc_zbs -mabi=lp64d'
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation/文档: The commented line suggests vector extensions were originally intended but disabled. This should be documented to explain why vector support is currently disabled.

English: The commented line shows that vector extensions (rv64gcv) were considered but the active configuration uses rv64gc without vector support. The reason for disabling vector extensions should be documented, especially since the PR description mentions RVV 1.0 vector extension support.

中文:注释行显示原本考虑了向量扩展(rv64gcv),但当前活跃的配置使用不支持向量的 rv64gc。应该记录禁用向量扩展的原因,特别是因为 PR 描述中提到了 RVV 1.0 向量扩展支持。

Suggested change
#DEVICE = ' -mcpu=spacemit-x60 -march=rv64gcv_zba_zbb_zbc_zbs -mabi=lp64d'
#DEVICE = ' -mcpu=spacemit-x60 -march=rv64gcv_zba_zbb_zbc_zbs -mabi=lp64d'
# Vector extension (rv64gcv) is currently disabled due to [insert reason here, e.g., toolchain limitations, incomplete hardware support, or stability concerns].
# Please refer to the PR description for RVV 1.0 status. Update this configuration when vector support is ready.

Copilot uses AI. Check for mistakes.

SRAM : ORIGIN = 0x80200000, LENGTH = 32M
}

__STACKSIZE__ = 4096;
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maintainability/可维护性: The hardcoded stack size conflicts with the configurable STACKSIZE from Kconfig (16384). The linker script should use the configured value instead of hardcoding it.

English: The linker script hardcodes __STACKSIZE__ = 4096 but the Kconfig sets __STACKSIZE__=16384. This creates a conflict where the actual stack size used will be the hardcoded value, ignoring the user's configuration choice.

中文:链接脚本硬编码了 __STACKSIZE__ = 4096,但 Kconfig 设置了 __STACKSIZE__=16384。这造成了冲突,实际使用的栈大小将是硬编码值,忽略了用户的配置选择。

Suggested change
__STACKSIZE__ = 4096;
/* __STACKSIZE__ is set via Kconfig/build system */

Copilot uses AI. Check for mistakes.

Comment on lines +151 to +156
k1_pinctrl_set_function(GPIO_68, MUX_MODE2);
k1_pinctrl_set_pull(GPIO_68, PULL_UP); // Set TX to pull-up as per DTS

// Configure RX pin
k1_pinctrl_set_function(GPIO_69, MUX_MODE2);
k1_pinctrl_set_pull(GPIO_69, PULL_UP); // Set RX to pull-up as per DTS
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maintainability/可维护性: GPIO pin numbers are hardcoded instead of using the configured pin values from rtconfig.h (BSP_UART0_TXD_PIN=20, BSP_UART0_RXD_PIN=21). This creates inconsistency between configuration and implementation.

English: The UART driver hardcodes GPIO_68 and GPIO_69 for TX/RX pins, but rtconfig.h defines BSP_UART0_TXD_PIN=20 and BSP_UART0_RXD_PIN=21. This mismatch means the configuration values are ignored and the wrong pins may be configured.

中文:UART 驱动程序为 TX/RX 引脚硬编码了 GPIO_68 和 GPIO_69,但 rtconfig.h 定义了 BSP_UART0_TXD_PIN=20 和 BSP_UART0_RXD_PIN=21。这种不匹配意味着配置值被忽略,可能配置了错误的引脚。

Suggested change
k1_pinctrl_set_function(GPIO_68, MUX_MODE2);
k1_pinctrl_set_pull(GPIO_68, PULL_UP); // Set TX to pull-up as per DTS
// Configure RX pin
k1_pinctrl_set_function(GPIO_69, MUX_MODE2);
k1_pinctrl_set_pull(GPIO_69, PULL_UP); // Set RX to pull-up as per DTS
k1_pinctrl_set_function(BSP_UART0_TXD_PIN, MUX_MODE2);
k1_pinctrl_set_pull(BSP_UART0_TXD_PIN, PULL_UP); // Set TX to pull-up as per DTS
// Configure RX pin
k1_pinctrl_set_function(BSP_UART0_RXD_PIN, MUX_MODE2);
k1_pinctrl_set_pull(BSP_UART0_RXD_PIN, PULL_UP); // Set RX to pull-up as per DTS

Copilot uses AI. Check for mistakes.

Comment on lines +58 to +64
switch (sel) {
case 0: return 57600000; // 57.6 MHz
case 1: return 14745600; // 14.7456 MHz
case 2: return 48000000; // 48 MHz
case 3: return 24000000; // UART_LP, assume 24MHz OSC clock as a safe default
default: return 57600000; // Default to 57.6 MHz
}
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maintainability/可维护性: Clock frequencies are hardcoded magic numbers without named constants or documentation of their source. These values should be defined as named constants with references to hardware documentation.

English: The clock frequencies (57600000, 14745600, etc.) are hardcoded magic numbers without clear documentation of where these values come from or what they represent. This makes the code difficult to maintain and verify against hardware specifications.

中文:时钟频率(57600000、14745600 等)是硬编码的魔法数字,没有清楚地记录这些值来自哪里或它们代表什么。这使得代码难以维护并难以根据硬件规格进行验证。

Copilot uses AI. Check for mistakes.

#define PULL_UP (6 << 13) /* bit[15:13] 110 */
#define PULL_DOWN (5 << 13) /* bit[15:13] 101 */

#define K1X_PADCONF(pinid, conf, mux) ((pinid) * 4) (conf) (mux)
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug/错误: The macro definition is malformed with missing operators between parameters. This will cause compilation errors when used.

English: The K1X_PADCONF macro definition is missing operators between the parameters. The current form ((pinid) * 4) (conf) (mux) is invalid C syntax and will cause compilation errors. It should likely be something like ((pinid) * 4) | (conf) | (mux) or similar.

中文K1X_PADCONF 宏定义在参数之间缺少操作符。当前的形式 ((pinid) * 4) (conf) (mux) 是无效的 C 语法,会导致编译错误。它应该可能是类似 ((pinid) * 4) | (conf) | (mux) 的形式。

Suggested change
#define K1X_PADCONF(pinid, conf, mux) ((pinid) * 4) (conf) (mux)
#define K1X_PADCONF(pinid, conf, mux) (((pinid) * 4) | (conf) | (mux))

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant