S25FL512S: erase fails with E_ERR on DYB-protected sectors, then WIP stays set

Open
#752 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
28/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp
Domain
cli, embedded-iot

Research direction

Start in spiFlash.cpp, where the erase loop checks only the BP bits and never sends Clear Status (0x30) after an E_ERR or P_ERR timeout, and where --unprotect-flash clears BP bits only. Reproducing needs a Spansion S25FL-S chip with DYB-protected sectors, which most contributors won't have. Done means a DYB-protected erase fails with a clear message or clears the DYBs, and an E_ERR state is cleared rather than timing out on every later sector.

Written by the indexing model from the issue text.

Description

Summary

Writing a Spansion S25FL512S fails when its sectors are protected by their DYB bits (Advanced Sector Protection). The status register's BP bits are clear. openFPGALoader checks only the BP bits, so it goes ahead with the erase. The chip refuses every sector erase and sets E_ERR. openFPGALoader never sends Clear Status (0x30), so WIP stays set and every later wait times out.

Board and versions

  • MEGA65 R6: xc7a200tfbg484, S25FL512S (JEDEC 01 02 20), FT2232H cable (-c ft2232)
  • openFPGALoader v0.12.0 (Ubuntu 24.04 package). The same code is on master: spiFlash.cpp has no DYB or PPB handling, and --unprotect-flash only clears the BP bits.

Command and output

openFPGALoader -c ft2232 --ftdi-serial 251633005A66 --fpga-part xc7a200tfbg484 \
    --write-flash --verify --file-type bin --offset 0x2800000 core.cor
use: /usr/share/openFPGALoader/spiOverJtag_xc7a200tfbg484.bit.gz
load program
Load SRAM: [==================================================] 100.00%
Done
Detected: spansion S25FL512S 1024 sectors size: 512Mb
02800000 00000000 00000000 00
timeout: 23 89 89
23
wait: Error
Erasing: [==============================================    ] 91.30%timeout: 23 89 89
23
wait: Error
Erasing: [==============================================    ] 91.44%timeout: 23 89 89
23
wait: Error
...
  • Status register 1 is 0x23: E_ERR (bit 5), WEL, and WIP. On the S-family, WIP stays set after an erase error until CLSR (0x30) or a reset.
  • The first erase already fails. The bar shows the absolute address over the end address, and 0x2800000 / 0x2BD0000 is 91.3 %. That is misleading when --offset is large. It may be worth showing (addr - start) / (end - start) instead.
  • The addressing is fine: v0.12.0 sends 4BE64 (0xDC) above 16 MiB.

Cause

On the MEGA65 the sectors are DYB-protected when a host gets to the flash. The MEGA65's own flash tool clears each 256 KiB sector's DYB before erasing it. It sends DYB Write (0xE1, a 4-byte address, 0xFF) until DYB Read (0xE0) returns 0xFF, and then sends Clear Status (0x30). See unprotect_flash() and erase_sector() in mega65-core's src/utilities/qspicommon.c.

Suggestion

For the Spansion S25FL-S chips (at least the S25FL512S):

  1. Before erasing, read each sector's PPB (0xE2) and DYB (0xE0) in the range. If the PPB is protected, stop with a clear message. If the DYB is protected, clear it with WREN and 0xE1 … 0xFF when --unprotect-flash is given (or always, as DYBs are volatile), and otherwise stop with a message rather than time out.
  2. After a timeout with E_ERR or P_ERR (0x60) set, send 0x30 and stop. At the moment the loop continues and every later sector times out.

As a workaround outside openFPGALoader, I'm going to clear the DYBs through the v1 spiOverJtag bridge after a --dump-flash --skip-reset, and then write with --skip-load-bridge. I'm happy to test a patch on the MEGA65 R6.

Dominant language
C++
Stars
1.7k
Forks
396
Avg merge
2d 4h
Merged PRs (30d)
15

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from trabucayre/openFPGALoader

All issues in trabucayre/openFPGALoader

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.