-
Notifications
You must be signed in to change notification settings - Fork 5.3k
bsp/spacemit/k1:first version #10817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
There was a problem hiding this 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' |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
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' |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
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 向量扩展支持。
#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; |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
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
。这造成了冲突,实际使用的栈大小将是硬编码值,忽略了用户的配置选择。
__STACKSIZE__ = 4096; | |
/* __STACKSIZE__ is set via Kconfig/build system */ |
Copilot uses AI. Check for mistakes.
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 |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
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。这种不匹配意味着配置值被忽略,可能配置了错误的引脚。
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.
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 | ||
} |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
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) |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
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)
的形式。
#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.
本次提交为对 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和相关驱动。