Skip to content

Commit 615a0b8

Browse files
committed
samples: boards: st: ble ieee802.15.4 concurrent mode
Add sample Bluetooth Heart Rate - 802154 Echo Client Signed-off-by: Vincent Tardy <[email protected]>
1 parent dc777e3 commit 615a0b8

File tree

15 files changed

+1959
-0
lines changed

15 files changed

+1959
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(sockets_echo_client)
7+
8+
if(CONFIG_NET_SOCKETS_SOCKOPT_TLS AND
9+
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED AND
10+
(CONFIG_NET_SAMPLE_PSK_HEADER_FILE STREQUAL "dummy_psk.h"))
11+
add_custom_target(development_psk
12+
COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------"
13+
COMMAND ${CMAKE_COMMAND} -E echo "--- WARNING: Using dummy PSK! Only suitable for ---"
14+
COMMAND ${CMAKE_COMMAND} -E echo "--- development. Set NET_SAMPLE_PSK_HEADER_FILE to use ---"
15+
COMMAND ${CMAKE_COMMAND} -E echo "--- own pre-shared key. ---"
16+
COMMAND ${CMAKE_COMMAND} -E echo "----------------------------------------------------------"
17+
)
18+
add_dependencies(app development_psk)
19+
endif()
20+
21+
target_sources( app PRIVATE src/echo-client.c)
22+
target_sources( app PRIVATE src/app_ble.c)
23+
target_sources_ifdef(CONFIG_NET_UDP app PRIVATE src/udp.c)
24+
target_sources_ifdef(CONFIG_NET_TCP app PRIVATE src/tcp.c)
25+
26+
include(${ZEPHYR_BASE}/samples/net/common/common.cmake)
27+
28+
set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/)
29+
30+
generate_inc_file_for_target(
31+
app
32+
src/echo-apps-cert.der
33+
${gen_dir}/echo-apps-cert.der.inc
34+
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Private config options for ble HR - Networking echo-client sample app
2+
3+
# Copyright (c) 2018 Intel Corporation
4+
# Copyright (c) 2025 STMicroelectronics
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
mainmenu "BLE Heart Rate - Networking echo-client sample application"
8+
9+
config NET_SAMPLE_IFACE2_MY_IPV6_ADDR
10+
string "My IPv6 address for second interface"
11+
help
12+
The value depends on your network setup.
13+
14+
config NET_SAMPLE_IFACE2_MY_IPV4_ADDR
15+
string "My IPv4 address for second interface"
16+
help
17+
The value depends on your network setup.
18+
19+
config NET_SAMPLE_IFACE2_VLAN_TAG
20+
int "VLAN tag for second interface"
21+
default 100
22+
range 0 4094
23+
depends on NET_VLAN
24+
help
25+
Set VLAN (virtual LAN) tag (id) that is used in the sample
26+
application.
27+
28+
config NET_SAMPLE_IFACE3_MY_IPV6_ADDR
29+
string "My IPv6 address for third interface"
30+
help
31+
The value depends on your network setup.
32+
33+
config NET_SAMPLE_IFACE3_MY_IPV4_ADDR
34+
string "My IPv4 address for third interface"
35+
help
36+
The value depends on your network setup.
37+
38+
config NET_SAMPLE_IFACE3_VLAN_TAG
39+
int "VLAN tag for third interface"
40+
default 200
41+
range 0 4094
42+
depends on NET_VLAN
43+
help
44+
Set VLAN (virtual LAN) tag (id) that is used in the sample
45+
application.
46+
47+
config NET_SAMPLE_PSK_HEADER_FILE
48+
string "Header file containing PSK"
49+
default "dummy_psk.h"
50+
depends on MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
51+
help
52+
Name of a header file containing a
53+
pre-shared key.
54+
55+
config NET_SAMPLE_SEND_ITERATIONS
56+
int "Send sample data this many times"
57+
default 0
58+
help
59+
Send sample data this many times before exiting. A value of
60+
zero means that the sample application is run forever.
61+
62+
source "Kconfig.zephyr"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
.. zephyr:code-sample:: stm32_ble_hr_802154_echo_client
2+
:name: BLE HR - 802154 Echo client (advanced)
3+
4+
Implement a Bluetooth |reg| Energy Heart Rate - ieee 802154 client.
5+
The BLE Heart Rate (HR) GATT Service generates dummy heart-rate
6+
values and the 802154 echo client sends IP packets, waits for data
7+
to be sent back, and verifies it.
8+
9+
Overview
10+
********
11+
12+
The sample application for Zephyr implements a concurrent mode
13+
BLE - IEEE 802.15.4.
14+
The 802.15.4 part implements UDP/TCP client that will send IPv4
15+
or IPv6 packets, wait for the data to be sent back, and then verify
16+
it matches the data that was sent.
17+
The BLE part exposes the HR (Heart Rate) GATT Service. Once a device
18+
connects it will generate dummy heart-rate values.
19+
20+
The source code for this sample application can be found at:
21+
:zephyr_file:`samples/boards/st/ble_802154/ble_hr_802154_echo_client`.
22+
23+
Requirements
24+
************
25+
26+
This sample has been tested on the STMicroelectonics NUCLEO-WBA65RI board
27+
(nucleo_wba65ri).
28+
29+
Building and Running
30+
********************
31+
32+
33+
There are configuration files for different boards and setups in the
34+
samples directory:
35+
36+
- :file:`prj.conf`
37+
Generic config file, normally you should use this.
38+
39+
- :file:`overlay-802154.conf`
40+
This overlay config enables support for native IEEE 802.15.4 connectivity.
41+
Note, that by default IEEE 802.15.4 L2 uses unacknowledged communication. To
42+
improve connection reliability, acknowledgments can be enabled with shell
43+
command: ``ieee802154 ack set``.
44+
45+
Build sample application like this:
46+
47+
.. zephyr-app-commands::
48+
:zephyr-app: samples/boards/st/ble_802154/ble_hr_802154_echo_client
49+
:board: <board to use>
50+
:conf: <config file to use>
51+
:goals: build
52+
:compact:
53+
54+
Example building for the IEEE 802.15.4 on nucleo_wba65ri:
55+
56+
.. zephyr-app-commands::
57+
:zephyr-app: samples/boards/st/ble_802154/ble_hr_802154_echo_client
58+
:board: nucleo_wba65ri
59+
:gen-args: -DEXTRA_CONF_FILE=overlay-802154.conf
60+
:goals: build
61+
:compact:
62+
63+
The LED 1 toggles while application is BLE advertising. Once a remote device
64+
connects, the LED 1 turns ON and application will generate dummy heart-rate values.
65+
Once remote device disconnects, the ammplication restarts BLE advertising and LED 1
66+
toggles.
67+
68+
Simultaneously, IEEE 802.15.4 feature is enabled.
69+
In remote device, you can run a echo-server sample application with overlay-802154.conf.
70+
Once both devices are connected, local device will send IPv4 or IPv6 packets,
71+
wait for the data to be sent back from the remote echo-server device,and then
72+
verify it matches the data that was sent.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2020 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if [ -z "$RUNNING_FROM_MAIN_SCRIPT" ]; then
5+
echo "Do not run this script directly!"
6+
echo "Run $ZEPHYR_BASE/scripts/net/run-sample-tests.sh instead."
7+
exit 1
8+
fi
9+
10+
start_configuration "--ip=192.0.2.1 --ip6=2001:db8::1" || return $?
11+
start_docker "/net-tools/echo-server -i eth0" || return $?
12+
13+
start_zephyr "$overlay" "-DCONFIG_NET_SAMPLE_SEND_ITERATIONS=10"
14+
15+
wait_zephyr
16+
result=$?
17+
18+
stop_docker
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
2+
CONFIG_NET_TCP=n
3+
CONFIG_NET_IPV4=n
4+
5+
CONFIG_NET_CONFIG_NEED_IPV6=y
6+
CONFIG_NET_CONFIG_NEED_IPV4=n
7+
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
8+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
9+
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
10+
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
11+
12+
CONFIG_NET_L2_IEEE802154=y
13+
CONFIG_NET_L2_IEEE802154_SHELL=y
14+
CONFIG_NET_L2_IEEE802154_LOG_LEVEL_INF=y
15+
16+
CONFIG_NET_CONFIG_IEEE802154_CHANNEL=26
17+
18+
CONFIG_NET_L2_IEEE802154_FRAGMENT_REASS_CACHE_SIZE=5
19+
20+
CONFIG_NET_RX_STACK_SIZE=2048
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Generic networking options
2+
CONFIG_NETWORKING=y
3+
CONFIG_NET_UDP=y
4+
CONFIG_NET_TCP=y
5+
CONFIG_NET_IPV6=y
6+
CONFIG_NET_IPV4=y
7+
CONFIG_NET_SOCKETS=y
8+
CONFIG_ZVFS_POLL_MAX=5
9+
CONFIG_NET_CONNECTION_MANAGER=y
10+
11+
CONFIG_POSIX_API=y
12+
13+
# Kernel options
14+
CONFIG_MAIN_STACK_SIZE=2048
15+
CONFIG_ENTROPY_GENERATOR=y
16+
CONFIG_TEST_RANDOM_GENERATOR=y
17+
CONFIG_INIT_STACKS=y
18+
CONFIG_MAX_THREAD_BYTES=3
19+
20+
# Logging
21+
CONFIG_NET_LOG=y
22+
CONFIG_LOG=y
23+
CONFIG_NET_STATISTICS=y
24+
CONFIG_PRINTK=y
25+
26+
# Network buffers
27+
CONFIG_NET_PKT_RX_COUNT=16
28+
CONFIG_NET_PKT_TX_COUNT=16
29+
CONFIG_NET_BUF_RX_COUNT=80
30+
CONFIG_NET_BUF_TX_COUNT=80
31+
CONFIG_NET_CONTEXT_NET_PKT_POOL=y
32+
33+
# IP address options
34+
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
35+
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
36+
CONFIG_NET_MAX_CONTEXTS=10
37+
CONFIG_NET_IF_MAX_IPV6_COUNT=3
38+
CONFIG_NET_IF_MAX_IPV4_COUNT=3
39+
40+
# Network shell
41+
CONFIG_NET_SHELL=y
42+
43+
# The addresses are selected so that qemu<->qemu connectivity works ok.
44+
# For linux<->qemu connectivity, create a new conf file and swap the
45+
# addresses (so that peer address is ending to 2).
46+
CONFIG_NET_CONFIG_SETTINGS=y
47+
CONFIG_NET_CONFIG_NEED_IPV6=y
48+
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
49+
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
50+
CONFIG_NET_CONFIG_NEED_IPV4=y
51+
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.2"
52+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.1"
53+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
54+
55+
# Bluetootn configuration
56+
CONFIG_BT=y
57+
CONFIG_BT_SMP=y
58+
CONFIG_BT_PERIPHERAL=y
59+
CONFIG_BT_DIS=y
60+
CONFIG_BT_DIS_PNP=n
61+
CONFIG_BT_BAS=y
62+
CONFIG_BT_HRS=y
63+
CONFIG_BT_DEVICE_NAME="Zephyr HR 802154 Echo Client"
64+
CONFIG_BT_DEVICE_APPEARANCE=833
65+
CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB=y
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sample:
2+
description: Test concurrent mode BLE Heart Rate - IEEE802.15.4 echo client
3+
name: BLE Heart Rate - Socket Echo Client
4+
tests:
5+
sample.boards.stm32.ble_802154.ble_hr_802154_echo_client:
6+
harness: net
7+
extra_args: EXTRA_CONF_FILE="overlay-802154.conf"
8+
platform_allow: nucleo_wba65ri
9+
tags:
10+
- bluetooth
11+
- net
12+
- socket

0 commit comments

Comments
 (0)