Skip to content

Commit

Permalink
USBUS: add minimal working example
Browse files Browse the repository at this point in the history
  • Loading branch information
bergzand committed Jun 5, 2019
1 parent 74e0b5b commit 3d30886
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/usbus_minimal/Makefile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions examples/usbus_minimal/README.md
Original file line number Diff line number Diff line change
@@ -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.
44 changes: 44 additions & 0 deletions examples/usbus_minimal/main.c
Original file line number Diff line number Diff line change
@@ -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 <koen@bergzand.net>
*
* @}
*/

#include <stdio.h>
#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;
}

0 comments on commit 3d30886

Please sign in to comment.