This skill should be used when the user asks to "dump SPI flash", "read EEPROM through OpenOCD", "dump flash via MCU", "read SPI through debug interface", "extract firmware from SPI", or mentions scenarios involving SPI flash connected to a microcontroller with SWD/JTAG debug access. Provides comprehensive guidance for RAM-resident SPI flash dumping without external programming hardware.
/plugin marketplace add lukejenkins/claude-openocd-spi-dump/plugin install lukejenkins-openocd-spi-dump@lukejenkins/claude-openocd-spi-dumpThis skill inherits all available tools. When active, it can use any tool Claude has access to.
examples/spi_dump.cexamples/spi_dump.ldexamples/spi_dump.tclreferences/mcu-registers.mdreferences/troubleshooting.mdThis skill enables dumping SPI flash or EEPROM memory through a microcontroller's SPI peripheral using OpenOCD/SWD, without requiring external SPI programming hardware.
When to use this approach:
┌─────────────┐ SWD ┌─────────────┐ SPI ┌─────────────┐
│ OpenOCD │◄────────────►│ Target MCU │◄────────────►│ SPI Flash │
│ (Host PC) │ │ (SRAM) │ │ │
└─────────────┘ └─────────────┘ └─────────────┘
The approach:
Before starting, gather this information:
MCU Information:
SPI Flash Information:
Connection:
Look up the MCU's datasheet for SPI register addresses. See references/mcu-registers.md for common MCU families.
Key registers to find:
The SPI chip select (CS) is often controlled via GPIO for precise timing. Find:
Plan SRAM layout for the dumper:
SRAM Layout (example: 64KB at 0x20000000):
0x20000000 ┌─────────────────┐
│ Vector Table │ 64 bytes (16 Cortex-M vectors)
0x20000040 ├─────────────────┤
│ Code │ ~400-600 bytes typical
0x2000E000 ├─────────────────┤
│ Read Buffer │ 4KB (adjustable)
0x2000FE00 ├─────────────────┤
│ Stack │ 256 bytes (grows down)
0x2000FF00 ├─────────────────┤
│ Comm Area │ 256 bytes
0x20010000 └─────────────────┘
Use fixed memory addresses for host-MCU communication:
| Offset | Name | Purpose |
|---|---|---|
| +0x00 | STATUS | Command/status register |
| +0x04 | FLASH_ADDR | 24-bit flash address to read |
| +0x08 | SIZE | Bytes to read |
| +0x0C | DEST | Destination buffer in SRAM |
| +0x10 | JEDEC_ID | Result of ID read |
Status values: 0x00=Idle, 0x01=Busy, 0x02=Done, 0xDEADxxxx=Error
Commands: 0x10=Read flash, 0x20=Get JEDEC ID, 0xFF=Exit
Create minimal C code with these components. See examples/spi_dump.c for complete template.
Critical requirements:
SCB_VTOR = 0x20000000Create TCL commands for loading and controlling the dumper. See examples/spi_dump.tcl for complete template.
Key procedures:
read_word - Memory read wrapper (use mem2array for compatibility)spi_load - Load binary into SRAMspi_init - Set PC/SP from vector table, resumespi_jedec - Read and display JEDEC IDspi_dump - Dump flash in chunks to fileWithout setting VTOR, any exception uses flash vector table, causing crashes:
*(volatile uint32_t*)0xE000ED08 = 0x20000000;
Even when using GPIO for chip select, SPI won't clock if PCS=0xF:
SPI_MR = SPI_MR_MSTR | SPI_MR_MODFDIS | (0x0E << 16); // PCS=NPCS0
Reclaim CS pin for GPIO control:
// SAM4S example for PA11
PIOA_PER = (1 << 11); // Enable PIO control
PIOA_OER = (1 << 11); // Enable output
Feed watchdog during long operations:
for (i = 0; i < size; i++) {
dest[i] = spi_transfer(0x00);
if ((i & 0xFFF) == 0) {
WDT_CR = 0xA5000001; // SAM4S watchdog feed
}
}
Standard JEDEC commands work with most SPI flash chips:
| Command | Hex | Description |
|---|---|---|
| READ | 0x03 | Read data (24-bit address follows) |
| RDID | 0x9F | Read JEDEC ID (3 bytes returned) |
| RDSR | 0x05 | Read status register |
JEDEC ID format: Byte1=Manufacturer, Byte2=Type, Byte3=Capacity
Common manufacturers: 0x1F=Atmel, 0xEF=Winbond, 0xC2=Macronix, 0x20=Micron
See references/troubleshooting.md for detailed solutions. Quick reference:
| Symptom | Likely Cause | Quick Fix |
|---|---|---|
| HardFault immediately | VTOR points to flash | Set SCB_VTOR = SRAM_BASE |
| SPI hangs polling | Clock not running | Check SPI_MR PCS field |
| JEDEC returns 0x000000 | CS not toggling | Check GPIO config |
| JEDEC returns 0xFFFFFF | No flash response | Check wiring, mode, speed |
To support a new MCU:
The core algorithm remains the same—only register addresses change.
references/mcu-registers.md - Detailed register maps for SAM4S, SAM3X, STM32F1, STM32F4, nRF52, LPC1768references/troubleshooting.md - Comprehensive troubleshooting guide with solutionsComplete, working templates in examples/:
spi_dump.c - RAM-resident C source with vector tablespi_dump.ld - Linker script for SRAM executionspi_dump.tcl - OpenOCD TCL commandsFor a guided interactive session, use the /spi-dump command which walks through the entire process step-by-step.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.