Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
z_qflash_W25QXXX.h File Reference

Driver for W25Qxxx series Quad-SPI NOR Flash memory. More...

#include "main.h"
Include dependency graph for z_qflash_W25QXXX.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define QFLASH_INSTRUCTION_MODE   QSPI_INSTRUCTION_1_LINE
 
#define QFLASH_ADDRESS_SIZE   QSPI_ADDRESS_32_BITS
 
#define QFLASH_ALTERNATE_BYTE_MODE   QSPI_ALTERNATE_BYTES_NONE
 
#define QFLASH_DDR_MODE   QSPI_DDR_MODE_DISABLE
 
#define QFLASH_DDR_HOLD_HALF_CYCLE   QSPI_DDR_HHC_ANALOG_DELAY
 
#define QFLASH_SIOO_MODE   QSPI_SIOO_INST_EVERY_CMD
 
#define QFLASH_DUMMY_CYCLES   0
 
#define QFLASH_DEF_TIMEOUT   HAL_QSPI_TIMEOUT_DEFAULT_VALUE
 
#define QFLASH_BSY_TIMEOUT   400000
 
#define QFLASH_ADDRESS_MODE   QSPI_ADDRESS_4_LINES
 
#define QFLASH_DATA_MODE   QSPI_DATA_4_LINES
 
#define QFLASH_READ_COMMAND   W25_FREAD_QUAD
 
#define QFLASH_READ_DUMMYC   4
 
#define QFLASH_ALT_BYTES   0xFF
 
#define QFLASH_ALT_BYTES_S   QSPI_ALTERNATE_BYTES_8_BITS
 
#define QFLASH_ALT_BYTES_M   QSPI_ALTERNATE_BYTES_4_LINES
 
#define QFLASH_WRITE_COMMAND   W25_FPAGE_P_QUAD_4B
 
#define QFLASH_WDATA_MODE   QSPI_DATA_4_LINES
 
#define W25_RESET_EN   0x66
 
#define W25_RESET   0x99
 
#define W25_W_ENABLE   0x06
 
#define W25_READ   0x03
 
#define W25_FREAD   0x0B
 
#define W25_FREAD_DUAL   0xBB
 
#define W25_FREAD_QUAD   0xEB
 
#define W25_PAGE_P   0x02
 
#define W25_FPAGE_P_QUAD   0x32
 
#define W25_FPAGE_P_QUAD_4B   0x34
 
#define W25_S_ERASE4K   0x20
 
#define W25_S_ERASE4K_4B   0x21
 
#define W25_B_ERASE32K   0x52
 
#define W25_B_ERASE64K   0xD8
 
#define W25_B_ERASE64K_4B   0xDC
 
#define W25_CH_ERASE   0xC7
 
#define W25_POWERDOWN   0xB9
 
#define W25_POWERUP_ID   0xAB
 
#define W25_JEDEC_ID   0x9F
 
#define W25_R_SR1   0x05
 
#define W25_R_SFPD_REG   0x5A
 
#define W25_W_DISABLE   0x04
 
#define W25_MAN_DEVICE_ID   0x90
 
#define W25_R_SR2   0x35
 
#define W25_W_SR2   0x31
 
#define W25_R_SR3   0x15
 
#define W25_W_SR3   0x11
 
#define W25_SR_W_ENABLE   0x50
 
#define W25_ENTER_4B_ADDR   0xB7
 
#define W25_DUMMY   0x00
 
#define SR1_BIT_BSY   (01U)
 
#define SR1_BIT_WEL   (02U)
 
#define SR2_BIT_QE   (0x02U)
 
HAL Handle Configuration
#define FLASH_QSPI_PORT   hqspi
 The HAL QSPI_HandleTypeDef defined in main.h.
 
QSPI Communication Mode

Selects between blocking (polling) and non-blocking (DMA) transfers. Uncomment ONE of the following options.

#define EXT_FLASH_QSPI_DMA_MODE
 
Flash Bus Protocol

Selects the SPI protocol (Single, Dual, or Quad). This must match the hardware wiring. Uncomment ONE of the following options.

#define FLASH_QMODE_4
 Quad SPI (4-bit data lines).
 
Target Flash Memory Layout

Defines the geometry of the specific W25Qxxx chip being used.

Warning
The EXT_FLASH_SIZE must correspond to the FSIZE parameter in the STM32CubeMX QSPI configuration. FSIZE = log2(total_bytes) - 1.
#define EXT_FLASH_PAGE_SIZE   0x0100
 256 bytes per programmable page.
 
#define EXT_FLASH_SECTOR_SIZE   0x1000
 4 KB per erasable sector.
 
#define EXT_FLASH_BLOCK_SIZE   0x00010000
 64 KB per erasable block.
 
#define EXT_FLASH_SIZE   0x04000000
 64 MB total capacity (W25Q512).
 
#define EXT_FLASH_PAGE_NUM   (EXT_FLASH_SIZE / EXT_FLASH_PAGE_SIZE)
 Total number of pages.
 
#define EXT_FLASH_SECTOR_NUM   (EXT_FLASH_SIZE / EXT_FLASH_SECTOR_SIZE)
 Total number of sectors.
 
#define EXT_FLASH_BLOCK_NUM   (EXT_FLASH_SIZE / EXT_FLASH_BLOCK_SIZE)
 Total number of blocks.
 

Enumerations

enum  HAL_StatusTypeDef { HAL_OK = 0x00 , HAL_ERROR = 0x01 , HAL_BUSY = 0x02 , HAL_TIMEOUT = 0x03 }
 HAL Status structures definition. More...
 

Functions

uint8_t QFlash_IsQSPIAvailable (void)
 
HAL_StatusTypeDef QFlash_WaitForQSPIAvailable (uint32_t timeout)
 
uint8_t QFlash_IsDataAvailable (void)
 
HAL_StatusTypeDef QFlash_WaitForDataAvailable (uint32_t timeout)
 
void QFlash_DefaultCmd (QSPI_CommandTypeDef *sCommand)
 
HAL_StatusTypeDef QFlash_Init (void)
 
HAL_StatusTypeDef QFlash_ReadJedecID (uint8_t *dataptr)
 
HAL_StatusTypeDef QFlash_ReadSFDP (uint8_t *dataptr)
 
HAL_StatusTypeDef QFlash_ReadDevID (uint8_t *dataptr)
 
HAL_StatusTypeDef QFlash_ReadManufactutrerAndDevID (uint16_t *dataptr)
 read id of the winbond
 
HAL_StatusTypeDef QFlash_Reset (void)
 
HAL_StatusTypeDef QFlash_WriteEnable (void)
 enables writes
 
HAL_StatusTypeDef QFlash_WriteDisable (void)
 disables writes
 
HAL_StatusTypeDef QFlash_ReadSR1 (uint8_t *dataptr)
 
HAL_StatusTypeDef QFlash_ReadSR2 (uint8_t *dataptr)
 
HAL_StatusTypeDef QFlash_ReadSR3 (uint8_t *dataptr)
 
HAL_StatusTypeDef QFlash_WriteSR2 (uint8_t data)
 writes to register 2
 
HAL_StatusTypeDef QFlash_WriteSR3 (uint8_t data)
 writes to register 3
 
HAL_StatusTypeDef QFlash_CheckSR1 (void)
 
HAL_StatusTypeDef QFlash_WaitForWritingComplete (void)
 
HAL_StatusTypeDef QFlash_PowerDown (void)
 
HAL_StatusTypeDef QFlash_PowerUp (void)
 
HAL_StatusTypeDef QFlash_Read (uint32_t address, uint8_t *buffer, uint32_t dataSize)
 
HAL_StatusTypeDef QFlash_Write (uint32_t addr, uint8_t *data, uint32_t dataSize)
 
HAL_StatusTypeDef QFlash_SErase4k (uint32_t addr)
 
HAL_StatusTypeDef QFlash_BErase32k (uint32_t addr)
 
HAL_StatusTypeDef QFlash_BErase64k (uint32_t addr)
 
HAL_StatusTypeDef QFlash_ChipErase (void)
 
void DataReader_WaitForReceiveDone (void)
 
void DataReader_ReadData (uint32_t address24, uint8_t *buffer, uint32_t length)
 
void DataReader_StartDMAReadData (uint32_t address24, uint8_t *buffer, uint32_t length)
 
void HAL_QSPI_CmdCpltCallback (QSPI_HandleTypeDef *hqspi)
 
void HAL_QSPI_RxCpltCallback (QSPI_HandleTypeDef *hqspi)
 
void HAL_QSPI_TxCpltCallback (QSPI_HandleTypeDef *hqspi)
 
void HAL_QSPI_ErrorCallback (QSPI_HandleTypeDef *hqspi)
 

Detailed Description

Driver for W25Qxxx series Quad-SPI NOR Flash memory.

Author
mauro, Francesco Abate
Date
2024-08-01
Version
1.0.0

This driver provides a complete set of functions to interface with a Winbond W25Qxxx series NOR Flash memory chip using the STM32's Quad-SPI peripheral. It serves as a hardware abstraction layer for all flash memory operations.

Configuration

This driver is highly configurable. All user-tunable parameters are located in this header file under the "User Configuration" group. Key features to configure include:

  • Communication mode (Polling vs. DMA).
  • Flash access mode (Indirect vs. Memory-Mapped).
  • QSPI protocol (Single, Dual, or Quad SPI mode).
  • Target flash chip memory layout (size, pages, sectors).

Definition in file z_qflash_W25QXXX.h.

Enumeration Type Documentation

◆ HAL_StatusTypeDef

HAL Status structures definition.

Enumerator
HAL_OK 
HAL_ERROR 
HAL_BUSY 
HAL_TIMEOUT 

Definition at line 314 of file z_qflash_W25QXXX.h.

315{
316 HAL_OK = 0x00,
317 HAL_ERROR = 0x01,
318 HAL_BUSY = 0x02,
319 HAL_TIMEOUT = 0x03
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_TIMEOUT
@ HAL_ERROR
@ HAL_OK
@ HAL_BUSY