Skip to content

Commit a1bc41f

Browse files
shell: introduce shell support using bm uarte shell backend
Implement shell support using zephyr's shell subsys with slight modifications to allow it to be used single threaded, and add nrfx uarte based shell backend for the shell to use. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent c6708e1 commit a1bc41f

File tree

15 files changed

+402
-0
lines changed

15 files changed

+402
-0
lines changed

boards/nordic/bm_nrf54l15dk/include/board-config.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ extern "C" {
6363
#define BOARD_CONSOLE_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(7, 1)
6464
#endif
6565

66+
/* UART Shell configuration */
67+
#ifndef BOARD_SHELL_UARTE_INST
68+
#define BOARD_SHELL_UARTE_INST 30
69+
#endif
70+
#ifndef BOARD_SHELL_UARTE_PIN_TX
71+
#define BOARD_SHELL_UARTE_PIN_TX NRF_PIN_PORT_TO_PIN_NUMBER(0, 0)
72+
#endif
73+
#ifndef BOARD_SHELL_UARTE_PIN_RX
74+
#define BOARD_SHELL_UARTE_PIN_RX NRF_PIN_PORT_TO_PIN_NUMBER(1, 0)
75+
#endif
76+
#ifndef BOARD_SHELL_UARTE_PIN_RTS
77+
#define BOARD_SHELL_UARTE_PIN_RTS NRF_PIN_PORT_TO_PIN_NUMBER(2, 0)
78+
#endif
79+
#ifndef BOARD_SHELL_UARTE_PIN_CTS
80+
#define BOARD_SHELL_UARTE_PIN_CTS NRF_PIN_PORT_TO_PIN_NUMBER(3, 0)
81+
#endif
82+
6683
/* Application UART configuration */
6784
#ifndef BOARD_APP_UARTE_INST
6885
#define BOARD_APP_UARTE_INST 30

include/shell/backend_bm_uarte.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/* Get pointer to BM UARTE shell backend */
8+
const struct shell *shell_backend_bm_uarte_get_ptr(void);

samples/shell/bm_uarte/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(leds)
11+
12+
target_sources(app PRIVATE src/main.c)

samples/shell/bm_uarte/README.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.. _shell_bm_uarte_sample:
2+
3+
UARTE shell sample
4+
##################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Shell sample demonstrates how to initialize and use the shell
11+
subsystem with an NRFX UARTE based backend with |BMlong|.
12+
13+
Requirements
14+
************
15+
16+
The sample supports the following development kits:
17+
18+
.. list-table::
19+
:header-rows: 1
20+
21+
* - Hardware platform
22+
- PCA
23+
- Board target
24+
* - `nRF54L15 DK`_
25+
- PCA10156
26+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
27+
* - `nRF54L15 DK`_ (emulating nRF54L10)
28+
- PCA10156
29+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
30+
* - `nRF54L15 DK`_ (emulating nRF54L05)
31+
- PCA10156
32+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
33+
34+
Overview
35+
********
36+
37+
The sample initializes and starts an interactive shell, which can be
38+
terminated by using the "terminate" shell command.
39+
40+
Building and running
41+
********************
42+
43+
This sample can be found under :file:`samples/shell/bm_uarte/` in the |BMshort| folder structure.
44+
45+
.. include:: /includes/create_sample.txt
46+
47+
.. include:: /includes/configure_and_build_sample.txt
48+
49+
.. include:: /includes/program_sample.txt
50+
51+
Testing
52+
=======
53+
54+
You can test this sample by performing the following steps:
55+
56+
1. Compile and program the application.
57+
#. Observe that the ``bm-uarte:~$`` prompt is printed.
58+
#. Write ``terminate`` and press enter
59+
#. Observe that ``goodbye`` message is printed.
60+
#. Observe that ``bm-uarte:~$`` prompt is printed.
61+
#. Observe that shell is now unresponsive.

samples/shell/bm_uarte/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_SHELL=y
2+
CONFIG_SHELL_MINIMAL=y
3+
CONFIG_SHELL_BACKEND_BM_UARTE=y

samples/shell/bm_uarte/sample.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sample:
2+
name: Shell sample
3+
tests:
4+
sample.shell.bm_uarte:
5+
sysbuild: true
6+
build_only: true
7+
integration_platforms:
8+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
9+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
10+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
11+
platform_allow:
12+
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
13+
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
14+
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
15+
tags: ci_build

samples/shell/bm_uarte/src/main.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/shell/shell.h>
8+
#include <zephyr/sys/atomic.h>
9+
#include <shell/backend_bm_uarte.h>
10+
11+
#include <zephyr/shell/shell.h>
12+
13+
static atomic_t running = ATOMIC_INIT(1);
14+
15+
static int sample_terminate_cmd(const struct shell *sh, size_t argc, char **argv)
16+
{
17+
shell_print(sh, "goodbye");
18+
atomic_set(&running, 0);
19+
return 0;
20+
}
21+
22+
SHELL_CMD_REGISTER(terminate, NULL, "terminate shell", sample_terminate_cmd);
23+
24+
int main(void)
25+
{
26+
const struct shell_backend_config_flags cfg_flags = SHELL_DEFAULT_BACKEND_CONFIG_FLAGS;
27+
28+
shell_init(shell_backend_bm_uarte_get_ptr(), NULL, cfg_flags, false, 0);
29+
shell_start(shell_backend_bm_uarte_get_ptr());
30+
printk("shell started\n");
31+
while (atomic_get(&running)) {
32+
shell_process(shell_backend_bm_uarte_get_ptr());
33+
k_busy_wait(10000);
34+
}
35+
shell_uninit(shell_backend_bm_uarte_get_ptr(), NULL);
36+
printk("shell terminated\n");
37+
return 0;
38+
}

subsys/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
add_subdirectory(bluetooth)
99
add_subdirectory(bm_installs)
1010
add_subdirectory(logging)
11+
add_subdirectory(shell)
1112
add_subdirectory_ifdef(CONFIG_NCS_BM_MCUMGR mgmt/mcumgr)
1213
add_subdirectory_ifdef(CONFIG_NRF_SDH softdevice_handler)
1314
add_subdirectory_ifdef(CONFIG_SOFTDEVICE softdevice)

subsys/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rsource "bluetooth/Kconfig"
1111
rsource "bm_installs/Kconfig"
1212
rsource "logging/Kconfig"
1313
rsource "mgmt/mcumgr/Kconfig"
14+
rsource "shell/Kconfig"
1415
rsource "softdevice/Kconfig"
1516
rsource "softdevice_handler/Kconfig"
1617
rsource "storage/flash_map/Kconfig"

subsys/shell/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
add_subdirectory(backends)

0 commit comments

Comments
 (0)