Skip to content

bsp: k230: support canmv-k230 #10221

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

Merged
merged 7 commits into from
Apr 24, 2025
Merged

Conversation

unicornx
Copy link
Contributor

@unicornx unicornx commented Apr 23, 2025

⭐ ⭐ ⭐ 本 PR 包含了 7 个 commit,建议 merge 时不要压缩,保留这 7 个修改记录。
这 7 个 commit 是故意保留的,不是临时的修改记录,一方面方便 review,另一方面方便回溯和 rollback。

原先的 bsp/k230 支持的是 evb 评估版,并不适合社区,现在改为 canmv-k230,并默认支持目前市面上比较常见的 01Studio CanMV-K230 这款板子。

其他是一些代码清理以及和最新的主线同步,为后面增加支持更多的驱动做准备。

更新了 README,详细描述了如何快速烧写。

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/workflows/bsp_buildings.yml 详细请参考链接BSP自查

@github-actions github-actions bot added the BSP label Apr 23, 2025
@unicornx unicornx added BSP: K230 BSP related with K230 Arch: RISC-V BSP related with risc-v RT-Smart RT-Thread Smart related PR or issues labels Apr 23, 2025
@unicornx unicornx requested a review from Rbb666 April 23, 2025 08:59
@supperthomas supperthomas requested a review from Copilot April 23, 2025 09:39
Copy link

@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 updates the BSP for the K230 platform to support the more widely used CanMV-K230 board, along with various code cleanups and synchronizations with the latest mainline. Key changes include:

  • Modification of toolchain and build configuration in rtconfig.py, including enhanced RTT_ROOT resolution and updated compiler paths.
  • Updates to kernel configuration settings in rtconfig.h (e.g. version, memory layout, and new driver options).
  • Driver updates (especially in the UART driver) and board memory map adjustments to better reflect the CanMV-K230 hardware.
  • Enhancements in the SConstruct build script to generate the linker script automatically.

Reviewed Changes

Copilot reviewed 8 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
bsp/k230/rtconfig.py Updates to toolchain paths, environment variable fallback, and build configuration logic
bsp/k230/rtconfig.h Kernel configuration updates and new options for klibc, memory management, and drivers
bsp/k230/drivers/interdrv/uart/drv_uart.c Improvements in UART initialization, hardware mapping, and safety checks in ISR
bsp/k230/board/mem_layout.h Addition of detailed memory layout definitions for the board
bsp/k230/board/board.h & board.c Expanded board hardware definitions and a modified static assert check with a FIXME hint
bsp/k230/SConstruct Revised linker script generation logic replacing the manual stack linker script generation
bsp/k230/README.md Detailed and updated user instructions for building and flashing the BSP for different setups
Files not reviewed (4)
  • bsp/k230/.config: Language not supported
  • bsp/k230/.gitignore: Language not supported
  • bsp/k230/link.lds: Language not supported
  • bsp/k230/link_stacksize.lds: Language not supported
Comments suppressed due to low confidence (1)

bsp/k230/drivers/interdrv/uart/drv_uart.c:142

  • [nitpick] The condition enforcing a minimum value for 'dll' is critical for baud rate calculation but may not be immediately clear. Consider extracting the minimum value condition into a well-named constant or helper function for improved clarity.
if((dlh == 0) && (dll < 1))

Comment on lines 48 to 49
RT_STATIC_ASSERT(kmem_region, (KERNEL_VADDR_START + MEM_OPENSBI_SIZE) == 0xffffffc000020000);

Copy link
Preview

Copilot AI Apr 23, 2025

Choose a reason for hiding this comment

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

The static assert now uses a hack (with a FIXME comment) to bypass proper bootloader alignment validation. Consider revisiting this check to implement a robust validation that accurately reflects the production board requirements.

Suggested change
RT_STATIC_ASSERT(kmem_region, (KERNEL_VADDR_START + MEM_OPENSBI_SIZE) == 0xffffffc000020000);
#define EXPECTED_BOOTLOADER_ALIGNMENT 0xffffffc000020000 /* Replace with dynamic calculation if possible */
RT_STATIC_ASSERT(kmem_region, (KERNEL_VADDR_START + MEM_OPENSBI_SIZE) == EXPECTED_BOOTLOADER_ALIGNMENT);

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个 ASSERT 没有必要,可以删除。

