芯片:W25X20CLUXIG-TR
大小:2M bit , 256Kbyte 字节 (0x40000=262144)
4个块(Block), 每块 64KB=0x10000
64个扇区(Sector), 每16个扇区组成1块, 每个扇区 4KB=0x1000, 最小一次擦除一共扇区。
Flash 厂商ID等
JEDEC:全称是Joint Electron Device Engineering Council 即电子元件工业联合会。JEDEC是由生产厂商们制定的国际性协议,主要为内存制定。JEDEC用来帮助程序读取Flash的制造商ID和设备ID,以确定Flash的大小和算法。
Flash 读写相关指令:
指令:
/* commands */
#define WRITE_ENABLE 0x06
#define WRITE_ENABLE_VOL 0x50
#define WRITE_DISABLE 0x04
#define READ_STATUS_REG 0x05
#define WRITE_STATUS_REG 0x01
#define PAGE_PROGRAM 0x02
#define QUAD_PAGE_PROGRAM 0x32
#define CHIP_ERASE 0xC7
// ^^^// or 0x60
#define ERASE_SUSPEND 0x75
#define ERASE_RESUME 0x7a
#define POWER_DOWN 0xb9
#define HIGH_PERF_MODE 0xa3
#define MODE_BIT_RESET 0xff
#define REL_POWER_DOWN 0xab
#define MAN_DEV_ID 0x90
#define READ_UNIQUE_ID 0x4b
#define JEDEC_ID 0x9f
#define READ_DATA 0x03
#define FAST_READ 0x0b
状态:
/* Status Register Bits */
#define STATUS_BUSY 0x01
#define STATUS_WEL 0x02
#define STATUS_BP0 0x04
#define STATUS_BP1 0x08
#define STATUS_TB 0x20
#define STATUS_SRP 0x80
#define ERR_OK 0
#define ERR_TIMEOUT -1
#define ERR_NOT_ERASED -2
#define ERR_PROTECTED -3
#define ERR_INVAL -4
#define ERR_ALIGN -5
#define ERR_UNKNOWN_FLASH_VENDOR -6
#define ERR_UNKNOWN_FLASH_TYPE -7
#define ERR_PROG_ERROR -8
各厂商芯片的参数:
// 1. W25X10CL
#define SPI_FLASH_DEVICE_INDEX_W25X10 0
#define W25X10_MAN_DEV_ID 0xEF10
#define W25X10_JEDEC_ID 0xEF3011
#define W25X10_JEDEC_ID_MATCHING_BITMASK 0xFFFFFF
#define W25X10_TOTAL_FLASH_SIZE 0x20000
#define W25X10_PAGE_SIZE 0x100
#define W25x10_MEM_PROT_NONE 0
#define W25x10_MEM_PROT_UPPER_HALF 4
#define W25x10_MEM_PROT_LOWER_HALF 36
#define W25x10_MEM_PROT_ALL 8
// 2. W25X20CL
#define SPI_FLASH_DEVICE_INDEX_W25X20 1
#define W25X20_MAN_DEV_ID 0xEF11
#define W25X20_JEDEC_ID 0xEF3012
#define W25X20_JEDEC_ID_MATCHING_BITMASK 0xFFFFFF
#define W25X20_TOTAL_FLASH_SIZE 0x40000
#define W25X20_PAGE_SIZE 0x100
#define W25x20_MEM_PROT_NONE 0
#define W25x20_MEM_PROT_UPPER_QUARTER 4
#define W25x20_MEM_PROT_UPPER_HALF 8
#define W25x20_MEM_PROT_LOWER_QUARTER 36
#define W25x20_MEM_PROT_LOWER_HALF 40
#define W25x20_MEM_PROT_ALL 12
// Parameters common to both W25X10 and W25X20
#define W25x_MEM_PROT_BITMASK 0x2C
// 3. AT25DN011, AT25DF011
#define SPI_FLASH_DEVICE_INDEX_AT25Dx011 2
#define AT25Dx011_JEDEC_ID 0x1F4200
#define AT25Dx011_JEDEC_ID_MATCHING_BITMASK 0xFFFF00
#define AT25Dx011_TOTAL_FLASH_SIZE 0x20000
#define AT25Dx011_PAGE_SIZE 0x100
#define AT25Dx011_MEM_PROT_BITMASK 4
#define AT25Dx011_MEM_PROT_NONE 0
#define AT25Dx011_MEM_PROT_ENTIRE_MEMORY_PROTECTED 4
// 4. MX25V1006E
#define SPI_FLASH_DEVICE_INDEX_MX25V1006E 3
#define MX25V1006E_MAN_DEV_ID 0xC210
#define MX25V1006E_JEDEC_ID 0xC22011
#define MX25V1006E_JEDEC_ID_MATCHING_BITMASK 0xFFFFFF
#define MX25V1006E_TOTAL_FLASH_SIZE 0x20000
#define MX25V1006E_PAGE_SIZE 0x100
#define MX25V1006E_MEM_PROT_BITMASK 0x0C
#define MX25V1006E_MEM_PROT_NONE 0
#define MX25V1006E_MEM_PROT_ENTIRE_MEMORY_PROTECTED 0x0C