Skip to content

Commit cffb09c

Browse files
nordic-bamirlubos
authored andcommitted
tests: benchmarks: Add USB and BT to peripheral load benchmark
Add USB driver and BT beacon to the load test. Signed-off-by: Bartosz Miller <[email protected]>
1 parent 314dff5 commit cffb09c

File tree

9 files changed

+356
-1
lines changed

9 files changed

+356
-1
lines changed

tests/benchmarks/peripheral_load/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
99
project(periph_stress)
1010

1111
FILE(GLOB app_sources src/*.c)
12+
13+
zephyr_include_directories_ifdef(CONFIG_DT_HAS_SNPS_DWC2_ENABLED ${ZEPHYR_BASE}/samples/subsys/usb/common)
14+
zephyr_sources_ifdef(CONFIG_DT_HAS_SNPS_DWC2_ENABLED ${ZEPHYR_BASE}/samples/subsys/usb/common/sample_usbd_init.c)
15+
1216
target_sources(app PRIVATE ${app_sources})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source "${ZEPHYR_BASE}/samples/subsys/usb/common/Kconfig.sample_usbd"
2+
3+
source "Kconfig.zephyr"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
11
CONFIG_CLOCK_CONTROL=y
2+
3+
CONFIG_USB_DEVICE_STACK_NEXT=y
4+
5+
CONFIG_STDOUT_CONSOLE=y
6+
CONFIG_SERIAL=y
7+
CONFIG_UART_LINE_CTRL=y
8+
CONFIG_USBD_CDC_ACM_CLASS=y
9+
10+
CONFIG_USBD_LOG_LEVEL_WRN=y
11+
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
12+
CONFIG_USBD_CDC_ACM_LOG_LEVEL_ERR=y
13+
14+
CONFIG_SAMPLE_USBD_PID=0x0001
15+
CONFIG_SAMPLE_USBD_PRODUCT="USBD CDC ACM sample"

tests/benchmarks/peripheral_load/boards/nrf54h20dk_nrf54h20_cpuapp.overlay

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ temp_sensor: &temp_nrfs {
5454
&wdt010 {
5555
status = "okay";
5656
};
57+
58+
&zephyr_udc0 {
59+
cdc_acm_uart0 {
60+
compatible = "zephyr,cdc-acm-uart";
61+
};
62+
};

tests/benchmarks/peripheral_load/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ CONFIG_GPIO=y
99
CONFIG_I2S=y
1010
CONFIG_PWM=y
1111
CONFIG_WATCHDOG=y
12+
CONFIG_BT=y
13+
CONFIG_BT_DEVICE_NAME="Test beacon"
14+
CONFIG_BT_CTLR_TX_PWR_PLUS_8=y
1215
CONFIG_ASSERT=y

tests/benchmarks/peripheral_load/sample.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ tests:
3737
- ".*WDT thread has completed"
3838
- ".*CPU load thread has completed"
3939
- ".*Clock thread has completed"
40+
- ".*usb_thread: Baudrate 9600"
41+
- ".*Bluetooth init OK"
4042
- ".*all \\d{1,} threads have completed"
4143
extra_args:
4244
- SHIELD=pca63566
45+
- SB_CONFIG_NETCORE_IPC_RADIO=y
46+
- SB_CONFIG_NETCORE_IPC_RADIO_BT_HCI_IPC=y
4347
platform_allow: nrf54h20dk/nrf54h20/cpuapp
4448
integration_platforms:
4549
- nrf54h20dk/nrf54h20/cpuapp
@@ -63,6 +67,7 @@ tests:
6367
- ".*Timer thread has completed"
6468
- ".*WDT thread has completed"
6569
- ".*CPU load thread has completed"
70+
- ".*Bluetooth init OK"
6671
- ".*all \\d{1,} threads have completed"
6772
extra_args:
6873
- SHIELD=pca63565
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/types.h>
8+
#include <stddef.h>
9+
#include <zephyr/sys/printk.h>
10+
#include <zephyr/sys/util.h>
11+
#include <zephyr/logging/log.h>
12+
#include <zephyr/bluetooth/bluetooth.h>
13+
#include <zephyr/bluetooth/hci.h>
14+
#include "common.h"
15+
16+
LOG_MODULE_REGISTER(bt_thread, LOG_LEVEL_INF);
17+
18+
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
19+
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
20+
21+
/*
22+
* Set Advertisement data. Based on the Eddystone specification:
23+
* https://github.com/google/eddystone/blob/master/protocol-specification.md
24+
* https://github.com/google/eddystone/tree/master/eddystone-url
25+
*/
26+
static const struct bt_data ad[] = {
27+
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
28+
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0xaa, 0xfe),
29+
BT_DATA_BYTES(BT_DATA_SVC_DATA16,
30+
0xaa, 0xfe, /* Eddystone UUID */
31+
0x10, /* Eddystone-URL frame type */
32+
0x00, /* Calibrated Tx power at 0m */
33+
0x00, /* URL Scheme Prefix http://www. */
34+
'z', 'e', 'p', 'h', 'y', 'r',
35+
'p', 'r', 'o', 'j', 'e', 'c', 't',
36+
0x08) /* .org */
37+
};
38+
39+
/* Set Scan Response data */
40+
static const struct bt_data sd[] = {
41+
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
42+
};
43+
44+
static void bt_ready(int err)
45+
{
46+
char addr_s[BT_ADDR_LE_STR_LEN];
47+
bt_addr_le_t addr = {0};
48+
size_t count = 1;
49+
50+
if (err) {
51+
LOG_ERR("Bluetooth init failed (err %d)", err);
52+
return;
53+
}
54+
55+
LOG_INF("Bluetooth initialized\n");
56+
57+
/* Start advertising */
58+
err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),
59+
sd, ARRAY_SIZE(sd));
60+
if (err) {
61+
LOG_ERR("Advertising failed to start (err %d)", err);
62+
return;
63+
}
64+
65+
66+
/* For connectable advertising you would use
67+
* bt_le_oob_get_local(). For non-connectable non-identity
68+
* advertising an non-resolvable private address is used;
69+
* there is no API to retrieve that.
70+
*/
71+
72+
bt_id_get(&addr, &count);
73+
bt_addr_le_to_str(&addr, addr_s, sizeof(addr_s));
74+
75+
LOG_INF("Beacon started, advertising as %s", addr_s);
76+
}
77+
78+
/* BT thread */
79+
static void bt_thread(void *arg1, void *arg2, void *arg3)
80+
{
81+
ARG_UNUSED(arg1);
82+
ARG_UNUSED(arg2);
83+
ARG_UNUSED(arg3);
84+
85+
LOG_INF("Starting BT beacon");
86+
87+
/* Initialize the Bluetooth Subsystem */
88+
if (bt_enable(bt_ready)) {
89+
LOG_ERR("Bluetooth init failed");
90+
} else {
91+
LOG_INF("Bluetooth init OK");
92+
}
93+
}
94+
95+
K_THREAD_DEFINE(thread_bt_id, BT_THREAD_STACKSIZE, bt_thread, NULL, NULL, NULL,
96+
K_PRIO_PREEMPT(BT_THREAD_PRIORITY), 0, 0);

tests/benchmarks/peripheral_load/src/common.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,21 @@ extern atomic_t completed_threads;
9696
#define CLOCK_THREAD_STACKSIZE (512)
9797
#define CLOCK_THREAD_PRIORITY (4)
9898

99-
10099
/* Busy load thread: */
101100
#define LOAD_THREAD_STACKSIZE (1024)
102101
#define LOAD_THREAD_PRIORITY (CONFIG_NUM_PREEMPT_PRIORITIES - 1)
103102
#define LOAD_THREAD_DURATION (ACCEL_THREAD_SLEEP * (ACCEL_THREAD_COUNT_MAX + 2))
104103

104+
/* USB thread */
105+
#define USB_THREAD_COUNT_MAX (40)
106+
#define USB_THREAD_STACKSIZE (1024)
107+
#define USB_THREAD_PRIORITY (5)
108+
#define USB_THREAD_SLEEP (200)
109+
110+
/* BT thread */
111+
#define BT_THREAD_COUNT_MAX (40)
112+
#define BT_THREAD_STACKSIZE (1024)
113+
#define BT_THREAD_PRIORITY (5)
114+
#define BT_THREAD_SLEEP (200)
105115

106116
#endif

0 commit comments

Comments
 (0)