ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
logger_rp2.cpp
Go to the documentation of this file.
1#ifdef USE_RP2
2#include "logger.h"
4#ifdef USE_RP2_CRASH_HANDLER
6#endif
7#include "esphome/core/log.h"
8
9namespace esphome::logger {
10
11ESPHOME_LOG_TAG(TAG, "logger");
12
13#if defined(USE_RP2_CRASH_HANDLER) && defined(USE_LOGGER_UART_SELECTION_USB_CDC)
15 if (this->hw_serial_ == nullptr || !crash_log_pending())
16 return;
17 // Report the crash each time a host opens the USB port (sets DTR)
18 this->set_interval(500, [opened_before = false]() mutable {
19 const bool opened = Serial.dtr();
20 if (opened && !opened_before)
22 opened_before = opened;
23 });
24}
25#endif
26
27void Logger::pre_setup() {
28 if (this->baud_rate_ > 0) {
29#if defined(USE_LOGGER_UART_SELECTION_USB_CDC)
30 this->hw_serial_ = &Serial;
31 Serial.begin(this->baud_rate_);
32#else
33#ifdef USE_LOGGER_UART_SELECTION_UART1
34 SerialUART &uart = Serial2;
35#else
36 SerialUART &uart = Serial1;
37#endif
38#ifdef USE_LOGGER_CONSOLE
39 // The core's default 32-byte receive queue is smaller than one Improv frame
40 uart.setFIFOSize(ESPHOME_LOGGER_CONSOLE_RX_BUFFER_SIZE);
41#endif
42 this->hw_serial_ = &uart;
43 uart.begin(this->baud_rate_);
44#endif
45 }
46 global_logger = this;
47 ESP_LOGI(TAG, "Log initialized");
48 // Nobody has a USB port open this early; setup() reports the crash once a host opens it
49#if defined(USE_RP2_CRASH_HANDLER) && !defined(USE_LOGGER_UART_SELECTION_USB_CDC)
51#endif
52}
53
54#ifdef USE_CRASH_HANDLER
57#endif
58
59} // namespace esphome::logger
60#endif // USE_RP2
void set_interval(const char *name, uint32_t interval, SchedulerCallback &&f)
Set an interval function with a const char* name.
Definition component.cpp:88
void pre_setup()
Set up this component.
void setup() override
bool crash_log_pending()
Whether a crash record from before this boot is waiting to be reported.
Logger * global_logger
Definition logger.cpp:468
void log_crash_to_client()
Log the previous crash for a client that just subscribed to the logs.
ESPHOME_LOG_TAG(TAG, "logger")
bool crash_handler_has_data()
Returns true if crash data was found this boot, reading it first if needed.
void crash_handler_log()
Log crash data if a crash was detected on previous boot.