Skip to content

Do not enter wfi when SBA access would not work#4782

Merged
bugadani merged 2 commits intoesp-rs:mainfrom
bugadani:debugger
Jan 15, 2026
Merged

Do not enter wfi when SBA access would not work#4782
bugadani merged 2 commits intoesp-rs:mainfrom
bugadani:debugger

Conversation

@bugadani
Copy link
Copy Markdown
Contributor

In a recent probe-rs PR I've fixed a bunch of issues that caused RISC-V CPUs to be halted when they otherwise don't need to be. This, however, caused some issues with RTT: on a C3, if the CPU entered WFI, probe-rs was no longer able to read the RTT buffer (originall reported here).

Turns out this issue has been worked around in esp-idf long ago. I'm applying that workaround to esp-hal here.

All RISC-V CPUs are affected, it just doesn't look like that, because we accidentally have SYSTEM_CPU_WAIT_MODE_FORCE_ON enabled on some of them.

@bugadani bugadani marked this pull request as ready for review January 15, 2026 07:22
Copilot AI review requested due to automatic review settings January 15, 2026 07:22
Copy link
Copy Markdown
Contributor

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 addresses an issue where RISC-V ESP32 CPUs entering WFI (Wait For Interrupt) prevented debuggers from reading memory via SBA (System Bus Access) when SYSTEM_CPU_WAIT_MODE_FORCE_ON is disabled. The solution applies a workaround from esp-idf that checks if a debugger is connected before entering WFI mode.

Changes:

  • Created a unified wait_for_interrupt() function in esp_hal::interrupt for both RISC-V and Xtensa architectures
  • Removed architecture-specific idle_hook() implementations from task modules and replaced them with a unified version that calls wait_for_interrupt()
  • Added RISC-V-specific logic to skip WFI when a debugger is connected and cpu_wait_mode_force_on is disabled

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
esp-hal/src/interrupt/riscv.rs Added wait_for_interrupt() function with debugger detection logic and cpu_wait_mode_on() helper
esp-hal/src/interrupt/xtensa.rs Added simple wait_for_interrupt() function wrapping waiti 0 instruction
esp-rtos/src/task/mod.rs Added unified idle_hook() using esp_hal::interrupt::wait_for_interrupt()
esp-rtos/src/task/riscv.rs Removed RISC-V-specific idle_hook() implementation
esp-rtos/src/task/xtensa.rs Removed Xtensa-specific idle_hook() implementation
esp-hal/CHANGELOG.md Added changelog entry for the new function
esp-rtos/CHANGELOG.md Added changelog entry for the idle hook fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread esp-hal/CHANGELOG.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 15, 2026 07:33
@bjoernQ
Copy link
Copy Markdown
Contributor

bjoernQ commented Jan 15, 2026

Interesting - I remember I stumbled upon esp_cpu_wait_for_intr (and SYSTEM_CPU_WAIT_MODE_FORCE_ON) a couple of times but never realized what is really happening there (and why) 🤷‍♂️

Nice find!

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bjoernQ
Copy link
Copy Markdown
Contributor

bjoernQ commented Jan 15, 2026

we accidentally have SYSTEM_CPU_WAIT_MODE_FORCE_ON enabled on some of them

should we align that?

@bugadani
Copy link
Copy Markdown
Contributor Author

bugadani commented Jan 15, 2026

Eventually yes, I imagine saving power is better than not saving power 😅 But this code comes from depths of C hell.

Copy link
Copy Markdown
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

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

LGTM

We probably want to create an issue to set SYSTEM_CPU_WAIT_MODE_FORCE_ON to a defined state?

@bugadani bugadani added this pull request to the merge queue Jan 15, 2026
Merged via the queue into esp-rs:main with commit 3d68e27 Jan 15, 2026
30 checks passed
@bugadani bugadani deleted the debugger branch January 15, 2026 09:17
@bugadani
Copy link
Copy Markdown
Contributor Author

bugadani commented Feb 1, 2026

@MabezDev I'd like this backported as latest probe-rs needs it

@MabezDev MabezDev added the esp-hal-backport Backport this PR to the latest esp-hal-x.y.x branch.” label Feb 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 2, 2026

Created backport PR for esp-hal-1.0.x:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-4782-to-esp-hal-1.0.x
git worktree add --checkout .worktree/backport-4782-to-esp-hal-1.0.x backport-4782-to-esp-hal-1.0.x
cd .worktree/backport-4782-to-esp-hal-1.0.x
git reset --hard HEAD^
git cherry-pick -x 3d68e27485e56aeeadc76ebe494a8bfd89579545
git push --force-with-lease

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

Labels

esp-hal-backport Backport this PR to the latest esp-hal-x.y.x branch.”

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants