You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.5 KiB
96 lines
3.5 KiB
#ifndef __W25QXX_H
|
|
#define __W25QXX_H
|
|
#include "common.h"
|
|
|
|
/* ===========================================================================
|
|
* W25QXX 传输层选择宏
|
|
* ---------------------------------------------------------------------------
|
|
* W25QXX_USE_QSPI -> 使用 STM32H7 QUADSPI 外设(1-Line/SPI 兼容时序)
|
|
* 依赖 CubeMX 生成的 quadspi.c 中全局句柄 hqspi。
|
|
* W25QXX_USE_SPI -> 使用经典 SPI 外设(原正点原子 F4 驱动),
|
|
* 依赖 bsp 中定义的 W25QXXSPI 与 W25QXX_CS_x。
|
|
*
|
|
* 若两者均未定义,则根据编译目标自动选择:
|
|
* STM32H7xx / STM32H743xx / STM32H750xx -> W25QXX_USE_QSPI
|
|
* 其余 (F4/F1 等) -> W25QXX_USE_SPI
|
|
* ===========================================================================*/
|
|
#if !defined(W25QXX_USE_QSPI) && !defined(W25QXX_USE_SPI)
|
|
#if defined(STM32H7xx) || defined(STM32H743xx) || defined(STM32H750xx)
|
|
#define W25QXX_USE_QSPI
|
|
#else
|
|
#define W25QXX_USE_SPI
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* W25Q 系列芯片型号(W25QXX_ReadID 返回值,Manufact/Device ID 0x90 读法) */
|
|
#define W25Q80 0xEF13
|
|
#define W25Q16 0xEF14
|
|
#define W25Q32 0xEF15
|
|
#define W25Q64 0xEF16
|
|
#define W25Q128 0xEF17
|
|
#define W25Q256 0xEF18
|
|
|
|
extern uint16_t W25QXX_TYPE; /* 当前芯片型号 */
|
|
|
|
/* 扇区 / 页大小 */
|
|
#define W25QXX_SECTOR_SIZE 4096
|
|
#define W25QXX_PAGE_SIZE 256
|
|
|
|
/* 指令表 */
|
|
#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_BlockErase 0xD8
|
|
#define W25X_SectorErase 0x20
|
|
#define W25X_ChipErase 0xC7
|
|
#define W25X_PowerDown 0xB9
|
|
#define W25X_ReleasePowerDown 0xAB
|
|
#define W25X_DeviceID 0xAB
|
|
#define W25X_ManufactDeviceID 0x90
|
|
#define W25X_JedecDeviceID 0x9F
|
|
#define W25X_Enable4ByteAddr 0xB7
|
|
#define W25X_Exit4ByteAddr 0xE9
|
|
#define W25X_ResetEnable 0x66
|
|
#define W25X_ResetMemory 0x99
|
|
|
|
/* SPI 模式下才需要片选信号(H7 QUADSPI 模式下由硬件 CS 管理,无需此宏) */
|
|
#ifdef W25QXX_USE_SPI
|
|
#define W25QXX_CS(n) (n?HAL_GPIO_WritePin(W25QXX_CS_GPIO_Port,W25QXX_CS_Pin,GPIO_PIN_SET):HAL_GPIO_WritePin(W25QXX_CS_GPIO_Port,W25QXX_CS_Pin,GPIO_PIN_RESET))
|
|
#endif
|
|
|
|
/* 对外 API(两种传输层共用同一套接口) */
|
|
void W25QXX_Init(void);
|
|
uint16_t W25QXX_ReadID(void);
|
|
uint8_t W25QXX_ReadSR(uint8_t regno);
|
|
void W25QXX_4ByteAddr_Enable(void);
|
|
void W25QXX_Write_SR(uint8_t regno, uint8_t sr);
|
|
void W25QXX_Write_Enable(void);
|
|
void W25QXX_Write_Disable(void);
|
|
int W25QXX_Write_Page(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
|
|
int W25QXX_Write_NoCheck(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
|
|
int 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_Erase_Chip(void);
|
|
int W25QXX_Erase_Sector(uint32_t Dst_Addr);
|
|
void W25QXX_Wait_Busy(void);
|
|
void W25QXX_PowerDown(void);
|
|
void W25QXX_WAKEUP(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __W25QXX_H */
|
|
|