stm32f4discovery: add composite device configuration

This commit is contained in:
raiden00pl 2023-04-03 16:07:46 +02:00 committed by Xiang Xiao
parent 023c0d7034
commit f29e802ca8
4 changed files with 455 additions and 1 deletions

View File

@ -0,0 +1,103 @@
#
# 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_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_SPI_CALLBACK is not set
CONFIG_ALLOW_BSD_COMPONENTS=y
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f4discovery"
CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_COMPOSITE_IAD=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_ELF=y
CONFIG_EXAMPLES_HELLO=m
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FS_FAT=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_ENVPATH=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_MMCSD=y
CONFIG_NET=y
CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0
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_NFS=y
CONFIG_NFS_STATISTICS=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_FILE_APPS=y
CONFIG_NSH_LINELEN=128
CONFIG_NSH_READLINE=y
CONFIG_NSH_SYMTAB=y
CONFIG_NSH_SYMTAB_ARRAYNAME="g_symtab"
CONFIG_NSH_SYMTAB_COUNTNAME="g_nsymbols"
CONFIG_PATH_INITIAL="/mnt/nfs/bin"
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RNDIS=y
CONFIG_RNDIS_COMPOSITE=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_SENSORS=y
CONFIG_START_DAY=13
CONFIG_START_MONTH=9
CONFIG_START_YEAR=2014
CONFIG_STM32_DMA2=y
CONFIG_STM32_DMACAPABLE=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_OTGFS=y
CONFIG_STM32_PWR=y
CONFIG_STM32_SPI2=y
CONFIG_STM32_USART2=y
CONFIG_SYMTAB_ORDEREDBYNAME=y
CONFIG_SYSTEM_COMPOSITE=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_PING=y
CONFIG_USART2_SERIAL_CONSOLE=y
CONFIG_USBDEV=y
CONFIG_USBDEV_COMPOSITE=y
CONFIG_USBMSC=y
CONFIG_USBMSC_COMPOSITE=y

View File

@ -187,6 +187,10 @@ ifeq ($(CONFIG_INPUT_DJOYSTICK),y)
CSRCS += stm32_djoystick.c
endif
ifeq ($(CONFIG_USBDEV_COMPOSITE),y)
CSRCS += stm32_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)

View File

@ -573,7 +573,7 @@ int stm32_bringup(void)
}
#endif
#if defined(CONFIG_RNDIS)
#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;

View File

@ -0,0 +1,347 @@
/****************************************************************************
* boards/arm/stm32/stm32f4discovery/src/stm32_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 <sys/types.h>
#include <debug.h>
#include <assert.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/rndis.h>
#include <nuttx/usb/cdcacm.h>
#include <nuttx/usb/usbmsc.h>
#include <nuttx/usb/composite.h>
#include "stm32_otgfs.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define COMPOSITE0_DEV (3)
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_USBMSC_COMPOSITE
static void *g_mschandle;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: board_mscclassobject
*
* Description:
* If the mass storage class driver is part of composite device, then
* its instantiation and configuration is a multi-step, board-specific,
* process (See comments for usbmsc_configure below). In this case,
* board-specific logic must provide board_mscclassobject().
*
* board_mscclassobject() is called from the composite driver. It must
* encapsulate the instantiation and configuration of the mass storage
* class and the return the mass storage device's class driver instance
* to the composite driver.
*
* Input Parameters:
* classdev - The location to return the mass storage class' device
* instance.
*
* Returned Value:
* 0 on success; a negated errno on failure
*
****************************************************************************/
#ifdef CONFIG_USBMSC_COMPOSITE
static int board_mscclassobject(int minor,
struct usbdev_devinfo_s *devinfo,
struct usbdevclass_driver_s **classdev)
{
int ret;
DEBUGASSERT(g_mschandle == NULL);
/* Configure the mass storage device */
uinfo("Configuring with NLUNS=1\n");
ret = usbmsc_configure(1, &g_mschandle);
if (ret < 0)
{
uerr("ERROR: usbmsc_configure failed: %d\n", -ret);
return ret;
}
uinfo("MSC handle=%p\n", g_mschandle);
/* Bind the LUN(s) */
uinfo("Bind LUN=0 to /dev/mmcsd0\n");
ret = usbmsc_bindlun(g_mschandle, "/dev/mmcsd0", 0, 0, 0, false);
if (ret < 0)
{
uerr("ERROR: usbmsc_bindlun failed for LUN 1 at /dev/mmcsd0: %d\n",
ret);
usbmsc_uninitialize(g_mschandle);
g_mschandle = NULL;
return ret;
}
/* Get the mass storage device's class object */
ret = usbmsc_classobject(g_mschandle, devinfo, classdev);
if (ret < 0)
{
uerr("ERROR: usbmsc_classobject failed: %d\n", -ret);
usbmsc_uninitialize(g_mschandle);
g_mschandle = NULL;
}
return ret;
}
#endif
/****************************************************************************
* Name: board_mscuninitialize
*
* Description:
* Un-initialize the USB storage class driver.
* This is just an application specific wrapper for usbmsc_unitialize()
* that is called form the composite device logic.
*
* Input Parameters:
* classdev - The class driver instrance previously give to the composite
* driver by board_mscclassobject().
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_USBMSC_COMPOSITE
static void board_mscuninitialize(struct usbdevclass_driver_s *classdev)
{
if (g_mschandle)
{
usbmsc_uninitialize(g_mschandle);
}
g_mschandle = NULL;
}
#endif
/****************************************************************************
* Name: board_composite_connect
*
* Description:
* Connect the USB composite device on the specified USB device port for
* configuration 0.
*
* Input Parameters:
* port - The USB device port.
*
* Returned Value:
* A non-NULL handle value is returned on success. NULL is returned on
* any failure.
*
****************************************************************************/
static void *board_composite0_connect(int port)
{
struct composite_devdesc_s dev[COMPOSITE0_DEV];
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_USBMSC_COMPOSITE
/* Configure the mass storage device device */
/* Ask the usbmsc driver to fill in the constants we didn't
* know here.
*/
usbmsc_get_composite_devdesc(&dev[dev_idx]);
/* Overwrite and correct some values... */
/* The callback functions for the USBMSC class */
dev[dev_idx].classobject = board_mscclassobject;
dev[dev_idx].uninitialize = board_mscuninitialize;
/* 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[USBMSC_EP_BULKIN_IDX] = epin++;
dev[dev_idx].devinfo.epno[USBMSC_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
/* Sanity checks */
DEBUGASSERT(epin < STM32_NENDPOINTS);
DEBUGASSERT(epout < STM32_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(port);
}
else
{
return NULL;
}
}