Skip to content

Commit 58afdce

Browse files
committed
samples: http_server: use new USB device stack
Remove netusb code, use new USB device stack and CDC NCM implementation. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
1 parent b5a07f5 commit 58afdce

File tree

9 files changed

+57
-43
lines changed

9 files changed

+57
-43
lines changed

samples/net/sockets/http_server/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ target_sources(app PRIVATE src/main.c)
4141
set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/)
4242

4343
target_sources_ifdef(CONFIG_NET_SAMPLE_WEBSOCKET_SERVICE app PRIVATE src/ws.c)
44-
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c)
44+
45+
if (CONFIG_USB_DEVICE_STACK_NEXT)
46+
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
47+
endif()
4548

4649
target_link_libraries(app PRIVATE zephyr_interface zephyr)
4750

samples/net/sockets/http_server/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,11 @@ config NET_SAMPLE_WEBSOCKET_STATS_INTERVAL
6969
This interval controls how often the net stats data shown on the web page
7070
will be updated.
7171

72+
if USB_DEVICE_STACK_NEXT
73+
# Source common USB sample options used to initialize new experimental USB
74+
# device stack. The scope of these options is limited to USB samples in project
75+
# tree, you cannot use them in your own application.
76+
source "samples/subsys/usb/common/Kconfig.sample_usbd"
77+
endif
78+
7279
source "Kconfig.zephyr"

samples/net/sockets/http_server/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ There are configuration files for various setups in the
3131
* - :zephyr_file:`ieee802154-overlay.conf <samples/net/sockets/http_server/ieee802154-overlay.conf>`
3232
- This overlay config can be added for IEEE 802.15.4 support.
3333

34-
* - :zephyr_file:`overlay-netusb.conf <samples/net/sockets/http_server/overlay-netusb.conf>`
34+
* - :zephyr_file:`overlay-usbd.conf <samples/net/sockets/http_server/overlay-usbd.conf>`
3535
- This overlay config can be added for connecting via network USB.
3636

3737
* - :zephyr_file:`overlay-tls.conf <samples/net/sockets/http_server/overlay-tls.conf>`

samples/net/sockets/http_server/overlay-netusb.conf

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CONFIG_USB_DEVICE_STACK_NEXT=y
2+
3+
CONFIG_LOG=y
4+
CONFIG_USBD_LOG_LEVEL_WRN=y
5+
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
6+
7+
CONFIG_NET_L2_ETHERNET=y

samples/net/sockets/http_server/sample.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ tests:
1616
sample.net.sockets.http.server: {}
1717
sample.net.sockets.https.server:
1818
extra_args: EXTRA_CONF_FILE="overlay-tls.conf"
19+
sample.net.sockets.http.server.usbd_cdc_ncm:
20+
depends_on: usbd
21+
extra_args: EXTRA_CONF_FILE="overlay-usbd.conf"
22+
EXTRA_DTC_OVERLAY_FILE="usbd_cdc_ncm.overlay"
23+
tags:
24+
- usb

samples/net/sockets/http_server/src/main.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <zephyr/drivers/led.h>
2020
#include <zephyr/data/json.h>
2121
#include <zephyr/sys/util_macro.h>
22+
#include <sample_usbd.h>
23+
#include <zephyr/net/net_config.h>
2224

2325
#include "ws.h"
2426

@@ -347,14 +349,27 @@ static void setup_tls(void)
347349
#endif /* defined(CONFIG_NET_SAMPLE_HTTPS_SERVICE) */
348350
}
349351

350-
#if defined(CONFIG_USB_DEVICE_STACK)
351-
int init_usb(void);
352-
#else
353-
static inline int init_usb(void)
352+
static int init_usb(void)
354353
{
354+
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
355+
struct usbd_context *sample_usbd;
356+
int err;
357+
358+
sample_usbd = sample_usbd_init_device(NULL);
359+
if (sample_usbd == NULL) {
360+
return -ENODEV;
361+
}
362+
363+
err = usbd_enable(sample_usbd);
364+
if (err) {
365+
return err;
366+
}
367+
368+
(void)net_config_init_app(NULL, "Initializing network");
369+
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */
370+
355371
return 0;
356372
}
357-
#endif /* CONFIG_USB_DEVICE_STACK */
358373

359374
int main(void)
360375
{

samples/net/sockets/http_server/src/usb.c

Lines changed: 0 additions & 26 deletions
This file was deleted.
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)