Skip to content

Commit 37cbaec

Browse files
Get real Flash Chip Size (#7159)
Co-authored-by: Jan Procházka <[email protected]>
1 parent 7f7f304 commit 37cbaec

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cores/esp32/Esp.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,17 @@ const char * EspClass::getSdkVersion(void)
305305
return esp_get_idf_version();
306306
}
307307

308+
uint32_t ESP_getFlashChipId(void)
309+
{
310+
uint32_t id = g_rom_flashchip.device_id;
311+
id = ((id & 0xff) << 16) | ((id >> 16) & 0xff) | (id & 0xff00);
312+
return id;
313+
}
314+
308315
uint32_t EspClass::getFlashChipSize(void)
309316
{
310-
esp_image_header_t fhdr;
311-
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
312-
return 0;
313-
}
314-
return magicFlashChipSize(fhdr.spi_size);
317+
uint32_t id = (ESP_getFlashChipId() >> 16) & 0xFF;
318+
return 2 << (id - 1);
315319
}
316320

317321
uint32_t EspClass::getFlashChipSpeed(void)

0 commit comments

Comments
 (0)