# Error: flash write protection violation at sector 5

- **ID:** `embedded/flash-write-protection-violation`
- **Domain:** embedded
- **Category:** config_error
- **Error Code:** `HAL_FLASH_ERROR_WRP`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Flash sector is write-protected via option bytes or WRP register, preventing programming or erase operations.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| STM32Cube FW_F4 V1.27.1 | active | — | — |
| STM32Cube FW_L4 V1.17.2 | active | — | — |
| IAR EWARM 8.50.6 | active | — | — |

## Workarounds

1. **Disable write protection via option bytes: HAL_FLASH_OB_Unlock(); FLASH_OB_WRPConfig(OB_WRP_SECTOR_5, DISABLE); HAL_FLASH_OB_Launch();** (90% success)
   ```
   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.** (95% success)
   ```
   Use STM32CubeProgrammer to clear protection: connect to target, go to Option Bytes, disable WRP for sector 5, apply.
   ```

## Dead Ends

- **Erase entire flash memory using mass erase** — Mass erase also respects write protection; protected sectors remain unerased. (80% fail)
- **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% fail)
