Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/net/sockets/echo_server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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)

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

Expand Down
9 changes: 9 additions & 0 deletions samples/net/sockets/echo_server/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ static inline bool is_tunnel(struct net_if *iface)
return false;
}
#endif /* CONFIG_NET_L2_IPIP */

#if defined(CONFIG_USB_DEVICE_STACK)
int init_usb(void);
#else
static inline int init_usb(void)
{
return 0;
}
#endif /* CONFIG_USB_DEVICE_STACK */
2 changes: 2 additions & 0 deletions samples/net/sockets/echo_server/src/echo-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ static void init_app(void)

init_vlan();
init_tunnel();

init_usb();
}

static int cmd_sample_quit(const struct shell *shell,
Expand Down
26 changes: 26 additions & 0 deletions samples/net/sockets/echo_server/src/usb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2021 TiaC Systems
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <logging/log.h>
LOG_MODULE_DECLARE(net_echo_server_sample, LOG_LEVEL_DBG);

#include <usb/usb_device.h>
#include <net/net_config.h>

int init_usb(void)
{
int ret;

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

(void)net_config_init_app(NULL, "Initializing network");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone wondering (like me) why is this needed for USB, config NET_CONFIG_AUTO_INIT has default n if USB_DEVICE_NETWORK


return 0;
}