Skip to content

Commit 17625f4

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 93bb5ff commit 17625f4

File tree

15 files changed

+1944
-0
lines changed

15 files changed

+1944
-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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Private config options for ble HR - Networking echo-client sample app
2+
3+
# Copyright (c) 2018 Intel Corporation
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
mainmenu "Ble Heart Rate - Networking echo-client sample application"
7+
8+
config NET_SAMPLE_IFACE2_MY_IPV6_ADDR
9+
string "My IPv6 address for second interface"
10+
help
11+
The value depends on your network setup.
12+
13+
config NET_SAMPLE_IFACE2_MY_IPV4_ADDR
14+
string "My IPv4 address for second interface"
15+
help
16+
The value depends on your network setup.
17+
18+
config NET_SAMPLE_IFACE2_VLAN_TAG
19+
int "VLAN tag for second interface"
20+
default 100
21+
range 0 4094
22+
depends on NET_VLAN
23+
help
24+
Set VLAN (virtual LAN) tag (id) that is used in the sample
25+
application.
26+
27+
config NET_SAMPLE_IFACE3_MY_IPV6_ADDR
28+
string "My IPv6 address for third interface"
29+
help
30+
The value depends on your network setup.
31+
32+
config NET_SAMPLE_IFACE3_MY_IPV4_ADDR
33+
string "My IPv4 address for third interface"
34+
help
35+
The value depends on your network setup.
36+
37+
config NET_SAMPLE_IFACE3_VLAN_TAG
38+
int "VLAN tag for third interface"
39+
default 200
40+
range 0 4094
41+
depends on NET_VLAN
42+
help
43+
Set VLAN (virtual LAN) tag (id) that is used in the sample
44+
application.
45+
46+
config NET_SAMPLE_PSK_HEADER_FILE
47+
string "Header file containing PSK"
48+
default "dummy_psk.h"
49+
depends on MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
50+
help
51+
Name of a header file containing a
52+
pre-shared key.
53+
54+
config NET_SAMPLE_SEND_ITERATIONS
55+
int "Send sample data this many times"
56+
default 0
57+
help
58+
Send sample data this many times before exiting. A value of
59+
zero means that the sample application is run forever.
60+
61+
source "Kconfig.zephyr"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.. zephyr:code-sample:: stm32_ble_hr_802154_echo_client
2+
:name: Ble HR - 802154 Echo client (advanced)
3+
4+
Implement a Bluetooth Heart Rate - 802154 client.
5+
The Bluetooth 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 - IEEE802.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+
- :ref:`networking_with_host`
27+
* BlueZ running on the host, or
28+
* A board with Bluetooth LE support
29+
30+
Building and Running
31+
********************
32+
33+
34+
There are configuration files for different boards and setups in the
35+
samplet directory:
36+
37+
- :file:`prj.conf`
38+
Generic config file, normally you should use this.
39+
40+
- :file:`overlay-802154.conf`
41+
This overlay config enables support for native IEEE 802.15.4 connectivity.
42+
Note, that by default IEEE 802.15.4 L2 uses unacknowledged communication. To
43+
improve connection reliability, acknowledgments can be enabled with shell
44+
command: ``ieee802154 ack set``.
45+
46+
Build sample application like this:
47+
48+
.. zephyr-app-commands::
49+
:zephyr-app: samples/boards/st/ble_802154/ble_hr_802154_echo_client
50+
:board: <board to use>
51+
:conf: <config file to use>
52+
:goals: build
53+
:compact:
54+
55+
Example building for the IEEE 802.15.4 on nucleo_wba65ri:
56+
57+
.. zephyr-app-commands::
58+
:zephyr-app: samples/boards/st/ble_802154/ble_hr_802154_echo_client
59+
:board: nucleo_wba65ri
60+
:gen-args: -DEXTRA_CONF_FILE=overlay-802154.conf
61+
:goals: build
62+
:compact:
63+
64+
In a terminal window you can check if communication is happen:
65+
66+
.. code-block:: console
67+
68+
$ minicom -D /dev/ttyACM1
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Disable TCP and IPv4 (TCP disabled to avoid heavy traffic)
2+
CONFIG_NET_TCP=n
3+
CONFIG_NET_IPV4=n
4+
CONFIG_NET_CONFIG_AUTO_INIT=n
5+
6+
CONFIG_NET_CONFIG_NEED_IPV6=y
7+
CONFIG_NET_CONFIG_NEED_IPV4=n
8+
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
9+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
10+
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::2"
11+
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::1"
12+
13+
CONFIG_NET_L2_IEEE802154=y
14+
CONFIG_NET_L2_IEEE802154_SHELL=y
15+
CONFIG_NET_L2_IEEE802154_LOG_LEVEL_INF=y
16+
17+
CONFIG_NET_CONFIG_IEEE802154_CHANNEL=26
18+
19+
CONFIG_NET_L2_IEEE802154_FRAGMENT_REASS_CACHE_SIZE=5
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sample:
2+
description: Test concurrent mode Ble HeartRate - 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:
7+
- bluetooth
8+
- net
9+
extra_args: EXTRA_CONF_FILE="overlay-802154.conf"
10+
platform_allow: nucleo_wba65ri
11+
tags:
12+
- bluetooth
13+
- net
14+
- socket

0 commit comments

Comments
 (0)