Files
Leakage-Control/calib_board/usr/bsp/bsp_w25q.h
2026-02-09 17:55:33 +08:00

73 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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
void w25q32_sector_erase(uint32_t sector_addr);
/* 状态寄存器位 */
#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空间用于用户数据 */
#define W25Q32_DEVICE_INFO_ADDR (0x001000) /* 设备信息存储地址 - 扇区14K对齐 */
#define DEVICE_INFO_STORAGE_SIZE (APP_LEAKAGE_SUB_DEVICE_NUM * sizeof(app_leakage_sub_device_flash_data_t)) /*设备信息存储大小*/
/* 历史报警存储地址和大小 */
#define W25Q32_HISTORY_ALARM_METADATA_ADDR 0x002000 /* 历史报警元数据存储地址 - 扇区2 */
#define W25Q32_HISTORY_ALARM_DATA_ADDR 0x003000 /* 历史报警数据存储地址 - 从扇区3开始 */
#define HISTORY_ALARM_RECORD_SIZE (sizeof(app_leakage_history_alarm_t)) /* 每条记录大小 */
#define HISTORY_ALARM_RECORDS_PER_SECTOR (W25Q32_SECTOR_SIZE / HISTORY_ALARM_RECORD_SIZE) /* 每扇区记录数 */
#define MAX_HISTORY_ALARM_RECORDS (1000) /* 最大历史报警记录数 */
#define HISTORY_ALARM_SECTORS_NEEDED ((MAX_HISTORY_ALARM_RECORDS * HISTORY_ALARM_RECORD_SIZE + W25Q32_SECTOR_SIZE - 1) / W25Q32_SECTOR_SIZE)
/* 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);
void (*sector_erase)(uint32_t sector_addr);
} w25q32_t;
/* 全局对象 */
extern w25q32_t w25q32;
#ifdef __cplusplus
}
#endif
#endif /* __BSP_W25Q_H__ */