Flash programming rejected

The flash controller rejected a page write (PGSERR). Usually this means the target is running, write-protected, or requires a full chip erase before re-programming.

FLASH_PROGRAM_FAILED

Symptoms

  • Flashing aborts with a programming error (PGSERR on STM32).
  • The first flash after receiving a board fails, or flashing fails only when firmware is running.

Likely causes

  • The target was running during programming and firmware touched the flash controller concurrently.
  • Write protection (WRP) rejects writes to some sectors.
  • The flash needs erasing first — programming over non-erased flash (bits 0→1) is rejected by the controller.
  • Dual-bank or option-byte configuration differs from what the flash algorithm assumes.

How to fix it

  1. Retry with the target halted

    MCUHex halts the target after this error — a simple retry often succeeds because firmware can no longer interfere.

  2. Check write protection

    Inspect WRP in the option bytes (see the flash write protected guide) if specific sectors keep failing.

  3. Do a full chip erase

    If the part came with unknown content (production programming, security bits), a mass erase from STM32CubeProgrammer resets flash to a clean state, then flash from MCUHex again.