36#if defined(ESP_PLATFORM)
41#include <esp_ota_ops.h>
42#include <esp_chip_info.h>
44namespace openmrn_arduino
47#if defined(CONFIG_IDF_TARGET_ESP32)
49static constexpr const char *
const RESET_REASONS[] =
55 "watchdog reset (legacy)",
58 "watchdog reset (group0)",
59 "watchdog reset (group1)",
61 "Intrusion test reset",
62 "WDT Timer group reset",
63 "software reset (CPU)",
65 "software reset (CPU)",
69#elif defined(CONFIG_IDF_TARGET_ESP32S2)
71static constexpr const char *
const RESET_REASONS[] =
80 "watchdog reset (group0)",
81 "watchdog reset (group1)",
83 "Intrusion test reset",
84 "WDT Timer group0 reset",
85 "software reset (CPU)",
90 "WDT Timer group1 reset",
94#elif defined(CONFIG_IDF_TARGET_ESP32C3)
96static constexpr const char *
const RESET_REASONS[] =
105 "watchdog reset (group0)",
106 "watchdog reset (group1)",
108 "Intrusion test reset",
109 "WDT Timer group0 reset",
110 "software reset (CPU)",
114 "RTC Reset (Normal)",
115 "WDT Timer group1 reset",
117 "RTC Reset (Glitch)",
121 "Power Glitch Reset",
123#elif defined(CONFIG_IDF_TARGET_ESP32S3)
125static constexpr const char *
const RESET_REASONS[] =
134 "watchdog reset (group0)",
135 "watchdog reset (group1)",
137 "Intrusion test reset",
138 "WDT Timer group0 reset",
139 "software reset (CPU)",
143 "RTC Reset (Normal)",
144 "WDT Timer group1 reset",
146 "RTC Reset (Glitch)",
150 "Power Glitch Reset",
152#elif defined(CONFIG_IDF_TARGET_ESP32H2)
154static constexpr const char *
const RESET_REASONS[] =
163 "watchdog reset (group0)",
164 "watchdog reset (group1)",
166 "Intrusion test reset",
167 "WDT Timer group0 reset",
168 "software reset (CPU)",
172 "RTC Reset (Normal)",
173 "WDT Timer group1 reset",
175 "RTC Reset (Glitch)",
179 "Power Glitch Reset",
182#elif defined(CONFIG_IDF_TARGET_ESP32C2)
184static constexpr const char *
const RESET_REASONS[] =
193 "MWDT (digital) reset",
198 "software reset (CPU)",
199 "RTC WDT reset (CPU)",
202 "RTC Reset (Normal)",
215static constexpr const char *
const CHIP_NAMES[] =
233uint8_t Esp32SocInfo::print_soc_info()
238 uint8_t reset_reason = rtc_get_reset_reason(PRO_CPU_NUM);
239 uint8_t orig_reset_reason = reset_reason;
241 if (reset_reason >=
ARRAYSIZE(RESET_REASONS))
245 esp_chip_info_t chip_info;
246 esp_chip_info(&chip_info);
247 size_t chip_model = chip_info.model;
254 LOG(
INFO,
"[SoC] reset reason:%d - %s", reset_reason,
255 RESET_REASONS[reset_reason]);
257 "[SoC] model:%s,rev:%d,cores:%d,flash:%s,WiFi:%s,BLE:%s,BT:%s",
258 CHIP_NAMES[chip_model], chip_info.revision,
260 chip_info.features & CHIP_FEATURE_EMB_FLASH ?
"Yes" :
"No",
261 chip_info.features & CHIP_FEATURE_WIFI_BGN ?
"Yes" :
"No",
262 chip_info.features & CHIP_FEATURE_BLE ?
"Yes" :
"No",
263 chip_info.features & CHIP_FEATURE_BT ?
"Yes" :
"No");
265 LOG(
INFO,
"[SoC] Heap: %.2fkB / %.2fkB",
266 heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024.0f,
267 heap_caps_get_total_size(MALLOC_CAP_INTERNAL) / 1024.0f);
268#if CONFIG_SPIRAM_SUPPORT || BOARD_HAS_PSRAM || CONFIG_SPIRAM
269 LOG(
INFO,
"[SoC] PSRAM: %.2fkB / %.2fkB",
270 heap_caps_get_free_size(MALLOC_CAP_SPIRAM) / 1024.0f,
271 heap_caps_get_total_size(MALLOC_CAP_SPIRAM) / 1024.0f);
274 LOG(
INFO,
"[SoC] App running from partition: %s",
275 esp_ota_get_running_partition()->label);
276 if (reset_reason != orig_reset_reason)
278 LOG(
WARNING,
"Reset reason mismatch: %d vs %d", reset_reason,
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int WARNING
Loglevel that is always printed, reporting a warning or a retryable error.
static const int INFO
Loglevel that is printed by default, reporting some status information.
#define ARRAYSIZE(a)
Returns the number of elements in a statically defined array (of static size)