Skip to content

Conversation

@kaabia
Copy link
Contributor

@kaabia kaabia commented Nov 1, 2025

Fixes #630

Summary

This PR addresses several critical protocol inconsistencies and a major bug
in the src/spi_flash.c driver for improved robustness and compliance.

Key Changes

  • Fix Verification Logic:

    • Replaced the error-prone verification in spi_flash_write_sb with a
      simple, correct check (read_value == written_value).
  • Standardize Write Enable (WREN) Protocol:

    • Protocol Fix: Corrected spi_flash_probe by adding the mandatory
      flash_write_enable() before WRSR to reliably clear block protection.
    • Performance: Removed redundant wait_busy() calls in spi_flash_write_page.
    • Robustness: Standardized the erase sequence by adding defensive
      wait_busy() after flash_write_enable() in erase functions.

@dgarske
Copy link
Contributor

dgarske commented Nov 3, 2025

Hi @kaabia , Thank you for this PR and fixes (also the ones in wolfMQTT). Can you tell us about your project and where you are located? To accept a code contribution we required a signed contributor agreement. To start that proccess please email support at wolfssl dot com and reference your PR's.
Thanks, David Garske, wolfSSL

This commit improves the robustness and protocol compliance of the SPI flash
driver by resolving critical bugs and standardizing command sequences.

Key Changes:

1.  **Write Verification Bug (spi_flash_write_sb):**
    * Replaced the complex bitwise verification logic with a direct comparison
      (`verify == buf[j]`) for robust data validation.

2.  **Protocol Violations & Performance:**
    * **spi_flash_probe:** Fixed silent protocol failure by adding mandatory
      `WREN` before `WRSR` and adding explicit `wait_busy()` and `WRDI`.
    * **spi_flash_write_page:** Removed redundant `wait_busy()` after `WREN`
      to improve performance.
    * **Erase Functions:** Standardized erase flow by ensuring an explicit
      `wait_busy()` is performed after `WREN` before issuing the command.

These changes prevent silent failures, potential flash corruption, and
unnecessary latency.

Signed-off-by: Badr Bacem KAABIA <[email protected]>
@kaabia
Copy link
Contributor Author

kaabia commented Nov 5, 2025

Hi @kaabia , Thank you for this PR and fixes (also the ones in wolfMQTT). Can you tell us about your project and where you are located? To accept a code contribution we required a signed contributor agreement. To start that proccess please email support at wolfssl dot com and reference your PR's.
Thanks, David Garske, wolfSSL

Thank you @dgarske . I can confirm the signed contributor agreement has been sent back to [email protected].

@dgarske
Copy link
Contributor

dgarske commented Nov 6, 2025

Contributor agreement on file

@dgarske dgarske assigned wolfSSL-Bot and danielinux and unassigned danielinux Nov 6, 2025
@danielinux danielinux merged commit 6313077 into wolfSSL:master Nov 18, 2025
220 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SPI Flash: Critical protocol inconsistencies and write verification bug in spi_flash.c

4 participants