Skip to content

Commit 934602b

Browse files
raiden00plxiaoxiang781216
authored andcommitted
boards/thingy53: add usb example
The board can act as an USB composite device. For now CDCACM and RNDIS are supported.
1 parent 04fa008 commit 934602b

File tree

5 files changed

+349
-0
lines changed

5 files changed

+349
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# This file is autogenerated: PLEASE DO NOT EDIT IT.
3+
#
4+
# You can use "make menuconfig" to make any modifications to the installed .config file.
5+
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
6+
# modifications.
7+
#
8+
# CONFIG_ARCH_FPU is not set
9+
CONFIG_ARCH="arm"
10+
CONFIG_ARCH_BOARD="thingy53"
11+
CONFIG_ARCH_BOARD_THINGY53=y
12+
CONFIG_ARCH_CHIP="nrf53"
13+
CONFIG_ARCH_CHIP_NRF5340=y
14+
CONFIG_ARCH_CHIP_NRF5340_CPUAPP=y
15+
CONFIG_ARCH_CHIP_NRF53=y
16+
CONFIG_ARCH_STACKDUMP=y
17+
CONFIG_ARCH_STDARG_H=y
18+
CONFIG_BOARD_LOOPSPERMSEC=5500
19+
CONFIG_BUILTIN=y
20+
CONFIG_CDCACM=y
21+
CONFIG_CDCACM_COMPOSITE=y
22+
CONFIG_COMPOSITE_IAD=y
23+
CONFIG_DEBUG_FULLOPT=y
24+
CONFIG_DEBUG_SYMBOLS=y
25+
CONFIG_EXPERIMENTAL=y
26+
CONFIG_FS_PROCFS=y
27+
CONFIG_INIT_ENTRYPOINT="nsh_main"
28+
CONFIG_INTELHEX_BINARY=y
29+
CONFIG_MM_REGIONS=2
30+
CONFIG_NET=y
31+
CONFIG_NETDB_DNSCLIENT=y
32+
CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0
33+
CONFIG_NETDEV_LATEINIT=y
34+
CONFIG_NETINIT_DHCPC=y
35+
CONFIG_NETINIT_DRIPADDR=0x0
36+
CONFIG_NETINIT_MACADDR_1=0xdeadcafe
37+
CONFIG_NETINIT_NETMASK=0x0
38+
CONFIG_NETINIT_NOMAC=y
39+
CONFIG_NETINIT_THREAD=y
40+
CONFIG_NETUTILS_DHCPC=y
41+
CONFIG_NETUTILS_IPERF=y
42+
CONFIG_NETUTILS_TELNETD=y
43+
CONFIG_NETUTILS_WEBCLIENT=y
44+
CONFIG_NET_ARP_SEND=y
45+
CONFIG_NET_BROADCAST=y
46+
CONFIG_NET_ICMP=y
47+
CONFIG_NET_ICMP_SOCKET=y
48+
CONFIG_NET_LL_GUARDSIZE=50
49+
CONFIG_NET_LOOPBACK=y
50+
CONFIG_NET_STATISTICS=y
51+
CONFIG_NET_TCP=y
52+
CONFIG_NET_TCP_WRITE_BUFFERS=y
53+
CONFIG_NET_UDP=y
54+
CONFIG_NRF53_HFCLK_XTAL=y
55+
CONFIG_NRF53_UART0=y
56+
CONFIG_NRF53_USBDEV=y
57+
CONFIG_NSH_ARCHINIT=y
58+
CONFIG_NSH_BUILTIN_APPS=y
59+
CONFIG_NSH_DISABLE_IFUPDOWN=y
60+
CONFIG_NSH_FILEIOSIZE=512
61+
CONFIG_NSH_LINELEN=64
62+
CONFIG_NSH_READLINE=y
63+
CONFIG_PREALLOC_TIMERS=4
64+
CONFIG_RAM_SIZE=524288
65+
CONFIG_RAM_START=0x20000000
66+
CONFIG_RAW_BINARY=y
67+
CONFIG_RNDIS=y
68+
CONFIG_RNDIS_COMPOSITE=y
69+
CONFIG_RR_INTERVAL=200
70+
CONFIG_SCHED_LPWORK=y
71+
CONFIG_SCHED_WAITPID=y
72+
CONFIG_START_DAY=26
73+
CONFIG_START_MONTH=3
74+
CONFIG_SYMTAB_ORDEREDBYNAME=y
75+
CONFIG_SYSTEM_COMPOSITE=y
76+
CONFIG_SYSTEM_NSH=y
77+
CONFIG_TASK_NAME_SIZE=32
78+
CONFIG_UART0_SERIAL_CONSOLE=y
79+
CONFIG_USBDEV_COMPOSITE=y

boards/arm/nrf53/thingy53/src/Make.defs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y)
3434
CSRCS += nrf53_buttons.c
3535
endif
3636

37+
ifeq ($(CONFIG_USBDEV),y)
38+
CSRCS += nrf53_usb.c
39+
endif
40+
41+
ifeq ($(CONFIG_USBDEV_COMPOSITE),y)
42+
CSRCS += nrf53_composite.c
43+
endif
44+
3745
DEPPATH += --dep-path board
3846
VPATH += :board
3947
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)

boards/arm/nrf53/thingy53/src/nrf53_bringup.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
# include <nuttx/input/buttons.h>
3939
#endif
4040

41+
#ifdef CONFIG_USBMONITOR
42+
# include <nuttx/usb/usbmonitor.h>
43+
#endif
44+
45+
#ifdef CONFIG_RNDIS
46+
# include <nuttx/usb/rndis.h>
47+
#endif
48+
4149
#ifdef CONFIG_NRF53_SOFTDEVICE_CONTROLLER
4250
# include "nrf53_sdc.h"
4351
#endif
@@ -203,6 +211,27 @@ int nrf53_bringup(void)
203211
#endif
204212
#endif
205213

214+
#ifdef CONFIG_USBMONITOR
215+
/* Start the USB Monitor */
216+
217+
ret = usbmonitor_start();
218+
if (ret != OK)
219+
{
220+
syslog(LOG_ERR, "ERROR: Failed to start USB monitor: %d\n", ret);
221+
}
222+
#endif
223+
224+
#if defined(CONFIG_RNDIS) && !defined(CONFIG_RNDIS_COMPOSITE)
225+
uint8_t mac[6];
226+
mac[0] = 0xa0; /* TODO */
227+
mac[1] = (CONFIG_NETINIT_MACADDR_2 >> (8 * 0)) & 0xff;
228+
mac[2] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 3)) & 0xff;
229+
mac[3] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 2)) & 0xff;
230+
mac[4] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 1)) & 0xff;
231+
mac[5] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 0)) & 0xff;
232+
usbdev_rndis_initialize(mac);
233+
#endif
234+
206235
/* Initialize BLE */
207236

208237
#ifdef CONFIG_NRF53_APPCORE
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/****************************************************************************
2+
* boards/arm/nrf53/thingy53/src/nrf53_composite.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include <nuttx/config.h>
26+
27+
#include <assert.h>
28+
29+
#include <nuttx/usb/usbdev.h>
30+
#include <nuttx/usb/cdcacm.h>
31+
#include <nuttx/usb/rndis.h>
32+
#include <nuttx/usb/composite.h>
33+
34+
#include "nrf53_usbd.h"
35+
36+
#include "thingy53.h"
37+
38+
/****************************************************************************
39+
* Pre-processor Definitions
40+
****************************************************************************/
41+
42+
/****************************************************************************
43+
* Private Functions
44+
****************************************************************************/
45+
46+
void *board_composite0_connect(void)
47+
{
48+
struct composite_devdesc_s dev[2];
49+
int ifnobase = 0;
50+
int strbase = COMPOSITE_NSTRIDS;
51+
int dev_idx = 0;
52+
int epin = 1;
53+
int epout = 1;
54+
55+
#ifdef CONFIG_RNDIS_COMPOSITE
56+
/* Configure the RNDIS USB device */
57+
58+
/* Ask the rndis driver to fill in the constants we didn't
59+
* know here.
60+
*/
61+
62+
usbdev_rndis_get_composite_devdesc(&dev[dev_idx]);
63+
64+
/* Interfaces */
65+
66+
dev[dev_idx].devinfo.ifnobase = ifnobase;
67+
dev[dev_idx].minor = 0;
68+
69+
/* Strings */
70+
71+
dev[dev_idx].devinfo.strbase = strbase;
72+
73+
/* Endpoints */
74+
75+
dev[dev_idx].devinfo.epno[RNDIS_EP_INTIN_IDX] = epin++;
76+
dev[dev_idx].devinfo.epno[RNDIS_EP_BULKIN_IDX] = epin++;
77+
dev[dev_idx].devinfo.epno[RNDIS_EP_BULKOUT_IDX] = epout++;
78+
79+
/* Count up the base numbers */
80+
81+
ifnobase += dev[dev_idx].devinfo.ninterfaces;
82+
strbase += dev[dev_idx].devinfo.nstrings;
83+
84+
dev_idx += 1;
85+
#endif
86+
87+
#ifdef CONFIG_CDCACM_COMPOSITE
88+
/* Configure the CDC/ACM device */
89+
90+
/* Ask the cdcacm driver to fill in the constants we didn't
91+
* know here.
92+
*/
93+
94+
cdcacm_get_composite_devdesc(&dev[dev_idx]);
95+
96+
/* Overwrite and correct some values... */
97+
98+
/* The callback functions for the CDC/ACM class */
99+
100+
dev[dev_idx].classobject = cdcacm_classobject;
101+
dev[dev_idx].uninitialize = cdcacm_uninitialize;
102+
103+
/* Interfaces */
104+
105+
dev[dev_idx].devinfo.ifnobase = ifnobase; /* Offset to Interface-IDs */
106+
dev[dev_idx].minor = 0; /* The minor interface number */
107+
108+
/* Strings */
109+
110+
dev[dev_idx].devinfo.strbase = strbase; /* Offset to String Numbers */
111+
112+
/* Endpoints */
113+
114+
dev[dev_idx].devinfo.epno[CDCACM_EP_INTIN_IDX] = epin++;
115+
dev[dev_idx].devinfo.epno[CDCACM_EP_BULKIN_IDX] = epin++;
116+
dev[dev_idx].devinfo.epno[CDCACM_EP_BULKOUT_IDX] = epout++;
117+
118+
/* Count up the base numbers */
119+
120+
ifnobase += dev[dev_idx].devinfo.ninterfaces;
121+
strbase += dev[dev_idx].devinfo.nstrings;
122+
123+
dev_idx += 1;
124+
#endif
125+
126+
DEBUGASSERT(epin <= NRF53_NENDPOINTS);
127+
DEBUGASSERT(epout <= NRF53_NENDPOINTS);
128+
129+
return composite_initialize(dev_idx, dev);
130+
}
131+
132+
/****************************************************************************
133+
* Public Functions
134+
****************************************************************************/
135+
136+
/****************************************************************************
137+
* Name: board_composite_initialize
138+
*
139+
* Description:
140+
* Perform architecture specific initialization of a composite USB device.
141+
*
142+
****************************************************************************/
143+
144+
int board_composite_initialize(int port)
145+
{
146+
return OK;
147+
}
148+
149+
/****************************************************************************
150+
* Name: board_composite_connect
151+
*
152+
* Description:
153+
* Connect the USB composite device on the specified USB device port using
154+
* the specified configuration. The interpretation of the configid is
155+
* board specific.
156+
*
157+
* Input Parameters:
158+
* port - The USB device port.
159+
* configid - The USB composite configuration
160+
*
161+
* Returned Value:
162+
* A non-NULL handle value is returned on success. NULL is returned on
163+
* any failure.
164+
*
165+
****************************************************************************/
166+
167+
void *board_composite_connect(int port, int configid)
168+
{
169+
if (configid == 0)
170+
{
171+
return board_composite0_connect();
172+
}
173+
else
174+
{
175+
return NULL;
176+
}
177+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/****************************************************************************
2+
* boards/arm/nrf53/thingy53/src/nrf53_usb.c
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
/****************************************************************************
22+
* Included Files
23+
****************************************************************************/
24+
25+
#include <nuttx/config.h>
26+
27+
#include <stdint.h>
28+
#include <stdbool.h>
29+
#include <debug.h>
30+
31+
#include <nuttx/usb/usbdev.h>
32+
33+
#include "nrf53_usbd.h"
34+
35+
#include "thingy53.h"
36+
37+
/****************************************************************************
38+
* Public Functions
39+
****************************************************************************/
40+
41+
/****************************************************************************
42+
* Name: nrf53_usbsuspend
43+
*
44+
* Description:
45+
* Board logic must provide the nrf53_usbsuspend logic if the USBDEV
46+
* driver is used. This function is called whenever the USB enters or
47+
* leaves suspend mode.
48+
* This is an opportunity for the board logic to shutdown clocks, power,
49+
* etc. while the USB is suspended.
50+
*
51+
****************************************************************************/
52+
53+
void nrf53_usbsuspend(struct usbdev_s *dev, bool resume)
54+
{
55+
uinfo("resume: %d\n", resume);
56+
}

0 commit comments

Comments
 (0)