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
entryPointCPP.cpp
1/*
2 * entryPointCPP.cpp
3 *
4 * Created on: Aug 30, 2026
5 * Author: johng
6 */
7
8#include "entryPointCPP.hpp"
9#include "W25QFlashSPI.hpp"
10#include "w25q_validation.hpp"
11#include <stdio.h>
12
14static W25QFlashSPI *w25qFlash = nullptr;
15
17static bool w25qReady = false;
18
19void initW25QFlash(void) {
20 w25qFlash = new W25QFlashSPI();
21 w25qReady = w25qFlash->Init();
22}
23
24bool w25qIsReady(void) {
25 return w25qReady;
26}
27
28bool w25qReadBuffer(uint32_t addr, uint8_t *buf, uint32_t len) {
29 if (w25qFlash == nullptr || !w25qReady) {
30 return false;
31 }
32 bool value = w25qFlash->readBuffer(addr, buf, len);
33 return value;
34}
35
36bool w25qWriteBuffer(uint32_t addr, const uint8_t *data, uint32_t len) {
37 if (w25qFlash == nullptr || !w25qReady) {
38 return false;
39 }
40 bool value = w25qFlash->writeBuffer(addr, data, len);
41 return value;
42}
43
44bool w25qEraseSector(uint32_t addr) {
45 if (w25qFlash == nullptr || !w25qReady) {
46 return false;
47 }
48 bool value = w25qFlash->eraseSector(addr);
49 return value;
50}
51
52bool w25qReadJEDECID(uint32_t *id) {
53 if (w25qFlash == nullptr || !w25qReady) {
54 return false;
55 }
56 bool value = w25qFlash->readJEDECID(*id);
57 return value;
58}
59
60void w25qRunValidation(void) {
61 if (w25qFlash == nullptr || !w25qReady) {
62 printf("W25Q validation skipped -- flash not initialized\r\n");
63 return;
64 }
65 W25QValidation validation(*w25qFlash);
66 validation.RunAll();
67}
STM32 HAL SPI1 driver for a Winbond W25Q-series flash chip (Adafruit 5632/5633/5634),...
bool eraseSector(uint32_t addr)
Erases the single 4KB sector containing the given address.
bool Init()
Resets the chip and verifies communication via the JEDEC ID.
bool readBuffer(uint32_t addr, uint8_t *buf, uint32_t len)
Reads len bytes starting at addr into buf.
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).
Destructive validation suite for a W25QFlashSPI driver – see w25q_validation.hpp's file header for th...