Hardware Debug Anything (HDA)
MCP server that decodes Cortex-M fault registers, ESP-IDF panic logs, and I2C/SPI/UART measurements, and that writes Renode and QEMU scripts. GDB, addr2line, Renode, and QEMU are used when they are installed. If they are not, the tool says so.
What it does
- Decodes CFSR, HFSR, and SFSR for Cortex-M3/M4/M7/M33/M55, including the bits that used to be ignored (INVSTATE, UNSTKERR, VECTTBL, LSPERR, MLSPERR, STKOF, and the rest of MMFSR/BFSR/UFSR). M0, M0+, and M23 have no CFSR; the decoder says that instead of inventing a fault.
- Classifies a fault address as null/low, flash, SRAM, peripheral, external, or PPB/system, and the advice follows the region.
BFAR 0x20001004is SRAM. - Decodes an exception frame (stacked R0–R3, R12, LR, PC, xPSR) and EXC_RETURN, including the extended FPU frame and lazy stacking when FPCCR.LSPACT is set.
- Parses CMSIS-SVD XML well enough to name the peripheral and register at an address and to decode bitfields.
- Parses ESP-IDF Guru Meditation logs (Xtensa and RISC-V), register dumps, EXCVADDR/MTVAL, and backtraces. A ROM line such as
rst:0x1 (POWERON_RESET)is not a panic. - Checks I2C 7-bit vs 8-bit addresses, suggests parts that commonly use the address, and sizes the pull-up from bus voltage, capacitance, and the UM10204 rise-time limits. Optional text bus logs are analyzed. SPI mode/clock checks are a separate tool.
- Estimates UART baud from pulse widths with glitch rejection. A large timing error is a failure, not a success.
- Checks a Cortex-M vector table against per-family memory maps (STM32F1/F4/H7, RP2040, nRF52, SAM D, and others).
- Builds a Renode script that loads a
.replpath that exists upstream, and aqemu-system-armcommand for machines mainline QEMU actually has. Either program is run only if it is onPATH.
Quick start
This package is not on PyPI until a release is published. Until then, install from git:
pip install "hardware-debug-anything @ git+https://github.com/hosseinnosrati/hardware-debug-anything.git"
hardware-debug-anything
python -m hda and python -m hda.server work after that install. They do not work from a bare checkout unless the package is on PYTHONPATH.
After the first PyPI release, this also works, because the distribution installs a console script of the same name:
uvx hardware-debug-anything
Cursor (~/.cursor/mcp.json)
{
"mcpServers": {
"hardware-debug-anything": {
"command": "hardware-debug-anything"
}
}
}
Claude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"hardware-debug-anything": {
"command": "hardware-debug-anything"
}
}
}
If the script is not on PATH, point command at the interpreter that has the package installed and pass ["-m", "hda"] as args.
Example transcript
The JSON below is the tool output for this call, not a hand-written diagnosis. BFAR 0x20001004 is SRAM, so the fix is about the pointer or the stack, not a peripheral clock.
Input:
decode_arm_hardfault(
cfsr_hex="0x00008200",
hfsr_hex="0x40000000",
bfar_hex="0x20001004",
pc_hex="0x08001234",
)
{
"status": "DIAGNOSED",
"fault_type": "BusFault (Precise)",
"severity": "FATAL",
"cause_summary": "Precise data bus fault. The instruction and, when BFARVALID is set, the address are exact. Address 0x20001004 is Main SRAM (0x20000000).",
"fault_address": "0x20001004",
"fault_address_register": "BFAR",
"fault_address_reliable": true,
"pc_address": "0x08001234",
"suggested_fix": "The address is in the SRAM region. The bus rejected the access, so this offset is outside the SRAM this part actually implements (a stack that grew past the end of RAM) or it landed in a hole in the SRAM window. Compare the address with the part's SRAM size and look for a wild pointer.",
"bits_set": [
"PRECISERR",
"FORCED"
],
"fault_region": {
"region": "sram",
"label": "Main SRAM (0x20000000)"
},
"pc_region": {
"region": "flash",
"label": "STM32 flash (0x08000000)"
}
}
A boot line is not a crash:
{
"status": "NO_PANIC",
"panic_found": false,
"panic_reason": null,
"reset": {
"code": "0x1",
"reason": "POWERON_RESET"
},
"root_cause": "No Guru Meditation panic and no abort() call in this log."
}
Input for that one is the single line rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT).
Tools
| Tool | What it returns |
|---|---|
decode_arm_hardfault |
CFSR/HFSR/SFSR decode, address region, optional stack frame and ELF symbols. |
decode_exception_frame |
Stacked registers, xPSR, EXC_RETURN. |
decode_exc_return_value |
Frame shape, thread/handler, MSP/PSP. |
classify_cortexm_address |
null/low, flash, SRAM, peripheral, external, or PPB/system. |
decode_esp32_panic_log |
Panic reason, core, registers, backtrace. NO_PANIC when there is no panic. |
diagnose_i2c_bus_failure |
7-bit/8-bit address, candidate parts, UM10204 pull-up, optional bus log. |
diagnose_spi_bus |
CPOL/CPHA mode mismatch, clock limit, stuck MISO. |
estimate_uart_baud_rate |
Standard baud, or FAIL / AMBIGUOUS when the trace does not support one. |
verify_arm_vector_table |
Stack and reset vector against a device family. |
decode_svd_address |
Peripheral, register, and bitfields from a CMSIS-SVD document or file. |
parse_gdb_output |
Fault decode of a pasted GDB/MI or console log. |
capture_gdb_fault_state |
Same, by running GDB against host:port when GDB is installed. |
resolve_elf_symbols |
Symbol table names, plus addr2line when it is installed. |
generate_renode_script |
A .resc that loads a real upstream .repl. |
run_renode_headless |
Runs that script when renode is on PATH. |
generate_qemu_invocation |
A qemu-system-arm command for a known machine. |
run_qemu_headless |
Runs it when qemu-system-arm is on PATH. |
Every tool sets readOnlyHint, destructiveHint, idempotentHint, and openWorldHint. The three that launch a program are not read-only and are marked open-world. Bad hex comes back as {"status": "ERROR", "error": {"code": "INVALID_HEX", ...}}.
Architecture
hda/debugger decodes fault registers, address regions, exception frames, ELF symbols, and GDB/MI. hda/analyzer parses ESP-IDF logs, I2C, SPI, UART, and SVD. hda/simulation writes Renode and QEMU commands and checks vector tables. hda/server.py is the FastMCP process.
Limits
- The SVD reader covers peripherals,
derivedFrom, one level of clusters,dim, and bitfields. It does not implement every CMSIS-SVD rule. - I2C part names are candidates. Several devices share an address.
- Pull-up values assume 200 pF when capacitance is omitted, and the result says so. Above 1 MHz is Hs-mode and gets no resistor.
- UART
SUCCESSrequires a unique standard baud within 2.5% and a trace that is not also a perfect fit for double that baud. - Renode upstream has no ESP32
.repl. Asking for one is an error. - QEMU support is a command line for machines in mainline
qemu-system-arm(netduino2, netduinoplus2, stm32vldiscovery, olimex-stm32-h405, mps2-an385/386/500/505/521, microbit). It is not a cycle-accurate model and not an ESP32 simulator. - A Renode or QEMU process that exits is reported as
EXITEDorFAILED. That is not a firmware pass. - Symbol resolution without addr2line is the ELF symbol table only. File and line need addr2line.
Development
pip install -e ".[dev]"
ruff check .
ruff format --check .
mypy hda
coverage run -m unittest discover -s tests -v
coverage report --fail-under=90
pre-commit runs Ruff. CI runs Ruff, mypy, a package build, and the tests on Python 3.10–3.13.
Suggested GitHub About text
The About blurb is repository metadata, not a file in this tree. A wording that matches this code:
MCP server for Cortex-M fault registers (CFSR/HFSR/SFSR, address regions, exception frames), CMSIS-SVD register decode, ESP-IDF panic logs, I2C/SPI/UART checks, and Renode/QEMU scripts. GDB/MI and addr2line are used when those tools are installed.
Topics that match the tools: mcp-server, embedded, arm-cortex-m, esp32, hardfault, cmsis-svd, gdb, renode, qemu, i2c, spi, uart, firmware.
License
Apache-2.0. See LICENSE.
Author: Hossein Nosrati • Portfolio
Metadata
Release files for hardware-debug-anything 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hardware_debug_anything-0.2.0.tar.gz | 77.0 kB | With provenance | Details for hardware_debug_anything-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hardware_debug_anything-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for hardware_debug_anything-0.2.0-py3-none-any.whl |
Total release size: 148.9 kB
Release files / hardware_debug_anything-0.2.0.tar.gz
| Download URL | hardware_debug_anything-0.2.0.tar.gz |
|---|---|
| Size | 77.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50830b8f8876a62e4add8617fbe99344cd87ba448e9cf8e0b2dfdf7d5d01bdd0
|
|
BLAKE2b-256 checksum How to use checksums |
00fe01777dd2fd04eb8acf02e871cf8c7af92147695910718e62a4db8fc7d734
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / hardware_debug_anything-0.2.0-py3-none-any.whl
| Download URL | hardware_debug_anything-0.2.0-py3-none-any.whl |
|---|---|
| Size | 71.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e639acadb00dacd4c60ed725693f93ebddd5c3974581c6b9c0eed543134c482d
|
|
BLAKE2b-256 checksum How to use checksums |
c215caea1c9f0c423e55a7e6df223dcb6d10098251eedca73d86d3429e4b0672
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for hardware-debug-anything 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for hardware_debug_anything-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.