5#include <zephyr/drivers/hwinfo.h>
6#include <hal/nrf_power.h>
9#define BOOTLOADER_VERSION_REGISTER NRF_TIMER2->CC[0]
14static const char *
const TAG =
"debug";
18static void show_reset_reason(std::string &reset_reason,
bool set,
const char *reason) {
22 if (!reset_reason.empty()) {
25 reset_reason += reason;
29 return *
reinterpret_cast<volatile uint32_t *
>(addr);
34 auto ret = hwinfo_get_reset_cause(&cause);
36 ESP_LOGE(TAG,
"Unable to get reset cause: %d", ret);
39 std::string reset_reason;
41 show_reset_reason(reset_reason, cause & RESET_PIN,
"External pin");
42 show_reset_reason(reset_reason, cause & RESET_SOFTWARE,
"Software reset");
43 show_reset_reason(reset_reason, cause & RESET_BROWNOUT,
"Brownout (drop in voltage)");
44 show_reset_reason(reset_reason, cause & RESET_POR,
"Power-on reset (POR)");
45 show_reset_reason(reset_reason, cause & RESET_WATCHDOG,
"Watchdog timer expiration");
46 show_reset_reason(reset_reason, cause & RESET_DEBUG,
"Debug event");
47 show_reset_reason(reset_reason, cause & RESET_SECURITY,
"Security violation");
48 show_reset_reason(reset_reason, cause & RESET_LOW_POWER_WAKE,
"Waking up from low power mode");
49 show_reset_reason(reset_reason, cause & RESET_CPU_LOCKUP,
"CPU lock-up detected");
50 show_reset_reason(reset_reason, cause & RESET_PARITY,
"Parity error");
51 show_reset_reason(reset_reason, cause & RESET_PLL,
"PLL error");
52 show_reset_reason(reset_reason, cause & RESET_CLOCK,
"Clock error");
53 show_reset_reason(reset_reason, cause & RESET_HARDWARE,
"Hardware reset");
54 show_reset_reason(reset_reason, cause & RESET_USER,
"User reset");
55 show_reset_reason(reset_reason, cause & RESET_TEMPERATURE,
"Temperature reset");
57 ESP_LOGD(TAG,
"Reset Reason: %s", reset_reason.c_str());
64 std::string supply =
"Main supply status: ";
65 if (nrf_power_mainregstatus_get(NRF_POWER) == NRF_POWER_MAINREGSTATUS_NORMAL) {
66 supply +=
"Normal voltage.";
68 supply +=
"High voltage.";
70 ESP_LOGD(TAG,
"%s", supply.c_str());
71 device_info +=
"|" + supply;
73 std::string reg0 =
"Regulator stage 0: ";
74 if (nrf_power_mainregstatus_get(NRF_POWER) == NRF_POWER_MAINREGSTATUS_HIGH) {
75 reg0 += nrf_power_dcdcen_vddh_get(NRF_POWER) ?
"DC/DC" :
"LDO";
77 switch (NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) {
78 case (UICR_REGOUT0_VOUT_DEFAULT << UICR_REGOUT0_VOUT_Pos):
79 reg0 +=
"1.8V (default)";
81 case (UICR_REGOUT0_VOUT_1V8 << UICR_REGOUT0_VOUT_Pos):
84 case (UICR_REGOUT0_VOUT_2V1 << UICR_REGOUT0_VOUT_Pos):
87 case (UICR_REGOUT0_VOUT_2V4 << UICR_REGOUT0_VOUT_Pos):
90 case (UICR_REGOUT0_VOUT_2V7 << UICR_REGOUT0_VOUT_Pos):
93 case (UICR_REGOUT0_VOUT_3V0 << UICR_REGOUT0_VOUT_Pos):
96 case (UICR_REGOUT0_VOUT_3V3 << UICR_REGOUT0_VOUT_Pos):
105 ESP_LOGD(TAG,
"%s", reg0.c_str());
106 device_info +=
"|" + reg0;
108 std::string reg1 =
"Regulator stage 1: ";
109 reg1 += nrf_power_dcdcen_get(NRF_POWER) ?
"DC/DC" :
"LDO";
110 ESP_LOGD(TAG,
"%s", reg1.c_str());
111 device_info +=
"|" + reg1;
113 std::string usb_power =
"USB power state: ";
114 if (nrf_power_usbregstatus_vbusdet_get(NRF_POWER)) {
115 if (nrf_power_usbregstatus_outrdy_get(NRF_POWER)) {
117 usb_power +=
"ready";
120 usb_power +=
"connected (regulator is not ready)";
124 usb_power +=
"disconected";
126 ESP_LOGD(TAG,
"%s", usb_power.c_str());
127 device_info +=
"|" + usb_power;
130 nrf_power_pof_thr_t pof_thr;
132 pof_thr = nrf_power_pofcon_get(NRF_POWER, &enabled);
133 std::string pof =
"Power-fail comparator: ";
136 case POWER_POFCON_THRESHOLD_V17:
139 case POWER_POFCON_THRESHOLD_V18:
142 case POWER_POFCON_THRESHOLD_V19:
145 case POWER_POFCON_THRESHOLD_V20:
148 case POWER_POFCON_THRESHOLD_V21:
151 case POWER_POFCON_THRESHOLD_V22:
154 case POWER_POFCON_THRESHOLD_V23:
157 case POWER_POFCON_THRESHOLD_V24:
160 case POWER_POFCON_THRESHOLD_V25:
163 case POWER_POFCON_THRESHOLD_V26:
166 case POWER_POFCON_THRESHOLD_V27:
169 case POWER_POFCON_THRESHOLD_V28:
174 if (nrf_power_mainregstatus_get(NRF_POWER) == NRF_POWER_MAINREGSTATUS_HIGH) {
176 switch (nrf_power_pofcon_vddh_get(NRF_POWER)) {
177 case NRF_POWER_POFTHRVDDH_V27:
180 case NRF_POWER_POFTHRVDDH_V28:
183 case NRF_POWER_POFTHRVDDH_V29:
186 case NRF_POWER_POFTHRVDDH_V30:
189 case NRF_POWER_POFTHRVDDH_V31:
192 case NRF_POWER_POFTHRVDDH_V32:
195 case NRF_POWER_POFTHRVDDH_V33:
198 case NRF_POWER_POFTHRVDDH_V34:
201 case NRF_POWER_POFTHRVDDH_V35:
204 case NRF_POWER_POFTHRVDDH_V36:
207 case NRF_POWER_POFTHRVDDH_V37:
210 case NRF_POWER_POFTHRVDDH_V38:
213 case NRF_POWER_POFTHRVDDH_V39:
216 case NRF_POWER_POFTHRVDDH_V40:
219 case NRF_POWER_POFTHRVDDH_V41:
222 case NRF_POWER_POFTHRVDDH_V42:
230 ESP_LOGD(TAG,
"%s", pof.c_str());
231 device_info +=
"|" + pof;
233 auto package = [](uint32_t value) {
236 return "QIxx - 7x7 73-pin aQFN";
238 return "QFxx - 6x6 48-pin QFN";
240 return "CKxx - 3.544 x 3.607 WLCSP";
242 return "Unspecified";
245 ESP_LOGD(TAG,
"Code page size: %u, code size: %u, device id: 0x%08x%08x", NRF_FICR->CODEPAGESIZE, NRF_FICR->CODESIZE,
246 NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]);
247 ESP_LOGD(TAG,
"Encryption root: 0x%08x%08x%08x%08x, Identity Root: 0x%08x%08x%08x%08x", NRF_FICR->ER[0],
248 NRF_FICR->ER[1], NRF_FICR->ER[2], NRF_FICR->ER[3], NRF_FICR->IR[0], NRF_FICR->IR[1], NRF_FICR->IR[2],
250 ESP_LOGD(TAG,
"Device address type: %s, address: %s", (NRF_FICR->DEVICEADDRTYPE & 0x1 ?
"Random" :
"Public"),
252 ESP_LOGD(TAG,
"Part code: nRF%x, version: %c%c%c%c, package: %s", NRF_FICR->INFO.PART,
253 NRF_FICR->INFO.VARIANT >> 24 & 0xFF, NRF_FICR->INFO.VARIANT >> 16 & 0xFF, NRF_FICR->INFO.VARIANT >> 8 & 0xFF,
254 NRF_FICR->INFO.VARIANT & 0xFF, package(NRF_FICR->INFO.PACKAGE));
255 ESP_LOGD(TAG,
"RAM: %ukB, Flash: %ukB, production test: %sdone", NRF_FICR->INFO.RAM, NRF_FICR->INFO.FLASH,
256 (NRF_FICR->PRODTEST[0] == 0xBB42319F ?
"" :
"not "));
258 TAG,
"GPIO as NFC pins: %s, GPIO as nRESET pin: %s",
259 YESNO((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)),
260 YESNO(((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) !=
261 (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) ||
262 ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) !=
263 (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))));
265#ifdef USE_BOOTLOADER_MCUBOOT
266 ESP_LOGD(TAG,
"bootloader: mcuboot");
268 ESP_LOGD(TAG,
"bootloader: Adafruit, version %u.%u.%u", (BOOTLOADER_VERSION_REGISTER >> 16) & 0xFF,
269 (BOOTLOADER_VERSION_REGISTER >> 8) & 0xFF, BOOTLOADER_VERSION_REGISTER & 0xFF);
277void DebugComponent::update_platform_() {}
uint32_t get_free_heap_()
std::string get_reset_reason_()
void get_device_info_(std::string &device_info)
constexpr std::uintptr_t MBR_PARAM_PAGE_ADDR
constexpr std::uintptr_t MBR_BOOTLOADER_ADDR
uint32_t read_mem_u32(uintptr_t addr)
Providing packet encoding functions for exchanging data with a remote host.
std::string get_mac_address_pretty()
Get the device MAC address as a string, in colon-separated uppercase hex notation.