Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4d1458

Browse filesBrowse files
authored
Real flash chip mode (espressif#7239)
1 parent 8191aaf commit d4d1458
Copy full SHA for d4d1458

File tree

Expand file treeCollapse file tree

1 file changed

+30
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+30
-6
lines changed

‎cores/esp32/Esp.cpp

Copy file name to clipboardExpand all lines: cores/esp32/Esp.cpp
+30-6Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
}
3131
#include <MD5Builder.h>
3232

33+
#include "soc/spi_reg.h"
3334
#include "esp_system.h"
3435
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
3536
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
@@ -55,6 +56,14 @@ extern "C" {
5556
#define ESP_FLASH_IMAGE_BASE 0x1000
5657
#endif
5758

59+
// REG_SPI_BASE is not defined for S3/C3 ??
60+
61+
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
62+
#ifndef REG_SPI_BASE
63+
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
64+
#endif // REG_SPI_BASE
65+
#endif // TARGET
66+
5867
/**
5968
* User-defined Literals
6069
* usage:
@@ -192,7 +201,7 @@ static uint32_t sketchSize(sketchSize_t response) {
192201
return data.image_len;
193202
}
194203
}
195-
204+
196205
uint32_t EspClass::getSketchSize () {
197206
return sketchSize(SKETCH_SIZE_TOTAL);
198207
}
@@ -329,11 +338,26 @@ uint32_t EspClass::getFlashChipSpeed(void)
329338

330339
FlashMode_t EspClass::getFlashChipMode(void)
331340
{
332-
esp_image_header_t fhdr;
333-
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
334-
return FM_UNKNOWN;
335-
}
336-
return magicFlashChipMode(fhdr.spi_mode);
341+
#if CONFIG_IDF_TARGET_ESP32S2
342+
uint32_t spi_ctrl = REG_READ(PERIPHS_SPI_FLASH_CTRL);
343+
#else
344+
uint32_t spi_ctrl = REG_READ(SPI_CTRL_REG(0));
345+
#endif
346+
/* Not all of the following constants are already defined in older versions of spi_reg.h, so do it manually for now*/
347+
if (spi_ctrl & BIT(24)) { //SPI_FREAD_QIO
348+
return (FM_QIO);
349+
} else if (spi_ctrl & BIT(20)) { //SPI_FREAD_QUAD
350+
return (FM_QOUT);
351+
} else if (spi_ctrl & BIT(23)) { //SPI_FREAD_DIO
352+
return (FM_DIO);
353+
} else if (spi_ctrl & BIT(14)) { // SPI_FREAD_DUAL
354+
return (FM_DOUT);
355+
} else if (spi_ctrl & BIT(13)) { //SPI_FASTRD_MODE
356+
return (FM_FAST_READ);
357+
} else {
358+
return (FM_SLOW_READ);
359+
}
360+
return (FM_DOUT);
337361
}
338362

339363
uint32_t EspClass::magicFlashChipSize(uint8_t byte)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.