H753_CPP_W25Q_SPI_Flash_Read_Write_01 1.0
STM32H753 W25Q SPI flash (Adafruit 5632/5633/5634) read/write tutorial
Loading...
Searching...
No Matches
w25q_validation.hpp
1/*
2 * w25q_validation.hpp
3 *
4 * Destructive validation test suite for the W25QFlashSPI driver, adapted
5 * from the SRAM validation suite in F439_CPP_AS6C4008_FMC_DaughterBoard_01
6 * (sram_validation.c/.h -- same architecture: test-ID/phase/status enums,
7 * one persistent report struct, self-contained per-test functions, a
8 * RunAll() orchestrator).
9 *
10 * Differences from the SRAM version, and why:
11 * - No address-alias test. That test exists to catch mis-wired/stuck
12 * parallel address lines on the FMC bus. SPI has no external address
13 * bus to mis-wire; a wiring mistake here shows up as total communication
14 * failure or a wrong JEDEC ID, both already caught by Init().
15 * - Every pattern write is preceded by an erase. NOR flash can only clear
16 * bits (1->0) via Page Program; setting a bit back to 1 requires an
17 * erase first. The SRAM version can freely write any value at any time,
18 * so it never needed this.
19 * - No whole-device full-sweep/full-range test. SRAM has unlimited write
20 * endurance; NOR flash sectors have a finite erase/program cycle count
21 * (commonly ~100,000 cycles), so treating a 16MB chip as disposable on
22 * every test run is a real cost, not just a time cost. Tests are scoped
23 * to a single sector instead.
24 * - Added an erased-state test (verify every byte reads 0xFF after erase)
25 * and a page-boundary test (write spans two pages, exercising
26 * writeBuffer()'s internal per-page splitting) -- both flash-specific
27 * concerns with no SRAM equivalent.
28 *
29 * This suite overwrites the first sector (W25Q_SECTOR_SIZE bytes) starting
30 * at W25Q_VALIDATION_BASE_ADDR. Run it only when destroying that sector's
31 * contents is acceptable -- see W25Q_VALIDATION_TEST_ENABLE in main.c, which
32 * keeps this suite from running as part of the normal demo path.
33 *
34 * Created on: Aug 30, 2026
35 * Author: johng
36 */
37
38#ifndef W25Q_W25Q_VALIDATION_HPP_
39#define W25Q_W25Q_VALIDATION_HPP_
40
41#include "main.h"
42#include "W25QFlashSPI.hpp"
43
45#define W25Q_VALIDATION_BASE_ADDR ((uint32_t)0x000000u)
46
48#define W25Q_VALIDATION_SMALL_RANGE_SIZE ((uint32_t)256u)
49
51#define W25Q_VALIDATION_PATTERN_TEST_SIZE ((uint32_t)256u)
52
54#define W25Q_VALIDATION_BOUNDARY_TEST_SIZE ((uint32_t)512u)
55
57typedef enum {
58 W25Q_VALIDATION_TEST_NONE = 0,
59 W25Q_VALIDATION_TEST_ERASED_STATE,
60 W25Q_VALIDATION_TEST_SMALL_RANGE,
61 W25Q_VALIDATION_TEST_PATTERN,
62 W25Q_VALIDATION_TEST_PAGE_BOUNDARY
63} w25qValidationTestId_t;
64
66typedef enum {
67 W25Q_VALIDATION_PHASE_IDLE = 0,
68 W25Q_VALIDATION_PHASE_ERASE,
69 W25Q_VALIDATION_PHASE_FILL,
70 W25Q_VALIDATION_PHASE_VERIFY
71} w25qValidationPhase_t;
72
74typedef enum {
75 W25Q_VALIDATION_STATUS_PASS = 0,
76 W25Q_VALIDATION_STATUS_FAIL
77} w25qValidationStatus_t;
78
80typedef struct {
81 w25qValidationStatus_t status;
82 w25qValidationTestId_t failedTest;
83 w25qValidationPhase_t failedPhase;
84 uint32_t failedOffset;
85 uint8_t expectedValue;
86 uint8_t actualValue;
87 uint32_t testsRun;
89
107public:
113 explicit W25QValidation(W25QFlashSPI &flash);
114
121
126 const w25qValidationReport_t *GetReport() const;
127
128private:
129 W25QFlashSPI &_flash;
131
132 void resetReport();
133 void recordFailure(w25qValidationTestId_t testId, w25qValidationPhase_t phase,
134 uint32_t offset, uint8_t expectedValue, uint8_t actualValue);
135 void printFailure() const;
136 static const char *getTestName(w25qValidationTestId_t testId);
137 static const char *getPhaseName(w25qValidationPhase_t phase);
138
140 bool runErasedStateTest();
141
143 bool runSmallRangeTest();
144
146 bool runPatternTest();
147
149 bool runPageBoundaryTest();
150};
151
152#endif /* W25Q_W25Q_VALIDATION_HPP_ */
STM32 HAL SPI1 driver for a Winbond W25Q-series flash chip (Adafruit 5632/5633/5634),...
Destructive validation suite for a W25QFlashSPI driver – see w25q_validation.hpp's file header for th...
const w25qValidationReport_t * GetReport() const
Gets the most recent validation report without rerunning tests.
const w25qValidationReport_t * RunAll()
Runs every validation test in sequence, stopping at the first failure, printing progress and results ...
W25QValidation(W25QFlashSPI &flash)
Constructs the validation suite against an already-initialized driver.
: Header for main.c file. This file contains the common defines of the application.
Detailed validation report, persistent for the life of the W25QValidation instance.
uint32_t failedOffset
Byte offset (from W25Q_VALIDATION_BASE_ADDR) where the failure was detected.
uint8_t actualValue
Value actually read back at failedOffset.
uint8_t expectedValue
Value expected to be read back at failedOffset.
w25qValidationTestId_t failedTest
Which test failed, or NONE if status is PASS.
w25qValidationStatus_t status
Overall PASS/FAIL outcome of the last RunAll().
uint32_t testsRun
Count of tests that started running, whether they passed or failed.
w25qValidationPhase_t failedPhase
Which phase of failedTest failed (erase/fill/verify).