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
W25QFlashQSPI.hpp
1/*
2 * W25QFlashQSPI.hpp
3 *
4 * STM32 HAL QUADSPI driver for the Winbond W25Q-series QSPI DIP breakout
5 * boards (Adafruit 5632/5633/5634 -- W25Q16/W25Q64/W25Q128), operated in
6 * single-line-address / single-line-data indirect mode -- see the class-level
7 * note below on why this isn't using all four IO lines for data yet.
8 *
9 * Adapted from Adafruit_SPIFlash (https://github.com/adafruit/Adafruit_SPIFlash,
10 * MIT License, Copyright (c) 2019 hathach for Adafruit Industries) as a design
11 * reference for the command set and driver structure -- this is an independent
12 * STM32 HAL implementation, not a direct port of Adafruit's Arduino source
13 * (which depends on Arduino-only types this toolchain doesn't have).
14 *
15 * Created on: Sep 3, 2026
16 * Author: johng
17 */
18
19#ifndef W25Q_W25QFLASHQSPI_HPP_
20#define W25Q_W25QFLASHQSPI_HPP_
21
22#include "main.h"
23#include "w25q_commands.h"
24
64public:
74 explicit W25QFlashQSPI(uint32_t qspiTimeoutMs = 100);
75
90 bool Init();
91
108 bool readJEDECID(uint32_t &id);
109
117 bool readStatus(uint8_t &status1, uint8_t &status2);
118
124 bool waitUntilReady(uint32_t timeout_ms = 100);
125
133 bool eraseSector(uint32_t addr);
134
167 bool eraseRange(uint32_t addr, uint32_t len);
168
176 bool eraseBlock(uint32_t addr);
177
186 bool eraseChip();
187
196 bool readBuffer(uint32_t addr, uint8_t *buf, uint32_t len);
197
212 bool writeBuffer(uint32_t addr, const uint8_t *data, uint32_t len);
213
214private:
215 QSPI_HandleTypeDef *_hqspi;
216
218 uint32_t _qspiTimeoutMs;
219
227 HAL_StatusTypeDef runCommand(uint8_t instruction);
228
238 HAL_StatusTypeDef readCommand(uint8_t instruction, uint8_t *resp, uint32_t len);
239
249 HAL_StatusTypeDef writeCommand(uint8_t instruction, const uint8_t *data, uint32_t len);
250
259 HAL_StatusTypeDef eraseCommand(uint8_t instruction, uint32_t addr);
260
266 HAL_StatusTypeDef writeEnable();
267};
268
269#endif /* W25Q_W25QFLASHQSPI_HPP_ */
STM32 HAL QUADSPI driver for a Winbond W25Q-series flash chip (Adafruit 5632/5633/5634),...
bool readStatus(uint8_t &status1, uint8_t &status2)
Reads both status registers.
bool waitUntilReady(uint32_t timeout_ms=100)
Polls Status Register 1's BUSY bit until clear or timeout.
bool eraseBlock(uint32_t addr)
Erases the single 64KB block containing the given address.
W25QFlashQSPI(uint32_t qspiTimeoutMs=100)
Constructs the driver.
bool writeBuffer(uint32_t addr, const uint8_t *data, uint32_t len)
Writes len bytes starting at addr, paging internally at 256-byte boundaries as the chip's Page Progra...
bool readJEDECID(uint32_t &id)
Reads the 3-byte JEDEC ID (manufacturer, memory type, capacity).
bool eraseChip()
Erases the entire chip. Can take tens of seconds on larger capacities – verify the timeout against th...
bool readBuffer(uint32_t addr, uint8_t *buf, uint32_t len)
Reads len bytes starting at addr into buf.
bool eraseRange(uint32_t addr, uint32_t len)
Erases every sector spanned by [addr, addr + len), computing the sector boundaries automatically – th...
bool Init()
Resets the chip and verifies communication via the JEDEC ID.
bool eraseSector(uint32_t addr)
Erases the single 4KB sector containing the given address.
: Header for main.c file. This file contains the common defines of the application.