|
| 1 | +#include "esp_heap_caps.h" |
| 2 | +#include "esp_chip_info.h" |
| 3 | +#include "esp_idf_version.h" |
| 4 | +#include "esp_arduino_version.h" |
| 5 | +#include "esp_rom_spiflash.h" |
| 6 | +#include "esp_flash.h" |
| 7 | +#include "esp_partition.h" |
| 8 | +#include "esp_app_format.h" |
| 9 | +#include "soc/efuse_reg.h" |
| 10 | +#include "soc/rtc.h" |
| 11 | +#include "soc/spi_reg.h" |
| 12 | +#if CONFIG_IDF_TARGET_ESP32S2 |
| 13 | +#include "esp32s2/rom/spi_flash.h" |
| 14 | +#endif |
| 15 | +#include "esp_bit_defs.h" |
| 16 | + |
| 17 | +#include "esp32-hal.h" |
| 18 | +#include "esp32-hal-periman.h" |
| 19 | + |
| 20 | +#define printMemCapsInfo(caps) _printMemCapsInfo(MALLOC_CAP_##caps, #caps) |
| 21 | +#define b2kb(b) ((float)b/1024.0) |
| 22 | +#define b2mb(b) ((float)b/(1024.0*1024.0)) |
| 23 | +static void _printMemCapsInfo(uint32_t caps, const char * caps_str){ |
| 24 | + multi_heap_info_t info; |
| 25 | + size_t total = heap_caps_get_total_size(caps); |
| 26 | + heap_caps_get_info(&info, caps); |
| 27 | + log_printf("%s Memory Info:\n", caps_str); |
| 28 | + log_printf("------------------------------------------\n"); |
| 29 | + log_printf(" Total Size : %8u B (%6.1f KB)\n", total, b2kb(total)); |
| 30 | + log_printf(" Free Bytes : %8u B (%6.1f KB)\n", info.total_free_bytes, b2kb(info.total_free_bytes)); |
| 31 | + log_printf(" Allocated Bytes : %8u B (%6.1f KB)\n", info.total_allocated_bytes, b2kb(info.total_allocated_bytes)); |
| 32 | + log_printf(" Minimum Free Bytes: %8u B (%6.1f KB)\n", info.minimum_free_bytes, b2kb(info.minimum_free_bytes)); |
| 33 | + log_printf(" Largest Free Block: %8u B (%6.1f KB)\n", info.largest_free_block, b2kb(info.largest_free_block)); |
| 34 | +} |
| 35 | + |
| 36 | +static void printPkgVersion(void){ |
| 37 | + log_printf(" Package : "); |
| 38 | +#if CONFIG_IDF_TARGET_ESP32 |
| 39 | + uint32_t pkg_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_PACKAGE); |
| 40 | + switch(pkg_ver){ |
| 41 | + case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDR2V3: log_printf("D0WD-R2-V3"); break; |
| 42 | + case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6 : log_printf("D0WD-Q6"); break; |
| 43 | + case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 : log_printf("D0WD-Q5"); break; |
| 44 | + case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 : log_printf("D2WD-Q5"); break; |
| 45 | + case EFUSE_RD_CHIP_VER_PKG_ESP32U4WDH : log_printf("U4WD-H"); break; |
| 46 | + case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 : log_printf("PICO-D4"); break; |
| 47 | + case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302: log_printf("PICO-V3-02"); break; |
| 48 | + } |
| 49 | +#elif CONFIG_IDF_TARGET_ESP32S2 |
| 50 | + uint32_t pkg_ver = REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_3_REG, EFUSE_PKG_VERSION); |
| 51 | + switch (pkg_ver) { |
| 52 | + case 1: log_printf("FH16"); break; |
| 53 | + case 2: log_printf("FH32"); break; |
| 54 | + default: log_printf("%lu", pkg_ver); break; |
| 55 | + } |
| 56 | +#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 |
| 57 | + uint32_t pkg_ver = REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_3_REG, EFUSE_PKG_VERSION); |
| 58 | + log_printf("%lu", pkg_ver); |
| 59 | +#elif CONFIG_IDF_TARGET_ESP32C2 |
| 60 | + uint32_t pkg_ver = REG_GET_FIELD(EFUSE_RD_BLK2_DATA1_REG, EFUSE_PKG_VERSION); |
| 61 | + log_printf("%lu", pkg_ver); |
| 62 | +#elif CONFIG_IDF_TARGET_ESP32H2 |
| 63 | + uint32_t pkg_ver = REG_GET_FIELD(EFUSE_RD_MAC_SYS_4_REG, EFUSE_PKG_VERSION); |
| 64 | + log_printf("%lu", pkg_ver); |
| 65 | +#else |
| 66 | + log_printf("Unknown"); |
| 67 | +#endif |
| 68 | + log_printf("\n"); |
| 69 | +} |
| 70 | + |
| 71 | +static void printChipInfo(void){ |
| 72 | + esp_chip_info_t info; |
| 73 | + esp_chip_info(&info); |
| 74 | + log_printf("Chip Info:\n"); |
| 75 | + log_printf("------------------------------------------\n"); |
| 76 | + log_printf(" Model : "); |
| 77 | + switch(info.model){ |
| 78 | + case CHIP_ESP32: log_printf("ESP32\n"); break; |
| 79 | + case CHIP_ESP32S2: log_printf("ESP32-S2\n"); break; |
| 80 | + case CHIP_ESP32S3: log_printf("ESP32-S3\n"); break; |
| 81 | + case CHIP_ESP32C2: log_printf("ESP32-C2\n"); break; |
| 82 | + case CHIP_ESP32C3: log_printf("ESP32-C3\n"); break; |
| 83 | + case CHIP_ESP32C6: log_printf("ESP32-C6\n"); break; |
| 84 | + case CHIP_ESP32H2: log_printf("ESP32-H2\n"); break; |
| 85 | + default: log_printf("Unknown %d\n", info.model); break; |
| 86 | + } |
| 87 | + printPkgVersion(); |
| 88 | + log_printf(" Revision : "); |
| 89 | + if(info.revision > 0xFF){ |
| 90 | + log_printf("%d.%d\n", info.revision >> 8, info.revision & 0xFF); |
| 91 | + } else { |
| 92 | + log_printf("%d\n", info.revision); |
| 93 | + } |
| 94 | + log_printf(" Cores : %d\n", info.cores); |
| 95 | + rtc_cpu_freq_config_t conf; |
| 96 | + rtc_clk_cpu_freq_get_config(&conf); |
| 97 | + log_printf(" Frequency : %lu MHz\n", conf.freq_mhz); |
| 98 | + log_printf(" Embedded Flash : %s\n", (info.features & CHIP_FEATURE_EMB_FLASH)?"Yes":"No"); |
| 99 | + log_printf(" Embedded PSRAM : %s\n", (info.features & CHIP_FEATURE_EMB_PSRAM)?"Yes":"No"); |
| 100 | + log_printf(" 2.4GHz WiFi : %s\n", (info.features & CHIP_FEATURE_WIFI_BGN)?"Yes":"No"); |
| 101 | + log_printf(" Classic BT : %s\n", (info.features & CHIP_FEATURE_BT)?"Yes":"No"); |
| 102 | + log_printf(" BT Low Energy : %s\n", (info.features & CHIP_FEATURE_BLE)?"Yes":"No"); |
| 103 | + log_printf(" IEEE 802.15.4 : %s\n", (info.features & CHIP_FEATURE_IEEE802154)?"Yes":"No"); |
| 104 | +} |
| 105 | + |
| 106 | +static void printFlashInfo(void){ |
| 107 | +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 |
| 108 | + #define ESP_FLASH_IMAGE_BASE 0x1000 |
| 109 | +#else |
| 110 | + #define ESP_FLASH_IMAGE_BASE 0x0000 |
| 111 | +#endif |
| 112 | +// REG_SPI_BASE is not defined for S3/C3 ?? |
| 113 | +#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 |
| 114 | + #ifndef REG_SPI_BASE |
| 115 | + #define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 ))) |
| 116 | + #endif // REG_SPI_BASE |
| 117 | +#endif // TARGET |
| 118 | + |
| 119 | + log_printf("Flash Info:\n"); |
| 120 | + log_printf("------------------------------------------\n"); |
| 121 | + uint32_t hw_size = 1 << (g_rom_flashchip.device_id & 0xFF); |
| 122 | + log_printf(" Chip Size : %8lu B (%.0f MB)\n", hw_size, b2mb(hw_size)); |
| 123 | + log_printf(" Block Size : %8lu B (%6.1f KB)\n", g_rom_flashchip.block_size, b2kb(g_rom_flashchip.block_size)); |
| 124 | + log_printf(" Sector Size : %8lu B (%6.1f KB)\n", g_rom_flashchip.sector_size, b2kb(g_rom_flashchip.sector_size)); |
| 125 | + log_printf(" Page Size : %8lu B (%6.1f KB)\n", g_rom_flashchip.page_size, b2kb(g_rom_flashchip.page_size)); |
| 126 | + esp_image_header_t fhdr; |
| 127 | + esp_flash_read(esp_flash_default_chip, (void*)&fhdr, ESP_FLASH_IMAGE_BASE, sizeof(esp_image_header_t)); |
| 128 | + if(fhdr.magic == ESP_IMAGE_HEADER_MAGIC) { |
| 129 | + uint32_t f_freq = 0; |
| 130 | + switch(fhdr.spi_speed) { |
| 131 | + case 0x0: f_freq = 40; break; |
| 132 | + case 0x1: f_freq = 26; break; |
| 133 | + case 0x2: f_freq = 20; break; |
| 134 | + case 0xf: f_freq = 80; break; |
| 135 | + default: f_freq = fhdr.spi_speed; break; |
| 136 | + } |
| 137 | + log_printf(" Bus Speed : %lu MHz\n", f_freq); |
| 138 | + } |
| 139 | + log_printf(" Bus Mode : "); |
| 140 | +#if CONFIG_ESPTOOLPY_OCT_FLASH |
| 141 | + log_printf("OPI\n"); |
| 142 | +#elif CONFIG_ESPTOOLPY_FLASHMODE_QIO |
| 143 | + log_printf("QIO\n"); |
| 144 | +#elif CONFIG_ESPTOOLPY_FLASHMODE_QOUT |
| 145 | + log_printf("QOUT\n"); |
| 146 | +#elif CONFIG_ESPTOOLPY_FLASHMODE_DIO |
| 147 | + log_printf("DIO\n"); |
| 148 | +#elif CONFIG_ESPTOOLPY_FLASHMODE_DOUT |
| 149 | + log_printf("DOUT\n"); |
| 150 | +#endif |
| 151 | +} |
| 152 | + |
| 153 | +static void printPartitionsInfo(void){ |
| 154 | + log_printf("Partitions Info:\n"); |
| 155 | + log_printf("------------------------------------------\n"); |
| 156 | + esp_partition_iterator_t iterator = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL); |
| 157 | + if(iterator != NULL){ |
| 158 | + esp_partition_iterator_t it = iterator; |
| 159 | + while(it != NULL){ |
| 160 | + const esp_partition_t* partition = esp_partition_get(it); |
| 161 | + if(partition){ |
| 162 | + log_printf(" %17s : addr: 0x%08X, size: %7.1f KB", partition->label, partition->address, b2kb(partition->size)); |
| 163 | + if(partition->type == ESP_PARTITION_TYPE_APP){ |
| 164 | + log_printf(", type: APP"); |
| 165 | + if(partition->subtype == 0){ |
| 166 | + log_printf(", subtype: FACTORY"); |
| 167 | + } else if(partition->subtype >= 0x10 && partition->subtype < 0x20){ |
| 168 | + log_printf(", subtype: OTA_%lu", partition->subtype - 0x10); |
| 169 | + } else if(partition->subtype == 0x20){ |
| 170 | + log_printf(", subtype: TEST"); |
| 171 | + } else { |
| 172 | + log_printf(", subtype: 0x%02X", partition->subtype); |
| 173 | + } |
| 174 | + } else { |
| 175 | + log_printf(", type: DATA"); |
| 176 | + log_printf(", subtype: "); |
| 177 | + switch(partition->subtype){ |
| 178 | + case ESP_PARTITION_SUBTYPE_DATA_OTA: log_printf("OTA"); break; |
| 179 | + case ESP_PARTITION_SUBTYPE_DATA_PHY: log_printf("PHY"); break; |
| 180 | + case ESP_PARTITION_SUBTYPE_DATA_NVS: log_printf("NVS"); break; |
| 181 | + case ESP_PARTITION_SUBTYPE_DATA_COREDUMP: log_printf("COREDUMP"); break; |
| 182 | + case ESP_PARTITION_SUBTYPE_DATA_NVS_KEYS: log_printf("NVS_KEYS"); break; |
| 183 | + case ESP_PARTITION_SUBTYPE_DATA_EFUSE_EM: log_printf("EFUSE_EM"); break; |
| 184 | + case ESP_PARTITION_SUBTYPE_DATA_UNDEFINED: log_printf("UNDEFINED"); break; |
| 185 | + case ESP_PARTITION_SUBTYPE_DATA_ESPHTTPD: log_printf("ESPHTTPD"); break; |
| 186 | + case ESP_PARTITION_SUBTYPE_DATA_FAT: log_printf("FAT"); break; |
| 187 | + case ESP_PARTITION_SUBTYPE_DATA_SPIFFS: log_printf("SPIFFS"); break; |
| 188 | + default: log_printf("0x%02X", partition->subtype); break; |
| 189 | + } |
| 190 | + } |
| 191 | + log_printf("\n"); |
| 192 | + } |
| 193 | + it = esp_partition_next(it); |
| 194 | + } |
| 195 | + //esp_partition_iterator_release(iterator); |
| 196 | + } |
| 197 | +} |
| 198 | + |
| 199 | +static void printSoftwareInfo(void){ |
| 200 | + log_printf("Software Info:\n"); |
| 201 | + log_printf("------------------------------------------\n"); |
| 202 | + log_printf(" Compile Date/Time : %s %s\n", __DATE__, __TIME__); |
| 203 | +#ifdef ARDUINO_HOST_OS |
| 204 | + log_printf(" Compile Host OS : %s\n", ARDUINO_HOST_OS); |
| 205 | +#endif |
| 206 | + log_printf(" ESP-IDF Version : %s\n", esp_get_idf_version()); |
| 207 | + log_printf(" Arduino Version : %s\n", ESP_ARDUINO_VERSION_STR); |
| 208 | +} |
| 209 | + |
| 210 | +static void printBoardInfo(void){ |
| 211 | + log_printf("Board Info:\n"); |
| 212 | + log_printf("------------------------------------------\n"); |
| 213 | + log_printf(" Arduino Board : %s\n", ARDUINO_BOARD); |
| 214 | + log_printf(" Arduino Variant : %s\n", ARDUINO_VARIANT); |
| 215 | +#ifdef ARDUINO_FQBN |
| 216 | + log_printf(" Arduino FQBN : %s\n", ARDUINO_FQBN); |
| 217 | +#else |
| 218 | + log_printf(" Core Debug Level : %d\n", CORE_DEBUG_LEVEL); |
| 219 | +#ifdef ARDUINO_RUNNING_CORE |
| 220 | + log_printf(" Arduino Runs Core : %d\n", ARDUINO_RUNNING_CORE); |
| 221 | + log_printf(" Arduino Events on : %d\n", ARDUINO_EVENT_RUNNING_CORE); |
| 222 | +#endif |
| 223 | +#ifdef ARDUINO_USB_MODE |
| 224 | + log_printf(" Arduino USB Mode : %d\n", ARDUINO_USB_MODE); |
| 225 | +#endif |
| 226 | +#ifdef ARDUINO_USB_CDC_ON_BOOT |
| 227 | + log_printf(" CDC On Boot : %d\n", ARDUINO_USB_CDC_ON_BOOT); |
| 228 | +#endif |
| 229 | +#endif /* ARDUINO_FQBN */ |
| 230 | +} |
| 231 | + |
| 232 | +static void printPerimanInfo(void){ |
| 233 | + log_printf("GPIO Info:\n"); |
| 234 | + log_printf("------------------------------------------\n"); |
| 235 | + for(uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++){ |
| 236 | + if(!perimanPinIsValid(i)){ |
| 237 | + continue;//invalid pin |
| 238 | + } |
| 239 | + peripheral_bus_type_t type = perimanGetPinBusType(i); |
| 240 | + if(type == ESP32_BUS_TYPE_INIT){ |
| 241 | + continue;//unused pin |
| 242 | + } |
| 243 | + log_printf(" %17u : ", i); |
| 244 | + switch(type){ |
| 245 | + case ESP32_BUS_TYPE_GPIO: log_printf("GPIO\n"); break; |
| 246 | + case ESP32_BUS_TYPE_UART: log_printf("UART\n"); break; |
| 247 | +#if SOC_SDM_SUPPORTED |
| 248 | + case ESP32_BUS_TYPE_SIGMADELTA: log_printf("SIGMADELTA\n"); break; |
| 249 | +#endif |
| 250 | +#if SOC_ADC_SUPPORTED |
| 251 | + case ESP32_BUS_TYPE_ADC_ONESHOT: log_printf("ADC_ONESHOT\n"); break; |
| 252 | + case ESP32_BUS_TYPE_ADC_CONT: log_printf("ADC_CONT\n"); break; |
| 253 | +#endif |
| 254 | +#if SOC_DAC_SUPPORTED |
| 255 | + case ESP32_BUS_TYPE_DAC_ONESHOT: log_printf("DAC_ONESHOT\n"); break; |
| 256 | + case ESP32_BUS_TYPE_DAC_CONT: log_printf("DAC_CONT\n"); break; |
| 257 | + case ESP32_BUS_TYPE_DAC_COSINE: log_printf("DAC_COSINE\n"); break; |
| 258 | +#endif |
| 259 | +#if SOC_LEDC_SUPPORTED |
| 260 | + case ESP32_BUS_TYPE_LEDC: log_printf("LEDC\n"); break; |
| 261 | +#endif |
| 262 | +#if SOC_RMT_SUPPORTED |
| 263 | + case ESP32_BUS_TYPE_RMT_TX: log_printf("RMT_TX\n"); break; |
| 264 | + case ESP32_BUS_TYPE_RMT_RX: log_printf("RMT_RX\n"); break; |
| 265 | +#endif |
| 266 | +#if SOC_I2S_SUPPORTED |
| 267 | + case ESP32_BUS_TYPE_I2S_STD: log_printf("I2S_STD\n"); break; |
| 268 | + case ESP32_BUS_TYPE_I2S_PDM: log_printf("I2S_PDM\n"); break; |
| 269 | + case ESP32_BUS_TYPE_I2S_TDM: log_printf("I2S_TDM\n"); break; |
| 270 | +#endif |
| 271 | +#if SOC_I2C_SUPPORTED |
| 272 | + case ESP32_BUS_TYPE_I2C_MASTER: log_printf("I2C_MASTER\n"); break; |
| 273 | + case ESP32_BUS_TYPE_I2C_SLAVE: log_printf("I2C_SLAVE\n"); break; |
| 274 | +#endif |
| 275 | +#if SOC_GPSPI_SUPPORTED |
| 276 | + case ESP32_BUS_TYPE_SPI_MASTER: log_printf("SPI_MASTER\n"); break; |
| 277 | +#endif |
| 278 | +#if SOC_SDMMC_HOST_SUPPORTED |
| 279 | + case ESP32_BUS_TYPE_SDMMC: log_printf("SDMMC\n"); break; |
| 280 | +#endif |
| 281 | +#if SOC_TOUCH_SENSOR_SUPPORTED |
| 282 | + case ESP32_BUS_TYPE_TOUCH: log_printf("TOUCH\n"); break; |
| 283 | +#endif |
| 284 | +#if SOC_USB_SERIAL_JTAG_SUPPORTED || SOC_USB_OTG_SUPPORTED |
| 285 | + case ESP32_BUS_TYPE_USB: log_printf("USB\n"); break; |
| 286 | +#endif |
| 287 | + default: log_printf("%d\n", type); break; |
| 288 | + } |
| 289 | + } |
| 290 | +} |
| 291 | + |
| 292 | +void printBeforeSetupInfo(void){ |
| 293 | +#if ARDUINO_USB_CDC_ON_BOOT |
| 294 | + Serial.begin(0); |
| 295 | + Serial.setDebugOutput(true); |
| 296 | + uint8_t t = 0; |
| 297 | + while(!Serial && (t++ < 200)) delay(10); //wait up to 2 seconds for the IDE to connect |
| 298 | +#endif |
| 299 | + log_printf("=========== Before Setup Start ===========\n"); |
| 300 | + printChipInfo(); |
| 301 | + log_printf("------------------------------------------\n"); |
| 302 | + printMemCapsInfo(INTERNAL); |
| 303 | + log_printf("------------------------------------------\n"); |
| 304 | + if(psramFound()){ |
| 305 | + printMemCapsInfo(SPIRAM); |
| 306 | + log_printf(" Bus Mode : "); |
| 307 | +#if CONFIG_SPIRAM_MODE_OCT |
| 308 | + log_printf("OPI\n"); |
| 309 | +#else |
| 310 | + log_printf("QSPI\n"); |
| 311 | +#endif |
| 312 | + log_printf("------------------------------------------\n"); |
| 313 | + } |
| 314 | + printFlashInfo(); |
| 315 | + log_printf("------------------------------------------\n"); |
| 316 | + printPartitionsInfo(); |
| 317 | + log_printf("------------------------------------------\n"); |
| 318 | + printSoftwareInfo(); |
| 319 | + log_printf("------------------------------------------\n"); |
| 320 | + printBoardInfo(); |
| 321 | + log_printf("============ Before Setup End ============\n"); |
| 322 | + delay(100); //allow the print to finish |
| 323 | +} |
| 324 | + |
| 325 | +void printAfterSetupInfo(void){ |
| 326 | + log_printf("=========== After Setup Start ============\n"); |
| 327 | + printMemCapsInfo(INTERNAL); |
| 328 | + log_printf("------------------------------------------\n"); |
| 329 | + if(psramFound()){ |
| 330 | + printMemCapsInfo(SPIRAM); |
| 331 | + log_printf("------------------------------------------\n"); |
| 332 | + } |
| 333 | + printPerimanInfo(); |
| 334 | + log_printf("============ After Setup End =============\n"); |
| 335 | + delay(20); //allow the print to finish |
| 336 | +} |
0 commit comments