mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 11:26:39 +00:00
Merge branch 'rp2040-wrap-printf' into integration
This commit is contained in:
@@ -21,7 +21,13 @@ from esphome.const import (
|
|||||||
from esphome.core import CORE, CoroPriority, EsphomeError, coroutine_with_priority
|
from esphome.core import CORE, CoroPriority, EsphomeError, coroutine_with_priority
|
||||||
from esphome.helpers import copy_file_if_changed, read_file, write_file_if_changed
|
from esphome.helpers import copy_file_if_changed, read_file, write_file_if_changed
|
||||||
|
|
||||||
from .const import KEY_BOARD, KEY_PIO_FILES, KEY_RP2040, rp2040_ns
|
from .const import (
|
||||||
|
CONF_ENABLE_FULL_PRINTF,
|
||||||
|
KEY_BOARD,
|
||||||
|
KEY_PIO_FILES,
|
||||||
|
KEY_RP2040,
|
||||||
|
rp2040_ns,
|
||||||
|
)
|
||||||
|
|
||||||
# force import gpio to register pin schema
|
# force import gpio to register pin schema
|
||||||
from .gpio import rp2040_pin_to_code # noqa
|
from .gpio import rp2040_pin_to_code # noqa
|
||||||
@@ -153,6 +159,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.positive_time_period_milliseconds,
|
cv.positive_time_period_milliseconds,
|
||||||
cv.Range(max=cv.TimePeriod(milliseconds=8388)),
|
cv.Range(max=cv.TimePeriod(milliseconds=8388)),
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ENABLE_FULL_PRINTF, default=False): cv.boolean,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
set_core_data,
|
set_core_data,
|
||||||
@@ -191,9 +198,12 @@ async def to_code(config):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Wrap FILE*-based printf functions to eliminate newlib's _vfprintf_r
|
# Wrap FILE*-based printf functions to eliminate newlib's _vfprintf_r
|
||||||
# (~8.9 KB). See printf_stubs.cpp for implementation.
|
# (~9.2 KB). See printf_stubs.cpp for implementation.
|
||||||
for symbol in ("vprintf", "printf", "fprintf"):
|
if config.get(CONF_ENABLE_FULL_PRINTF):
|
||||||
cg.add_build_flag(f"-Wl,--wrap={symbol}")
|
cg.add_define("USE_FULL_PRINTF")
|
||||||
|
else:
|
||||||
|
for symbol in ("vprintf", "printf", "fprintf"):
|
||||||
|
cg.add_build_flag(f"-Wl,--wrap={symbol}")
|
||||||
|
|
||||||
cg.add_platformio_option("board_build.core", "earlephilhower")
|
cg.add_platformio_option("board_build.core", "earlephilhower")
|
||||||
cg.add_platformio_option("board_build.filesystem_size", "1m")
|
cg.add_platformio_option("board_build.filesystem_size", "1m")
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
|
||||||
|
CONF_ENABLE_FULL_PRINTF = "enable_full_printf"
|
||||||
KEY_BOARD = "board"
|
KEY_BOARD = "board"
|
||||||
KEY_RP2040 = "rp2040"
|
KEY_RP2040 = "rp2040"
|
||||||
KEY_PIO_FILES = "pio_files"
|
KEY_PIO_FILES = "pio_files"
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ static int write_printf_buffer(FILE *stream, char *buf, int len) {
|
|||||||
size_t write_len = len;
|
size_t write_len = len;
|
||||||
if (write_len >= PRINTF_BUFFER_SIZE) {
|
if (write_len >= PRINTF_BUFFER_SIZE) {
|
||||||
fwrite(buf, 1, PRINTF_BUFFER_SIZE - 1, stream);
|
fwrite(buf, 1, PRINTF_BUFFER_SIZE - 1, stream);
|
||||||
|
// Use fwrite for the message to avoid recursive __wrap_printf call
|
||||||
|
static const char msg[] = "\nprintf buffer overflow\n";
|
||||||
|
fwrite(msg, 1, sizeof(msg) - 1, stream);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
if (fwrite(buf, 1, write_len, stream) < write_len || ferror(stream)) {
|
if (fwrite(buf, 1, write_len, stream) < write_len || ferror(stream)) {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
rp2040:
|
||||||
|
enable_full_printf: false
|
||||||
|
|
||||||
logger:
|
logger:
|
||||||
level: VERBOSE
|
level: VERBOSE
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user