Skip to content

Fix ETH RX HardFault and KSEM scale factor#6

Merged
flottokarotto merged 1 commit intomasterfrom
fix/eth-rx-hardfault
Feb 20, 2026
Merged

Fix ETH RX HardFault and KSEM scale factor#6
flottokarotto merged 1 commit intomasterfrom
fix/eth-rx-hardfault

Conversation

@flottokarotto
Copy link
Owner

Summary

  • Fix HardFault: Remove SCB_InvalidateDCache_by_Addr() in HAL_ETH_RxLinkCallback — causes IMPRECISERR on Cortex-M7 when D-Cache is not enabled. Also remove incorrect ACTLR.DISDEFWBUF write (Cortex-M3/M4 bit layout, not valid on M7).
  • Fix KSEM readings: Handle arbitrary SunSpec scale factors (10^SF) instead of only SF ∈ {-1, 0, 1}. The KSEM dynamically changes W_SF (e.g. to -2), which caused 100× inflated power readings.

Test plan

  • Flash on NUCLEO-H753ZI, no HardFault after 20+ Modbus TCP reads
  • KSEM power values consistent across dynamic SF changes
  • Zero-copy RX path retained (no architectural change needed)

Closes #5

🤖 Generated with Claude Code

Remove SCB_InvalidateDCache_by_Addr call in HAL_ETH_RxLinkCallback —
D-Cache is not enabled in this project, and calling cache maintenance
operations with D-Cache disabled causes IMPRECISERR HardFault on
Cortex-M7. Also remove incorrect ACTLR.DISDEFWBUF write (M3/M4 bit
layout, not valid on Cortex-M7).

Fix KSEM power readings by handling arbitrary SunSpec scale factors
(10^SF) instead of only SF ∈ {-1, 0, 1}. The KSEM dynamically changes
W_SF (e.g. to -2) based on value magnitude, which previously caused
100× inflated readings.

Closes #5
Copilot AI review requested due to automatic review settings February 20, 2026 20:43
Copy link

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 fixes two critical bugs in the NUCLEO-H753 KSEM test example: a HardFault crash in Ethernet RX processing and incorrect power readings from the KSEM energy meter due to improper scale factor handling.

Changes:

  • Remove harmful D-Cache invalidation call in ETH RX callback that caused IMPRECISERR HardFault when D-Cache is disabled
  • Remove incorrect ACTLR register manipulation using Cortex-M3/M4 bit patterns on Cortex-M7 hardware
  • Replace hardcoded scale factor handling with full SunSpec 10^SF implementation to support arbitrary scale factors

Reviewed changes

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

File Description
examples/embedded/nucleo_h753_ksem_test/src/ksem_client.adb Implements proper SunSpec scale factor handling using 10^SF formula with loops, replacing hardcoded support for only SF ∈ {-1, 0, 1}
examples/embedded/nucleo_h753_ksem_test/lwip_port/ethernetif.c Removes SCB_InvalidateDCache_by_Addr call that caused HardFault when D-Cache disabled, and removes incorrect ACTLR.DISDEFWBUF write for Cortex-M7

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

@flottokarotto flottokarotto merged commit 8cb8efa into master Feb 20, 2026
8 checks passed
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

ETH RX HardFault: stale DMA buffer in HAL_ETH_RxLinkCallback

3 participants