H753_CPP_W25Q_QSPI_Flash_Read_Write_01 1.0
STM32H753 W25Q QSPI 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 W25QFlashQSPI 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. QSPI's address phase rides on
13 * the same 1-4 data/address lines as everything else, with no separate
14 * external address bus to mis-wire; a wiring mistake here shows up as total communication
15 * failure or a wrong JEDEC ID, both already caught by Init().
16 * - Every pattern write is preceded by an erase. NOR flash can only clear
17 * bits (1->0) via Page Program; setting a bit back to 1 requires an
18 * erase first. The SRAM version can freely write any value at any time,
19 * so it never needed this.
20 * - No whole-device full-sweep/full-range test. SRAM has unlimited write
21 * endurance; NOR flash sectors have a finite erase/program cycle count
22 * (commonly ~100,000 cycles), so treating a 16MB chip as disposable on
23 * every test run is a real cost, not just a time cost. Tests are scoped
24 * to a single sector instead.
25 * - Added an erased-state test (verify every byte reads 0xFF after erase)
26 * and a page-boundary test (write spans two pages, exercising
27 * writeBuffer()'s internal per-page splitting) -- both flash-specific
28 * concerns with no SRAM equivalent.
29 *
30 * This suite overwrites the first sector (W25Q_SECTOR_SIZE bytes) starting
31 * at W25Q_VALIDATION_BASE_ADDR. Run it only when destroying that sector's
32 * contents is acceptable -- see W25Q_VALIDATION_TEST_ENABLE in main.c, which
33 * keeps this suite from running as part of the normal demo path.
34 *
35 * Created on: Aug 30, 2026
36 * Author: johng
37 */
38
39#ifndef W25Q_W25Q_VALIDATION_HPP_
40#define W25Q_W25Q_VALIDATION_HPP_
41
42#include "main.h"
43#include "W25QFlashQSPI.hpp"
44
46#define W25Q_VALIDATION_BASE_ADDR ((uint32_t)0x000000u)
47
49#define W25Q_VALIDATION_SMALL_RANGE_SIZE ((uint32_t)256u)
50
52#define W25Q_VALIDATION_PATTERN_TEST_SIZE ((uint32_t)256u)
53
55#define W25Q_VALIDATION_BOUNDARY_TEST_SIZE ((uint32_t)512u)
56
58typedef enum {
59 W25Q_VALIDATION_TEST_NONE = 0,
60 W25Q_VALIDATION_TEST_ERASED_STATE,
61 W25Q_VALIDATION_TEST_SMALL_RANGE,
62 W25Q_VALIDATION_TEST_PATTERN,
63 W25Q_VALIDATION_TEST_PAGE_BOUNDARY
64} w25qValidationTestId_t;
65
67typedef enum {
68 W25Q_VALIDATION_PHASE_IDLE = 0,
69 W25Q_VALIDATION_PHASE_ERASE,
70 W25Q_VALIDATION_PHASE_FILL,
71 W25Q_VALIDATION_PHASE_VERIFY
72} w25qValidationPhase_t;
73
75typedef enum {
76 W25Q_VALIDATION_STATUS_PASS = 0,
77 W25Q_VALIDATION_STATUS_FAIL
78} w25qValidationStatus_t;
79
81typedef struct {
82 w25qValidationStatus_t status;
83 w25qValidationTestId_t failedTest;
84 w25qValidationPhase_t failedPhase;
85 uint32_t failedOffset;
86 uint8_t expectedValue;
87 uint8_t actualValue;
88 uint32_t testsRun;
90
108public:
114 explicit W25QValidation(W25QFlashQSPI &flash);
115
122
127 const w25qValidationReport_t *GetReport() const;
128
129private:
130 W25QFlashQSPI &_flash;
132
133 void resetReport();
134 void recordFailure(w25qValidationTestId_t testId, w25qValidationPhase_t phase,
135 uint32_t offset, uint8_t expectedValue, uint8_t actualValue);
136 void printFailure() const;
137 static const char *getTestName(w25qValidationTestId_t testId);
138 static const char *getPhaseName(w25qValidationPhase_t phase);
139
141 bool runErasedStateTest();
142
144 bool runSmallRangeTest();
145
147 bool runPatternTest();
148
150 bool runPageBoundaryTest();
151};
152
153#endif /* W25Q_W25Q_VALIDATION_HPP_ */
STM32 HAL QUADSPI driver for a Winbond W25Q-series flash chip (Adafruit 5632/5633/5634),...
Destructive validation suite for a W25QFlashQSPI driver – see w25q_validation.hpp's file header for t...
W25QValidation(W25QFlashQSPI &flash)
Constructs the validation suite against an already-initialized driver.
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 ...
: 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).