Skip to content

Commit

Permalink
Get real Flash Chip Size (#7159)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Procházka <[email protected]>
  • Loading branch information
Jason2866 and P-R-O-C-H-Y authored Sep 7, 2022
1 parent 7f7f304 commit 37cbaec
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cores/esp32/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,17 @@ const char * EspClass::getSdkVersion(void)
return esp_get_idf_version();
}

uint32_t ESP_getFlashChipId(void)
{
uint32_t id = g_rom_flashchip.device_id;
id = ((id & 0xff) << 16) | ((id >> 16) & 0xff) | (id & 0xff00);
return id;
}

uint32_t EspClass::getFlashChipSize(void)
{
esp_image_header_t fhdr;
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
return 0;
}
return magicFlashChipSize(fhdr.spi_size);
uint32_t id = (ESP_getFlashChipId() >> 16) & 0xFF;
return 2 << (id - 1);
}

uint32_t EspClass::getFlashChipSpeed(void)
Expand Down

0 comments on commit 37cbaec

Please sign in to comment.