mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-23 19:25:09 +08:00
60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
#ifndef W25Q64_H
|
|
#define W25Q64_H
|
|
|
|
#include "main.h"
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define W25Q64_PAGE_SIZE 256U
|
|
#define W25Q64_SECTOR_SIZE 4096U
|
|
#define W25Q64_FLASH_SIZE 0x800000U
|
|
#define W25Q64_JEDEC_ID 0xEF4017U
|
|
|
|
#define W25Q64_CMD_WRITE_ENABLE 0x06U
|
|
#define W25Q64_CMD_READ_STATUS_1 0x05U
|
|
#define W25Q64_CMD_READ_ID 0x9FU
|
|
#define W25Q64_CMD_READ_DATA 0x03U
|
|
#define W25Q64_CMD_PAGE_PROGRAM 0x02U
|
|
#define W25Q64_CMD_SECTOR_ERASE 0x20U
|
|
#define W25Q64_CMD_BLOCK_ERASE_64K 0xD8U
|
|
#define W25Q64_CMD_CHIP_ERASE 0xC7U
|
|
|
|
typedef enum
|
|
{
|
|
W25Q64_OK = 0,
|
|
W25Q64_ERR_PARAM = -1,
|
|
W25Q64_ERR_NOT_ATTACHED = -2,
|
|
W25Q64_ERR_HAL = -3,
|
|
W25Q64_ERR_ID = -4,
|
|
W25Q64_ERR_BUSY = -5
|
|
} W25Q64_Status_t;
|
|
|
|
typedef struct
|
|
{
|
|
SPI_HandleTypeDef *hspi;
|
|
GPIO_TypeDef *cs_port;
|
|
uint16_t cs_pin;
|
|
uint32_t timeout_ms;
|
|
} W25Q64_Handle_t;
|
|
|
|
void W25Q64_Attach(W25Q64_Handle_t *handle);
|
|
void W25Q64_Detach(void);
|
|
|
|
W25Q64_Status_t W25Q64_Init(void);
|
|
W25Q64_Status_t W25Q64_ReadID(uint32_t *jedec_id);
|
|
W25Q64_Status_t W25Q64_Read(uint32_t addr, uint8_t *data, uint32_t len);
|
|
W25Q64_Status_t W25Q64_Write(uint32_t addr, const uint8_t *data, uint32_t len);
|
|
W25Q64_Status_t W25Q64_EraseSector(uint32_t addr);
|
|
W25Q64_Status_t W25Q64_Erase64K(uint32_t addr);
|
|
W25Q64_Status_t W25Q64_ChipErase(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|