add debug information

This commit is contained in:
Tomasz Duda 2024-01-14 18:10:48 +01:00
parent 89121938ad
commit 0aa4a1e845

View File

@ -35,6 +35,12 @@
#endif
#endif
#ifdef USE_NRF52
#include <Adafruit_TinyUSB.h>
#include "esphome/core/application.h"
#include "nrf52/nrf_mbr.h"
#endif
namespace esphome {
namespace debug {
@ -49,9 +55,46 @@ static uint32_t get_free_heap() {
return rp2040.getFreeHeap();
#elif defined(USE_LIBRETINY)
return lt_heap_get_free();
#elif defined(USE_NRF52)
//TODO
return 0;
#endif
}
#ifdef USE_NRF52
static std::string nrf52_get_reset_reason_name(){
uint32_t rr = readResetReason();
if (rr & POWER_RESETREAS_VBUS_Msk){
return "VBUS";
}
if (rr & POWER_RESETREAS_NFC_Msk){
return "NFC";
}
if (rr & POWER_RESETREAS_DIF_Msk){
return "DIF";
}
if (rr & POWER_RESETREAS_LPCOMP_Msk){
return "LPCOMP";
}
if (rr & POWER_RESETREAS_OFF_Msk){
return "OFF";
}
if (rr & POWER_RESETREAS_LOCKUP_Msk){
return "LOCKUP";
}
if (rr & POWER_RESETREAS_SREQ_Msk){
return "SREQ";
}
if (rr & POWER_RESETREAS_DOG_Msk){
return "DOG";
}
if (rr & POWER_RESETREAS_RESETPIN_Msk){
return "RESETPIN";
}
return "NONE";
}
#endif
void DebugComponent::dump_config() {
#ifndef ESPHOME_LOG_HAS_DEBUG
return; // Can't log below if debug logging is disabled
@ -373,6 +416,14 @@ void DebugComponent::dump_config() {
reset_reason = lt_get_reboot_reason_name(lt_get_reboot_reason());
#endif // USE_LIBRETINY
#ifdef USE_NRF52
ESP_LOGD(TAG, "bootloader version %lu.%lu.%lu", (bootloaderVersion >> 16) & 0xFF, (bootloaderVersion >> 8) & 0xFF, bootloaderVersion & 0xFF);
ESP_LOGD(TAG, "MBR bootloader addr 0x%08lx, UICR bootloader addr 0x%08lx", (*((uint32_t *)MBR_BOOTLOADER_ADDR)), NRF_UICR->NRFFW[0]);
ESP_LOGD(TAG, "MBR param page addr 0x%08lx, UICR param page addr 0x%08lx", (*((uint32_t *) MBR_PARAM_PAGE_ADDR)), NRF_UICR->NRFFW[1]);
reset_reason = nrf52_get_reset_reason_name();
ESP_LOGD(TAG, "Reset Reason: %s", reset_reason.c_str());
#endif
#ifdef USE_TEXT_SENSOR
if (this->device_info_ != nullptr) {
if (device_info.length() > 255)
@ -386,6 +437,14 @@ void DebugComponent::dump_config() {
}
void DebugComponent::loop() {
//TODO move to logger
static bool d = false;
if (d != Serial){
if(false == d){
App.schedule_dump_config();
}
d = !d;
}
// log when free heap space has halved
uint32_t new_free_heap = get_free_heap();
if (new_free_heap < this->free_heap_ / 2) {