STM32 W25Qxx QuadSPI Driver  0.1a
https://github.com/Crazy-Geeks/STM32-W25Q-QSPI
W25Qxxx QSPI STM32 Library

HAL STM32 Driver for Winbond W25Q-series memory, using Quad-SPI interface

Poster

Open "Modules" to get easy access to Function Reference

Features:

  • Easy applying: ST's HAL functions are used
  • Uses Quad-SPI interface (4 lines)
  • Supports (almost) all chip commands (later)
  • Simple usage with data types wrapper-functions, or use raw 8-bit data

Function reference (from .h file):

W25Q_STATE W25Q_Init(void); // Initalize function
W25Q_STATE W25Q_ReadStatusReg(u8_t *reg_data, u8_t reg_num); // Read status register to variable
W25Q_STATE W25Q_WriteStatusReg(u8_t reg_data, u8_t reg_num); // Write status register from variable
W25Q_STATE W25Q_ReadStatusStruct(W25Q_STATUS_REG *status); // Read all status registers to struct
W25Q_STATE W25Q_IsBusy(void); // Check chip's busy status
W25Q_STATE W25Q_ReadSByte(i8_t *buf, u8_t pageShift, u32_t pageNum); // Read signed 8-bit variable
W25Q_STATE W25Q_ReadByte(u8_t *buf, u8_t pageShift, u32_t pageNum); // Read 8-bit variable
W25Q_STATE W25Q_ReadSWord(i16_t *buf, u8_t pageShift, u32_t pageNum); // Read signed 16-bit variable
W25Q_STATE W25Q_ReadWord(u16_t *buf, u8_t pageShift, u32_t pageNum); // Read 16-bit variable
W25Q_STATE W25Q_ReadSLong(i32_t *buf, u8_t pageShift, u32_t pageNum); // Read signed 32-bit variable
W25Q_STATE W25Q_ReadLong(u32_t *buf, u8_t pageShift, u32_t pageNum); // Read 32-bit variable
W25Q_STATE W25Q_ReadData(u8_t *buf, u16_t len, u8_t pageShift, u32_t pageNum); // Read any 8-bit data
W25Q_STATE W25Q_ReadRaw(u8_t *buf, u16_t data_len, u32_t rawAddr); // Read data from raw addr
W25Q_STATE W25Q_SingleRead(u8_t *buf, u32_t len, u32_t Addr); // Read data from raw addr by single line
W25Q_STATE W25Q_EraseSector(u32_t SectAddr); // Erase 4KB Sector
W25Q_STATE W25Q_EraseBlock(u32_t BlockAddr, u8_t size); // Erase 32KB/64KB Sector
W25Q_STATE W25Q_EraseChip(void); // Erase all chip
W25Q_STATE W25Q_ProgramSByte(i8_t buf, u8_t pageShift, u32_t pageNum); // Program signed 8-bit variable
W25Q_STATE W25Q_ProgramByte(u8_t buf, u8_t pageShift, u32_t pageNum); // Program 8-bit variable
W25Q_STATE W25Q_ProgramSWord(i16_t buf, u8_t pageShift, u32_t pageNum); // Program signed 16-bit variable
W25Q_STATE W25Q_ProgramWord(u16_t buf, u8_t pageShift, u32_t pageNum); // Program 16-bit variable
W25Q_STATE W25Q_ProgramSLong(i32_t buf, u8_t pageShift, u32_t pageNum); // Program signed 32-bit variable
W25Q_STATE W25Q_ProgramLong(u32_t buf, u8_t pageShift, u32_t pageNum); // Program 32-bit variable
W25Q_STATE W25Q_ProgramData(u8_t *buf, u16_t len, u8_t pageShift, u32_t pageNum); // Program any 8-bit data
W25Q_STATE W25Q_ProgramRaw(u8_t *buf, u16_t data_len, u32_t rawAddr); // Program data to raw addr
W25Q_STATE W25Q_ProgSuspend(void); // Pause Programm/Erase operation
W25Q_STATE W25Q_ProgResume(void); // Resume Programm/Erase operation
W25Q_STATE W25Q_Sleep(void); // Set low current consumption
W25Q_STATE W25Q_WakeUP(void); // Wake the chip up from sleep mode
W25Q_STATE W25Q_ReadID(u8_t *buf); // Read chip ID
W25Q_STATE W25Q_SwReset(bool force); // Software reset
W25Q_STATE
W25Q Return State Lib's functions status returns.
Definition: w25q_mem.h:61
W25Q_STATE W25Q_EraseChip(void)
W25Q Chip erase Func to erase all the data on chip.
Definition: w25q_mem.c:931
W25Q_STATE W25Q_EraseSector(u32_t SectAddr)
W25Q Sector erase (4KB) Minimal size operation to erase data.
Definition: w25q_mem.c:800
W25Q_STATE W25Q_EraseBlock(u32_t BlockAddr, u8_t size)
W25Q Block erase (32/64 KB) Func to erase big block.
Definition: w25q_mem.c:858
W25Q_STATE W25Q_ReadID(u8_t *buf)
W25Q Read ID Function for reading chip ID.
Definition: w25q_mem.c:1163
W25Q_STATE W25Q_Init(void)
W25Q Init function.
Definition: w25q_mem.c:72
W25Q_STATE W25Q_SwReset(bool force)
W25Q Software Reset Reset by register (not by external GPIO pin)
Definition: w25q_mem.c:1350
W25Q_STATE W25Q_ReadData(u8_t *buf, u16_t len, u8_t pageShift, u32_t pageNum)
W25Q Read any 8-bit data Read any 8-bit data from preffered page place.
Definition: w25q_mem.c:464
W25Q_STATE W25Q_ReadSLong(i32_t *buf, u8_t pageShift, u32_t pageNum)
W25Q Read single Signed Long Read signed 32-bit long variable.
Definition: w25q_mem.c:418
W25Q_STATE W25Q_ReadByte(u8_t *buf, u8_t pageShift, u32_t pageNum)
W25Q Read single Unsigned Byte Read unsigned 8-bit byte variable.
Definition: w25q_mem.c:353
W25Q_STATE W25Q_ReadSByte(i8_t *buf, u8_t pageShift, u32_t pageNum)
W25Q Read single Signed Byte Read signed 8-bit byte variable.
Definition: w25q_mem.c:332
W25Q_STATE W25Q_ReadRaw(u8_t *buf, u16_t data_len, u32_t rawAddr)
W25Q Read any 8-bit data from raw addr Read any 8-bit data from preffered chip address.
Definition: w25q_mem.c:483
W25Q_STATE W25Q_ReadSWord(i16_t *buf, u8_t pageShift, u32_t pageNum)
W25Q Read single Signed Word Read signed 16-bit word variable.
Definition: w25q_mem.c:374
W25Q_STATE W25Q_SingleRead(u8_t *buf, u32_t len, u32_t Addr)
W25Q Read any 8-bit data from raw addr Read any 8-bit data from preffered chip address by SINGLE SPI.
Definition: w25q_mem.c:536
W25Q_STATE W25Q_ReadWord(u16_t *buf, u8_t pageShift, u32_t pageNum)
W25Q Read single Unsigned Word Read unsigned 16-bit word variable.
Definition: w25q_mem.c:396
W25Q_STATE W25Q_ReadLong(u32_t *buf, u8_t pageShift, u32_t pageNum)
W25Q Read single Signed Long Read signed 32-bit long variable.
Definition: w25q_mem.c:440
W25Q_STATE W25Q_ReadStatusReg(u8_t *reg_data, u8_t reg_num)
W25Q Read Status Register Read one status register.
Definition: w25q_mem.c:156
W25Q_STATE W25Q_ReadStatusStruct(W25Q_STATUS_REG *status)
W25Q Read Status Registers Read all status registers to struct.
Definition: w25q_mem.c:262
W25Q_STATE W25Q_WriteStatusReg(u8_t reg_data, u8_t reg_num)
W25Q Write Status Register Write one status register.
Definition: w25q_mem.c:206
W25Q_STATE W25Q_IsBusy(void)
W25Q Check Busy flag Fast checking Busy flag.
Definition: w25q_mem.c:303
W25Q_STATE W25Q_ProgResume(void)
W25Q Programm/Erase Resume Resume suspended state.
Definition: w25q_mem.c:1026
W25Q_STATE W25Q_ProgSuspend(void)
W25Q Programm/Erase Suspend Pause programm or suspend operatiom.
Definition: w25q_mem.c:986
W25Q_STATE W25Q_Sleep(void)
W25Q Sleep / Power Down Set chip to low-power state.
Definition: w25q_mem.c:1078
W25Q_STATE W25Q_WakeUP(void)
W25Q WakeUP Wake UP function.
Definition: w25q_mem.c:1118
W25Q_STATE W25Q_ProgramSByte(i8_t buf, u8_t pageShift, u32_t pageNum)
W25Q Program single Signed Byte Program signed 8-bit byte variable.
Definition: w25q_mem.c:601
W25Q_STATE W25Q_ProgramData(u8_t *buf, u16_t len, u8_t pageShift, u32_t pageNum)
W25Q Program any 8-bit data Program any 8-bit data to preffered page place.
Definition: w25q_mem.c:715
W25Q_STATE W25Q_ProgramLong(u32_t buf, u8_t pageShift, u32_t pageNum)
W25Q Program single Unigned Long Program unsigned 32-bit long vairable.
Definition: w25q_mem.c:694
W25Q_STATE W25Q_ProgramSWord(i16_t buf, u8_t pageShift, u32_t pageNum)
W25Q Program single Signed Word Program signed 16-bit word vairable.
Definition: w25q_mem.c:637
W25Q_STATE W25Q_ProgramRaw(u8_t *buf, u16_t data_len, u32_t rawAddr)
W25Q Program any 8-bit data to raw addr Program any 8-bit data to preffered chip address.
Definition: w25q_mem.c:734
W25Q_STATE W25Q_ProgramWord(u16_t buf, u8_t pageShift, u32_t pageNum)
W25Q Program single Unsigned Word Program unsigned 16-bit word vairable.
Definition: w25q_mem.c:656
W25Q_STATE W25Q_ProgramByte(u8_t buf, u8_t pageShift, u32_t pageNum)
W25Q Program single Unsigned Byte Program unsigned 8-bit byte vairable.
Definition: w25q_mem.c:619
W25Q_STATE W25Q_ProgramSLong(i32_t buf, u8_t pageShift, u32_t pageNum)
W25Q Program single Signed Long Program signed 32-bit long vairable.
Definition: w25q_mem.c:675
int8_t i8_t
8-bit signed
Definition: libs.h:18
uint32_t u32_t
32-bit unsigned
Definition: libs.h:21
uint8_t u8_t
< Lib for sprintf, strlen, etc
Definition: libs.h:17
uint16_t u16_t
16-bit unsigned
Definition: libs.h:19
int32_t i32_t
32-bit signed
Definition: libs.h:22
int16_t i16_t
16-bit signed
Definition: libs.h:20
W25Q Status Registers @TODO: Mem protected recognition.
Definition: w25q_mem.h:79

