Skip to content

Commit

Permalink
samples: net: echo-server: Add USB CDC NCM support
Browse files Browse the repository at this point in the history
Add support for USB cdc_ncm to echo-server application.

Signed-off-by: Jukka Rissanen <[email protected]>
  • Loading branch information
jukkar committed Oct 9, 2024
1 parent 48922c8 commit d1efbbf
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 2 deletions.
10 changes: 9 additions & 1 deletion samples/net/sockets/echo_server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ target_sources_ifdef(CONFIG_NET_UDP app PRIVATE src/udp.c)
target_sources_ifdef(CONFIG_NET_TCP app PRIVATE src/tcp.c)
target_sources_ifdef(CONFIG_NET_VLAN app PRIVATE src/vlan.c)
target_sources_ifdef(CONFIG_NET_L2_IPIP app PRIVATE src/tunnel.c)
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c)

if (CONFIG_USB_DEVICE_STACK)
target_sources(app PRIVATE src/usb.c)
endif()

if (CONFIG_USB_DEVICE_STACK_NEXT)
target_sources(app PRIVATE src/usb.c)
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
endif()

include(${ZEPHYR_BASE}/samples/net/common/common.cmake)

Expand Down
7 changes: 7 additions & 0 deletions samples/net/sockets/echo_server/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@ config NET_SAMPLE_CERTS_WITH_SC
Enable this flag, if you are interested to run this
application with signed certificates and keys.

if USB_DEVICE_STACK_NEXT
# Source common USB sample options used to initialize new experimental USB
# device stack. The scope of these options is limited to USB samples in project
# tree, you cannot use them in your own application.
source "samples/subsys/usb/common/Kconfig.sample_usbd"

Check warning on line 94 in samples/net/sockets/echo_server/Kconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/Kconfig:94 please, no spaces at the start of a line

Check warning on line 94 in samples/net/sockets/echo_server/Kconfig

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/Kconfig:94 please, no spaces at the start of a line
endif

source "Kconfig.zephyr"
7 changes: 7 additions & 0 deletions samples/net/sockets/echo_server/overlay-usbd_next.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONFIG_USB_DEVICE_STACK_NEXT=y

CONFIG_LOG=y
CONFIG_USBD_LOG_LEVEL_WRN=y
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
2 changes: 1 addition & 1 deletion samples/net/sockets/echo_server/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static inline bool is_tunnel(struct net_if *iface)
}
#endif /* CONFIG_NET_L2_IPIP */

#if defined(CONFIG_USB_DEVICE_STACK)
#if defined(CONFIG_USB_DEVICE_STACK) || defined(CONFIG_USB_DEVICE_STACK_NEXT)
int init_usb(void);
#else
static inline int init_usb(void)
Expand Down
31 changes: 31 additions & 0 deletions samples/net/sockets/echo_server/src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,46 @@ LOG_MODULE_DECLARE(net_echo_server_sample, LOG_LEVEL_DBG);
#include <zephyr/usb/usb_device.h>
#include <zephyr/net/net_config.h>

#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
#include <sample_usbd.h>

static struct usbd_context *sample_usbd;

