mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-03 08:31:44 +01:00
spi_flash: Fix issue that cannot get accurate flash size when encounter large size memory,
Closes https://github.com/espressif/esp-idf/pull/9566
This commit is contained in:
@@ -66,6 +66,9 @@ DRAM_ATTR static spi_flash_encryption_t esp_flash_encryption_default __attribute
|
||||
#define HOST_DELAY_INTERVAL_US 1
|
||||
#define CHIP_WAIT_IDLE_INTERVAL_US 20
|
||||
|
||||
#define SPI_FLASH_LINEAR_DENSITY_LAST_VALUE (0x19)
|
||||
#define SPI_FLASH_HEX_A_F_RANGE (6)
|
||||
|
||||
const DRAM_ATTR flash_chip_op_timeout_t spi_flash_chip_generic_timeout = {
|
||||
.idle_timeout = SPI_FLASH_DEFAULT_IDLE_TIMEOUT_MS * 1000,
|
||||
.chip_erase_timeout = SPI_FLASH_GENERIC_CHIP_ERASE_TIMEOUT_MS * 1000,
|
||||
@@ -82,6 +85,30 @@ const DRAM_ATTR flash_chip_op_timeout_t spi_flash_chip_generic_timeout = {
|
||||
|
||||
static const char TAG[] = "chip_generic";
|
||||
|
||||
esp_err_t spi_flash_chip_generic_detect_size(esp_flash_t *chip, uint32_t *size)
|
||||
{
|
||||
uint32_t id = chip->chip_id;
|
||||
*size = 0;
|
||||
|
||||
/* Can't detect size unless the high byte of the product ID matches the same convention, which is usually 0x40 or
|
||||
* 0xC0 or similar. */
|
||||
if (((id & 0xFFFF) == 0x0000) || ((id & 0xFFFF) == 0xFFFF)) {
|
||||
return ESP_ERR_FLASH_UNSUPPORTED_CHIP;
|
||||
}
|
||||
|
||||
/* Get flash capacity from flash chip id depends on different vendors. According to majority of flash datasheets,
|
||||
Flash 256Mb to 512Mb directly from 0x19 to 0x20, instead of from 0x19 to 0x1a. So here we leave the common behavior.
|
||||
However, some other flash vendors also have their own rule, we will add them in chip specific files.
|
||||
*/
|
||||
uint32_t mem_density = (id & 0xFF);
|
||||
if (mem_density > SPI_FLASH_LINEAR_DENSITY_LAST_VALUE ) {
|
||||
mem_density -= SPI_FLASH_HEX_A_F_RANGE;
|
||||
}
|
||||
|
||||
*size = 1 << mem_density;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_SPI_FLASH_ROM_IMPL
|
||||
|
||||
esp_err_t spi_flash_chip_generic_probe(esp_flash_t *chip, uint32_t flash_id)
|
||||
@@ -115,22 +142,6 @@ esp_err_t spi_flash_chip_generic_reset(esp_flash_t *chip)
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t spi_flash_chip_generic_detect_size(esp_flash_t *chip, uint32_t *size)
|
||||
{
|
||||
uint32_t id = chip->chip_id;
|
||||
*size = 0;
|
||||
|
||||
/* Can't detect size unless the high byte of the product ID matches the same convention, which is usually 0x40 or
|
||||
* 0xC0 or similar. */
|
||||
if (((id & 0xFFFF) == 0x0000) || ((id & 0xFFFF) == 0xFFFF)) {
|
||||
return ESP_ERR_FLASH_UNSUPPORTED_CHIP;
|
||||
}
|
||||
|
||||
*size = 1 << (id & 0xFF);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t spi_flash_chip_generic_erase_chip(esp_flash_t *chip)
|
||||
{
|
||||
esp_err_t err;
|
||||
|
||||
Reference in New Issue
Block a user