summaryrefslogtreecommitdiff
path: root/digital/ucoolib/ucoolib
diff options
context:
space:
mode:
authorNicolas Schodet2012-11-02 22:47:12 +0100
committerNicolas Schodet2012-11-02 22:47:12 +0100
commitd460aec6700de247640affc3142d46c604b39ce0 (patch)
tree46bd9a1152b1a09e362e11976006607bf747b949 /digital/ucoolib/ucoolib
parent8207c14ce5241c7515c213901417ea8f6b7485e8 (diff)
digital/ucoolib/ucoolib/hal/usb: add UsbStream
Diffstat (limited to 'digital/ucoolib/ucoolib')
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/Config15
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/Module1
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/test/Config5
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/test/Makefile9
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/test/test_usb.cc76
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/usb.hh33
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/usb.stm32.cc159
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/usb.stm32.hh96
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.c193
-rw-r--r--digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.h33
10 files changed, 620 insertions, 0 deletions
diff --git a/digital/ucoolib/ucoolib/hal/usb/Config b/digital/ucoolib/ucoolib/hal/usb/Config
new file mode 100644
index 00000000..1d05df2f
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/Config
@@ -0,0 +1,15 @@
+[hal/usb]
+# Taken from LUFA IDs, not for commercial use. Do not use them as default so
+# that comment is not missed.
+#vendor_id = 0x03eb
+#product_id = 0x204e
+vendor_id =
+product_id =
+# Number of streams, interfaces, or pair of endpoints.
+stream_nb = 1
+# Set to 0 if powered from USB cable, 1 if device has its own power supply.
+self_powered = 0
+# Maximum power consumed from USB cable (mA).
+max_power = 100
+# End point size, you should use 64.
+ep_size = 64
diff --git a/digital/ucoolib/ucoolib/hal/usb/Module b/digital/ucoolib/ucoolib/hal/usb/Module
new file mode 100644
index 00000000..433c8b2c
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/Module
@@ -0,0 +1 @@
+hal_usb_SOURCES = usb.stm32.cc usb_desc.stm32.c
diff --git a/digital/ucoolib/ucoolib/hal/usb/test/Config b/digital/ucoolib/ucoolib/hal/usb/test/Config
new file mode 100644
index 00000000..e8c63711
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/test/Config
@@ -0,0 +1,5 @@
+[hal/usb]
+# Taken from LUFA IDs, not for commercial use.
+vendor_id = 0x03eb
+product_id = 0x204e
+stream_nb = 1
diff --git a/digital/ucoolib/ucoolib/hal/usb/test/Makefile b/digital/ucoolib/ucoolib/hal/usb/test/Makefile
new file mode 100644
index 00000000..3bd40283
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/test/Makefile
@@ -0,0 +1,9 @@
+BASE = ../../../..
+
+TARGETS = stm32f4
+stm32f4_PROGS = test_usb
+test_usb_SOURCES = test_usb.cc
+
+MODULES = hal/usb intf
+
+include $(BASE)/build/top.mk
diff --git a/digital/ucoolib/ucoolib/hal/usb/test/test_usb.cc b/digital/ucoolib/ucoolib/hal/usb/test/test_usb.cc
new file mode 100644
index 00000000..72c4745e
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/test/test_usb.cc
@@ -0,0 +1,76 @@
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// APBTeam:
+// Web: http://apbteam.org/
+// Email: team AT apbteam DOT org
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "ucoolib/hal/usb/usb.hh"
+
+#include <libopencm3/stm32/f4/rcc.h>
+#include <libopencm3/stm32/f4/gpio.h>
+
+int
+main ()
+{
+ rcc_clock_setup_hse_3v3 (&hse_8mhz_3v3[CLOCK_3V3_120MHZ]);
+ rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN);
+ ucoo::UsbStreamControl usc ("APBTeam", "USB test");
+ ucoo::UsbStream us[] = {
+ ucoo::UsbStream (usc, 0),
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 2
+ ucoo::UsbStream (usc, 1),
+#endif
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 3
+ ucoo::UsbStream (usc, 2),
+#endif
+ };
+ if (UCOO_CONFIG_HAL_USB_STREAM_NB > 1)
+ {
+ for (int i = 0; i < UCOO_CONFIG_HAL_USB_STREAM_NB; i++)
+ us[i].block (false);
+ }
+ char buf[6];
+ while (1)
+ {
+ for (int i = 0; i < UCOO_CONFIG_HAL_USB_STREAM_NB; i++)
+ {
+ int len = us[i].read (buf + 2, sizeof (buf) - 2);
+ if (len)
+ {
+ buf[0] = i + '0';
+ buf[1] = '>';
+ len += 2;
+ if (UCOO_CONFIG_HAL_USB_STREAM_NB == 1)
+ us[i].write (buf, len);
+ else
+ {
+ const char *p = buf;
+ while (len)
+ {
+ int r = us[i].write (p, len);
+ p += r;
+ len -= r;
+ }
+ }
+ }
+ }
+ }
+}
+
diff --git a/digital/ucoolib/ucoolib/hal/usb/usb.hh b/digital/ucoolib/ucoolib/hal/usb/usb.hh
new file mode 100644
index 00000000..c05b7a06
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/usb.hh
@@ -0,0 +1,33 @@
+#ifndef ucoolib_hal_usb_usb_hh
+#define ucoolib_hal_usb_usb_hh
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// APBTeam:
+// Web: http://apbteam.org/
+// Email: team AT apbteam DOT org
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#ifdef TARGET_SUB_stm32
+# include "usb.stm32.hh"
+#else
+# error "not implemented for this target"
+#endif
+
+#endif // ucoolib_hal_usb_usb_hh
diff --git a/digital/ucoolib/ucoolib/hal/usb/usb.stm32.cc b/digital/ucoolib/ucoolib/hal/usb/usb.stm32.cc
new file mode 100644
index 00000000..58435cd1
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/usb.stm32.cc
@@ -0,0 +1,159 @@
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// APBTeam:
+// Web: http://apbteam.org/
+// Email: team AT apbteam DOT org
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "usb.stm32.hh"
+#include <algorithm>
+
+#include <libopencm3/stm32/f4/rcc.h>
+#include <libopencm3/stm32/f4/gpio.h>
+#include <libopencm3/stm32/nvic.h>
+#include <libopencm3/usb/usbd.h>
+
+#include "usb_desc.stm32.h"
+
+extern "C" {
+
+void
+otg_fs_isr ()
+{
+ usbd_poll ();
+}
+
+}
+
+namespace ucoo {
+
+UsbStreamControl *UsbStreamControl::instance_;
+
+const char *strings[] = {
+ "x",
+ NULL,
+ NULL,
+ NULL
+};
+
+UsbStreamControl::RxBuffer::RxBuffer (void)
+ : size (0), offset (0)
+{
+}
+
+UsbStreamControl::UsbStreamControl (const char *vendor, const char *product)
+ : configured_ (false)
+{
+ //assert (!instance_);
+ instance_ = this;
+ strings[1] = vendor;
+ strings[2] = product;
+ rcc_peripheral_enable_clock (&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN);
+ rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
+ gpio_mode_setup (GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE,
+ GPIO9 | GPIO11 | GPIO12);
+ gpio_set_af (GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12);
+ usbd_init (&otgfs_usb_driver, &usb_desc_dev, &usb_desc_config, strings);
+ usbd_register_set_config_callback (set_config);
+ nvic_enable_irq (NVIC_OTG_FS_IRQ);
+}
+
+void
+UsbStreamControl::set_config (uint16_t configured)
+{
+ instance_->configured_ = configured;
+ if (configured)
+ {
+ for (int i = 0; i < stream_nb_; i++)
+ {
+ usbd_ep_setup (0x01 + i, USB_ENDPOINT_ATTR_BULK, ep_size_,
+ rx_callback);
+ usbd_ep_setup (0x81 + i, USB_ENDPOINT_ATTR_BULK, ep_size_, NULL);
+ }
+ }
+}
+
+void
+UsbStreamControl::rx_callback (uint8_t ep)
+{
+ //assert (ep > 0 && ep <= stream_nb_);
+ int num = ep - 1;
+ RxBuffer &rb = instance_->rx_buffer_[num];
+ //assert (rb.size == 0 && rb.offset == 0);
+ usbd_ep_nak_set (ep, 1);
+ rb.size = usbd_ep_read_packet (ep, rb.buf, ep_size_);
+}
+
+UsbStream::UsbStream (UsbStreamControl &control, int num)
+ : control_ (control), num_ (num)
+{
+ //assert (num < UsbStreamControl::stream_nb_);
+}
+
+int
+UsbStream::read (char *buf, int count)
+{
+ UsbStreamControl::RxBuffer &rb = control_.rx_buffer_[num_];
+ /* Wait for reception. */
+ if (!rb.size && !block_)
+ return 0;
+ while (!rb.size)
+ barrier ();
+ /* Copy to provided buffer. */
+ int len = std::min (count, rb.size - rb.offset);
+ buf = std::copy (rb.buf + rb.offset, rb.buf + rb.offset + len, buf);
+ rb.offset += len;
+ /* Reload buffer? */
+ if (rb.offset == rb.size)
+ {
+ rb.offset = rb.size = 0;
+ barrier ();
+ usbd_ep_nak_set (num_ + 1, 0);
+ }
+ /* Done. */
+ return len;
+}
+
+int
+UsbStream::write (const char *buf, int count)
+{
+ int left = count;
+ while (left)
+ {
+ if (control_.configured_)
+ {
+ int len = std::min (left, UsbStreamControl::ep_size_);
+ len = usbd_ep_write_packet (num_ + 0x81, buf, len);
+ buf += len;
+ left -= len;
+ }
+ if (!block_)
+ break;
+ }
+ return count - left;
+}
+
+int
+UsbStream::poll ()
+{
+ UsbStreamControl::RxBuffer &rb = control_.rx_buffer_[num_];
+ return rb.size - rb.offset;
+}
+
+} // namespace ucoo
diff --git a/digital/ucoolib/ucoolib/hal/usb/usb.stm32.hh b/digital/ucoolib/ucoolib/hal/usb/usb.stm32.hh
new file mode 100644
index 00000000..022b2faa
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/usb.stm32.hh
@@ -0,0 +1,96 @@
+#ifndef ucoolib_hal_usb_usb_stm32_hh
+#define ucoolib_hal_usb_usb_stm32_hh
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2012 Nicolas Schodet
+//
+// APBTeam:
+// Web: http://apbteam.org/
+// Email: team AT apbteam DOT org
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+#include "ucoolib/intf/stream.hh"
+#include "ucoolib/common.hh"
+
+#include "config/hal/usb.hh"
+
+namespace ucoo {
+
+class UsbStream;
+
+/// Top control class for an USB device. This is a limited implementation
+/// which fulfill most of our needs: one or more interfaces, each of them is
+/// handled as a character stream. This should be instantiated only once.
+class UsbStreamControl
+{
+ public:
+ /// Construct a new USB control object, with given VENDOR and PRODUCT
+ /// strings.
+ UsbStreamControl (const char *vendor, const char *product);
+ /// Return true if the device is configured. This means that the
+ /// connection is done with the host and data can be exchanged.
+ bool is_configured () const { return configured_; }
+ private:
+ /// Called by USB stack when device is configured. This is expected to
+ /// setup endpoints.
+ static void set_config (uint16_t wValue);
+ /// Called by USB stack when a frame is received on a OUT endpoint.
+ static void rx_callback (uint8_t ep);
+ private:
+ /// Size of endpoints.
+ static const int ep_size_ = UCOO_CONFIG_HAL_USB_EP_SIZE;
+ /// Number of streams (also interfaces or pair of endpoints).
+ static const int stream_nb_ = UCOO_CONFIG_HAL_USB_STREAM_NB;
+ /// Pointer to the one and only instance.
+ static UsbStreamControl *instance_;
+ /// Whether device is currently configured.
+ bool configured_;
+ /// Internal RX buffer type.
+ struct RxBuffer
+ {
+ char buf[ep_size_];
+ int size, offset;
+ RxBuffer (void);
+ };
+ /// Internal RX buffer, one per stream.
+ RxBuffer rx_buffer_[stream_nb_];
+ friend class UsbStream;
+};
+
+/// One USB stream, instantiated for each stream, interface, or pair of
+/// endpoints.
+class UsbStream : public Stream
+{
+ public:
+ /// Construct from control object and stream index.
+ UsbStream (UsbStreamControl &control, int num);
+ /// See Stream::read.
+ int read (char *buf, int count);
+ /// See Stream::write.
+ int write (const char *buf, int count);
+ /// See Stream::poll.
+ int poll ();
+ private:
+ /// Reference to control object.
+ UsbStreamControl &control_;
+ /// Stream index.
+ int num_;
+};
+
+} // namespace ucoo
+
+#endif // ucoolib_hal_usb_usb_stm32_hh
diff --git a/digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.c b/digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.c
new file mode 100644
index 00000000..51e6ea13
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.c
@@ -0,0 +1,193 @@
+/* ucoolib - Microcontroller object oriented library. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "usb_desc.stm32.h"
+
+#include "config/hal/usb.hh"
+
+const struct usb_device_descriptor usb_desc_dev = {
+ .bLength = USB_DT_DEVICE_SIZE,
+ .bDescriptorType = USB_DT_DEVICE,
+ .bcdUSB = 0x0200,
+ .bDeviceClass = 0xff,
+ .bDeviceSubClass = 0,
+ .bDeviceProtocol = 0,
+ .bMaxPacketSize0 = 64,
+ .idVendor = UCOO_CONFIG_HAL_USB_VENDOR_ID,
+ .idProduct = UCOO_CONFIG_HAL_USB_PRODUCT_ID,
+ .bcdDevice = 0x0000,
+ .iManufacturer = 1,
+ .iProduct = 2,
+ .iSerialNumber = 0,
+ .bNumConfigurations = 1,
+};
+
+static const struct usb_endpoint_descriptor usb_desc_endp_1[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x01,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x81,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+};
+
+static const struct usb_interface_descriptor usb_desc_iface_1[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 0,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = 0xff,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0,
+ .iInterface = 0,
+
+ .endpoint = usb_desc_endp_1,
+ },
+};
+
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 2
+
+static const struct usb_endpoint_descriptor usb_desc_endp_2[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x02,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x82,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+};
+
+static const struct usb_interface_descriptor usb_desc_iface_2[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 1,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = 0xff,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0,
+ .iInterface = 0,
+
+ .endpoint = usb_desc_endp_2,
+ },
+};
+
+#endif /* UCOO_CONFIG_HAL_USB_STREAM_NB >= 2 */
+
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 3
+
+static const struct usb_endpoint_descriptor usb_desc_endp_3[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x03,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x83,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = UCOO_CONFIG_HAL_USB_EP_SIZE,
+ .bInterval = 0,
+ },
+};
+
+static const struct usb_interface_descriptor usb_desc_iface_3[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 2,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = 0xff,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0,
+ .iInterface = 0,
+
+ .endpoint = usb_desc_endp_3,
+ },
+};
+
+#endif /* UCOO_CONFIG_HAL_USB_STREAM_NB >= 3 */
+
+#if UCOO_CONFIG_HAL_USB_STREAM_NB > 3
+# error "too many streams requested"
+#endif
+
+static const struct usb_interface usb_desc_ifaces[] = {
+ {
+ .num_altsetting = 1,
+ .altsetting = usb_desc_iface_1,
+ },
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 2
+ {
+ .num_altsetting = 1,
+ .altsetting = usb_desc_iface_2,
+ },
+#endif
+#if UCOO_CONFIG_HAL_USB_STREAM_NB >= 3
+ {
+ .num_altsetting = 1,
+ .altsetting = usb_desc_iface_3,
+ },
+#endif
+};
+
+const struct usb_config_descriptor usb_desc_config = {
+ .bLength = USB_DT_CONFIGURATION_SIZE,
+ .bDescriptorType = USB_DT_CONFIGURATION,
+ .wTotalLength = 0,
+ .bNumInterfaces = UCOO_CONFIG_HAL_USB_STREAM_NB,
+ .bConfigurationValue = 1,
+ .iConfiguration = 0,
+ .bmAttributes = 0x80 | (UCOO_CONFIG_HAL_USB_SELF_POWERED ? 0x40 : 0),
+ .bMaxPower = UCOO_CONFIG_HAL_USB_MAX_POWER / 2,
+
+ .interface = usb_desc_ifaces,
+};
+
diff --git a/digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.h b/digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.h
new file mode 100644
index 00000000..7c202843
--- /dev/null
+++ b/digital/ucoolib/ucoolib/hal/usb/usb_desc.stm32.h
@@ -0,0 +1,33 @@
+#ifndef ucoolib_hal_usb_usb_desc_stm32_h
+#define ucoolib_hal_usb_usb_desc_stm32_h
+/* ucoolib - Microcontroller object oriented library. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include <libopencm3/usb/usbstd.h>
+
+/** USB device descriptor. */
+extern const struct usb_device_descriptor usb_desc_dev;
+/** USB configuration descriptor. */
+extern const struct usb_config_descriptor usb_desc_config;
+
+#endif /* ucoolib_hal_usb_usb_desc_stm32_h */