Comment on lines +27 to +28
child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

Copy link
Preview

Copilot AI Apr 23, 2025

Choose a reason for hiding this comment

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

Consider using a list of arguments for subprocess.Popen instead of string concatenation with shell=True to improve cross-platform reliability and reduce potential security risks.

Suggested change
child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
child = subprocess.Popen([gcc_cmd, '-E', '-P', '-x', 'c', input, '-o', output], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这么改无法解决问题,这个问题以前也提过,see #10202 (comment)


# toolchains options
ARCH ='risc-v'
VENDOR ='t-head'
CPU ='c908'
CROSS_TOOL ='gcc'

RTT_ROOT = os.getenv('RTT_ROOT', r'../..')
RTT_ROOT = os.getenv('RTT_ROOT', r'../..') or os.path.join(os.getcwd(),'..','..')
Copy link
Preview

Copilot AI Apr 23, 2025

Choose a reason for hiding this comment

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

[nitpick] Using os.getcwd() as a fallback for RTT_ROOT may lead to inconsistent paths if the current working directory isn’t as expected. Consider adding documentation or explicit error handling when RTT_ROOT is not set.

Suggested change
RTT_ROOT = os.getenv('RTT_ROOT', r'../..') or os.path.join(os.getcwd(),'..','..')
RTT_ROOT = os.getenv('RTT_ROOT')
if not RTT_ROOT:
raise EnvironmentError("RTT_ROOT environment variable is not set. Please set it to the root directory of the project.")

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这行代码的修改有问题,已经恢复原来的写法。

Some changes to support canmv board, such as:
- Address constant, some may need be set as configuration later.
- link script
- build script

Signed-off-by: Wang Chen <unicorn_wang@outlook.com>
Signed-off-by: Wang Chen <unicorn_wang@outlook.com>
KERNEL_VADDR_START changed to 0xffffffc000020000.
__STACKSIZE__ changed to 65536.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
For linker script, use constant macro defined from
rtconfig.h, not immediate value.

Also cleanup the link_statksize.lds, it is also not
needed when using new mechanism.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
@BernardXiong
Copy link
Member

不同的板卡是否用不同的设备树即可?

The original code used immediate values directly when it
came to memory layout, which was not a good programming
habit.

Now we use macros and try to be compatible with SDK
configuration values in the SDK compilation environment.

The main changes are to clean up board.h, and extract
some memory layout constants to define a new header
file mem_layout.h.

Also update KERNEL_VADDR_START to the default value for
Smart, so we can use it as base to calculate other mapping
address.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
@BernardXiong
Copy link
Member

有好几种板卡,
K230-Edu,CanMV-K230(还有庐山派 CanMV-K230,不知道是否完全一致),K230 Box

image

@unicornx
Copy link
Contributor Author

unicornx commented Apr 23, 2025

不同的板卡是否用不同的设备树即可?

暂时没有精力支持设备树,目前主要的精力是希望先将 canaan 内部的 vendor bsp 先移植升级到最新的主线,他们的代码没有实现设备树,所以对设备树的支持要计划放在下一阶段考虑了。

另外对于不同 canmv-k230 的板卡支持,目前的方案实际上是有计划兼容 canaan 的 rtos-only sdk 的,具体看 commit “bsp: k230: use configuration instead of immediate value” 的描述。或者看 bsp/k230/board/mem_layout.h 中的注释。等 rtt 主线支持好后, canaan 的 rtos-only sdk 可以集成 RTT 的主线代码,然后通过 SDK 的配置导入 rtconfig.h 后就可以通过配置支持不同的 canmv 板卡了, 这也是现阶段 SDK 的做法,只不过现在 SDK 中集成的还是老版本的 RTT。

在没有和 SDK 集成之前,和 canaan 开发组讨论后,决定在 RTT 主线仓库中先只支持默认的 01Studio 512MB。

@Rbb666 Rbb666 merged commit 283c2fb into RT-Thread:master Apr 24, 2025
33 checks passed
@unicornx unicornx deleted the dev-canmv-basic branch April 24, 2025 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: RISC-V BSP related with risc-v BSP: K230 BSP related with K230 BSP RT-Smart RT-Thread Smart related PR or issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants