Files
2026-02-03 12:01:38 +08:00

58 lines
1.6 KiB
C

#ifndef __BSP_W25Q_H__
#define __BSP_W25Q_H__
#include "main.h"
#ifdef __cplusplus
extern "C" {
#endif
/* w25q32jvssiq 容量参数 */
#define W25Q32_FLASH_SIZE (0x400000UL) /* 4mb = 32mb */
#define W25Q32_PAGE_SIZE (256) /* 页大小 */
#define W25Q32_SECTOR_SIZE (4096) /* 扇区大小 */
#define W25Q32_BLOCK_SIZE (65536) /* 块大小 */
/* w25q32jvssiq 命令字 */
#define W25Q32_WRITE_ENABLE 0x06
#define W25Q32_WRITE_DISABLE 0x04
#define W25Q32_READ_STATUS_REG1 0x05
#define W25Q32_WRITE_STATUS_REG 0x01
#define W25Q32_READ_DATA 0x03
#define W25Q32_FAST_READ 0x0B
#define W25Q32_PAGE_PROGRAM 0x02
#define W25Q32_SECTOR_ERASE 0x20
#define W25Q32_BLOCK_ERASE_32K 0x52
#define W25Q32_BLOCK_ERASE_64K 0xD8
#define W25Q32_CHIP_ERASE 0xC7
#define W25Q32_POWER_DOWN 0xB9
#define W25Q32_RELEASE_POWER_DOWN 0xAB
#define W25Q32_DEVICE_ID 0xAB
#define W25Q32_MANUFACTURER_ID 0x90
#define W25Q32_JEDEC_ID 0x9F
/* 状态寄存器位 */
#define W25Q32_STATUS_BUSY (1 << 0)
#define W25Q32_STATUS_WRITE_EN (1 << 1)
/* flash 存储区域 */
#define W25Q32_USER_DATA_ADDR 0x000000 /* 用户数据存储起始地址 */
#define W25Q32_USER_DATA_SIZE 0x100000 /* 大约1mb空间用于用户数据 */
/* w25q32 对象结构体 */
typedef struct {
void (*init)(void);
void (*read)(uint32_t addr, uint8_t *data, uint32_t len);
void (*write)(uint32_t addr, uint8_t *data, uint32_t len);
void (*chip_erase)(void);
} w25q32_t;
/* 全局对象 */
extern w25q32_t w25q32;
#ifdef __cplusplus
}
#endif
#endif /* __BSP_W25Q_H__ */