Skip to content

Commit ea236e2

Browse files
authored
Fix incorrect Flash Size in Esp32c3 (#5279)
original PR #5278 from @s-hadinger, which is not accepted because of failure of CLAassistant `ESP.getFlashChipSize()` always returns `0` on Esp32c3 due to a change in the Flash layout. It looks like to Espressif documentation was not updated accordingly. https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/storage/spi_flash.html#spi-flash-size - Esp32 and Esp32s3 have the flash information update by esptool.py and decribed here - https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/spi_flash.html Esp32c3 has no image information at 0x0000 and contrary to the docu this information is at offset 0x0000
1 parent 5ae3e83 commit ea236e2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cores/esp32/Esp.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@ extern "C" {
3535
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
3636
#include "esp32/rom/spi_flash.h"
3737
#include "soc/efuse_reg.h"
38+
#define ESP_FLASH_IMAGE_BASE 0x1000 // Flash offset containing flash size and spi mode
3839
#elif CONFIG_IDF_TARGET_ESP32S2
3940
#include "esp32s2/rom/spi_flash.h"
41+
#define ESP_FLASH_IMAGE_BASE 0x1000
4042
#elif CONFIG_IDF_TARGET_ESP32C3
4143
#include "esp32c3/rom/spi_flash.h"
44+
#define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32c3 is located at 0x0000
4245
#else
4346
#error Target CONFIG_IDF_TARGET is not supported
4447
#endif
4548
#else // ESP32 Before IDF 4.0
4649
#include "rom/spi_flash.h"
50+
#define ESP_FLASH_IMAGE_BASE 0x1000
4751
#endif
4852

4953
/**
@@ -289,7 +293,7 @@ const char * EspClass::getSdkVersion(void)
289293
uint32_t EspClass::getFlashChipSize(void)
290294
{
291295
esp_image_header_t fhdr;
292-
if(flashRead(0x1000, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
296+
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
293297
return 0;
294298
}
295299
return magicFlashChipSize(fhdr.spi_size);
@@ -298,7 +302,7 @@ uint32_t EspClass::getFlashChipSize(void)
298302
uint32_t EspClass::getFlashChipSpeed(void)
299303
{
300304
esp_image_header_t fhdr;
301-
if(flashRead(0x1000, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
305+
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
302306
return 0;
303307
}
304308
return magicFlashChipSpeed(fhdr.spi_speed);
@@ -307,7 +311,7 @@ uint32_t EspClass::getFlashChipSpeed(void)
307311
FlashMode_t EspClass::getFlashChipMode(void)
308312
{
309313
esp_image_header_t fhdr;
310-
if(flashRead(0x1000, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
314+
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
311315
return FM_UNKNOWN;
312316
}
313317
return magicFlashChipMode(fhdr.spi_mode);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy