boards/thingy53: add usb example
The board can act as an USB composite device. For now CDCACM and RNDIS are supported.
This commit is contained in:
parent
04fa008018
commit
934602b76e
79
boards/arm/nrf53/thingy53/configs/composite_cpuapp/defconfig
Normal file
79
boards/arm/nrf53/thingy53/configs/composite_cpuapp/defconfig
Normal file
@ -0,0 +1,79 @@
|
||||
#
|
||||
# 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_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="thingy53"
|
||||
CONFIG_ARCH_BOARD_THINGY53=y
|
||||
CONFIG_ARCH_CHIP="nrf53"
|
||||
CONFIG_ARCH_CHIP_NRF5340=y
|
||||
CONFIG_ARCH_CHIP_NRF5340_CPUAPP=y
|
||||
CONFIG_ARCH_CHIP_NRF53=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_STDARG_H=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=5500
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_CDCACM=y
|
||||
CONFIG_CDCACM_COMPOSITE=y
|
||||
CONFIG_COMPOSITE_IAD=y
|
||||
CONFIG_DEBUG_FULLOPT=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_EXPERIMENTAL=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_MM_REGIONS=2
|
||||
CONFIG_NET=y
|
||||
CONFIG_NETDB_DNSCLIENT=y
|
||||
CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NETINIT_DHCPC=y
|
||||
CONFIG_NETINIT_DRIPADDR=0x0
|
||||
CONFIG_NETINIT_MACADDR_1=0xdeadcafe
|
||||
CONFIG_NETINIT_NETMASK=0x0
|
||||
CONFIG_NETINIT_NOMAC=y
|
||||
CONFIG_NETINIT_THREAD=y
|
||||
CONFIG_NETUTILS_DHCPC=y
|
||||
CONFIG_NETUTILS_IPERF=y
|
||||
CONFIG_NETUTILS_TELNETD=y
|
||||
CONFIG_NETUTILS_WEBCLIENT=y
|
||||
CONFIG_NET_ARP_SEND=y
|
||||
CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ICMP=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_LL_GUARDSIZE=50
|
||||
CONFIG_NET_LOOPBACK=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_WRITE_BUFFERS=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NRF53_HFCLK_XTAL=y
|
||||
CONFIG_NRF53_UART0=y
|
||||
CONFIG_NRF53_USBDEV=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_DISABLE_IFUPDOWN=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=524288
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RNDIS=y
|
||||
CONFIG_RNDIS_COMPOSITE=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_START_DAY=26
|
||||
CONFIG_START_MONTH=3
|
||||
CONFIG_SYMTAB_ORDEREDBYNAME=y
|
||||
CONFIG_SYSTEM_COMPOSITE=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_TASK_NAME_SIZE=32
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_USBDEV_COMPOSITE=y
|
@ -34,6 +34,14 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y)
|
||||
CSRCS += nrf53_buttons.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USBDEV),y)
|
||||
CSRCS += nrf53_usb.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USBDEV_COMPOSITE),y)
|
||||
CSRCS += nrf53_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)
|
||||
|
@ -38,6 +38,14 @@
|
||||
# include <nuttx/input/buttons.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBMONITOR
|
||||
# include <nuttx/usb/usbmonitor.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RNDIS
|
||||
# include <nuttx/usb/rndis.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NRF53_SOFTDEVICE_CONTROLLER
|
||||
# include "nrf53_sdc.h"
|
||||
#endif
|
||||
@ -203,6 +211,27 @@ int nrf53_bringup(void)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBMONITOR
|
||||
/* Start the USB Monitor */
|
||||
|
||||
ret = usbmonitor_start();
|
||||
if (ret != OK)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to start USB monitor: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_RNDIS) && !defined(CONFIG_RNDIS_COMPOSITE)
|
||||
uint8_t mac[6];
|
||||
mac[0] = 0xa0; /* TODO */
|
||||
mac[1] = (CONFIG_NETINIT_MACADDR_2 >> (8 * 0)) & 0xff;
|
||||
mac[2] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 3)) & 0xff;
|
||||
mac[3] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 2)) & 0xff;
|
||||
mac[4] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 1)) & 0xff;
|
||||
mac[5] = (CONFIG_NETINIT_MACADDR_1 >> (8 * 0)) & 0xff;
|
||||
usbdev_rndis_initialize(mac);
|
||||
#endif
|
||||
|
||||
/* Initialize BLE */
|
||||
|
||||
#ifdef CONFIG_NRF53_APPCORE
|
||||
|
177
boards/arm/nrf53/thingy53/src/nrf53_composite.c
Normal file
177
boards/arm/nrf53/thingy53/src/nrf53_composite.c
Normal file
@ -0,0 +1,177 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/nrf53/thingy53/src/nrf53_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 "nrf53_usbd.h"
|
||||
|
||||
#include "thingy53.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 <= NRF53_NENDPOINTS);
|
||||
DEBUGASSERT(epout <= NRF53_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;
|
||||
}
|
||||
}
|
56
boards/arm/nrf53/thingy53/src/nrf53_usb.c
Normal file
56
boards/arm/nrf53/thingy53/src/nrf53_usb.c
Normal file
@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/nrf53/thingy53/src/nrf53_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 "nrf53_usbd.h"
|
||||
|
||||
#include "thingy53.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nrf53_usbsuspend
|
||||
*
|
||||
* Description:
|
||||
* Board logic must provide the nrf53_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 nrf53_usbsuspend(struct usbdev_s *dev, bool resume)
|
||||
{
|
||||
uinfo("resume: %d\n", resume);
|
||||
}
|
Loading…
Reference in New Issue
Block a user