Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cores/arduino/zephyrSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ void arduino::ZephyrSerial::flush() {
}
}

#if CONFIG_ARDUINO_SERIAL_PRINTF
void arduino::ZephyrSerial::printf(const char *fmt, ...) {
char message[CONFIG_ARDUINO_SERIAL_PRINTF_BUFFER_SIZE];
va_list args;
va_start(args, fmt);
vsnprintf(message, sizeof(message), fmt, args);
va_end(args);
this->write((uint8_t *)message, strlen(message));
}
#endif

#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm))
#define FIRST_UART_INDEX 1
#else
Expand Down
4 changes: 4 additions & 0 deletions cores/arduino/zephyrSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class ZephyrSerial : public HardwareSerial {
int peek();
int read();

#if CONFIG_ARDUINO_SERIAL_PRINTF
void printf(const char *fmt, ...);
#endif

operator bool() {
return true;
}
Expand Down
13 changes: 13 additions & 0 deletions loader/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ config MAIN_STACK_REGION
depends on CODE_DATA_RELOCATION
help
Specify the memory region for main stack.

config ARDUINO_SERIAL_PRINTF
bool "Enable Serial.printf()"
default n
help
Enable the Serial.printf() function.

config ARDUINO_SERIAL_PRINTF_BUFFER_SIZE
int "Serial.printf() buffer size"
depends on ARDUINO_SERIAL_PRINTF
default 128
help
Set the buffer size for the Serial.printf() function.
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ CONFIG_STACK_CANARIES=n
CONFIG_THREAD_ANALYZER=n
CONFIG_SYS_HEAP_RUNTIME_STATS=n
# CONFIG_LOG_DEFAULT_LEVEL=3

CONFIG_ARDUINO_SERIAL_PRINTF=y