Skip to content

Commit bed1d2a

Browse files
committed
ci: patch to implement weak _write() hook for Print
Signed-off-by: Aymane Bahssain <aymane.bahssain@st.com>
1 parent aaba003 commit bed1d2a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
From ed7ffc8cc475b05bf50fed6ef91007c3d75f0393 Mon Sep 17 00:00:00 2001
2+
From: Aymane Bahssain <aymane.bahssain@st.com>
3+
Date: Fri, 23 Jan 2026 17:05:29 +0100
4+
Subject: [PATCH] feat: implement weak _write() hook for Print
5+
6+
Signed-off-by: Aymane Bahssain <aymane.bahssain@st.com>
7+
---
8+
api/Print.cpp | 34 ++++++++++++++++++++++++++++++++++
9+
1 file changed, 34 insertions(+)
10+
11+
diff --git a/api/Print.cpp b/api/Print.cpp
12+
index d827f2e..54319f1 100644
13+
--- a/api/Print.cpp
14+
+++ b/api/Print.cpp
15+
@@ -24,6 +24,14 @@
16+
17+
#include "Print.h"
18+
19+
+#ifdef ARDUINO_ARCH_STM32
20+
+#include <unistd.h>
21+
+#include "uart.h"
22+
+#if defined (VIRTIO_LOG)
23+
+ #include "virtio_log.h"
24+
+#endif
25+
+#endif
26+
+
27+
using namespace arduino;
28+
29+
// Public Methods //////////////////////////////////////////////////////////////
30+
@@ -248,6 +256,32 @@ size_t Print::println(const Printable& x)
31+
return n;
32+
}
33+
34+
+#ifdef ARDUINO_ARCH_STM32
35+
+extern "C" {
36+
+ __attribute__((weak))
37+
+ int _write(int file, char *ptr, int len)
38+
+ {
39+
+ switch (file) {
40+
+ case STDOUT_FILENO:
41+
+ case STDERR_FILENO:
42+
+ /* Used for core_debug() */
43+
+#if defined (VIRTIO_LOG)
44+
+ virtio_log((uint8_t *)ptr, (uint32_t)len);
45+
+#elif defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
46+
+ uart_debug_write((uint8_t *)ptr, (uint32_t)len);
47+
+#endif
48+
+ break;
49+
+ case STDIN_FILENO:
50+
+ break;
51+
+ default:
52+
+ ((class Print *)file)->write((uint8_t *)ptr, len);
53+
+ break;
54+
+ }
55+
+ return len;
56+
+ }
57+
+}
58+
+#endif
59+
+
60+
int Print::printf(const char *format, ...)
61+
{
62+
va_list ap;
63+
--
64+
2.51.2.windows.1
65+

0 commit comments

Comments
 (0)