forked from espressif/esp-idf
feat(spi_flash): Add support for winbond flash chip
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -15,6 +15,11 @@
|
|||||||
#define REGION_32BIT(start, len) ((start) + (len) > (1<<24))
|
#define REGION_32BIT(start, len) ((start) + (len) > (1<<24))
|
||||||
#define ADDR_32BIT(addr) (addr >= (1<<24))
|
#define ADDR_32BIT(addr) (addr >= (1<<24))
|
||||||
|
|
||||||
|
#define SET_FLASH_ERASE_STATUS(CHIP, status) do { \
|
||||||
|
if (CHIP->os_func->set_flash_op_status) { \
|
||||||
|
CHIP->os_func->set_flash_op_status(status); \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
static const char TAG[] = "chip_wb";
|
static const char TAG[] = "chip_wb";
|
||||||
|
|
||||||
@@ -76,15 +81,19 @@ esp_err_t spi_flash_chip_winbond_page_program(esp_flash_t *chip, const void *buf
|
|||||||
|
|
||||||
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->idle_timeout);
|
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->idle_timeout);
|
||||||
|
|
||||||
if (err == ESP_OK) {
|
if (err == ESP_OK || err == ESP_ERR_NOT_SUPPORTED) {
|
||||||
// Perform the actual Page Program command
|
// Perform the actual Page Program command
|
||||||
err = spi_flash_command_winbond_program_4B(chip, buffer, address, length);
|
err = spi_flash_command_winbond_program_4B(chip, buffer, address, length);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
chip->busy = 1;
|
||||||
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->page_program_timeout);
|
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->page_program_timeout);
|
||||||
}
|
}
|
||||||
|
// Ensure WEL is 0, even if the page program failed.
|
||||||
|
if (err == ESP_ERR_NOT_SUPPORTED) {
|
||||||
|
err = chip->chip_drv->set_chip_write_protect(chip, true);
|
||||||
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,11 +104,13 @@ esp_err_t spi_flash_chip_winbond_erase_sector(esp_flash_t *chip, uint32_t start_
|
|||||||
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->idle_timeout);
|
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->idle_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err == ESP_OK) {
|
if (err == ESP_OK || err == ESP_ERR_NOT_SUPPORTED) {
|
||||||
|
SET_FLASH_ERASE_STATUS(chip, SPI_FLASH_OS_IS_ERASING_STATUS_FLAG);
|
||||||
err = spi_flash_command_winbond_erase_sector_4B(chip, start_address);
|
err = spi_flash_command_winbond_erase_sector_4B(chip, start_address);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
chip->busy = 1;
|
||||||
//to save time, flush cache here
|
//to save time, flush cache here
|
||||||
if (chip->host->driver->flush_cache) {
|
if (chip->host->driver->flush_cache) {
|
||||||
err = chip->host->driver->flush_cache(chip->host, start_address, chip->chip_drv->sector_size);
|
err = chip->host->driver->flush_cache(chip->host, start_address, chip->chip_drv->sector_size);
|
||||||
@@ -107,7 +118,16 @@ esp_err_t spi_flash_chip_winbond_erase_sector(esp_flash_t *chip, uint32_t start_
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_SPI_FLASH_CHECK_ERASE_TIMEOUT_DISABLED
|
||||||
|
err = chip->chip_drv->wait_idle(chip, ESP_FLASH_CHIP_GENERIC_NO_TIMEOUT);
|
||||||
|
#else
|
||||||
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->sector_erase_timeout);
|
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->sector_erase_timeout);
|
||||||
|
#endif
|
||||||
|
SET_FLASH_ERASE_STATUS(chip, 0);
|
||||||
|
}
|
||||||
|
// Ensure WEL is 0, even if the erase failed.
|
||||||
|
if (err == ESP_ERR_NOT_SUPPORTED) {
|
||||||
|
err = chip->chip_drv->set_chip_write_protect(chip, true);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -119,11 +139,13 @@ esp_err_t spi_flash_chip_winbond_erase_block(esp_flash_t *chip, uint32_t start_a
|
|||||||
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->idle_timeout);
|
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->idle_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err == ESP_OK) {
|
if (err == ESP_OK || err == ESP_ERR_NOT_SUPPORTED) {
|
||||||
|
SET_FLASH_ERASE_STATUS(chip, SPI_FLASH_OS_IS_ERASING_STATUS_FLAG);
|
||||||
err = spi_flash_command_erase_block_4B(chip, start_address);
|
err = spi_flash_command_erase_block_4B(chip, start_address);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
chip->busy = 1;
|
||||||
//to save time, flush cache here
|
//to save time, flush cache here
|
||||||
if (chip->host->driver->flush_cache) {
|
if (chip->host->driver->flush_cache) {
|
||||||
err = chip->host->driver->flush_cache(chip->host, start_address, chip->chip_drv->block_erase_size);
|
err = chip->host->driver->flush_cache(chip->host, start_address, chip->chip_drv->block_erase_size);
|
||||||
@@ -131,7 +153,16 @@ esp_err_t spi_flash_chip_winbond_erase_block(esp_flash_t *chip, uint32_t start_a
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_SPI_FLASH_CHECK_ERASE_TIMEOUT_DISABLED
|
||||||
|
err = chip->chip_drv->wait_idle(chip, ESP_FLASH_CHIP_GENERIC_NO_TIMEOUT);
|
||||||
|
#else
|
||||||
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->block_erase_timeout);
|
err = chip->chip_drv->wait_idle(chip, chip->chip_drv->timeout->block_erase_timeout);
|
||||||
|
#endif
|
||||||
|
SET_FLASH_ERASE_STATUS(chip, 0);
|
||||||
|
}
|
||||||
|
// Ensure WEL is 0, even if the erase failed.
|
||||||
|
if (err == ESP_ERR_NOT_SUPPORTED) {
|
||||||
|
err = chip->chip_drv->set_chip_write_protect(chip, true);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -143,12 +174,33 @@ spi_flash_caps_t spi_flash_chip_winbond_get_caps(esp_flash_t *chip)
|
|||||||
if ((chip->chip_id & 0xFF) >= 0x19) {
|
if ((chip->chip_id & 0xFF) >= 0x19) {
|
||||||
caps_flags |= SPI_FLASH_CHIP_CAP_32MB_SUPPORT;
|
caps_flags |= SPI_FLASH_CHIP_CAP_32MB_SUPPORT;
|
||||||
}
|
}
|
||||||
// flash-suspend is not supported
|
#if CONFIG_SPI_FLASH_AUTO_SUSPEND
|
||||||
|
switch (chip->chip_id) {
|
||||||
|
/* The flash listed here can support suspend */
|
||||||
|
case 0xEF4017:
|
||||||
|
caps_flags |= SPI_FLASH_CHIP_CAP_SUSPEND;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
// flash read unique id.
|
// flash read unique id.
|
||||||
caps_flags |= SPI_FLASH_CHIP_CAP_UNIQUE_ID;
|
caps_flags |= SPI_FLASH_CHIP_CAP_UNIQUE_ID;
|
||||||
return caps_flags;
|
return caps_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t spi_flash_chip_winbond_suspend_cmd_conf(esp_flash_t *chip)
|
||||||
|
{
|
||||||
|
spi_flash_sus_cmd_conf sus_conf = {
|
||||||
|
.sus_mask = 0x80,
|
||||||
|
.cmd_rdsr = CMD_RDSR2,
|
||||||
|
.sus_cmd = CMD_SUSPEND,
|
||||||
|
.res_cmd = CMD_RESUME,
|
||||||
|
};
|
||||||
|
|
||||||
|
return chip->host->driver->sus_setup(chip->host, &sus_conf);
|
||||||
|
}
|
||||||
|
|
||||||
static const char chip_name[] = "winbond";
|
static const char chip_name[] = "winbond";
|
||||||
|
|
||||||
// The issi chip can use the functions for generic chips except from set read mode and probe,
|
// The issi chip can use the functions for generic chips except from set read mode and probe,
|
||||||
@@ -185,7 +237,7 @@ const spi_flash_chip_t esp_flash_chip_winbond = {
|
|||||||
|
|
||||||
.read_reg = spi_flash_chip_generic_read_reg,
|
.read_reg = spi_flash_chip_generic_read_reg,
|
||||||
.yield = spi_flash_chip_generic_yield,
|
.yield = spi_flash_chip_generic_yield,
|
||||||
.sus_setup = spi_flash_chip_generic_suspend_cmd_conf,
|
.sus_setup = spi_flash_chip_winbond_suspend_cmd_conf,
|
||||||
.read_unique_id = spi_flash_chip_generic_read_unique_id,
|
.read_unique_id = spi_flash_chip_generic_read_unique_id,
|
||||||
.get_chip_caps = spi_flash_chip_winbond_get_caps,
|
.get_chip_caps = spi_flash_chip_winbond_get_caps,
|
||||||
.config_host_io_mode = spi_flash_chip_generic_config_host_io_mode,
|
.config_host_io_mode = spi_flash_chip_generic_config_host_io_mode,
|
||||||
|
@@ -292,6 +292,8 @@ static esp_err_t spi_flash_hpm_probe_chip_with_doing_nothing(uint32_t flash_id)
|
|||||||
// GD25LQ255E.
|
// GD25LQ255E.
|
||||||
case 0xC86019:
|
case 0xC86019:
|
||||||
break;
|
break;
|
||||||
|
case 0xEF4017:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ret = ESP_ERR_NOT_FOUND;
|
ret = ESP_ERR_NOT_FOUND;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user