Skip to content

Commit 62e5102

Browse files
arun-silabsrestyled-commitslpbeliveau-silabs
authored
[Silabs] [WiFi] Made changes to get logs on uart port (project-chip#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>
1 parent ccc391c commit 62e5102

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

examples/platform/silabs/SiWx917/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ source_set("siwx917-common") {
223223
"SiWx917/wfx_rsi_host.c",
224224
]
225225

226-
if (chip_enable_pw_rpc || chip_build_libshell) {
226+
if (chip_enable_pw_rpc || chip_build_libshell || sl_uart_log_output) {
227227
sources += [ "uart.cpp" ]
228228
}
229229

examples/platform/silabs/SiWx917/uart.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C" {
2626
#endif
2727
#include "assert.h"
2828
#include "rsi_board.h"
29+
#include "rsi_debug.h"
2930
#include "uart.h"
3031
#include <stddef.h>
3132
#include <string.h>
@@ -118,6 +119,30 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength)
118119
return BufLength;
119120
}
120121

122+
/**
123+
* @brief Write Logs to the Uart. Appends a return character
124+
*
125+
* @param log pointer to the logs
126+
* @param length number of bytes to write
127+
* @return int16_t Amount of bytes written or ERROR (-1)
128+
*/
129+
int16_t uartLogWrite(const char * log, uint16_t length)
130+
{
131+
if (log == NULL || length == 0)
132+
{
133+
return UART_CONSOLE_ERR;
134+
}
135+
for (uint16_t i = 0; i < length; i++)
136+
{
137+
Board_UARTPutChar(log[i]);
138+
}
139+
// To print next log in new line with proper formatting
140+
Board_UARTPutChar('\r');
141+
Board_UARTPutChar('\n');
142+
143+
return length + 2;
144+
}
145+
121146
/*
122147
* @brief Read the data available from the console Uart
123148
* @param Buffer for the data to be read, number bytes to read.

src/platform/silabs/Logging.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void PrintLog(const char * msg)
140140
PigweedLogger::putString(msg, sz);
141141
#else
142142
SEGGER_RTT_WriteNoLock(LOG_RTT_BUFFER_INDEX, msg, sz);
143-
#endif
143+
#endif // SILABS_LOG_OUT_UART
144144

145145
#if SILABS_LOG_OUT_RTT || PW_RPC_ENABLED
146146
const char * newline = "\r\n";

third_party/silabs/SiWx917_sdk.gni

+7
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ template("siwx917_sdk") {
282282
}
283283
}
284284

285+
if (sl_uart_log_output) {
286+
defines += [
287+
"SILABS_LOG_OUT_UART=1",
288+
"SILABS_LOG_OUT_RTT=0",
289+
]
290+
}
291+
285292
if (chip_build_libshell) { # matter shell
286293
defines += [ "ENABLE_CHIP_SHELL" ]
287294
}

0 commit comments

Comments
 (0)