Skip to content

[bsp][wch] Support PM on CH32V208 - #12007

Draft
kaidegit wants to merge 7 commits into
RT-Thread:masterfrom
kaidegit:feat/wch-pm-and-ble
Draft

kaidegit wants to merge 7 commits into
RT-Thread:masterfrom
kaidegit:feat/wch-pm-and-ble

Conversation

@kaidegit

@kaidegit kaidegit commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

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

[

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

为bsp ch32v208支持pm组件

依赖#12004

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

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

  • BSP:

CH32V208

  • .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
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

Add RTC tickless STOP with LSI/LSE selection, clock snapshot restore, optional GPIO parking, and a CI attachconfig build. Document the timer_app power test (82 uA average, 18 uA STOP floor).
@github-actions

github-actions Bot commented Nov 8, 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 分支 feat/wch-pm-and-ble
    Enter PR branch feat/wch-pm-and-ble 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.

完成后,提交将自动更新至 feat/wch-pm-and-ble 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the feat/wch-pm-and-ble 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 BSP: WCH BSP related with WCH labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: bsp_wch

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • bsp/wch/risc-v/ch32v208w-r0/.ci/attachconfig/ci.attachconfig.yml
  • bsp/wch/risc-v/ch32v208w-r0/.config
  • bsp/wch/risc-v/ch32v208w-r0/board/Kconfig
  • bsp/wch/risc-v/ch32v208w-r0/board/SConscript
  • bsp/wch/risc-v/ch32v208w-r0/board/drv_pm.c
  • bsp/wch/risc-v/ch32v208w-r0/figures/pm_timer_app_power.png
  • bsp/wch/risc-v/ch32v208w-r0/readme.md
  • bsp/wch/risc-v/ch32v208w-r0/rtconfig.py

📊 Current Review Status (Last Updated: 2026-11-13 22:50 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.

@Rbb666 Rbb666 closed this Nov 9, 2026
@Rbb666 Rbb666 reopened this Nov 9, 2026

@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.

两处 PM 计时问题,详见行内评论。

Two PM timing issues are noted inline.

{
SysTick->CTLR = 0;
SysTick->CMP = pm_state.runtime.tick_cmp;
SysTick->CNT = pm_state.runtime.resume_phase;

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] 补偿恢复阶段耗时 / Preserve elapsed recovery time

中文:STOP 唤醒后,resume_phase 在 tick 处理和设备恢复回调之前就已计算。这里用旧值覆盖 CNT,会丢弃这些操作的耗时,反复休眠使系统时间累计偏慢。请在最终恢复 SysTick 时计入新增周期,并补偿跨越的完整 tick。

English: After STOP, this assignment discards cycles spent processing ticks and resume callbacks after resume_phase was calculated. Include those elapsed cycles and any complete ticks when restoring SysTick.

}

if (lsi_measuring &&
now - lsi_measure_started >= rt_tick_from_millisecond(PM_LSI_TIMEOUT_MS))

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] 避免低 tick 频率下校准提前超时 / Allow calibration at low tick rates

中文:配置为 10–20 Hz 时,初始化的 rt_thread_mdelay(1) 和这里的 50 ms 超时均为 1 tick。首次捕获被丢弃并重启后,立即命中超时,第二次采样无法完成,导致 PM 初始化失败。请让超时预算覆盖轮询粒度和两次捕获,或调整初始化采样方式。

English: At 10–20 Hz, both the polling delay and timeout become one tick. Discarding the first capture immediately triggers this timeout, preventing the second capture and failing PM initialization. Account for polling granularity and both captures.

@kaidegit

kaidegit commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

晚上处理一下

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

wch-ch32v208w-r0

  • FLASH: .text +88 B (+0.1%, 159,976 B / 491,520 B, total: 33% used)

Catch memory regressions in CI with MemBrowse. Free for open source.

@kaidegit

Copy link
Copy Markdown
Contributor Author

@Rbb666

@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.

复核当前 PM 实现,恢复阶段的时间补偿仍有重复计数问题,详见行内场景;建议修复后用持续唤醒测试与独立时基比较,覆盖跨 tick 的设备 resume 回调。另请处理当前失败的格式检查。提交历史含已合并的 fast-interrupt 前置提交、同步 merge 与本功能修正,最终合并前宜整理为一个可独立验证的 PM 提交。

if (pm_state.runtime.systick_suspended)
{
SysTick->CTLR = 0;
total = pm_state.runtime.resume_phase + SysTick->CNT;

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] 仅补偿上次采样之后新增的恢复周期

pm_stop() 第 418–421 行已把 recovery_cycles = SysTick->CNT 计入 sleep_ticks/resume_phase,但计数器从第 407 行清零后一直继续运行。这里再加整个 CNT 会把那一段恢复时间计算两次。例如每 tick 为 1000 周期、RTC 部分正好对齐、首次采样 CNT=100、退出时 CNT=300,实际经过 300 周期,却恢复为 400 周期;重复 STOP 会使系统 tick 累计偏快。请保存已计入的计数器基线并仅补偿差值,或将首次恢复周期统一留到退出时结算,确保每个周期只统计一次。

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.

已修复:pm_stop() 不再提前计入 recovery_cycles,所有恢复周期统一在 rt_pm_exit_critical() 通过 resume_phase + SysTick->CNT 结算,避免重复计数,跨 tick 补偿仍保留。本地已通过 clang-format 22.1.8 检查和 devices.pm 配置的 CH32V208 BSP 编译。

@kaidegit
kaidegit marked this pull request as draft November 13, 2026 02:38

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

BSP: WCH BSP related with WCH BSP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants