Skip to content

Commit 48922c8

Browse files
committed
samples: net: zperf: Add USB CDC NCM support
Add support for USB cdc_ncm to zperf application. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 31b2713 commit 48922c8

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

samples/net/zperf/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ if (CONFIG_NET_L2_ETHERNET)
2222
LOCATION "${CONFIG_NET_SAMPLE_CODE_RAM_NAME}_TEXT" NOKEEP)
2323
endif()
2424
endif()
25+
26+
if (CONFIG_USB_DEVICE_STACK_NEXT)
27+
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
28+
endif()

samples/net/zperf/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ config NET_SAMPLE_CODE_RAM_NAME
2020
Region to relocate networking code to
2121

2222
endif # NET_SAMPLE_CODE_RELOCATE
23+
24+
if USB_DEVICE_STACK_NEXT
25+
# Source common USB sample options used to initialize new experimental USB
26+
# device stack. The scope of these options is limited to USB samples in project
27+
# tree, you cannot use them in your own application.
28+
source "samples/subsys/usb/common/Kconfig.sample_usbd"
29+
endif
File renamed without changes.

samples/net/zperf/sample.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ tests:
4646
- native_sim/native/64
4747
sample.net.zperf.device_next_ecm:
4848
harness: net
49-
extra_args: OVERLAY_CONFIG="overlay-usbd_next_ecm.conf"
49+
extra_args: OVERLAY_CONFIG="overlay-usbd_next.conf"
5050
DTC_OVERLAY_FILE="usbd_next_ecm.overlay"
5151
platform_allow: nrf52840dk/nrf52840 frdm_k64f
5252
tags: usb net zperf
5353
depends_on: usb_device
54+
sample.net.zperf.device_next_ncm:
55+
harness: net
56+
extra_args: OVERLAY_CONFIG="overlay-usbd_next.conf"
57+
DTC_OVERLAY_FILE="usbd_next_ncm.overlay"
58+
platform_allow: nrf52840dk/nrf52840 frdm_k64f
59+
tags: usb net zperf
60+
depends_on: usb_device
5461
sample.net.zperf.netusb_eem:
5562
harness: net
5663
extra_args: OVERLAY_CONFIG="overlay-netusb.conf"

samples/net/zperf/src/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,36 @@
99
* @brief Zperf sample.
1010
*/
1111
#include <zephyr/usb/usb_device.h>
12+
#include <zephyr/usb/usbd.h>
1213
#include <zephyr/net/net_config.h>
1314

1415
#ifdef CONFIG_NET_LOOPBACK_SIMULATE_PACKET_DROP
1516
#include <zephyr/net/loopback.h>
1617
#endif
18+
19+
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
20+
#include <sample_usbd.h>
21+
22+
static struct usbd_context *sample_usbd;
23+
24+
static int enable_usb_device_next(void)
25+
{
26+
int err;
27+
28+
sample_usbd = sample_usbd_init_device(NULL);
29+
if (sample_usbd == NULL) {
30+
return -ENODEV;
31+
}
32+
33+
err = usbd_enable(sample_usbd);
34+
if (err) {
35+
return err;
36+
}
37+
38+
return 0;
39+
}
40+
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */
41+
1742
int main(void)
1843
{
1944
#if defined(CONFIG_USB_DEVICE_STACK)
@@ -26,6 +51,13 @@ int main(void)
2651

2752
(void)net_config_init_app(NULL, "Initializing network");
2853
#endif /* CONFIG_USB_DEVICE_STACK */
54+
55+
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
56+
if (enable_usb_device_next()) {
57+
return 0;
58+
}
59+
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */
60+
2961
#ifdef CONFIG_NET_LOOPBACK_SIMULATE_PACKET_DROP
3062
loopback_set_packet_drop_ratio(1);
3163
#endif
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
cdc_ncm_eth0: cdc_ncm_eth0 {
9+
compatible = "zephyr,cdc-ncm-ethernet";
10+
remote-mac-address = "00005E005301";
11+
};
12+
};

0 commit comments

Comments
 (0)