Skip to content

[libcpu][bsp] Add Renesas RH850 G4KH port and qemu-rh850-u2c BSP - #11998

Open
parthitce wants to merge 4 commits into
RT-Thread:masterfrom
linumiz:rh850/upstream
Open

parthitce wants to merge 4 commits into
RT-Thread:masterfrom
linumiz:rh850/upstream

Conversation

@parthitce

@parthitce parthitce commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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

Add support for the Renesas RH850 G4KH core, tested on the QEMU rh850-u2c machine.

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

  • libcpu/rh850: thread switch through TRAP0, nested interrupts, FPU context, fault dumps
  • bsp/renesas/rh850: startup, INTC, OSTM and RLIN3 UART drivers, and the qemu-rh850-u2c board. The UART driver supports serial V1 only (BSP_USING_UART depends on RT_USING_SERIAL_V1)
  • CI: hard and soft float builds and kernel utests on QEMU. The toolchain and QEMU archives are checked with SHA-256 before unpacking

Tested with toolchain v1.2.0 (GCC 14.3, picolibc) and qemu-rh850 v1.2.0:

  • bsp_buildings hard and soft float, scons --dist build, msh boots (list thread, free)
  • utest default, kernel_basic 22/22 and mem pass, with and without --strict
  • clang-format and cppcheck clean

Common fixes found while testing this port, sent separately:

Releases, with sources and build scripts:

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

@CLAassistant

CLAassistant commented Nov 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

👋 感谢您对 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

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 rh850/upstream
    Enter PR branch rh850/upstream in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 rh850/upstream 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the rh850/upstream 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 BSP action github action yml imporve tools BSP: Renesas BSP related with Renesas libcpu labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: bsp_renesas

Reviewers: @kurisaW

Changed Files (Click to expand)
  • bsp/renesas/rh850/libraries/Kconfig
  • bsp/renesas/rh850/libraries/SConscript
  • bsp/renesas/rh850/libraries/common/SConscript
  • bsp/renesas/rh850/libraries/common/startup_gcc.S
  • bsp/renesas/rh850/libraries/drivers/SConscript
  • bsp/renesas/rh850/libraries/drivers/drv_intc.c
  • bsp/renesas/rh850/libraries/drivers/drv_intc.h
  • bsp/renesas/rh850/libraries/drivers/drv_ostm.c
  • bsp/renesas/rh850/libraries/drivers/drv_ostm.h
  • bsp/renesas/rh850/libraries/drivers/drv_usart.c
  • bsp/renesas/rh850/libraries/drivers/drv_usart.h
  • bsp/renesas/rh850/libraries/u2c/SConscript
  • bsp/renesas/rh850/libraries/u2c/soc.c
  • bsp/renesas/rh850/libraries/u2c/soc.h
  • bsp/renesas/rh850/qemu-rh850-u2c/.ci/attachconfig/ci.attachconfig.yml
  • bsp/renesas/rh850/qemu-rh850-u2c/.config
  • bsp/renesas/rh850/qemu-rh850-u2c/Kconfig
  • bsp/renesas/rh850/qemu-rh850-u2c/README.md
  • bsp/renesas/rh850/qemu-rh850-u2c/SConscript
  • bsp/renesas/rh850/qemu-rh850-u2c/SConstruct
  • bsp/renesas/rh850/qemu-rh850-u2c/applications/SConscript
  • bsp/renesas/rh850/qemu-rh850-u2c/applications/main.c
  • bsp/renesas/rh850/qemu-rh850-u2c/applications/utest/SConscript
  • bsp/renesas/rh850/qemu-rh850-u2c/applications/utest/tc_cxx_ctor.cpp
  • bsp/renesas/rh850/qemu-rh850-u2c/applications/utest/tc_uart_config.c

🏷️ Tag: workflow

Reviewers: @Rbb666 @kurisaW @supperthomas

Changed Files (Click to expand)
  • .github/ALL_BSP_COMPILE.json
  • .github/utest/configs/components/cplusplus.cfg
  • .github/workflows/bsp_buildings.yml
  • .github/workflows/utest_auto_run.yml

📊 Current Review Status (Last Updated: 2026-11-19 00:26 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

@Rbb666
Rbb666 requested a balanced review from Copilot November 7, 2026 06:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Rbb666 Rbb666 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

English: Please address the selectable Serial V2 build failure and resolve the documented picolibc dependency before merging. The RH850 hard- and soft-float build checks passed, but the three RH850 utest jobs in run 42290504980 failed during compilation and did not execute QEMU. Validation here consists of static review, a minimal host-compiler reproduction of the UART operations initializer, and inspection of the existing CI logs; a full RH850/QEMU run was not repeated locally.

中文:请修复可选 Serial V2 配置下的编译失败,并在合并前解决 PR 已声明的 picolibc 依赖。RH850 硬浮点、软浮点构建检查已通过,但运行 42290504980 中的三个 RH850 utest 任务都在编译阶段失败,尚未执行 QEMU。本次验证包括静态审查、UART 操作表的宿主编译器最小复现和现有 CI 日志核查,未在本地重跑完整 RH850/QEMU 测试。

.control = rh850_uart_control,
.putc = rh850_uart_putc,
.getc = rh850_uart_getc,
.dma_transmit = RT_NULL,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2][Serial/串口] Restrict the configuration to V1 or implement V2 support / 限制为 V1 或补齐 V2 支持

English: The BSP sources the common serial Kconfig, which allows selecting RT_USING_SERIAL_V2, while this driver is compiled whenever RT_USING_SERIAL is enabled. The V2 struct rt_uart_ops has a transmit member rather than dma_transmit, so selecting V2 fails to compile here. A minimal compilation using the PR's operations-structure definitions and this initializer passes for V1 and fails for V2 with has no member named 'dma_transmit'. Please constrain the selectable configuration to the supported V1 driver, or implement the V2 operations and control handling.

中文:BSP 引入的公共串口 Kconfig 允许选择 RT_USING_SERIAL_V2,而本驱动只判断 RT_USING_SERIAL。V2 的 struct rt_uart_ops 成员为 transmit,没有 dma_transmit,因此切换到 V2 会在这里编译失败。使用 PR 中的操作表结构定义与此初始化代码做最小编译复现,V1 通过,V2 报 has no member named 'dma_transmit'。请将可选配置约束到已支持的 V1,或完整实现 V2 的操作表及控制逻辑。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Restricted to V1. BSP_USING_UART now depends on RT_USING_SERIAL_V1, so V2 cannot be selected with this driver. V2 support can come later as a separate change.

- { UTEST: "AARCH64-rtsmart", RTT_BSP: "bsp/zynqmp-a53-dfzu2eg", QEMU_ARCH: "aarch64", QEMU_MACHINE: "xlnx-zcu102", SD_FILE: "None", KERNEL: "rtsmart", "SMP_RUN":"" }
- { UTEST: "AARCH64-smp", RTT_BSP: "bsp/zynqmp-a53-dfzu2eg", QEMU_ARCH: "aarch64", QEMU_MACHINE: "xlnx-zcu102", SD_FILE: "None", KERNEL: "standard", "SMP_RUN":"smp" }

- { UTEST: "RH850", RTT_BSP: "bsp/renesas/rh850/qemu-rh850-u2c", QEMU_ARCH: "rh850", QEMU_MACHINE: "rh850-u2c", SD_FILE: "None", KERNEL: "standard", "SMP_RUN":"" }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[CI/持续集成] Resolve the documented picolibc dependency before merging / 合并前解决已声明的 picolibc 依赖

English: This records the dependency already acknowledged in the PR description. In run 42290504980, all three RH850 jobs (default.cfg, kernel/kernel_basic.cfg, and kernel/mem.cfg) fail at Build BSP, so the new QEMU test entries have no execution results. The kernel_basic build log shows ctime.c failing under --strict with -Werror=array-parameter for asctime_r/ctime_r and -Werror=nonnull-compare. Please land the separate picolibc compatibility fix, update this branch to include it, and rerun these jobs successfully before merging, keeping the strict checks enabled.

中文:此评论记录 PR 描述中已说明的依赖问题。运行 42290504980 中三个 RH850 任务(default.cfg、kernel/kernel_basic.cfg、kernel/mem.cfg)均在 Build BSP 阶段失败,新增 QEMU 测试尚无运行结果。kernel_basic 编译日志 显示 ctime.c 在 --strict 下触发 asctime_r/ctime_r 的 -Werror=array-parameter 以及 -Werror=nonnull-compare。请先合入独立的 picolibc 兼容修复,将其纳入本分支,再保持严格检查重跑这些任务,通过后再合并。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The picolibc fix landed as #11999 and this branch is now rebased on master with it. Strict checks are kept. The RH850 utest jobs build and run on QEMU now: https://github.com/RT-Thread/rt-thread/actions/runs/44156842325

@parthitce

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review. I will address it during this week.

Thread switch through TRAP0 and nested EIINT, FPU context and fault dumps.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
@parthitce

Copy link
Copy Markdown
Contributor Author

English: Please address the selectable Serial V2 build failure and resolve the documented picolibc dependency before merging. The RH850 hard- and soft-float build checks passed, but the three RH850 utest jobs in run 42290504980 failed during compilation and did not execute QEMU. Validation here consists of static review, a minimal host-compiler reproduction of the UART operations initializer, and inspection of the existing CI logs; a full RH850/QEMU run was not repeated locally.

中文:请修复可选 Serial V2 配置下的编译失败,并在合并前解决 PR 已声明的 picolibc 依赖。RH850 硬浮点、软浮点构建检查已通过,但运行 42290504980 中的三个 RH850 utest 任务都在编译阶段失败,尚未执行 QEMU。本次验证包括静态审查、UART 操作表的宿主编译器最小复现和现有 CI 日志核查,未在本地重跑完整 RH850/QEMU 测试。

@Rbb666 Both points are addressed. Serial is restricted to V1, and the branch is rebased on master with the picolibc fix from #11999. The RH850 utest jobs now build and run on QEMU with strict checks: https://github.com/RT-Thread/rt-thread/actions/runs/44156842325

@parthitce
parthitce marked this pull request as ready for review November 17, 2026 19:27
@parthitce
parthitce requested a review from Rbb666 November 17, 2026 19:27

if (div == 0U)
{
div = 1U;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Reject baud rates outside the divider range

With the BSP's 20 MHz clock and 16 samples per bit, the highest attainable rate is 1.25 Mbaud. BAUD_RATE_4000000 produces a rounded divisor of zero. Clamping it to one makes configuration report success at 1.25 Mbaud, so a peer configured for 4 Mbaud cannot receive the stream reliably.

Please validate the rate before writing any registers. Compute 16 * baud and the rounded divisor in 64-bit arithmetic, reject rates outside the hardware range, and check that the divisor is in 1..65536 before storing div - 1 in LBRP01. Propagate -RT_EINVAL to the caller. A boundary test can check that 1250000 succeeds and 4000000 fails with the default clock.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Out of range rates now return -RT_EINVAL before any register write.

Comment on lines +108 to +109
if (cfg->data_bits != DATA_BITS_8 || cfg->stop_bits != STOP_BITS_1 ||
cfg->parity != PARITY_NONE || cfg->baud_rate == 0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Reject serial options the driver does not program

A caller can request RTS/CTS on an open port and receive RT_EOK even though rlin3_setup() never enables flow control. Serial V1 then records the requested settings in serial->config. MSB-first and inverted mode also pass this check without being applied. Extend the existing validation so these requests return -RT_EINVAL before the UART is reconfigured.

Suggested change
if (cfg->data_bits != DATA_BITS_8 || cfg->stop_bits != STOP_BITS_1 ||
cfg->parity != PARITY_NONE || cfg->baud_rate == 0)
if (cfg->data_bits != DATA_BITS_8 || cfg->stop_bits != STOP_BITS_1 ||
cfg->parity != PARITY_NONE || cfg->baud_rate == 0 ||
cfg->bit_order != BIT_ORDER_LSB || cfg->invert != NRZ_NORMAL ||
cfg->flowcontrol != RT_SERIAL_FLOWCONTROL_NONE)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied as suggested.

___rt_utest_tc_tab_end = .;
} > FLASH

.rodata :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Retain the C++ constructor table in flash

This BSP links with -nostartfiles and its startup code calls entry directly. When RT_USING_CPLUSPLUS is enabled, cplusplus_system_init() walks constructor tables using weak boundary symbols. This script defines neither range, so the firmware can link successfully and reach main() with global C++ objects still uninitialized.

Please inspect a global object's sections with v850-elf-objdump -h and retain the emitted table with KEEP. For .init_array, place KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*))) and KEEP(*(.init_array)) between ___init_array_start and ___init_array_end in a 4-byte-aligned flash section. If the toolchain emits .ctors, provide the corresponding ___ctors_start__ and ___ctors_end__ range. The extra leading underscore matches this target's C symbol prefix. A QEMU smoke test can have a global constructor set a value and check it in main().

I verified the missing table with an ARM GNU ELF link using the same section layout. The RH850 C++ build and runtime still need verification.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Both .ctors and .init_array are kept now, with a utest for a global constructor.

Startup code, INTC, OSTM and RLIN3 UART drivers and the U2C SoC setup.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
RH850/U2C8 on the QEMU rh850-u2c machine, msh on RLIN311.
BSP utest cases check the UART config and C++ global constructors.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
Hard and soft float builds, kernel and C++ utests with toolchain v1.2.0.
The toolchain and QEMU downloads are checked with SHA-256.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
@parthitce

Copy link
Copy Markdown
Contributor Author

@Rbb666 thanks for your review. Addressed, kindly revisit.

@parthitce
parthitce requested a review from Rbb666 November 18, 2026 16:29
@BernardXiong

Copy link
Copy Markdown
Member

增量复核 / Incremental check at 6309b2b4(针对 “Addressed, kindly revisit”):

  • drv_usart.c:66-90:波特率校验已改为 64 位计算,拒绝 baud == 0、16*baud > clk、div > 0x10000 及超出 RLIN3_BAUD_TOL 的配置,且在写寄存器前返回 -RT_EINVAL。✅
  • drv_usart.c:124-135:data/stop/parity/bit-order/invert/flow-control 的不支持组合现在返回 -RT_EINVAL。✅
  • link.lds:56-66:.ctors 与 .init_array 两个区间均已用 KEEP 保留并导出边界符号,配套 C++ 全局构造用例已加入。✅

CI at this head:RH850 job 与 utest_auto_run 通过;唯一失败是 ESP32C6 job 在 “Install riscv32-esp-elf ToolChains” 中执行空 token 的 curl -H "Authorization: token " 得到 401 Bad credentials,属 fork PR 的凭据/环境问题,与本 PR 代码无关。

The three P2 items are addressed at this head. The only red check is ESP32C6 failing on an empty-token GitHub API call (401), unrelated to this PR. 完整 review 仍未进行;待 CI 恢复后继续。

@parthitce

Copy link
Copy Markdown
Contributor Author

增量复核 / Incremental check at 6309b2b4(针对 “Addressed, kindly revisit”):

* [drv_usart.c:66-90](https://github.com/RT-Thread/rt-thread/blob/6309b2b4754e0e35b269cf0264d523d7956610ad/bsp/renesas/rh850/libraries/drivers/drv_usart.c#L66-L90):波特率校验已改为 64 位计算,拒绝 `baud == 0`、`16*baud > clk`、`div > 0x10000` 及超出 `RLIN3_BAUD_TOL` 的配置,且在写寄存器前返回 `-RT_EINVAL`。✅

* [drv_usart.c:124-135](https://github.com/RT-Thread/rt-thread/blob/6309b2b4754e0e35b269cf0264d523d7956610ad/bsp/renesas/rh850/libraries/drivers/drv_usart.c#L124-L135):data/stop/parity/bit-order/invert/flow-control 的不支持组合现在返回 `-RT_EINVAL`。✅

* [link.lds:56-66](https://github.com/RT-Thread/rt-thread/blob/6309b2b4754e0e35b269cf0264d523d7956610ad/bsp/renesas/rh850/qemu-rh850-u2c/board/linker_scripts/link.lds#L56-L66):`.ctors` 与 `.init_array` 两个区间均已用 `KEEP` 保留并导出边界符号,配套 C++ 全局构造用例已加入。✅

CI at this head:RH850 job 与 utest_auto_run 通过;唯一失败是 ESP32C6 job 在 “Install riscv32-esp-elf ToolChains” 中执行空 token 的 curl -H "Authorization: token " 得到 401 Bad credentials,属 fork PR 的凭据/环境问题,与本 PR 代码无关。

The three P2 items are addressed at this head. The only red check is ESP32C6 failing on an empty-token GitHub API call (401), unrelated to this PR. 完整 review 仍未进行;待 CI 恢复后继续。

Thanks for checking @BernardXiong. The ESP32C6 job failed while downloading its toolchain, so it is unrelated to this PR. Could you re-run it?

This branch has not been deployed

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

Labels

action github action yml imporve BSP: Renesas BSP related with Renesas BSP libcpu tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants