Skip to content

[improvement] hrtim: disable all outputs on fatal error - #163

Draft
luizvilla wants to merge 1 commit into
owntech-foundation:mainfrom
luizvilla:improvement/hrtim-fatal-outputs-off
Draft

luizvilla wants to merge 1 commit into
owntech-foundation:mainfrom
luizvilla:improvement/hrtim-fatal-outputs-off

Conversation

@luizvilla

Copy link
Copy Markdown
Member

Summary

On a CPU fault or kernel panic, Zephyr's default k_sys_fatal_error_handler logs and halts. The HRTIM keeps running, so the gates keep switching at their last duty cycle with no software in control.

This PR has the HRTIM driver provide k_sys_fatal_error_handler. It disables every HRTIM output (TA1..TF2), then flushes the logs (LOG_PANIC) and halts.

Context

On the bench, a fault in the critical task (an allocation from interrupt context) stopped the board while the power stage was supplied, and nothing was left to stop the HRTIM.

Notes for reviewers

  • Zephyr's handler is weak. This one is a regular definition, so an application that defines its own k_sys_fatal_error_handler would now get a duplicate symbol at link time. No module or example in Core defines one today. If you want applications to be able to override it, we could make this one weak, or call a weak hrtim_fatal_hook instead.
  • It doesn't depend on the DMA duty sequence PR, but it matters more with it, since a sequence can hold a leg at 100 %.

Test

  • Builds on spin@1_2_0 / twist_v1_4_2.
  • The fault path has not been tested on hardware yet. Proposed test, with the power stage off: start PWM on a leg, then trigger a fault from the critical task (for example a null pointer write). The outputs should go low on the scope and the fatal error should appear in the log.

Before marking ready

  • Fault test on the bench, power stage off: outputs go low (planned next week)
  • Decide whether the handler should be weak / overridable

🤖 Generated with Claude Code

On a CPU fault or kernel panic, Zephyr's default handler logs and halts,
but the HRTIM keeps running: the gates keep switching at their last duty
cycle with no software in control. This was observed on the bench with a
fault in the critical task while the power stage was on.

The HRTIM driver now provides k_sys_fatal_error_handler, which disables
every HRTIM output (TA1..TF2) before flushing the logs and halting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant