Skip to content

Commit ca1f3c3

Browse files
rexutcarlescufi
authored andcommitted
samples: echo_server: Enable USB by the application
This commit allows let build echo_server sample with overlay-netusb.conf. USB subsystem must be enabled by the application. Signed-off-by: Stephan Linz <[email protected]>
1 parent 3844b79 commit ca1f3c3

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

samples/net/sockets/echo_server/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ target_sources_ifdef(CONFIG_NET_UDP app PRIVATE src/udp.c)
2222
target_sources_ifdef(CONFIG_NET_TCP app PRIVATE src/tcp.c)
2323
target_sources_ifdef(CONFIG_NET_VLAN app PRIVATE src/vlan.c)
2424
target_sources_ifdef(CONFIG_NET_L2_IPIP app PRIVATE src/tunnel.c)
25+
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c)
2526

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

samples/net/sockets/echo_server/src/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,12 @@ static inline bool is_tunnel(struct net_if *iface)
9797
return false;
9898
}
9999
#endif /* CONFIG_NET_L2_IPIP */
100+
101+
#if defined(CONFIG_USB_DEVICE_STACK)
102+
int init_usb(void);
103+
#else
104+
static inline int init_usb(void)
105+
{
106+
return 0;
107+
}
108+
#endif /* CONFIG_USB_DEVICE_STACK */

samples/net/sockets/echo_server/src/echo-server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ static void init_app(void)
198198

199199
init_vlan();
200200
init_tunnel();
201+
202+
init_usb();
201203
}
202204

203205
static int cmd_sample_quit(const struct shell *shell,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2021 TiaC Systems
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <logging/log.h>
8+
LOG_MODULE_DECLARE(net_echo_server_sample, LOG_LEVEL_DBG);
9+
10+
#include <usb/usb_device.h>
11+
#include <net/net_config.h>
12+
13+
int init_usb(void)
14+
{
15+
int ret;
16+
17+
ret = usb_enable(NULL);
18+
if (ret != 0) {
19+
LOG_ERR("Cannot enable USB (%d)", ret);
20+
return ret;
21+
}
22+
23+
(void)net_config_init_app(NULL, "Initializing network");
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)