Skip to content

Commit

Permalink
protocol_serialization: Fix random k_oops in nrf54l.
Browse files Browse the repository at this point in the history
Commit fixes random k_oops on nrf54l15pdk caused by overlapping init
of DK buttons and comunication UART.

Signed-off-by: Przemyslaw Bida <[email protected]>
  • Loading branch information
canisLupus1313 authored and nordicjm committed Sep 6, 2024
1 parent 02d8dd5 commit 6561a7e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
1 change: 0 additions & 1 deletion samples/nrf_rpc/protocols_serialization/server/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions samples/nrf_rpc/protocols_serialization/server/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
********************
Expand Down Expand Up @@ -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).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,58 @@
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <dk_buttons_and_leds.h>

#include <zephyr/init.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/util.h>
#include <zephyr/logging/log.h>

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);

0 comments on commit 6561a7e

Please sign in to comment.