From 3d3088658ac6baa5c6d37fa987a4e5b85883cf55 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Fri, 1 Feb 2019 14:29:51 +0100 Subject: [PATCH] USBUS: add minimal working example --- examples/usbus_minimal/Makefile | 31 ++++++++++++++++++++++ examples/usbus_minimal/README.md | 16 ++++++++++++ examples/usbus_minimal/main.c | 44 ++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 examples/usbus_minimal/Makefile create mode 100644 examples/usbus_minimal/README.md create mode 100644 examples/usbus_minimal/main.c diff --git a/examples/usbus_minimal/Makefile b/examples/usbus_minimal/Makefile new file mode 100644 index 0000000000000..77e1033ca6eba --- /dev/null +++ b/examples/usbus_minimal/Makefile @@ -0,0 +1,31 @@ +# name of your application +APPLICATION = usbus_minimal + +# If no BOARD is found in the environment, use this default: +BOARD ?= samr21-xpro + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +USEMODULE += usbus + +# USB device vendor and product ID +USB_VID ?= 1209 +USB_PID ?= 0001 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +CFLAGS += -DUSB_CONFIG_VID=0x$(USB_PID) -DUSB_CONFIG_PID=0x$(USB_VID) + +include $(RIOTBASE)/Makefile.include + +ifeq ($(USB_VID):$(USB_PID), 1209:0001) + $(shell $(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2) + $(shell $(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2) +endif diff --git a/examples/usbus_minimal/README.md b/examples/usbus_minimal/README.md new file mode 100644 index 0000000000000..c8794837561ef --- /dev/null +++ b/examples/usbus_minimal/README.md @@ -0,0 +1,16 @@ +# usbus_minimal example + +This is a minimalistic example for RIOT's USB stack. The application will +initialize and start the USB stack. The stack is started without any USB +handlers, it should show up as an empty USB device on the host. + +RIOT doesn't own any USB vendor and product ID. To compile this example, add +your own vendor and product ID to the makefile: + +``` +CFLAGS += -DUSB_CONFIG_VID=0xYOURVID -DUSB_CONFIG_PID=0xYOURPID +``` + +The example demonstrates basic USB communication between a host and a RIOT +based USB peripheral. Tools such as `lsusb` should display the device and +detailed information about the device such as descriptor strings. diff --git a/examples/usbus_minimal/main.c b/examples/usbus_minimal/main.c new file mode 100644 index 0000000000000..995f707890670 --- /dev/null +++ b/examples/usbus_minimal/main.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 Koen Zandberg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Example application for demonstrating the RIOT USB stack + * + * @author Koen Zandberg + * + * @} + */ + +#include +#include "usb/usbus.h" + +static char _stack[USBUS_STACKSIZE]; + +static usbus_t usbus; +/* TODO: remove as soon as we have decent auto_init */ +#include "periph_conf.h" +#include "sam_usb.h" + +int main(void) +{ + puts("RIOT USB stack example application"); + + /* TODO: remove as soon as we have decent auto_init */ + usbdev_t *usbdev_ctx = usbdev_get_ctx(0); + /* start usb stack */ + usbus_init(&usbus, usbdev_ctx); + usbus_create(_stack, sizeof(_stack), USBUS_PRIO, USBUS_TNAME, &usbus); + + /* start shell */ + puts("Started USB stack!"); + return 0; +}