[Silabs] [WiFi] Made changes to get logs on uart port (#32242)
* Made changes to get logs on uart port
* Added some checks to enable uart logging for SoC and efr.
* Removed macro in common code and moved the logging code to uartLogWrite API.
* Restyled by clang-format
* Returning number of bytes written to uart console.
* Restyled by clang-format
* Modified code as per review comments.
* Restyled by clang-format
* Fixed the typo.
* Update examples/platform/silabs/SiWx917/uart.cpp
Co-authored-by: lpbeliveau-silabs <112982107+lpbeliveau-silabs@users.noreply.github.com>
---------
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: lpbeliveau-silabs <112982107+lpbeliveau-silabs@users.noreply.github.com>
diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn
index bbfeee1..9214e97 100644
--- a/examples/platform/silabs/SiWx917/BUILD.gn
+++ b/examples/platform/silabs/SiWx917/BUILD.gn
@@ -223,7 +223,7 @@
"SiWx917/wfx_rsi_host.c",
]
- if (chip_enable_pw_rpc || chip_build_libshell) {
+ if (chip_enable_pw_rpc || chip_build_libshell || sl_uart_log_output) {
sources += [ "uart.cpp" ]
}
diff --git a/examples/platform/silabs/SiWx917/uart.cpp b/examples/platform/silabs/SiWx917/uart.cpp
index ee6f9ab..91df5d5 100644
--- a/examples/platform/silabs/SiWx917/uart.cpp
+++ b/examples/platform/silabs/SiWx917/uart.cpp
@@ -26,6 +26,7 @@
#endif
#include "assert.h"
#include "rsi_board.h"
+#include "rsi_debug.h"
#include "uart.h"
#include <stddef.h>
#include <string.h>
@@ -118,6 +119,30 @@
return BufLength;
}
+/**
+ * @brief Write Logs to the Uart. Appends a return character
+ *
+ * @param log pointer to the logs
+ * @param length number of bytes to write
+ * @return int16_t Amount of bytes written or ERROR (-1)
+ */
+int16_t uartLogWrite(const char * log, uint16_t length)
+{
+ if (log == NULL || length == 0)
+ {
+ return UART_CONSOLE_ERR;
+ }
+ for (uint16_t i = 0; i < length; i++)
+ {
+ Board_UARTPutChar(log[i]);
+ }
+ // To print next log in new line with proper formatting
+ Board_UARTPutChar('\r');
+ Board_UARTPutChar('\n');
+
+ return length + 2;
+}
+
/*
* @brief Read the data available from the console Uart
* @param Buffer for the data to be read, number bytes to read.
diff --git a/src/platform/silabs/Logging.cpp b/src/platform/silabs/Logging.cpp
index 353c647..71f377f 100644
--- a/src/platform/silabs/Logging.cpp
+++ b/src/platform/silabs/Logging.cpp
@@ -140,7 +140,7 @@
PigweedLogger::putString(msg, sz);
#else
SEGGER_RTT_WriteNoLock(LOG_RTT_BUFFER_INDEX, msg, sz);
-#endif
+#endif // SILABS_LOG_OUT_UART
#if SILABS_LOG_OUT_RTT || PW_RPC_ENABLED
const char * newline = "\r\n";
diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni
index f3bf92d..0853c03 100644
--- a/third_party/silabs/SiWx917_sdk.gni
+++ b/third_party/silabs/SiWx917_sdk.gni
@@ -282,6 +282,13 @@
}
}
+ if (sl_uart_log_output) {
+ defines += [
+ "SILABS_LOG_OUT_UART=1",
+ "SILABS_LOG_OUT_RTT=0",
+ ]
+ }
+
if (chip_build_libshell) { # matter shell
defines += [ "ENABLE_CHIP_SHELL" ]
}