static int enable_usb_device_next(void)
{
int err;

Check failure on line 20 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:20 code indent should use tabs where possible

Check warning on line 20 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:20 please, no spaces at the start of a line

Check failure on line 20 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:20 code indent should use tabs where possible

Check warning on line 20 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:20 please, no spaces at the start of a line

sample_usbd = sample_usbd_init_device(NULL);

Check failure on line 22 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:22 code indent should use tabs where possible

Check warning on line 22 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:22 please, no spaces at the start of a line

Check failure on line 22 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:22 code indent should use tabs where possible

Check warning on line 22 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:22 please, no spaces at the start of a line
if (sample_usbd == NULL) {

Check failure on line 23 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:23 code indent should use tabs where possible

Check warning on line 23 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:23 please, no spaces at the start of a line

Check failure on line 23 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:23 code indent should use tabs where possible

Check warning on line 23 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:23 please, no spaces at the start of a line
return -ENODEV;

Check failure on line 24 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:24 code indent should use tabs where possible

Check warning on line 24 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:24 please, no spaces at the start of a line

Check failure on line 24 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:24 code indent should use tabs where possible

Check warning on line 24 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:24 please, no spaces at the start of a line
}

Check failure on line 25 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:25 code indent should use tabs where possible

Check warning on line 25 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:25 please, no spaces at the start of a line

Check failure on line 25 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:25 code indent should use tabs where possible

Check warning on line 25 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:25 please, no spaces at the start of a line

err = usbd_enable(sample_usbd);

Check failure on line 27 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:27 code indent should use tabs where possible

Check warning on line 27 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:27 please, no spaces at the start of a line

Check failure on line 27 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:27 code indent should use tabs where possible

Check warning on line 27 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:27 please, no spaces at the start of a line
if (err) {

Check failure on line 28 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:28 code indent should use tabs where possible

Check warning on line 28 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:28 please, no spaces at the start of a line

Check failure on line 28 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:28 code indent should use tabs where possible

Check warning on line 28 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:28 please, no spaces at the start of a line
return err;

Check failure on line 29 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:29 code indent should use tabs where possible

Check warning on line 29 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:29 please, no spaces at the start of a line

Check failure on line 29 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:29 code indent should use tabs where possible

Check warning on line 29 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:29 please, no spaces at the start of a line
}

Check failure on line 30 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:30 code indent should use tabs where possible

Check warning on line 30 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:30 please, no spaces at the start of a line

Check failure on line 30 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:30 code indent should use tabs where possible

Check warning on line 30 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

samples/net/sockets/echo_server/src/usb.c:30 please, no spaces at the start of a line

return 0;

Check failure on line 32 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:32 code indent should use tabs where possible

Check failure on line 32 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

samples/net/sockets/echo_server/src/usb.c:32 code indent should use tabs where possible
}

Check notice on line 33 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/net/sockets/echo_server/src/usb.c:33 - int err; + int err; - sample_usbd = sample_usbd_init_device(NULL); - if (sample_usbd == NULL) { - return -ENODEV; - } + sample_usbd = sample_usbd_init_device(NULL); + if (sample_usbd == NULL) { + return -ENODEV; + } - err = usbd_enable(sample_usbd); - if (err) { - return err; - } + err = usbd_enable(sample_usbd); + if (err) { + return err; + } - return 0; + return 0;

Check notice on line 33 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/net/sockets/echo_server/src/usb.c:33 - int err; + int err; - sample_usbd = sample_usbd_init_device(NULL); - if (sample_usbd == NULL) { - return -ENODEV; - } + sample_usbd = sample_usbd_init_device(NULL); + if (sample_usbd == NULL) { + return -ENODEV; + } - err = usbd_enable(sample_usbd); - if (err) { - return err; - } + err = usbd_enable(sample_usbd); + if (err) { + return err; + } - return 0; + return 0;
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */

int init_usb(void)
{
#if defined(CONFIG_USB_DEVICE_STACK)
int ret;

ret = usb_enable(NULL);
if (ret != 0) {
LOG_ERR("Cannot enable USB (%d)", ret);
return ret;
}
#endif /* CONFIG_USB_DEVICE_STACK */

#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
if (enable_usb_device_next()) {
return 0;
}
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */

Check notice on line 52 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/net/sockets/echo_server/src/usb.c:52 - if (enable_usb_device_next()) { - return 0; - } + if (enable_usb_device_next()) { + return 0; + }

Check notice on line 52 in samples/net/sockets/echo_server/src/usb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/net/sockets/echo_server/src/usb.c:52 - if (enable_usb_device_next()) { - return 0; - } + if (enable_usb_device_next()) { + return 0; + }

(void)net_config_init_app(NULL, "Initializing network");

Expand Down
12 changes: 12 additions & 0 deletions samples/net/sockets/echo_server/usbd_next_ncm.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
cdc_ncm_eth0: cdc_ncm_eth0 {
compatible = "zephyr,cdc-ncm-ethernet";
remote-mac-address = "00005E005301";
};
};

0 comments on commit d1efbbf

Please sign in to comment.