Skip to content

Commit

Permalink
ESP.getChipModel() and ESP.getChipCores() (#3847)
Browse files Browse the repository at this point in the history
* ESP.getChipModel() returns model of the chip

* ESP.getChipCores() returns the core count.

* Example gives chip model, revision and core count.

* Read efuse for chipmodel

Co-authored-by: Martijn Scheepers <[email protected]>
  • Loading branch information
PA4WD and Martijn Scheepers authored Sep 30, 2020
1 parent e34e0b4 commit 7e9d42d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cores/esp32/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,33 @@ uint8_t EspClass::getChipRevision(void)
return chip_info.revision;
}

const char * EspClass::getChipModel(void)
{
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
uint32_t pkg_ver = chip_ver & 0x7;
switch (pkg_ver) {
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6 :
return "ESP32-D0WDQ6";
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 :
return "ESP32-D0WDQ5";
case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 :
return "ESP32-D2WDQ5";
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 :
return "ESP32-PICO-D2";
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 :
return "ESP32-PICO-D4";
default:
return "Unknown";
}
}

uint8_t EspClass::getChipCores(void)
{
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
return chip_info.cores;
}

const char * EspClass::getSdkVersion(void)
{
return esp_get_idf_version();
Expand Down
2 changes: 2 additions & 0 deletions cores/esp32/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class EspClass
uint32_t getMaxAllocPsram();

uint8_t getChipRevision();
const char * getChipModel();
uint8_t getChipCores();
uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); }
inline uint32_t getCycleCount() __attribute__((always_inline));
const char * getSdkVersion();
Expand Down
3 changes: 3 additions & 0 deletions libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ void loop() {
Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes.

Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
Serial.printf("This chip has %d cores\n", ESP.getChipCores());

delay(3000);

}

0 comments on commit 7e9d42d

Please sign in to comment.