Skip to content

Commit 80c019b

Browse files
committed
core: serial: implement Serial.printf()
1 parent dd1bf3c commit 80c019b

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

cores/arduino/zephyrSerial.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ void arduino::ZephyrSerial::flush() {
187187
}
188188
}
189189

190+
#if CONFIG_ARDUINO_SERIAL_PRINTF
191+
void arduino::ZephyrSerial::printf(const char *fmt, ...) {
192+
char message[CONFIG_ARDUINO_SERIAL_PRINTF_BUFFER_SIZE];
193+
va_list args;
194+
va_start(args, fmt);
195+
vsnprintf(message, sizeof(message), fmt, args);
196+
va_end(args);
197+
this->write((uint8_t *)message, strlen(message));
198+
}
199+
#endif
200+
190201
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm))
191202
#define FIRST_UART_INDEX 1
192203
#else

cores/arduino/zephyrSerial.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class ZephyrSerial : public HardwareSerial {
8989
int peek();
9090
int read();
9191

92+
#if CONFIG_ARDUINO_SERIAL_PRINTF
93+
void printf(const char *fmt, ...);
94+
#endif
95+
9296
operator bool() {
9397
return true;
9498
}

loader/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ config MAIN_STACK_REGION
1717
depends on CODE_DATA_RELOCATION
1818
help
1919
Specify the memory region for main stack.
20+
21+
config ARDUINO_SERIAL_PRINTF
22+
bool "Enable Serial.printf()"
23+
default n
24+
help
25+
Enable the Serial.printf() function.
26+
27+
config ARDUINO_SERIAL_PRINTF_BUFFER_SIZE
28+
int "Serial.printf() buffer size"
29+
depends on ARDUINO_SERIAL_PRINTF
30+
default 128
31+
help
32+
Set the buffer size for the Serial.printf() function.

variants/arduino_nano_matter_mgm240sd22vna/arduino_nano_matter_mgm240sd22vna.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ CONFIG_STACK_CANARIES=n
3535
CONFIG_THREAD_ANALYZER=n
3636
CONFIG_SYS_HEAP_RUNTIME_STATS=n
3737
# CONFIG_LOG_DEFAULT_LEVEL=3
38+
39+
CONFIG_ARDUINO_SERIAL_PRINTF=y

0 commit comments

Comments
 (0)