This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new b9f9ba2600 boards/nrf52840-dongle: add usb support and usbnsh example
b9f9ba2600 is described below
commit b9f9ba26000b82cd0bdff830e5293920972433de
Author: raiden00pl <[email protected]>
AuthorDate: Fri May 26 12:09:58 2023 +0200
boards/nrf52840-dongle: add usb support and usbnsh example
This board is designed to work as a USB dongle, from now it is possible.
---
.../nrf52/nrf52840-dongle/configs/usbnsh/defconfig | 45 ++++++
boards/arm/nrf52/nrf52840-dongle/src/Make.defs | 8 +
.../nrf52/nrf52840-dongle/src/nrf52_composite.c | 177 +++++++++++++++++++++
boards/arm/nrf52/nrf52840-dongle/src/nrf52_usb.c | 56 +++++++
4 files changed, 286 insertions(+)
diff --git a/boards/arm/nrf52/nrf52840-dongle/configs/usbnsh/defconfig
b/boards/arm/nrf52/nrf52840-dongle/configs/usbnsh/defconfig
new file mode 100644
index 0000000000..483540ee29
--- /dev/null
+++ b/boards/arm/nrf52/nrf52840-dongle/configs/usbnsh/defconfig
@@ -0,0 +1,45 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed
.config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that
includes your
+# modifications.
+#
+# CONFIG_ARCH_FPU is not set
+# CONFIG_DEV_CONSOLE is not set
+# CONFIG_SYSLOG_DEFAULT is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nrf52840-dongle"
+CONFIG_ARCH_BOARD_NRF52840_DONGLE=y
+CONFIG_ARCH_CHIP="nrf52"
+CONFIG_ARCH_CHIP_NRF52840=y
+CONFIG_ARCH_CHIP_NRF52=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_STDARG_H=y
+CONFIG_BOARDCTL_USBDEVCTRL=y
+CONFIG_BOARD_LOOPSPERMSEC=5500
+CONFIG_BUILTIN=y
+CONFIG_CDCACM=y
+CONFIG_CDCACM_CONSOLE=y
+CONFIG_DEBUG_FULLOPT=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_EXAMPLES_HELLO=y
+CONFIG_IDLETHREAD_STACKSIZE=2048
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_MM_REGIONS=2
+CONFIG_NRF52_HFCLK_XTAL=y
+CONFIG_NRF52_USBDEV=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=65535
+CONFIG_RAM_START=0x20000000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_START_DAY=26
+CONFIG_START_MONTH=3
+CONFIG_SYSTEM_NSH=y
diff --git a/boards/arm/nrf52/nrf52840-dongle/src/Make.defs
b/boards/arm/nrf52/nrf52840-dongle/src/Make.defs
index fc0f5486c2..119cbe14c0 100644
--- a/boards/arm/nrf52/nrf52840-dongle/src/Make.defs
+++ b/boards/arm/nrf52/nrf52840-dongle/src/Make.defs
@@ -32,6 +32,14 @@ else
CSRCS += nrf52_userleds.c
endif
+ifeq ($(CONFIG_USBDEV),y)
+CSRCS += nrf52_usb.c
+endif
+
+ifeq ($(CONFIG_USBDEV_COMPOSITE),y)
+CSRCS += nrf52_composite.c
+endif
+
DEPPATH += --dep-path board
VPATH += :board
CFLAGS += $(shell $(INCDIR) "$(CC)"
$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
diff --git a/boards/arm/nrf52/nrf52840-dongle/src/nrf52_composite.c
b/boards/arm/nrf52/nrf52840-dongle/src/nrf52_composite.c
new file mode 100644
index 0000000000..0d03224fa3
--- /dev/null
+++ b/boards/arm/nrf52/nrf52840-dongle/src/nrf52_composite.c
@@ -0,0 +1,177 @@
+/****************************************************************************
+ * boards/arm/nrf52/nrf52840-dongle/src/nrf52_composite.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+
+#include <nuttx/usb/usbdev.h>
+#include <nuttx/usb/cdcacm.h>
+#include <nuttx/usb/rndis.h>
+#include <nuttx/usb/composite.h>
+
+#include "nrf52_usbd.h"
+
+#include "nrf52840-dongle.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+void *board_composite0_connect(void)
+{
+ struct composite_devdesc_s dev[2];
+ int ifnobase = 0;
+ int strbase = COMPOSITE_NSTRIDS;
+ int dev_idx = 0;
+ int epin = 1;
+ int epout = 1;
+
+#ifdef CONFIG_RNDIS_COMPOSITE
+ /* Configure the RNDIS USB device */
+
+ /* Ask the RNDIS driver to fill in the constants we didn't
+ * know here.
+ */
+
+ usbdev_rndis_get_composite_devdesc(&dev[dev_idx]);
+
+ /* Interfaces */
+
+ dev[dev_idx].devinfo.ifnobase = ifnobase;
+ dev[dev_idx].minor = 0;
+
+ /* Strings */
+
+ dev[dev_idx].devinfo.strbase = strbase;
+
+ /* Endpoints */
+
+ dev[dev_idx].devinfo.epno[RNDIS_EP_INTIN_IDX] = epin++;
+ dev[dev_idx].devinfo.epno[RNDIS_EP_BULKIN_IDX] = epin++;
+ dev[dev_idx].devinfo.epno[RNDIS_EP_BULKOUT_IDX] = epout++;
+
+ /* Count up the base numbers */
+
+ ifnobase += dev[dev_idx].devinfo.ninterfaces;
+ strbase += dev[dev_idx].devinfo.nstrings;
+
+ dev_idx += 1;
+#endif
+
+#ifdef CONFIG_CDCACM_COMPOSITE
+ /* Configure the CDC/ACM device */
+
+ /* Ask the cdcacm driver to fill in the constants we didn't
+ * know here.
+ */
+
+ cdcacm_get_composite_devdesc(&dev[dev_idx]);
+
+ /* Overwrite and correct some values... */
+
+ /* The callback functions for the CDC/ACM class */
+
+ dev[dev_idx].classobject = cdcacm_classobject;
+ dev[dev_idx].uninitialize = cdcacm_uninitialize;
+
+ /* Interfaces */
+
+ dev[dev_idx].devinfo.ifnobase = ifnobase; /* Offset to
Interface-IDs */
+ dev[dev_idx].minor = 0; /* The minor interface
number */
+
+ /* Strings */
+
+ dev[dev_idx].devinfo.strbase = strbase; /* Offset to String
Numbers */
+
+ /* Endpoints */
+
+ dev[dev_idx].devinfo.epno[CDCACM_EP_INTIN_IDX] = epin++;
+ dev[dev_idx].devinfo.epno[CDCACM_EP_BULKIN_IDX] = epin++;
+ dev[dev_idx].devinfo.epno[CDCACM_EP_BULKOUT_IDX] = epout++;
+
+ /* Count up the base numbers */
+
+ ifnobase += dev[dev_idx].devinfo.ninterfaces;
+ strbase += dev[dev_idx].devinfo.nstrings;
+
+ dev_idx += 1;
+#endif
+
+ DEBUGASSERT(epin <= NRF52_NENDPOINTS);
+ DEBUGASSERT(epout <= NRF52_NENDPOINTS);
+
+ return composite_initialize(dev_idx, dev);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_composite_initialize
+ *
+ * Description:
+ * Perform architecture specific initialization of a composite USB device.
+ *
+ ****************************************************************************/
+
+int board_composite_initialize(int port)
+{
+ return OK;
+}
+
+/****************************************************************************
+ * Name: board_composite_connect
+ *
+ * Description:
+ * Connect the USB composite device on the specified USB device port using
+ * the specified configuration. The interpretation of the configid is
+ * board specific.
+ *
+ * Input Parameters:
+ * port - The USB device port.
+ * configid - The USB composite configuration
+ *
+ * Returned Value:
+ * A non-NULL handle value is returned on success. NULL is returned on
+ * any failure.
+ *
+ ****************************************************************************/
+
+void *board_composite_connect(int port, int configid)
+{
+ if (configid == 0)
+ {
+ return board_composite0_connect();
+ }
+ else
+ {
+ return NULL;
+ }
+}
diff --git a/boards/arm/nrf52/nrf52840-dongle/src/nrf52_usb.c
b/boards/arm/nrf52/nrf52840-dongle/src/nrf52_usb.c
new file mode 100644
index 0000000000..85abb747e8
--- /dev/null
+++ b/boards/arm/nrf52/nrf52840-dongle/src/nrf52_usb.c
@@ -0,0 +1,56 @@
+/****************************************************************************
+ * boards/arm/nrf52/nrf52840-dongle/src/nrf52_usb.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <debug.h>
+
+#include <nuttx/usb/usbdev.h>
+
+#include "nrf52_usbd.h"
+
+#include "nrf52840-dongle.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nrf52_usbsuspend
+ *
+ * Description:
+ * Board logic must provide the nrf52_usbsuspend logic if the USBDEV
+ * driver is used. This function is called whenever the USB enters or
+ * leaves suspend mode.
+ * This is an opportunity for the board logic to shutdown clocks, power,
+ * etc. while the USB is suspended.
+ *
+ ****************************************************************************/
+
+void nrf52_usbsuspend(struct usbdev_s *dev, bool resume)
+{
+ uinfo("resume: %d\n", resume);
+}