Skip to content

W25Qxx.h 源代码

c
/**
  ******************************************************************************
  * @file    w25qxx.h
  * @brief   W25Q128 Flash驱动头文件
  ******************************************************************************
  */

#ifndef __W25QXX_H
#define __W25QXX_H

#ifdef __cplusplus
extern "C" {
#endif

/* 包含头文件 */
#include "main.h"

/* W25QXX 参数定义 */
#define W25QXX_CS_PIN       GPIO_PIN_4
#define W25QXX_CS_PORT      GPIOA
/* 使用项目中的hspi1句柄 */

/* W25QXX 容量 */
#define W25QXX_FLASH_SIZE    8 * 1024 * 1024  // 8MB
#define W25QXX_PAGE_SIZE     256
#define W25QXX_SECTOR_SIZE   4096
#define W25QXX_BLOCK_SIZE    65536
#define W25QXX_PAGE_NUM      (W25QXX_FLASH_SIZE / W25QXX_PAGE_SIZE)
#define W25QXX_SECTOR_NUM    (W25QXX_FLASH_SIZE / W25QXX_SECTOR_SIZE)
#define W25QXX_BLOCK_NUM     (W25QXX_FLASH_SIZE / W25QXX_BLOCK_SIZE)

/* W25QXX 指令集 */
#define W25X_WriteEnable              0x06
#define W25X_WriteDisable             0x04
#define W25X_ReadStatusReg1           0x05
#define W25X_ReadStatusReg2           0x35
#define W25X_ReadStatusReg3           0x15
#define W25X_WriteStatusReg1          0x01
#define W25X_WriteStatusReg2          0x31
#define W25X_WriteStatusReg3          0x11
#define W25X_ReadData                 0x03
#define W25X_FastReadData             0x0B
#define W25X_FastReadDual             0x3B
#define W25X_PageProgram              0x02
#define W25X_BlockErase32KB           0x52
#define W25X_BlockErase64KB           0xD8
#define W25X_SectorErase4KB           0x20
#define W25X_ChipErase                0xC7
#define W25X_PowerDown                0xB9
#define W25X_ReleasePowerDown         0xAB
#define W25X_ManufactDeviceID         0x90
#define W25X_JedecDeviceID            0x9F
#define W25X_EnableReset              0x66
#define W25X_ResetDevice              0x99

/* W25QXX 状态寄存器位定义 */
#define W25X_Busy                     0x01
#define W25X_WEL                      0x02
#define W25X_BP0                      0x04
#define W25X_BP1                      0x08
#define W25X_BP2                      0x10
#define W25X_TB                       0x20
#define W25X_SEC                      0x40
#define W25X_RP0                      0x80

/* 函数声明 */
void W25QXX_Init(void);
void W25QXX_CS(uint8_t level);
uint8_t W25QXX_ReadByte(void);
void W25QXX_WriteByte(uint8_t txData);
uint16_t W25QXX_ReadID(void);
void W25QXX_Read(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
void W25QXX_Write(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
void W25QXX_Write_Page(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
void W25QXX_Write_NoCheck(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
void W25QXX_Erase_Sector(uint32_t SectorAddr);
void W25QXX_Erase_Block32K(uint32_t BlockAddr);
void W25QXX_Erase_Block64K(uint32_t BlockAddr);
void W25QXX_Erase_Chip(void);
void W25QXX_Wait_Busy(void);
void W25QXX_WriteEnable(void);
void W25QXX_WriteDisable(void);
uint8_t W25QXX_ReadStatusReg1(void);
uint8_t W25QXX_ReadStatusReg2(void);
uint8_t W25QXX_ReadStatusReg3(void);
void W25QXX_WriteStatusReg(uint8_t status);
void W25QXX_PowerDown(void);
void W25QXX_WAKEUP(void);

#ifdef __cplusplus
}
#endif

#endif /* __W25QXX_H */