7#include <zephyr/device.h>
8#include <zephyr/drivers/uart.h>
9#include <zephyr/sys/printk.h>
10#include <zephyr/usb/usb_device.h>
11#ifdef USE_LOGGER_EARLY_MESSAGE
24#if KERNEL_VERSION_NUMBER >= 0x030700
35#if defined(CONFIG_THREAD_NAME)
36 char thread[CONFIG_THREAD_MAX_NAME_LEN];
40static const char *
const TAG =
"logger";
42#ifdef USE_LOGGER_UART_SELECTION_USB_CDC
47 static bool opened =
false;
49 uart_line_ctrl_get(this->
uart_dev_, UART_LINE_CTRL_DTR, &dtr);
66 static const struct device *uart_dev =
nullptr;
67 switch (this->
uart_) {
69 uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(uart0));
72 uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(uart1));
74#ifdef USE_LOGGER_USB_CDC
76#ifdef CONFIG_USB_DEVICE_STACK
77 uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(cdc_acm_uart0));
78 if (device_is_ready(uart_dev)) {
85 if (device_is_ready(uart_dev)) {
87#if defined(USE_LOGGER_WAIT_FOR_CDC) && defined(USE_LOGGER_UART_SELECTION_USB_CDC)
89 int32_t
count = (10 * 100);
90 while (dtr == 0 &&
count-- > 0) {
91 uart_line_ctrl_get(this->
uart_dev_, UART_LINE_CTRL_DTR, &dtr);
100 ESP_LOGI(TAG,
"Log initialized");
101#ifdef USE_LOGGER_EARLY_MESSAGE
102 char reason_buffer[zephyr::RESET_REASON_BUFFER_SIZE];
103 const char *reset_reason =
zephyr::get_reset_reason(std::span<char, zephyr::RESET_REASON_BUFFER_SIZE>(reason_buffer));
104 ESP_LOGI(TAG,
"Reset reason: %s", reset_reason);
106 zephyr_coredump::print_coredump();
115 printk(
"%.*s",
static_cast<int>(
len), msg);
120 for (uint16_t i = 0; i <
len; ++i) {
126 switch (this->
uart_) {
128 return LOG_STR(
"UART0");
130 return LOG_STR(
"UART1");
131#ifdef USE_LOGGER_USB_CDC
133 return LOG_STR(
"USB_CDC");
136 return LOG_STR(
"UNKNOWN");
140static const uint8_t REASON_BUF_SIZE = 32;
142static const char *reason_to_str(
unsigned int reason,
char *buf) {
144 case K_ERR_CPU_EXCEPTION:
145 return "CPU exception";
146 case K_ERR_SPURIOUS_IRQ:
147 return "Unhandled interrupt";
148 case K_ERR_STACK_CHK_FAIL:
149 return "Stack overflow";
150 case K_ERR_KERNEL_OOPS:
151 return "Kernel oops";
152 case K_ERR_KERNEL_PANIC:
153 return "Kernel panic";
155 snprintf(buf, REASON_BUF_SIZE,
"Unknown error (%u)", reason);
161 ESP_LOGD(TAG,
"Crash buffer address %p", &
crash_buf);
163 char reason_buf[REASON_BUF_SIZE];
164 ESP_LOGE(TAG,
"Last crash:");
165 ESP_LOGE(TAG,
"Reason=%s PC=0x%08x LR=0x%08x", reason_to_str(
crash_buf.reason, reason_buf),
crash_buf.pc,
167#if defined(CONFIG_THREAD_NAME)
168 ESP_LOGE(TAG,
"Thread: %s",
crash_buf.thread);
170 int32_t
count = (2 * 100);
171 while (
count-- > 0) {
185#if defined(CONFIG_THREAD_NAME)
186 auto thread = k_current_get();
187 const char *name = k_thread_name_get(thread);
uint32_t get_config_hash()
Get the config hash as a 32-bit integer.
void schedule_dump_config()
void write_msg_(const char *msg, uint16_t len)
const LogString * get_uart_selection_()
void pre_setup()
Set up this component.
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
void k_sys_fatal_error_handler(unsigned int reason, const esphome::logger::FatalErrorEsf *esf)
void k_sys_fatal_error_handler(unsigned int reason, const FatalErrorEsf *esf)
const char * get_reset_reason(std::span< char, RESET_REASON_BUFFER_SIZE > buffer)
void HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.