# 错误：扇区 5 闪存写保护违规

- **ID:** `embedded/flash-write-protection-violation`
- **领域:** embedded
- **类别:** config_error
- **错误码:** `HAL_FLASH_ERROR_WRP`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

通过选项字节或 WRP 寄存器对闪存扇区进行了写保护，阻止了编程或擦除操作。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| STM32Cube FW_F4 V1.27.1 | active | — | — |
| STM32Cube FW_L4 V1.17.2 | active | — | — |
| IAR EWARM 8.50.6 | active | — | — |

## 解决方案

1. ```
   Disable write protection via option bytes: HAL_FLASH_OB_Unlock(); FLASH_OB_WRPConfig(OB_WRP_SECTOR_5, DISABLE); HAL_FLASH_OB_Launch();
   ```
2. ```
   Use STM32CubeProgrammer to clear protection: connect to target, go to Option Bytes, disable WRP for sector 5, apply.
   ```

## 无效尝试

- **Erase entire flash memory using mass erase** — Mass erase also respects write protection; protected sectors remain unerased. (80% 失败率)
- **Change linker script to place data in a different sector** — The target sector is still write-protected; linker change only redirects writes but does not remove protection. (65% 失败率)
