# STM32 Unlock Planner: RDP, Write Protection & PCROP

> Flashing fails with "failed to erase memory"? It could be RDP Level 1, write protection or PCROP, each with a very different fix. This skill reads your STM32 option bytes read-only, finds the real cause and plans the cheapest safe fix, with exact commands and the manual page behind each step.

STM32 Unlock Planner: RDP, Write Protection & PCROP is a free AI agent skill on Agensi by Khaled, STM32 Engineer, in Testing & Debugging. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Khaled, STM32 Engineer](https://www.agensi.io/creators/dhif-kaled)
- Category: [Testing & Debugging](https://www.agensi.io/skills/testing-debugging)
- Version: 1.2
- Last updated: 2026-11-20
- Security: scan passed (2026-11-20); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/stm32-unlock-planner-rdp-write-protection-pcrop
- Tags: testing, security, stm32, embedded-systems, firmware, microcontrollers

## About this skill

Reads your STM32 option bytes read-only, finds why flashing fails (RDP Level 1, write protection or PCROP) and plans the cheapest safe fix, with exact commands and the manual page behind each step.

"My STM32 is locked" has four causes, and STM32CubeProgrammer gives the same error for three of them.

- RDP Level 1: RDP regression. Cost: erases the flash.
- Write protection: clear the WRP bits. Cost: nothing.
- PCROP or secure areas: one exact combined command. Cost: erases the flash.
- RDP Level 2: no fix. It's permanent.

The usual advice ("just run a mass erase") destroys firmware that didn't need to die, and fails on PCROP-protected parts. This skill makes your agent diagnose first.

**What it does**
1. **Reads** the option bytes through STM32CubeProgrammer, read-only. This works even on a read-protected chip.
2. **Decodes** RDP level, sector and area write protection, PCROP, H7 secure-only areas and boot settings, using the device database already installed with CubeProgrammer.
3. **Plans** the fix: `unlock`, `remove-wrp`, `lock-rdp1` (production protection) or `explain`. Every step shows the exact command, what it erases, whether it can be undone, and the reference-manual section and page it relies on.
4. **Asks before every write**, runs one step at a time and re-reads after each.

**Traps it handles**
- **F42x/43x:** `SPRMOD=1` inverts the meaning of the `nWRP` bits. PCROP can only be released inside the RDP 1 → 0 command.
- **F72x/73x:** `PCROP_RDP` must already be set *before* the regression command.
- **H7:** PCROP and secure areas need DMEP/DMES = 1 *and* START > END. The factory "START > END" default is disabled, not active PCROP.
- **G4:** `BOOT_LOCK`. **L4/G4:** `PCROP_RDP` and partial mass erase.

**Safety**
- It never generates RDP Level 2 (`0xCC`).
- It refuses TrustZone and product-state parts (H5, U5, L5, WBA, H7RS, N6, C5, U3) rather than guessing.
- Steps that haven't been tested on hardware are marked VERIFY, with the manual citation.

**Where it stops**
- Covers STM32F4, F7, H7, L4 and G4. Rules come from RM0090, RM0410, RM0431, RM0433, RM0351 and RM0440.
- Tested on hardware with an STM32H750: lock to Level 1, unlock with `-rdu`, set and remove sector write protection.
- The PCROP paths follow the manuals but haven't been tested on hardware.

Not affiliated with STMicroelectronics.

## Requires

- Python

## Known limitations

No support for TrustZone/product-state parts (H5, U5, L5, etc.). Requires STM32_Programmer_CLI. Verified only for specific F4, F7, H7, L4, and G4 device IDs.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the STM32 Unlock Planner: RDP, Write Protection & PCROP skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### Can it recover a chip at RDP Level 2?

No. Level 2 is permanent on every STM32. The skill says so and stops.

### Does it run anything on my board without asking?

Only the read-only option-byte read. Every write is printed with its cost and runs only after your yes.

### Can it get my firmware back from a Level 1 chip?

No. At Level 1 no debugger can read the flash, and unlocking erases it. Back up at Level 0.

### Why is my H5/U5/N6 refused?

TrustZone and product-state devices use different regression procedures. Guessing could brick them, so they're out of scope for v1.

### Which steps are hardware-tested?

H7 lock, unlock and write-protection removal. PCROP steps follow the cited manual pages and are marked VERIFY.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
