From 99cd9340f51941fbccb488b31f5fcf8dad322932 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sun, 22 Sep 2019 16:13:06 -0600 Subject: [PATCH] boards/arm/samd2l2/arduino-m0/src/sam_usb.c: Add usbnsh board configuration. --- boards/arm/samd2l2/arduino-m0/README.txt | 6 + .../arduino-m0/configs/usbnsh/defconfig | 70 ++++++++++ boards/arm/samd2l2/arduino-m0/src/Makefile | 4 + boards/arm/samd2l2/arduino-m0/src/sam_usb.c | 129 ++++++++++++++++++ 4 files changed, 209 insertions(+) create mode 100644 boards/arm/samd2l2/arduino-m0/configs/usbnsh/defconfig create mode 100644 boards/arm/samd2l2/arduino-m0/src/sam_usb.c diff --git a/boards/arm/samd2l2/arduino-m0/README.txt b/boards/arm/samd2l2/arduino-m0/README.txt index 9df8cfd0d0..024ae34c3d 100644 --- a/boards/arm/samd2l2/arduino-m0/README.txt +++ b/boards/arm/samd2l2/arduino-m0/README.txt @@ -141,3 +141,9 @@ Configuration sub-directories 37 PB22 SERCOM5 / USART RX 38 PB23 SERCOM5 / USART TX + usbnsh: + This configuration directory will build the NuttShell to work over USB. + It uses the internal SAMD21 USB port working as CDC/ACM Serial/Modem. + + Using the configuration you don't need to solder the header pins RXD/TXD + to get access the NSH terminal. diff --git a/boards/arm/samd2l2/arduino-m0/configs/usbnsh/defconfig b/boards/arm/samd2l2/arduino-m0/configs/usbnsh/defconfig new file mode 100644 index 0000000000..4e3a1ebeaa --- /dev/null +++ b/boards/arm/samd2l2/arduino-m0/configs/usbnsh/defconfig @@ -0,0 +1,70 @@ +# +# 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_DISABLE_POSIX_TIMERS is not set +# CONFIG_NSH_DISABLEBG is not set +# CONFIG_NSH_DISABLESCRIPT is not set +# CONFIG_NSH_DISABLE_CMP is not set +# CONFIG_NSH_DISABLE_DD is not set +# CONFIG_NSH_DISABLE_EXEC is not set +# CONFIG_NSH_DISABLE_EXIT is not set +# CONFIG_NSH_DISABLE_GET is not set +# CONFIG_NSH_DISABLE_HEXDUMP is not set +# CONFIG_NSH_DISABLE_IFCONFIG is not set +# CONFIG_NSH_DISABLE_ITEF is not set +# CONFIG_NSH_DISABLE_LOOPS is not set +# CONFIG_NSH_DISABLE_LOSETUP is not set +# CONFIG_NSH_DISABLE_MKRD is not set +# CONFIG_NSH_DISABLE_PS is not set +# CONFIG_NSH_DISABLE_PUT is not set +# CONFIG_NSH_DISABLE_SEMICOLON is not set +# CONFIG_NSH_DISABLE_WGET is not set +# CONFIG_NSH_DISABLE_XD is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="arduino-m0" +CONFIG_ARCH_BOARD_ARDUINO_M0=y +CONFIG_ARCH_CHIP="samd2l2" +CONFIG_ARCH_CHIP_SAMD21G18A=y +CONFIG_ARCH_CHIP_SAMD2X=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARDCTL_USBDEVCTRL=y +CONFIG_BOARD_LOOPSPERMSEC=3410 +CONFIG_BUILTIN=y +CONFIG_CDCACM=y +CONFIG_CDCACM_CONSOLE=y +CONFIG_DEFAULT_SMALL=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_LIB_BOARDCTL=y +CONFIG_MAX_TASKS=16 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PREALLOC_WDOGS=4 +CONFIG_PTHREAD_STACK_DEFAULT=1536 +CONFIG_RAM_SIZE=32768 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SAMD2L2_SERCOM5=y +CONFIG_SAMD2L2_USB=y +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_START_DAY=22 +CONFIG_START_MONTH=9 +CONFIG_START_YEAR=2019 +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_CXXINITIALIZE=y +CONFIG_TASK_NAME_SIZE=0 +CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=1536 +CONFIG_USBDEV=y +CONFIG_USERMAIN_STACKSIZE=1536 +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_WDOG_INTRESERVE=0 diff --git a/boards/arm/samd2l2/arduino-m0/src/Makefile b/boards/arm/samd2l2/arduino-m0/src/Makefile index d45135aadf..e456aeaac3 100644 --- a/boards/arm/samd2l2/arduino-m0/src/Makefile +++ b/boards/arm/samd2l2/arduino-m0/src/Makefile @@ -56,4 +56,8 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y) CSRCS += sam_appinit.c endif +ifeq ($(CONFIG_USBDEV),y) +CSRCS += sam_usb.c +endif + include $(TOPDIR)/boards/Board.mk diff --git a/boards/arm/samd2l2/arduino-m0/src/sam_usb.c b/boards/arm/samd2l2/arduino-m0/src/sam_usb.c new file mode 100644 index 0000000000..d00431b06a --- /dev/null +++ b/boards/arm/samd2l2/arduino-m0/src/sam_usb.c @@ -0,0 +1,129 @@ +/**************************************************************************** + * boards/arm/samd2l2/arduino-m0/src/sam_usb.c + * + * Copyright (C) 2019 Alan Carvalho de Assis. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Parts of code from here and there + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "debug.h" +#include "chip.h" +#include "sam_port.h" +#include "saml_periphclks.h" +#include "arduino_m0.h" + +#if defined(CONFIG_SAMD2L2_USB) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_usbinitialize + * + * Description: + * Called from sam_boot very early in initialization to setup + * USB-related GPIO pins for the SAML21-Xplained board. + * + * USB Ports + * The SAML21 features USB device and host: + * + * + ****************************************************************************/ + +void weak_function sam_usbinitialize(void) +{ +#ifdef HAVE_USBDEV + + /* Detect when a target USB cable is connected in self-powered mode */ + + /* The Engie CE0035 doesn't have VBUS SENSE support */ + + /* sam_configport(PORT_USB_VBUS_SENSE); */ + + /* TODO: Configure an interrupt on VBUS sense */ + +#endif + +#ifdef HAVE_USBHOST + /* In USB host mode VBUS voltage is provided by the kit and can thus not + * identify a connected device, so another GPIO is used to detect + * the USB ID of the device. + */ + + /* The Engie CE0035 doesn't have the USB ID pin connected */ + + /* sam_configport(PORT_USB_ID_DETECT); */ /* ID detect */ + +#endif +} + +/**************************************************************************** + * Name: sam_usbsuspend + * + * Description: + * Board logic must provide the sam_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. + * + ****************************************************************************/ + +#ifdef CONFIG_USBDEV +void sam_usb_suspend(FAR struct usbdev_s *dev, bool resume) +{ + uinfo("board: resume: %d\n", resume); +} +#endif + +#endif /* CONFIG_SAMDL_USB */