Functions that aren't yet ready:

W25Q_STATE W25Q_EnableVolatileSR(void); // Make Status Register Volatile
W25Q_STATE W25Q_SetBurstWrap(u8_t WrapSize); // Set Burst with Wrap
W25Q_STATE W25Q_ReadFullID(u8_t *buf); // Read full chip ID (Manufacturer ID + Device ID)
W25Q_STATE W25Q_ReadUID(u8_t *buf); // Read unique chip ID
W25Q_STATE W25Q_ReadJEDECID(u8_t *buf); // Read ID by JEDEC Standards
W25Q_STATE W25Q_ReadSFDPRegister(u8_t *buf); // Read device descriptor (SFDP Standard)
W25Q_STATE W25Q_EraseSecurityRegisters(u8_t numReg); // Erase security register
W25Q_STATE W25Q_ProgSecurityRegisters(u8_t *buf, u8_t numReg, u8_t byteAddr); // Program security register
W25Q_STATE W25Q_ReadSecurityRegisters(u8_t *buf, u8_t numReg, u8_t byteAddr); // Read security register
W25Q_STATE W25Q_BlockReadOnly(u32_t Addr, bool enable); // Individual block/sector read-only lock
W25Q_STATE W25Q_BlockReadOnlyCheck(bool *state, u32_t Addr); // Check block's/sector's read-only lock status
W25Q_STATE W25Q_GlobalReadOnly(bool enable); // Set read-only param to all chip
W25Q_STATE W25Q_ReadJEDECID(u8_t *buf)
W25Q Read JEDEC ID Read ID by JEDEC standards.
Definition: w25q_mem.c:1228
W25Q_STATE W25Q_ReadFullID(u8_t *buf)
W25Q Read chip Full ID Read Manufacturer ID + Device ID.
Definition: w25q_mem.c:1204
W25Q_STATE W25Q_ReadUID(u8_t *buf)
W25Q Read chip UID Read Unique ID.
Definition: w25q_mem.c:1216
W25Q_STATE W25Q_ReadSFDPRegister(u8_t *buf)
W25Q Read SFDP Register Read device descriptor by SFDP standard.
Definition: w25q_mem.c:1240
W25Q_STATE W25Q_BlockReadOnlyCheck(bool *state, u32_t Addr)
W25Q 4K Block lock CHECK Check read-only status from 4K block.
Definition: w25q_mem.c:1320
W25Q_STATE W25Q_GlobalReadOnly(bool enable)
W25Q Global read-only lock Set read-only status to the whole chip.
Definition: w25q_mem.c:1332
W25Q_STATE W25Q_BlockReadOnly(u32_t Addr, bool enable)
W25Q 4K Block lock Set read-only status to 4K block.
Definition: w25q_mem.c:1307
W25Q_STATE W25Q_EnableVolatileSR(void)
W25Q Enable Volatile SR Makes status register volatile (temporary)
Definition: w25q_mem.c:144
W25Q_STATE W25Q_ProgSecurityRegisters(u8_t *buf, u8_t numReg, u8_t byteAddr)
W25Q Program Security Register Write data to security reg.
Definition: w25q_mem.c:1273
W25Q_STATE W25Q_ReadSecurityRegisters(u8_t *buf, u8_t numReg, u8_t byteAddr)
W25Q Read Security Register Read data from security reg.
Definition: w25q_mem.c:1287
W25Q_STATE W25Q_EraseSecurityRegisters(u8_t numReg)
W25Q Erase Security Registers Clean security registers (one or all)
Definition: w25q_mem.c:1259
W25Q_STATE W25Q_SetBurstWrap(u8_t WrapSize)
W25Q Burst Wrap settings.
Definition: w25q_mem.c:588

Instructions for use:

  • Use CubeMX to configure QUADSPI peripheral reffer to your datasheet
  • Memory size calculation (AN4760 page 45):
    2^(N+1) = Mem size in bytes
    Example: 256 Mbit = 32 MByte = 32'768 KByte = 33'554'432 Byte = 2^25 Byte => N = 24
    Flash size
  • Connect memory to STM reffer to Datasheet, or your's chip datasheet
  • Include "w25q_mem.h" to your code
  • Start with Init function
  • Enjoy )

Any questions? Write an issue!

Donate: PayPal / DonationAlerts