From 9a9ff6baa3c0b5bfe55304b7b30f0f01349b729f Mon Sep 17 00:00:00 2001 From: lpbeliveau-silabs <112982107+lpbeliveau-silabs@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:08:02 -0500 Subject: [PATCH] [Silabs] Silabs Uart Shell fixes (#36667) * [SL-UP] Bugfix/silabs out rtt removal (#142) * [SL-UP] Bugfix/matter shell crash nullptr (#125) * Added checks on null ptr to prevent uart shell crash and modified ICD shell commands to be compatible with our internal structure --- examples/platform/silabs/shell/BUILD.gn | 10 +++++----- .../silabs/shell/{ => icd}/ICDShellCommands.cpp | 0 .../silabs/shell/{ => icd}/ICDShellCommands.h | 0 src/lib/shell/Engine.cpp | 2 ++ src/platform/silabs/Logging.cpp | 13 ++++--------- third_party/silabs/SiWx917_sdk.gni | 7 +++---- third_party/silabs/efr32_sdk.gni | 7 +++---- 7 files changed, 17 insertions(+), 22 deletions(-) rename examples/platform/silabs/shell/{ => icd}/ICDShellCommands.cpp (100%) rename examples/platform/silabs/shell/{ => icd}/ICDShellCommands.h (100%) diff --git a/examples/platform/silabs/shell/BUILD.gn b/examples/platform/silabs/shell/BUILD.gn index 74613aeac91031..8d4cab328e71dc 100644 --- a/examples/platform/silabs/shell/BUILD.gn +++ b/examples/platform/silabs/shell/BUILD.gn @@ -23,17 +23,17 @@ if (use_SiWx917) { shell_dependency_path = "${chip_root}/examples/platform/silabs/SiWx917" } -config("shell-config") { - include_dirs = [ "." ] +config("icd-shell-config") { + include_dirs = [ "./icd/" ] } source_set("icd") { sources = [ - "ICDShellCommands.cpp", - "ICDShellCommands.h", + "./icd/ICDShellCommands.cpp", + "./icd/ICDShellCommands.h", ] - public_configs = [ ":shell-config" ] + public_configs = [ ":icd-shell-config" ] deps = [ "${shell_dependency_path}:matter-shell" ] } diff --git a/examples/platform/silabs/shell/ICDShellCommands.cpp b/examples/platform/silabs/shell/icd/ICDShellCommands.cpp similarity index 100% rename from examples/platform/silabs/shell/ICDShellCommands.cpp rename to examples/platform/silabs/shell/icd/ICDShellCommands.cpp diff --git a/examples/platform/silabs/shell/ICDShellCommands.h b/examples/platform/silabs/shell/icd/ICDShellCommands.h similarity index 100% rename from examples/platform/silabs/shell/ICDShellCommands.h rename to examples/platform/silabs/shell/icd/ICDShellCommands.h diff --git a/src/lib/shell/Engine.cpp b/src/lib/shell/Engine.cpp index 809d44cc3c2bd4..ac914012819d66 100644 --- a/src/lib/shell/Engine.cpp +++ b/src/lib/shell/Engine.cpp @@ -86,6 +86,8 @@ CHIP_ERROR Engine::ExecCommand(int argc, char * argv[]) CHIP_ERROR retval = CHIP_ERROR_INVALID_ARGUMENT; VerifyOrReturnError(argc > 0, retval); + VerifyOrReturnError(nullptr != argv, retval); + // Find the command for (unsigned i = 0; i < _commandSetCount; i++) { diff --git a/src/platform/silabs/Logging.cpp b/src/platform/silabs/Logging.cpp index dea891379140fa..8b34308ba02f7e 100644 --- a/src/platform/silabs/Logging.cpp +++ b/src/platform/silabs/Logging.cpp @@ -51,13 +51,8 @@ #include "uart.h" #endif -// Enable RTT by default -#ifndef SILABS_LOG_OUT_RTT -#define SILABS_LOG_OUT_RTT 1 -#endif - // SEGGER_RTT includes -#if SILABS_LOG_OUT_RTT +#if !SILABS_LOG_OUT_UART #include "SEGGER_RTT.h" #include "SEGGER_RTT_Conf.h" #endif @@ -136,7 +131,7 @@ static void PrintLog(const char * msg) SEGGER_RTT_WriteNoLock(LOG_RTT_BUFFER_INDEX, msg, sz); #endif // SILABS_LOG_OUT_UART -#if SILABS_LOG_OUT_RTT || PW_RPC_ENABLED +#if !SILABS_LOG_OUT_UART || PW_RPC_ENABLED const char * newline = "\r\n"; sz = strlen(newline); #if PW_RPC_ENABLED @@ -154,7 +149,7 @@ static void PrintLog(const char * msg) extern "C" void silabsInitLog(void) { #if SILABS_LOG_ENABLED -#if SILABS_LOG_OUT_RTT +#if !SILABS_LOG_OUT_UART #if LOG_RTT_BUFFER_INDEX != 0 SEGGER_RTT_ConfigUpBuffer(LOG_RTT_BUFFER_INDEX, LOG_RTT_BUFFER_NAME, sLogBuffer, LOG_RTT_BUFFER_SIZE, SEGGER_RTT_MODE_NO_BLOCK_TRIM); @@ -164,7 +159,7 @@ extern "C" void silabsInitLog(void) #else SEGGER_RTT_SetFlagsUpBuffer(LOG_RTT_BUFFER_INDEX, SEGGER_RTT_MODE_NO_BLOCK_TRIM); #endif -#endif // SILABS_LOG_OUT_RTT +#endif // !SILABS_LOG_OUT_UART #ifdef PW_RPC_ENABLED PigweedLogger::init(); diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 0bc8c7c69318c4..63a0add4c4a5e9 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -331,10 +331,9 @@ template("siwx917_sdk") { } if (sl_uart_log_output) { - defines += [ - "SILABS_LOG_OUT_UART=1", - "SILABS_LOG_OUT_RTT=0", - ] + defines += [ "SILABS_LOG_OUT_UART=1" ] + } else { + defines += [ "SILABS_LOG_OUT_UART=0" ] } if (chip_build_libshell) { # matter shell diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 7861e827d7bdfb..bb621e0dce84b5 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -487,10 +487,9 @@ template("efr32_sdk") { } if (sl_uart_log_output) { - defines += [ - "SILABS_LOG_OUT_UART=1", - "SILABS_LOG_OUT_RTT=0", - ] + defines += [ "SILABS_LOG_OUT_UART=1" ] + } else { + defines += [ "SILABS_LOG_OUT_UART=0" ] } if (use_silabs_thread_lib) {