From 6561a7e0a3fa3201871ab6c772828d9639ea7a91 Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Thu, 5 Sep 2024 15:25:40 +0200 Subject: [PATCH] protocol_serialization: Fix random k_oops in nrf54l. Commit fixes random k_oops on nrf54l15pdk caused by overlapping init of DK buttons and comunication UART. Signed-off-by: Przemyslaw Bida --- .../protocols_serialization/server/Kconfig | 1 - .../protocols_serialization/server/README.rst | 19 +++++-- .../server/src/fatal_error_trigger.c | 53 ++++++++++++++++--- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/samples/nrf_rpc/protocols_serialization/server/Kconfig b/samples/nrf_rpc/protocols_serialization/server/Kconfig index 7bb8255e8974..11f00349cf38 100644 --- a/samples/nrf_rpc/protocols_serialization/server/Kconfig +++ b/samples/nrf_rpc/protocols_serialization/server/Kconfig @@ -24,7 +24,6 @@ config LOG_BACKEND_UART config NRF_PS_SERVER_FATAL_ERROR_TRIGGER bool "Fatal error trigger" - select DK_LIBRARY help Enables triggering a fatal error by pressing Button 1 on the development kit. This trigger allows for testing the feature of logging over RPC that diff --git a/samples/nrf_rpc/protocols_serialization/server/README.rst b/samples/nrf_rpc/protocols_serialization/server/README.rst index 17f55dc9c7f4..43a42536b83f 100644 --- a/samples/nrf_rpc/protocols_serialization/server/README.rst +++ b/samples/nrf_rpc/protocols_serialization/server/README.rst @@ -48,10 +48,19 @@ The following snippets are available: User interface ************** -Button 1: - * When the ``log_rpc`` snippet is enabled: triggers a fatal error. - This is used for testing the crash log feature. - * Otherwise: not available. +.. tabs:: + .. group-tab:: nRF52840 DK + + Button 4: + * When the ``log_rpc`` snippet is enabled: triggers a fatal error. + This is used for testing the crash log feature. + * Otherwise: not available. + + .. group-tab:: nRF54L15 DK + Button 3: + * When the ``log_rpc`` snippet is enabled: triggers a fatal error. + This is used for testing the crash log feature. + * Otherwise: not available. Building and running ******************** @@ -113,7 +122,7 @@ In the protocols serialization samples, one peripheral is used for shell and log .. figure:: /images/ps_nrf52_connections.png :alt: nRF52840 DK server and client pin connections - .. group-tab:: nRF54l15 DK + .. group-tab:: nRF54L15 DK By default, the nRF54L15 DK uses the ``uart20`` peripheral for shell and logging purposes, and the ``uart21`` peripheral for sending OpenThread and Bluetooth remote procedure calls (RPCs). diff --git a/samples/nrf_rpc/protocols_serialization/server/src/fatal_error_trigger.c b/samples/nrf_rpc/protocols_serialization/server/src/fatal_error_trigger.c index 2a3241d48980..a659bd1a6948 100644 --- a/samples/nrf_rpc/protocols_serialization/server/src/fatal_error_trigger.c +++ b/samples/nrf_rpc/protocols_serialization/server/src/fatal_error_trigger.c @@ -4,21 +4,58 @@ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ -#include - #include #include +#include +#include +#include + +LOG_MODULE_DECLARE(nrf_ps_server, CONFIG_NRF_PS_SERVER_LOG_LEVEL); + +/* + * This module intentionally do not use DK library. + * On nRF54l15 default buttons overlap with UART pins configuration. + */ + +#define SW0_NODE DT_ALIAS(sw3) -static void button_handler(uint32_t button_state, uint32_t has_changed) +static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0}); +static struct gpio_callback button_cb_data; + +void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { - if (button_state & DK_BTN1_MSK) { - k_oops(); - } + LOG_ERR("Button causing k_oops pressed.\n"); + k_oops(); } static int button_handler_init(void) { - return dk_buttons_init(button_handler); + int ret; + + if (!gpio_is_ready_dt(&button)) { + LOG_DBG("Error: button device %s is not ready\n", button.port->name); + return 0; + } + + ret = gpio_pin_configure_dt(&button, GPIO_INPUT); + if (ret != 0) { + LOG_DBG("Error %d: failed to configure %s pin %d\n", ret, button.port->name, + button.pin); + return 0; + } + + ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE); + if (ret != 0) { + LOG_DBG("Error %d: failed to configure interrupt on %s pin %d\n", ret, + button.port->name, button.pin); + return 0; + } + + gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin)); + gpio_add_callback(button.port, &button_cb_data); + LOG_DBG("Set up button at %s pin %d\n", button.port->name, button.pin); + + return 0; } -SYS_INIT(button_handler_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); +SYS_INIT(button_handler_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);