From e3b01eef59f04eb07257035425a3a464235eeddf Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 11 Mar 2022 14:52:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=A4=E4=B8=AA=E5=A4=A7?= =?UTF-8?q?=E5=AE=B9=E9=87=8FFlash=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=9A[W25Q512JV=E3=80=81W25Q01JV]=20=E6=B7=BB=E5=8A=A04?= =?UTF-8?q?=E5=AD=97=E8=8A=82=E6=A8=A1=E5=BC=8F=E6=8C=87=E4=BB=A4=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=A7=E5=AE=B9=E9=87=8FFlash=E4=B8=8BInst?= =?UTF-8?q?ruction+1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 + sfud/inc/sfud_def.h | 20 +++++++++ sfud/inc/sfud_flash_def.h | 6 +++ sfud/src/sfud.c | 85 ++++++++++++++++++++++++++++++++------- 4 files changed, 98 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 42ac6c9..992a88d 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ |[W25Q64CV](http://www.winbond.com/resource-files/w25q64cv_revh_052214[2].pdf)|Winbond|64Mb|80Mhz|支持|四线|| |[W25Q128BV](http://www.winbond.com/resource-files/w25q128bv_revh_100313_wo_automotive.pdf)|Winbond|128Mb|104Mhz|支持|四线|| |[W25Q256FV](http://www.winbond.com/resource-files/w25q256fv%20revi%2002262016%20kms.pdf)|Winbond|256Mb|104Mhz|支持|四线|| +|[W25Q512JV](https://www.winbond.com/resource-files/W25Q512JV%20SPI%20RevG%2001122022Plus.pdf)|Winbond|512Mb|133Mhz|支持|四线| 似乎不支持SFUD 请不要开启| +|[W25Q01JV](https://www.winbond.com/resource-files/W25Q01JV%20SPI%20RevC%2005032021%20Plus%20dummy.pdf)|Winbond|1024Mb|133Mhz|支持|四线|似乎不支持SFUD 请不要开启| |[MX25L3206E](http://www.macronix.com/Lists/DataSheet/Attachments/3199/MX25L3206E,%203V,%2032Mb,%20v1.5.pdf)|Macronix|32Mb|86MHz|支持|双线|| |[KH25L4006E](http://www.macronix.com.hk/Lists/Datasheet/Attachments/117/KH25L4006E.pdf)|Macronix|4Mb|86Mhz|支持|未测试| by [JiapengLi](https://github.com/JiapengLi)| |[KH25L3206E](http://www.macronix.com.hk/Lists/Datasheet/Attachments/131/KH25L3206E.pdf)|Macronix|32Mb|86Mhz|支持|双线|| diff --git a/sfud/inc/sfud_def.h b/sfud/inc/sfud_def.h index fe78766..caef29e 100644 --- a/sfud/inc/sfud_def.h +++ b/sfud/inc/sfud_def.h @@ -106,6 +106,10 @@ if (!(EXPR)) \ #define SFUD_CMD_PAGE_PROGRAM 0x02 #endif +#ifndef SFUD_CMD_PAGE_PROGRAM_4_BYTES_MODE +#define SFUD_CMD_PAGE_PROGRAM_4_BYTES_MODE 0x12 +#endif + #ifndef SFUD_CMD_AAI_WORD_PROGRAM #define SFUD_CMD_AAI_WORD_PROGRAM 0xAD #endif @@ -122,18 +126,34 @@ if (!(EXPR)) \ #define SFUD_CMD_DUAL_OUTPUT_READ_DATA 0x3B #endif +#ifndef SFUD_CMD_DUAL_OUTPUT_READ_DATA_4_BYTES_MODE +#define SFUD_CMD_DUAL_OUTPUT_READ_DATA_4_BYTES_MODE 0x3C +#endif + #ifndef SFUD_CMD_DUAL_IO_READ_DATA #define SFUD_CMD_DUAL_IO_READ_DATA 0xBB #endif +#ifndef SFUD_CMD_DUAL_IO_READ_DATA_4_BYTES_MODE +#define SFUD_CMD_DUAL_IO_READ_DATA_4_BYTES_MODE 0xBC +#endif + #ifndef SFUD_CMD_QUAD_IO_READ_DATA #define SFUD_CMD_QUAD_IO_READ_DATA 0xEB #endif +#ifndef SFUD_CMD_QUAD_IO_READ_DATA_4_BYTES_MODE +#define SFUD_CMD_QUAD_IO_READ_DATA_4_BYTES_MODE 0xEC +#endif + #ifndef SFUD_CMD_QUAD_OUTPUT_READ_DATA #define SFUD_CMD_QUAD_OUTPUT_READ_DATA 0x6B #endif +#ifndef SFUD_CMD_QUAD_OUTPUT_READ_DATA_4_BYTES_MODE +#define SFUD_CMD_QUAD_OUTPUT_READ_DATA_4_BYTES_MODE 0x6C +#endif + #ifndef SFUD_CMD_MANUFACTURER_DEVICE_ID #define SFUD_CMD_MANUFACTURER_DEVICE_ID 0x90 #endif diff --git a/sfud/inc/sfud_flash_def.h b/sfud/inc/sfud_flash_def.h index 44f4c44..946c3d8 100644 --- a/sfud/inc/sfud_flash_def.h +++ b/sfud/inc/sfud_flash_def.h @@ -131,6 +131,8 @@ typedef struct { {"W25Q64DW", SFUD_MF_ID_WINBOND, 0x60, 0x17, 8L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ {"W25Q128BV", SFUD_MF_ID_WINBOND, 0x40, 0x18, 16L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ {"W25Q256FV", SFUD_MF_ID_WINBOND, 0x40, 0x19, 32L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ + {"W25Q512JV", SFUD_MF_ID_WINBOND, 0x40, 0x20, 64L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ + {"W25Q01JV", SFUD_MF_ID_WINBOND, 0x40, 0x21, 128L*1024L*1024L, SFUD_WM_PAGE_256B, 4096, 0x20}, \ {"SST25VF080B", SFUD_MF_ID_SST, 0x25, 0x8E, 1L*1024L*1024L, SFUD_WM_BYTE|SFUD_WM_AAI, 4096, 0x20}, \ {"SST25VF016B", SFUD_MF_ID_SST, 0x25, 0x41, 2L*1024L*1024L, SFUD_WM_BYTE|SFUD_WM_AAI, 4096, 0x20}, \ {"M25P32", SFUD_MF_ID_MICRON, 0x20, 0x16, 4L*1024L*1024L, SFUD_WM_PAGE_256B, 64L*1024L, 0xD8}, \ @@ -170,6 +172,10 @@ typedef struct { {SFUD_MF_ID_WINBOND, 0x40, 0x18, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \ /* W25Q256FV */ \ {SFUD_MF_ID_WINBOND, 0x40, 0x19, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \ + /* W25Q512JV */ \ + {SFUD_MF_ID_WINBOND, 0x40, 0x20, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \ + /* W25Q01JV */ \ + {SFUD_MF_ID_WINBOND, 0x40, 0x21, NORMAL_SPI_READ|DUAL_OUTPUT|DUAL_IO|QUAD_OUTPUT|QUAD_IO}, \ /* EN25Q32B */ \ {SFUD_MF_ID_EON, 0x30, 0x16, NORMAL_SPI_READ|DUAL_OUTPUT|QUAD_IO}, \ /* S25FL216K */ \ diff --git a/sfud/src/sfud.c b/sfud/src/sfud.c index d6f0c23..aa20f2e 100644 --- a/sfud/src/sfud.c +++ b/sfud/src/sfud.c @@ -163,14 +163,23 @@ const sfud_flash *sfud_get_device_table(void) { } #ifdef SFUD_USING_QSPI +/*** + * QSPI Set Read Command Format + * @param flash + * @param ins + * @param ins_lines + * @param addr_lines + * @param dummy_cycles + * @param data_lines + */ static void qspi_set_read_cmd_format(sfud_flash *flash, uint8_t ins, uint8_t ins_lines, uint8_t addr_lines, uint8_t dummy_cycles, uint8_t data_lines) { - /* if medium size greater than 16Mb, use 4-Byte address, instruction should be added one */ + + flash->read_cmd_format.instruction = ins; + /* if medium size greater than 16MB(128Mbit), use 4-Byte address, instruction should be added one */ if (flash->chip.capacity <= 0x1000000) { - flash->read_cmd_format.instruction = ins; flash->read_cmd_format.address_size = 24; } else { - flash->read_cmd_format.instruction = ins + 1; flash->read_cmd_format.address_size = 32; } @@ -217,21 +226,67 @@ sfud_err sfud_qspi_fast_read_enable(sfud_flash *flash, uint8_t data_line_width) qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); break; case 2: - if (read_mode & DUAL_IO) { - qspi_set_read_cmd_format(flash, SFUD_CMD_DUAL_IO_READ_DATA, 1, 2, 8, 2); - } else if (read_mode & DUAL_OUTPUT) { - qspi_set_read_cmd_format(flash, SFUD_CMD_DUAL_OUTPUT_READ_DATA, 1, 1, 8, 2); - } else { - qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); + if (flash->addr_in_4_byte) + { + if (read_mode & DUAL_IO) + { + qspi_set_read_cmd_format(flash, SFUD_CMD_DUAL_IO_READ_DATA_4_BYTES_MODE, 1, 2, 4, 2); + } + else if (read_mode & DUAL_OUTPUT) + { + qspi_set_read_cmd_format(flash, SFUD_CMD_DUAL_OUTPUT_READ_DATA_4_BYTES_MODE, 1, 1, 8, 2); + } + else + { + qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); + } + } + else + { + if (read_mode & DUAL_IO) + { + qspi_set_read_cmd_format(flash, SFUD_CMD_DUAL_IO_READ_DATA, 1, 2, 4, 2); + } + else if (read_mode & DUAL_OUTPUT) + { + qspi_set_read_cmd_format(flash, SFUD_CMD_DUAL_OUTPUT_READ_DATA, 1, 1, 8, 2); + } + else + { + qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); + } } break; case 4: - if (read_mode & QUAD_IO) { - qspi_set_read_cmd_format(flash, SFUD_CMD_QUAD_IO_READ_DATA, 1, 4, 6, 4); - } else if (read_mode & QUAD_OUTPUT) { - qspi_set_read_cmd_format(flash, SFUD_CMD_QUAD_OUTPUT_READ_DATA, 1, 1, 8, 4); - } else { - qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); + if (flash->addr_in_4_byte) + { + if (read_mode & QUAD_IO) + { + qspi_set_read_cmd_format(flash, SFUD_CMD_QUAD_IO_READ_DATA_4_BYTES_MODE, 1, 4, 6, 4); + } + else if (read_mode & QUAD_OUTPUT) + { + qspi_set_read_cmd_format(flash, SFUD_CMD_QUAD_OUTPUT_READ_DATA_4_BYTES_MODE, 1, 1, 8, 4); + } + else + { + qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); + } + } + else + { + if (read_mode & QUAD_IO) + { + qspi_set_read_cmd_format(flash, SFUD_CMD_QUAD_IO_READ_DATA, 1, 4, 6, 4); + } + else if (read_mode & QUAD_OUTPUT) + { + qspi_set_read_cmd_format(flash, SFUD_CMD_QUAD_OUTPUT_READ_DATA, 1, 1, 8, 4); + } + else + { + qspi_set_read_cmd_format(flash, SFUD_CMD_READ_DATA, 1, 1, 0, 1); + } } break; }