Skip to content

Commit 3f5c804

Browse files
Damian-Nordicnordicjm
authored andcommitted
samples: nrf_rpc: ps_server: update fatal error trigger
1. Use /alias/fatal-error-trigger DTS property to select button (or GPIO pin) that triggers the fatal error. 2. Trigger fatal error from GPIO interrupt handler instead of DK_LIBRARY handler as the latter is run from the system workqueue context and we want the fatal error trigger to work even if the system work queue is stuck. Signed-off-by: Damian Krolik <[email protected]>
1 parent e5dd556 commit 3f5c804

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
lines changed

samples/nrf_rpc/protocols_serialization/server/Kconfig

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ menu "Protocols serialization server"
88

99
config NRF_PS_SERVER_FATAL_ERROR_TRIGGER
1010
bool "Fatal error trigger"
11-
select DK_LIBRARY
11+
depends on $(dt_alias_enabled,fatal-error-trigger)
1212
help
13-
Enables triggering a fatal error by pressing Button 1 on the development
14-
kit. This trigger allows for testing the feature of logging over RPC that
15-
provides an RPC client with access to the crash log stored in the retained
16-
RAM partition.
13+
Enables triggering a fatal error by pressing the button selected with
14+
"/aliases/fatal-error-trigger" DTS property. This feature can be used
15+
to generate a core dump into a flash/RRAM partition. The core dump can
16+
then be retrieved by the RPC client using the "Logging over RPC"
17+
library.
1718

1819
config NRF_PS_SERVER_RPC_ALIVE_LED
1920
bool "RPC alive LED"
2021
default y
2122
depends on $(dt_alias_enabled,rpc-alive-led)
2223
help
23-
Turns on the LED selected with "/alias/rpc-alive-led" DTS property when
24-
the UART transport is alive and ready to receive nRF RPC packets.
24+
Turns on the LED selected with "/aliases/rpc-alive-led" DTS property
25+
when the UART transport is alive and ready to receive nRF RPC packets.
2526

2627
module = NRF_PS_SERVER
2728
module-str = nrf_ps_server

samples/nrf_rpc/protocols_serialization/server/boards/nrf52840dk_nrf52840.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
aliases {
1212
rpc-alive-led = &led0;
13+
fatal-error-trigger = &button0;
1314
};
1415
};
1516

samples/nrf_rpc/protocols_serialization/server/boards/nrf54l15dk_nrf54l15_cpuapp.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
aliases {
1212
rpc-alive-led = &led0;
13+
fatal-error-trigger = &button0;
1314

1415
/* delete all buttons except button0 to free GPIO pins assigned to uart21 below */
1516
/delete-property/ sw1;

samples/nrf_rpc/protocols_serialization/server/src/fatal_error_trigger.c

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,53 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7-
#include <dk_buttons_and_leds.h>
8-
7+
#include <zephyr/drivers/gpio.h>
98
#include <zephyr/init.h>
10-
#include <zephyr/kernel.h>
119
#include <zephyr/logging/log.h>
10+
#include <zephyr/sys/util_macro.h>
1211

1312
LOG_MODULE_DECLARE(nrf_ps_server, CONFIG_NRF_PS_SERVER_LOG_LEVEL);
1413

15-
static void button_handler(uint32_t button_state, uint32_t has_changed)
14+
const struct gpio_dt_spec gpio_pin = GPIO_DT_SPEC_GET(DT_ALIAS(fatal_error_trigger), gpios);
15+
static struct gpio_callback gpio_cb;
16+
17+
static void trigger_handler(const struct device *port, struct gpio_callback *cb,
18+
gpio_port_pins_t pins)
1619
{
17-
if (button_state & DK_BTN1_MSK) {
18-
LOG_ERR("Fatal error button pressed - triggering k_oops");
19-
k_oops();
20-
}
20+
ARG_UNUSED(port);
21+
ARG_UNUSED(cb);
22+
ARG_UNUSED(pins);
23+
24+
LOG_ERR("Fatal error button pressed - triggering k_oops");
25+
k_oops();
2126
}
2227

23-
static int button_handler_init(void)
28+
static int trigger_init(void)
2429
{
25-
return dk_buttons_init(button_handler);
30+
int rc;
31+
32+
if (!gpio_is_ready_dt(&gpio_pin)) {
33+
return -ENODEV;
34+
}
35+
36+
rc = gpio_pin_configure_dt(&gpio_pin, GPIO_INPUT);
37+
if (rc) {
38+
return rc;
39+
}
40+
41+
gpio_init_callback(&gpio_cb, trigger_handler, BIT(gpio_pin.pin));
42+
43+
rc = gpio_add_callback_dt(&gpio_pin, &gpio_cb);
44+
if (rc) {
45+
return rc;
46+
}
47+
48+
rc = gpio_pin_interrupt_configure_dt(&gpio_pin, GPIO_INT_EDGE_TO_ACTIVE);
49+
if (rc) {
50+
return rc;
51+
}
52+
53+
return 0;
2654
}
2755

28-
SYS_INIT(button_handler_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
56+
SYS_INIT(trigger_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);

0 commit comments

Comments
 (0)