2021-11-06 05:21:57 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ROM_SPI_FLASH_H_
|
|
|
|
#define _ROM_SPI_FLASH_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "esp_attr.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PERIPHS_SPI_FLASH_CMD SPI_MEM_CMD_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_ADDR SPI_MEM_ADDR_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_CTRL SPI_MEM_CTRL_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_CTRL1 SPI_MEM_CTRL1_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_STATUS SPI_MEM_RD_STATUS_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_USRREG SPI_MEM_USER_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_USRREG1 SPI_MEM_USER1_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_USRREG2 SPI_MEM_USER2_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_C0 SPI_MEM_W0_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_C1 SPI_MEM_W1_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_C2 SPI_MEM_W2_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_C3 SPI_MEM_W3_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_C4 SPI_MEM_W4_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_C5 SPI_MEM_W5_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_C6 SPI_MEM_W6_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_C7 SPI_MEM_W7_REG(1)
|
|
|
|
#define PERIPHS_SPI_FLASH_TX_CRC SPI_MEM_TX_CRC_REG(1)
|
|
|
|
|
|
|
|
#define SPI0_R_QIO_DUMMY_CYCLELEN 5
|
|
|
|
#define SPI0_R_QIO_ADDR_BITSLEN 23
|
|
|
|
#define SPI0_R_FAST_DUMMY_CYCLELEN 7
|
|
|
|
#define SPI0_R_DIO_DUMMY_CYCLELEN 3
|
|
|
|
#define SPI0_R_FAST_ADDR_BITSLEN 23
|
|
|
|
#define SPI0_R_SIO_ADDR_BITSLEN 23
|
|
|
|
|
|
|
|
#define SPI1_R_QIO_DUMMY_CYCLELEN 5
|
|
|
|
#define SPI1_R_QIO_ADDR_BITSLEN 23
|
|
|
|
#define SPI1_R_FAST_DUMMY_CYCLELEN 7
|
|
|
|
#define SPI1_R_DIO_DUMMY_CYCLELEN 3
|
|
|
|
#define SPI1_R_DIO_ADDR_BITSLEN 23
|
|
|
|
#define SPI1_R_FAST_ADDR_BITSLEN 23
|
|
|
|
#define SPI1_R_SIO_ADDR_BITSLEN 23
|
|
|
|
|
|
|
|
#define ESP_ROM_SPIFLASH_W_SIO_ADDR_BITSLEN 23
|
|
|
|
|
|
|
|
#define ESP_ROM_SPIFLASH_TWO_BYTE_STATUS_EN SPI_MEM_WRSR_2B
|
|
|
|
|
|
|
|
//SPI address register
|
|
|
|
#define ESP_ROM_SPIFLASH_BYTES_LEN 24
|
|
|
|
#define ESP_ROM_SPIFLASH_BUFF_BYTE_WRITE_NUM 32
|
|
|
|
#define ESP_ROM_SPIFLASH_BUFF_BYTE_READ_NUM 16
|
|
|
|
#define ESP_ROM_SPIFLASH_BUFF_BYTE_READ_BITS 0xf
|
|
|
|
|
|
|
|
//SPI status register
|
|
|
|
#define ESP_ROM_SPIFLASH_BUSY_FLAG BIT0
|
|
|
|
#define ESP_ROM_SPIFLASH_WRENABLE_FLAG BIT1
|
|
|
|
#define ESP_ROM_SPIFLASH_BP0 BIT2
|
|
|
|
#define ESP_ROM_SPIFLASH_BP1 BIT3
|
|
|
|
#define ESP_ROM_SPIFLASH_BP2 BIT4
|
|
|
|
#define ESP_ROM_SPIFLASH_WR_PROTECT (ESP_ROM_SPIFLASH_BP0|ESP_ROM_SPIFLASH_BP1|ESP_ROM_SPIFLASH_BP2)
|
|
|
|
#define ESP_ROM_SPIFLASH_QE BIT9
|
|
|
|
|
|
|
|
#define FLASH_ID_GD25LQ32C 0xC86016
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ESP_ROM_SPIFLASH_RESULT_OK,
|
|
|
|
ESP_ROM_SPIFLASH_RESULT_ERR,
|
|
|
|
ESP_ROM_SPIFLASH_RESULT_TIMEOUT
|
|
|
|
} esp_rom_spiflash_result_t;
|
|
|
|
|
|
|
|
typedef void (* spi_flash_func_t)(void);
|
2021-09-28 07:35:36 -04:00
|
|
|
typedef esp_rom_spiflash_result_t (* spi_flash_op_t)(void);
|
|
|
|
typedef esp_rom_spiflash_result_t (* spi_flash_erase_t)(uint32_t);
|
|
|
|
typedef esp_rom_spiflash_result_t (* spi_flash_rd_t)(uint32_t, uint32_t*, int);
|
|
|
|
typedef esp_rom_spiflash_result_t (* spi_flash_wr_t)(uint32_t, const uint32_t*, int);
|
|
|
|
typedef esp_rom_spiflash_result_t (* spi_flash_ewr_t)(uint32_t, const void*, uint32_t);
|
|
|
|
typedef esp_rom_spiflash_result_t (* spi_flash_wren_t)(void*);
|
2021-11-06 05:21:57 -04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t read_sub_len;
|
|
|
|
uint32_t write_sub_len;
|
|
|
|
spi_flash_op_t unlock;
|
|
|
|
spi_flash_erase_t erase_sector;
|
|
|
|
spi_flash_erase_t erase_block;
|
|
|
|
spi_flash_rd_t read;
|
|
|
|
spi_flash_wr_t write;
|
|
|
|
spi_flash_ewr_t encrypt_write;
|
|
|
|
spi_flash_func_t check_sus;
|
|
|
|
spi_flash_wren_t wren;
|
|
|
|
spi_flash_op_t wait_idle;
|
|
|
|
} spiflash_legacy_funcs_t;
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _ROM_SPI_FLASH_H_ */
|