mirror of
https://github.com/esphome/esphome.git
synced 2026-10-01 17:00:21 +00:00
[nrf52] Use full newlib when the logger is enabled, disable unused serial and printk (#19766)
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
co-authored by
J. Nick Koston
parent
3fb4a9cb3a
commit
b4f2334b99
@@ -62,6 +62,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
zephyr_add_prj_conf("BT_NUS", True)
|
||||
zephyr_add_prj_conf("RING_BUFFER", True)
|
||||
request_ble_l2cap_mtu(247) # DLE sweet spot: one NUS frame per LL PDU
|
||||
expose_log = config[CONF_TYPE] == CONF_LOGS
|
||||
cg.add(var.set_expose_log(expose_log))
|
||||
|
||||
@@ -60,6 +60,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
zephyr_add_prj_conf("LOG_BLOCK_IN_THREAD", True)
|
||||
zephyr_add_prj_conf("LOG_BUFFER_SIZE", 4096)
|
||||
zephyr_add_prj_conf("SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL", True)
|
||||
zephyr_add_prj_conf("PRINTK", True)
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
cg.add_define("USE_DEBUG")
|
||||
|
||||
@@ -504,6 +504,7 @@ async def _late_logger_init(config: ConfigType) -> None:
|
||||
zephyr_add_prj_conf("RESET_ON_FATAL_ERROR", False)
|
||||
zephyr_add_prj_conf("THREAD_LOCAL_STORAGE", True)
|
||||
if has_serial_logging:
|
||||
zephyr_add_prj_conf("SERIAL", True)
|
||||
if config[CONF_HARDWARE_UART] == UART0:
|
||||
zephyr_add_overlay("""&uart0 { status = "okay";};""")
|
||||
if config[CONF_HARDWARE_UART] == UART1:
|
||||
|
||||
@@ -54,6 +54,7 @@ void Logger::cdc_loop_() {
|
||||
#endif
|
||||
|
||||
void Logger::pre_setup() {
|
||||
#ifdef CONFIG_SERIAL
|
||||
if (this->baud_rate_ > 0) {
|
||||
static const struct device *uart_dev = nullptr;
|
||||
switch (this->uart_) {
|
||||
@@ -87,6 +88,7 @@ void Logger::pre_setup() {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
global_logger = this;
|
||||
ESP_LOGI(TAG, "Log initialized");
|
||||
#ifdef USE_LOGGER_EARLY_MESSAGE
|
||||
|
||||
@@ -175,6 +175,8 @@ def _detect_bootloader(config: ConfigType) -> ConfigType:
|
||||
"""Detect the bootloader for the given board."""
|
||||
config = config.copy()
|
||||
bootloaders: list[str] = []
|
||||
if CONF_BOARD not in config:
|
||||
raise cv.Invalid("'board' is a required option for [nrf52].")
|
||||
board = config[CONF_BOARD]
|
||||
|
||||
if board in BOARDS_ZEPHYR and KEY_BOOTLOADER in BOARDS_ZEPHYR[board]:
|
||||
@@ -249,7 +251,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
): cv.Schema(
|
||||
{
|
||||
cv.Optional(CONF_VERSION): cv.string_strict,
|
||||
cv.Optional(CONF_LIBC_NANO, default=True): cv.boolean,
|
||||
cv.Optional(CONF_LIBC_NANO): cv.boolean,
|
||||
cv.Optional(
|
||||
CONF_ADVANCED, default={}, visibility=cv.Visibility.YAML_ONLY
|
||||
): cv.Schema(
|
||||
@@ -295,7 +297,7 @@ def _final_validate(config):
|
||||
conf = config[CONF_FRAMEWORK]
|
||||
advanced = conf[CONF_ADVANCED]
|
||||
|
||||
if conf[CONF_LIBC_NANO] and "logger" in CORE.loaded_integrations:
|
||||
if conf.get(CONF_LIBC_NANO, False) and "logger" in CORE.loaded_integrations:
|
||||
_LOGGER.warning(
|
||||
"Logger is enabled with newlib-nano (libc_nano: true). Some format specifiers "
|
||||
"such as %%zu are not supported and will print incorrectly. "
|
||||
@@ -401,7 +403,10 @@ async def to_code(config: ConfigType) -> None:
|
||||
cg.add_define("USE_OTA_ROLLBACK")
|
||||
zephyr_add_prj_conf("NEWLIB_LIBC", True)
|
||||
zephyr_add_prj_conf("NEWLIB_LIBC_FLOAT_PRINTF", True)
|
||||
zephyr_add_prj_conf("NEWLIB_LIBC_NANO", conf[CONF_LIBC_NANO])
|
||||
zephyr_add_prj_conf(
|
||||
"NEWLIB_LIBC_NANO",
|
||||
conf.get(CONF_LIBC_NANO, "logger" not in CORE.loaded_integrations),
|
||||
)
|
||||
# c++ support
|
||||
if framework_ver < cv.Version(2, 9, 2):
|
||||
zephyr_add_prj_conf("CPLUSPLUS", True)
|
||||
@@ -412,9 +417,6 @@ async def to_code(config: ConfigType) -> None:
|
||||
# watchdog
|
||||
zephyr_add_prj_conf("WATCHDOG", True)
|
||||
zephyr_add_prj_conf("WDT_DISABLE_AT_BOOT", False)
|
||||
# disable console
|
||||
zephyr_add_prj_conf("UART_CONSOLE", False)
|
||||
zephyr_add_prj_conf("CONSOLE", False, False)
|
||||
# use NFC pins as GPIO
|
||||
if framework_ver < cv.Version(2, 9, 2):
|
||||
zephyr_add_prj_conf("NFCT_PINS_AS_GPIOS", True)
|
||||
@@ -428,9 +430,17 @@ async def to_code(config: ConfigType) -> None:
|
||||
)
|
||||
zephyr_add_prj_conf("REBOOT", True)
|
||||
|
||||
# some boards enable USB by default.
|
||||
# some boards enable USB and UART by default.
|
||||
# disable it to prevent extra current consumption.
|
||||
zephyr_add_prj_conf("USB_DEVICE_STACK", False, False)
|
||||
zephyr_add_prj_conf("SERIAL", False, False)
|
||||
|
||||
# disable stuff to make image smaller by default
|
||||
zephyr_add_prj_conf("NCS_BOOT_BANNER", False, False)
|
||||
zephyr_add_prj_conf("BOOT_BANNER", False, False)
|
||||
zephyr_add_prj_conf("PRINTK", False, False)
|
||||
zephyr_add_prj_conf("CONSOLE", False, False)
|
||||
zephyr_add_prj_conf("UART_CONSOLE", False)
|
||||
|
||||
|
||||
@coroutine_with_priority(CoroPriority.DIAGNOSTICS)
|
||||
@@ -445,6 +455,7 @@ async def _dfu_to_code(dfu_config):
|
||||
zephyr_add_prj_conf("USB_DEVICE_STACK", True)
|
||||
zephyr_add_prj_conf("USB_CDC_ACM", True)
|
||||
zephyr_add_prj_conf("CDC_ACM_DTE_RATE_CALLBACK_SUPPORT", True)
|
||||
zephyr_add_prj_conf("SERIAL", True)
|
||||
await cg.register_component(var, dfu_config)
|
||||
|
||||
|
||||
|
||||
@@ -210,6 +210,7 @@ def zephyr_add_cdc_acm(config: ConfigType, id: int) -> None:
|
||||
zephyr_add_prj_conf("CONFIG_USB_DEVICE_STACK_NEXT", False)
|
||||
zephyr_add_prj_conf("USB_DEVICE_STACK", True)
|
||||
zephyr_add_prj_conf("USB_CDC_ACM", True)
|
||||
zephyr_add_prj_conf("SERIAL", True)
|
||||
# prevent device to go to susspend, without this communication stop working in python
|
||||
# there should be a way to solve it
|
||||
zephyr_add_prj_conf("USB_DEVICE_REMOTE_WAKEUP", False)
|
||||
|
||||
@@ -147,6 +147,7 @@ async def to_code(config: ConfigType) -> None:
|
||||
zephyr_add_prj_conf("NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUP", True)
|
||||
request_ble_l2cap_mtu(498) # matches NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUP
|
||||
if CONF_HARDWARE_UART in transport:
|
||||
zephyr_add_prj_conf("SERIAL", True)
|
||||
uart = UARTS[transport[CONF_HARDWARE_UART]]
|
||||
uart_name = uart[0]
|
||||
cdc_id = uart[1]
|
||||
|
||||
@@ -5,3 +5,4 @@ esphome:
|
||||
|
||||
logger:
|
||||
level: DEBUG
|
||||
hardware_uart: UART0
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
"""Tests for the nRF52 configuration validation."""
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.components.nrf52 import _detect_bootloader
|
||||
import esphome.config_validation as cv
|
||||
|
||||
|
||||
def test_detect_bootloader_reports_a_missing_board() -> None:
|
||||
"""The bootloader check runs before the schema, so it reports the missing key."""
|
||||
with pytest.raises(cv.Invalid, match="'board' is a required option"):
|
||||
_detect_bootloader({})
|
||||
Reference in New Issue
Block a user