You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2020/05/18 09:35:57 UTC
[mynewt-core] 05/07: tinyusb: Add package for standard descriptors
CDC, HID
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 371c3d0556c7e7b1a38a6c6a1e7f7fb2ee04680d
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 14:57:53 2020 +0200
tinyusb: Add package for standard descriptors CDC,HID
---
hw/usb/tinyusb/README.md | 12 +
hw/usb/tinyusb/nrf5x/include/tusb_hw.h | 50 ++++
hw/usb/tinyusb/pkg.yml | 11 +
.../tinyusb/std_descriptors/include/tusb_config.h | 91 +++++++
hw/usb/tinyusb/{ => std_descriptors}/pkg.yml | 21 +-
.../tinyusb/std_descriptors/src/std_descriptors.c | 261 +++++++++++++++++++++
hw/usb/tinyusb/std_descriptors/syscfg.yml | 121 ++++++++++
hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h | 50 ++++
hw/usb/tinyusb/synopsys/include/tusb_hw.h | 48 ++++
hw/usb/tinyusb/syscfg.yml | 5 +
10 files changed, 656 insertions(+), 14 deletions(-)
diff --git a/hw/usb/tinyusb/README.md b/hw/usb/tinyusb/README.md
index 9c4d160..5142326 100644
--- a/hw/usb/tinyusb/README.md
+++ b/hw/usb/tinyusb/README.md
@@ -34,3 +34,15 @@ This dependency will start USB stack task.
pkg.deps:
- "@apache-mynewt-core/hw/usb/tinyusb"
```
+
+To easy add support for CDC or HID class device simply add
+**hw/usb/tinyusb/std_descriptors** package to project
+```yaml
+pkg.deps:
+ - "@apache-mynewt-core/hw/usb/tinyusb/std_descriptors"
+```
+Vendor and product ID must be specified in **syscfg.vals:** section
+```yaml
+ USBD_VID: 0xABCD
+ USBD_PID: 0x1234
+```
diff --git a/hw/usb/tinyusb/nrf5x/include/tusb_hw.h b/hw/usb/tinyusb/nrf5x/include/tusb_hw.h
index c3a280f..682e08b 100755
--- a/hw/usb/tinyusb/nrf5x/include/tusb_hw.h
+++ b/hw/usb/tinyusb/nrf5x/include/tusb_hw.h
@@ -22,4 +22,54 @@
#define CFG_TUSB_MCU OPT_MCU_NRF5X
+#include <syscfg/syscfg.h>
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP)
+#define USBD_CDC_NOTIFY_EP MYNEWT_VAL(USBD_CDC_NOTIFY_EP)
+#else
+#define USBD_CDC_NOTIFY_EP 0x81
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP_SIZE)
+#define USBD_CDC_NOTIFY_EP_SIZE MYNEWT_VAL(USBD_CDC_NOTIFY_EP_SIZE)
+#else
+#define USBD_CDC_NOTIFY_EP_SIZE 0x08
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_OUT_EP)
+#define USBD_CDC_DATA_OUT_EP MYNEWT_VAL(USBD_CDC_DATA_OUT_EP)
+#else
+#define USBD_CDC_DATA_OUT_EP 0x02
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_IN_EP)
+#define USBD_CDC_DATA_IN_EP MYNEWT_VAL(USBD_CDC_DATA_IN_EP)
+#else
+#define USBD_CDC_DATA_IN_EP 0x82
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_EP_SIZE)
+#define USBD_CDC_DATA_EP_SIZE MYNEWT_VAL(USBD_CDC_DATA_EP_SIZE)
+#else
+#define USBD_CDC_DATA_EP_SIZE 0x40
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP)
+#define USBD_HID_REPORT_EP MYNEWT_VAL(USBD_HID_REPORT_EP)
+#else
+#define USBD_HID_REPORT_EP 0x83
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_SIZE)
+#define USBD_HID_REPORT_EP_SIZE MYNEWT_VAL(USBD_HID_REPORT_EP_SIZE)
+#else
+#define USBD_HID_REPORT_EP_SIZE 0x10
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_INTERVAL)
+#define USBD_HID_REPORT_EP_INTERVAL MYNEWT_VAL(USBD_HID_REPORT_EP_INTERVAL)
+#else
+#define USBD_HID_REPORT_EP_INTERVAL 10
+#endif
+
#endif
diff --git a/hw/usb/tinyusb/pkg.yml b/hw/usb/tinyusb/pkg.yml
index 2ff9a3f..aeeaa94 100644
--- a/hw/usb/tinyusb/pkg.yml
+++ b/hw/usb/tinyusb/pkg.yml
@@ -36,5 +36,16 @@ pkg.deps:
pkg.init:
tinyusb_start: 'MYNEWT_VAL(USBD_SYSINIT_STAGE)'
+pkg.deps.USBD_STD_DESCRIPTORS:
+ - "@apache-mynewt-core/hw/usb/tinyusb/std_descriptors"
+pkg.deps.'MCU_TARGET == "nRF52840"':
+ - "@apache-mynewt-core/hw/usb/tinyusb/nrf5x"
+pkg.deps.MCU_STM32F4:
+ - "@apache-mynewt-core/hw/usb/tinyusb/synopsys"
+pkg.deps.MCU_STM32L4:
+ - "@apache-mynewt-core/hw/usb/tinyusb/synopsys"
+pkg.deps.MCU_STM32F1:
+ - "@apache-mynewt-core/hw/usb/tinyusb/stm32_fsdev"
+
pkg.req_apis:
- TINYUSB_HW_INIT
diff --git a/hw/usb/tinyusb/std_descriptors/include/tusb_config.h b/hw/usb/tinyusb/std_descriptors/include/tusb_config.h
new file mode 100755
index 0000000..3a8310d
--- /dev/null
+++ b/hw/usb/tinyusb/std_descriptors/include/tusb_config.h
@@ -0,0 +1,91 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#ifndef _TUSB_CONFIG_H_
+#define _TUSB_CONFIG_H_
+
+#include "syscfg/syscfg.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * COMMON CONFIGURATION
+ */
+
+#include <tusb_hw.h>
+
+/* defined by compiler flags for flexibility */
+#ifndef CFG_TUSB_MCU
+#error CFG_TUSB_MCU must be defined
+#endif
+
+#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
+
+#define CFG_TUSB_OS OPT_OS_MYNEWT
+#define CFG_TUSB_DEBUG 0
+
+/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
+ * Tinyusb use follows macros to declare transferring memory so that they can be put
+ * into those specific section.
+ * e.g
+ * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
+ * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
+ */
+#ifndef CFG_TUSB_MEM_SECTION
+#define CFG_TUSB_MEM_SECTION
+#endif
+
+#ifndef CFG_TUSB_MEM_ALIGN
+#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
+#endif
+
+/**
+ * DEVICE CONFIGURATION
+ */
+#define CFG_TUD_ENDPOINT0_SIZE MYNEWT_VAL(USBD_EP0_SIZE)
+
+/* ------------- CLASS ------------- */
+#define CFG_TUD_CDC MYNEWT_VAL(USBD_CDC)
+#define CFG_TUD_HID MYNEWT_VAL(USBD_HID)
+#define CFG_TUD_MSC 0
+#define CFG_TUD_MIDI 0
+#define CFG_TUD_VENDOR 0
+#define CFG_TUD_USBTMC 0
+#define CFG_TUD_DFU_RT 0
+#define CFG_TUD_NET 0
+
+/* CDC FIFO size of TX and RX */
+#define CFG_TUD_CDC_RX_BUFSIZE 64
+#define CFG_TUD_CDC_TX_BUFSIZE 64
+
+/* HID buffer size Should be sufficient to hold ID (if any) + Data */
+#define CFG_TUD_HID_BUFSIZE 16
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _TUSB_CONFIG_H_ */
diff --git a/hw/usb/tinyusb/pkg.yml b/hw/usb/tinyusb/std_descriptors/pkg.yml
similarity index 75%
copy from hw/usb/tinyusb/pkg.yml
copy to hw/usb/tinyusb/std_descriptors/pkg.yml
index 2ff9a3f..5a68cda 100644
--- a/hw/usb/tinyusb/pkg.yml
+++ b/hw/usb/tinyusb/std_descriptors/pkg.yml
@@ -6,7 +6,7 @@
# 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,
@@ -17,24 +17,17 @@
# under the License.
#
-pkg.name: hw/usb/tinyusb
-pkg.description: >
- Package provides task for TinyUSB.
- This package requires API TINYUSB_HW_INIT that will
- provide function tinyusb_hardware_init().
-
+pkg.name: hw/usb/tinyusb/std_descriptors
+pkg.description: TinyUSB standard descriptor package
pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
- usb
- tinyusb
+ - CDC
+ - HID
+ - MSC
pkg.deps:
- "@apache-mynewt-core/kernel/os"
- - "@tinyusb/tinyusb"
-
-pkg.init:
- tinyusb_start: 'MYNEWT_VAL(USBD_SYSINIT_STAGE)'
-
-pkg.req_apis:
- - TINYUSB_HW_INIT
+ - "@apache-mynewt-core/hw/usb/tinyusb"
diff --git a/hw/usb/tinyusb/std_descriptors/src/std_descriptors.c b/hw/usb/tinyusb/std_descriptors/src/std_descriptors.c
new file mode 100755
index 0000000..6825a33
--- /dev/null
+++ b/hw/usb/tinyusb/std_descriptors/src/std_descriptors.c
@@ -0,0 +1,261 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018, hathach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include <syscfg/syscfg.h>
+#include <bsp/bsp.h>
+#include <string.h>
+#include <tusb.h>
+#include <device/usbd.h>
+#include <os/util.h>
+#include <console/console.h>
+#include <hal/hal_gpio.h>
+
+#define USBD_PRODUCT_RELEASE_NUMBER MYNEWT_VAL(USBD_PRODUCT_RELEASE_NUMBER)
+
+#ifndef CONFIG_NUM
+#define CONFIG_NUM 1
+#endif
+
+#define CDC_IF_STR_IX (MYNEWT_VAL(USBD_CDC_DESCRIPTOR_STRING) == NULL ? 0 : 4)
+#define MSC_IF_STR_IX (MYNEWT_VAL(USBD_MSC_DESCRIPTOR_STRING) == NULL ? 0 : 5)
+#define HID_IF_STR_IX (MYNEWT_VAL(USBD_HID_DESCRIPTOR_STRING) == NULL ? 0 : 6)
+
+
+#if CFG_TUD_HID
+
+#if MYNEWT_VAL(USBD_HID_REPORT_ID_KEYBOARD) || MYNEWT_VAL(USBD_HID_REPORT_ID_MOUSE)
+const uint8_t desc_hid_report[] = {
+#if MYNEWT_VAL(USBD_HID_REPORT_ID_KEYBOARD)
+ TUD_HID_REPORT_DESC_KEYBOARD(MYNEWT_VAL(USBD_HID_REPORT_ID_KEYBOARD),),
+#endif
+#if MYNEWT_VAL(USBD_HID_REPORT_ID_MOUSE)
+ TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE),)
+#endif
+};
+#else
+#error Please specify keybaord and/or mouse report id
+#endif
+
+/*
+ * Invoked when received GET HID REPORT DESCRIPTOR
+ * Application return pointer to descriptor
+ * Descriptor contents must exist long enough for transfer to complete
+ */
+const uint8_t *
+tud_hid_descriptor_report_cb(void)
+{
+ return desc_hid_report;
+}
+
+/*
+ * Invoked when received GET_REPORT control request
+ * Application must fill buffer report's content and return its length.
+ * Return zero will cause the stack to STALL request
+ */
+uint16_t
+tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen)
+{
+ /* TODO: not implemented yet */
+ (void)report_id;
+ (void)report_type;
+ (void)buffer;
+ (void)reqlen;
+
+ return 0;
+}
+
+/*
+ * Invoked when received SET_REPORT control request or
+ * received data on OUT endpoint ( Report ID = 0, Type = 0 )
+ */
+void
+tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, const uint8_t *report, uint16_t report_size)
+{
+ (void)report_id;
+ (void)report_type;
+ (void)report_size;
+ if (MYNEWT_VAL(USBD_HID_CAPS_LOCK_LED_PIN) >= 0) {
+ hal_gpio_write(MYNEWT_VAL(USBD_HID_CAPS_LOCK_LED_PIN),
+ 1 & ((report[0] >> 1) ^ 1u ^ MYNEWT_VAL(USBD_HID_CAPS_LOCK_LED_ON_VALUE)));
+ }
+ if (MYNEWT_VAL(USBD_HID_NUM_LOCK_LED_PIN) >= 0) {
+ hal_gpio_write(MYNEWT_VAL(USBD_HID_NUM_LOCK_LED_PIN),
+ 1 & (report[0] ^ 1u ^ MYNEWT_VAL(USBD_HID_CAPS_LOCK_LED_ON_VALUE)));
+ }
+}
+#endif /* CFG_TUD_HID */
+
+const tusb_desc_device_t desc_device = {
+ .bLength = sizeof(tusb_desc_device_t),
+ .bDescriptorType = TUSB_DESC_DEVICE,
+ .bcdUSB = 0x0200,
+
+#if CFG_TUD_CDC
+ /*
+ * Use Interface Association Descriptor (IAD) for CDC
+ * As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
+ */
+ .bDeviceClass = TUSB_CLASS_MISC,
+ .bDeviceSubClass = MISC_SUBCLASS_COMMON,
+ .bDeviceProtocol = MISC_PROTOCOL_IAD,
+#else
+ .bDeviceClass = 0x00,
+ .bDeviceSubClass = 0x00,
+ .bDeviceProtocol = 0x00,
+#endif
+
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+
+ .idVendor = MYNEWT_VAL(USBD_VID),
+ .idProduct = MYNEWT_VAL(USBD_PID),
+ .bcdDevice = USBD_PRODUCT_RELEASE_NUMBER,
+
+ .iManufacturer = 0x02,
+ .iProduct = 0x03,
+ .iSerialNumber = 0x01,
+
+ .bNumConfigurations = 0x01
+};
+
+/*
+ * Invoked when received GET DEVICE DESCRIPTOR
+ * Application return pointer to descriptor
+ */
+const uint8_t *
+tud_descriptor_device_cb(void)
+{
+ return (const uint8_t *)&desc_device;
+}
+
+/*
+ * Configuration Descriptor
+ */
+
+enum {
+#if CFG_TUD_CDC
+ ITF_NUM_CDC,
+ ITF_NUM_CDC_DATA,
+#endif
+
+#if CFG_TUD_MSC
+ ITF_NUM_MSC,
+#endif
+
+#if CFG_TUD_HID
+ ITF_NUM_HID,
+#endif
+
+ ITF_NUM_TOTAL
+};
+
+#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
+ CFG_TUD_CDC * TUD_CDC_DESC_LEN + \
+ CFG_TUD_MSC * TUD_MSC_DESC_LEN + \
+ CFG_TUD_HID * TUD_HID_DESC_LEN + \
+ 0)
+
+const uint8_t desc_configuration[] = {
+ TUD_CONFIG_DESCRIPTOR(CONFIG_NUM, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
+ MYNEWT_VAL(USBD_CONFIGURATION_MAX_POWER)),
+
+#if CFG_TUD_CDC
+ TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, CDC_IF_STR_IX, USBD_CDC_NOTIFY_EP, USBD_CDC_NOTIFY_EP_SIZE,
+ USBD_CDC_DATA_OUT_EP, USBD_CDC_DATA_IN_EP, USBD_CDC_DATA_EP_SIZE),
+#endif
+
+#if CFG_TUD_MSC
+ /* TODO: MSC not handled yet */
+ TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, MSC_IF_STR_IX, EPNUM_MSC_OUT, EPNUM_MSC_IN,
+ (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED) ? 512 : 64),
+#endif
+
+#if CFG_TUD_HID
+ TUD_HID_DESCRIPTOR(ITF_NUM_HID, HID_IF_STR_IX, HID_PROTOCOL_NONE, sizeof(desc_hid_report),
+ USBD_HID_REPORT_EP, USBD_HID_REPORT_EP_SIZE, USBD_HID_REPORT_EP_INTERVAL),
+#endif
+};
+
+/**
+ * Invoked when received GET CONFIGURATION DESCRIPTOR
+ * Application return pointer to descriptor
+ * Descriptor contents must exist long enough for transfer to complete
+ */
+const uint8_t *
+tud_descriptor_configuration_cb(uint8_t index)
+{
+ (void)index;
+
+ return desc_configuration;
+}
+
+const char *string_desc_arr[] = {
+ MYNEWT_VAL(USBD_VENDOR_STRING),
+ MYNEWT_VAL(USBD_PRODUCT_STRING),
+ MYNEWT_VAL(USBD_CDC_DESCRIPTOR_STRING),
+ MYNEWT_VAL(USBD_MSC_DESCRIPTOR_STRING),
+ MYNEWT_VAL(USBD_HID_DESCRIPTOR_STRING),
+};
+
+static uint16_t desc_string[MYNEWT_VAL(USBD_STRING_DESCRIPTOR_MAX_LENGTH) + 1];
+
+/*
+ * Invoked when received GET STRING DESCRIPTOR request
+ * Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+ */
+const uint16_t *
+tud_descriptor_string_cb(uint8_t index, uint16_t langid)
+{
+ int char_num = 0;
+ int i;
+ const char *str;
+
+ if (index == 0) {
+ desc_string[1] = MYNEWT_VAL(USBD_LANGID);
+ char_num = 1;
+ } else if (index == 1) {
+ /* TODO: Add function call to get serial number */
+ desc_string[1] = '1';
+ char_num = 1;
+ } else if (index - 2 < ARRAY_SIZE(string_desc_arr)) {
+ str = string_desc_arr[index - 2];
+
+ char_num = strlen(str);
+ if (char_num >= ARRAY_SIZE(desc_string)) {
+ char_num = ARRAY_SIZE(desc_string);
+ }
+
+ for (i = 0; i < char_num; ++i) {
+ desc_string[1 + i] = str[i];
+ }
+ }
+
+ if (char_num) {
+ /* Encode length in first byte */
+ desc_string[0] = (TUSB_DESC_STRING << 8) | (2 * char_num + 2);
+ return desc_string;
+ } else {
+ return NULL;
+ }
+}
diff --git a/hw/usb/tinyusb/std_descriptors/syscfg.yml b/hw/usb/tinyusb/std_descriptors/syscfg.yml
new file mode 100644
index 0000000..f313028
--- /dev/null
+++ b/hw/usb/tinyusb/std_descriptors/syscfg.yml
@@ -0,0 +1,121 @@
+#
+# 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.
+#
+
+syscfg.defs:
+ USBD_STRING_DESCRIPTOR_MAX_LENGTH:
+ description: Maximum length of string descriptor in characters
+ value: 31
+ USBD_EP0_SIZE:
+ description: >
+ Endpoint 0 size
+ value: 64
+ USBD_VID:
+ description: Vendor ID
+ value:
+ restrictions:
+ - $notnull
+ USBD_PID:
+ description: Product ID
+ value:
+ restrictions:
+ - $notnull
+ USBD_PRODUCT_RELEASE_NUMBER:
+ description: Product release number needed for USB descriptor
+ value: 0x100
+ USBD_CONFIGURATION_MAX_POWER:
+ description: >
+ Maximum power consumption of the USB device from the bus in this specific
+ configuration when the device is fully operational. Expressed in 2 mA units
+ (i.e., 50 = 100 mA).
+ value: 100
+ USBD_LANGID:
+ description: Language ID as specified by usb.org
+ value: 0x0409
+ USBD_VENDOR_STRING:
+ description: Manufacturer identification string
+ value: '"Vendor string"'
+ USBD_PRODUCT_STRING:
+ description: Device friendly name
+ value: '"Dev device"'
+ USBD_CDC:
+ description: Enable CDC device
+ value: 0
+ USBD_HID:
+ description: Enable HID device
+ value: 0
+ USBD_MSC:
+ description: Enable MSC device
+ value: 0
+
+ USBD_CDC_DATA_OUT_EP:
+ description: CDC data out endpoint number
+ value:
+ USBD_CDC_DATA_IN_EP:
+ description: CDC data out endpoint number
+ value:
+ USBD_CDC_DATA_EP_SIZE:
+ description: CDC data endpoint size
+ value:
+ USBD_CDC_NOTIFY_EP:
+ description: CDC notify endpoint number
+ value:
+ USBD_CDC_NOTIFY_EP_SIZE:
+ description: CDC notify endpoint size
+ value:
+
+ USBD_CDC_DESCRIPTOR_STRING:
+ description: String for CDC interface
+ value: NULL
+
+ USBD_MSC_DESCRIPTOR_STRING:
+ description: String for MSC interface
+ value: NULL
+
+ USBD_HID_DESCRIPTOR_STRING:
+ description: String for HID interface
+ value: NULL
+
+ USBD_HID_REPORT_EP:
+ description: HID report endpoint number
+ value:
+ USBD_HID_REPORT_EP_SIZE:
+ description: HID report endpoint size
+ value:
+ USBD_HID_REPORT_EP_INTERVAL:
+ description: HID report endpoint interval
+ value:
+
+ USBD_HID_REPORT_ID_KEYBOARD:
+ description: HID keyboard report ID
+ value:
+ USBD_HID_CAPS_LOCK_LED_PIN:
+ description: Caps Lock LED
+ value: -1
+ USBD_HID_CAPS_LOCK_LED_ON_VALUE:
+ description: Value to set to pin to turn led on
+ value: 0
+ USBD_HID_NUM_LOCK_LED_PIN:
+ description: Num Lock LED
+ value: -1
+ USBD_HID_NUM_LOCK_LED_ON_VALUE:
+ description: Value to set to pin to turn led on
+ value: 0
+ USBD_HID_REPORT_ID_MOUSE:
+ description: HID keyboard report ID
+ value:
diff --git a/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h b/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
index e8cbe2a..9a4752e 100755
--- a/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
+++ b/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
@@ -22,4 +22,54 @@
#define CFG_TUSB_MCU OPT_MCU_STM32F1
+#include <syscfg/syscfg.h>
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP)
+#define USBD_CDC_NOTIFY_EP MYNEWT_VAL(USBD_CDC_NOTIFY_EP)
+#else
+#define USBD_CDC_NOTIFY_EP 0x81
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP_SIZE)
+#define USBD_CDC_NOTIFY_EP_SIZE MYNEWT_VAL(USBD_CDC_NOTIFY_EP_SIZE)
+#else
+#define USBD_CDC_NOTIFY_EP_SIZE 0x08
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_OUT_EP)
+#define USBD_CDC_DATA_OUT_EP MYNEWT_VAL(USBD_CDC_DATA_OUT_EP)
+#else
+#define USBD_CDC_DATA_OUT_EP 0x01
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_IN_EP)
+#define USBD_CDC_DATA_IN_EP MYNEWT_VAL(USBD_CDC_DATA_IN_EP)
+#else
+#define USBD_CDC_DATA_IN_EP 0x82
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_EP_SIZE)
+#define USBD_CDC_DATA_EP_SIZE MYNEWT_VAL(USBD_CDC_DATA_EP_SIZE)
+#else
+#define USBD_CDC_DATA_EP_SIZE 0x40
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP)
+#define USBD_HID_REPORT_EP MYNEWT_VAL(USBD_HID_REPORT_EP)
+#else
+#define USBD_HID_REPORT_EP 0x83
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_SIZE)
+#define USBD_HID_REPORT_EP_SIZE MYNEWT_VAL(USBD_HID_REPORT_EP_SIZE)
+#else
+#define USBD_HID_REPORT_EP_SIZE 0x10
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_INTERVAL)
+#define USBD_HID_REPORT_EP_INTERVAL MYNEWT_VAL(USBD_HID_REPORT_EP_INTERVAL)
+#else
+#define USBD_HID_REPORT_EP_INTERVAL 10
+#endif
+
#endif
diff --git a/hw/usb/tinyusb/synopsys/include/tusb_hw.h b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
index fe1dd71..34471fd 100755
--- a/hw/usb/tinyusb/synopsys/include/tusb_hw.h
+++ b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
@@ -28,4 +28,52 @@
#define CFG_TUSB_MCU OPT_MCU_STM32L4
#endif
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP)
+#define USBD_CDC_NOTIFY_EP MYNEWT_VAL(USBD_CDC_NOTIFY_EP)
+#else
+#define USBD_CDC_NOTIFY_EP 0x81
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_NOTIFY_EP_SIZE)
+#define USBD_CDC_NOTIFY_EP_SIZE MYNEWT_VAL(USBD_CDC_NOTIFY_EP_SIZE)
+#else
+#define USBD_CDC_NOTIFY_EP_SIZE 0x08
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_OUT_EP)
+#define USBD_CDC_DATA_OUT_EP MYNEWT_VAL(USBD_CDC_DATA_OUT_EP)
+#else
+#define USBD_CDC_DATA_OUT_EP 0x01
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_IN_EP)
+#define USBD_CDC_DATA_IN_EP MYNEWT_VAL(USBD_CDC_DATA_IN_EP)
+#else
+#define USBD_CDC_DATA_IN_EP 0x82
+#endif
+
+#if defined(MYNEWT_VAL_USBD_CDC_DATA_EP_SIZE)
+#define USBD_CDC_DATA_EP_SIZE MYNEWT_VAL(USBD_CDC_DATA_EP_SIZE)
+#else
+#define USBD_CDC_DATA_EP_SIZE 0x40
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP)
+#define USBD_HID_REPORT_EP MYNEWT_VAL(USBD_HID_REPORT_EP)
+#else
+#define USBD_HID_REPORT_EP 0x83
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_SIZE)
+#define USBD_HID_REPORT_EP_SIZE MYNEWT_VAL(USBD_HID_REPORT_EP_SIZE)
+#else
+#define USBD_HID_REPORT_EP_SIZE 0x10
+#endif
+
+#if defined(MYNEWT_VAL_USBD_HID_REPORT_EP_INTERVAL)
+#define USBD_HID_REPORT_EP_INTERVAL MYNEWT_VAL(USBD_HID_REPORT_EP_INTERVAL)
+#else
+#define USBD_HID_REPORT_EP_INTERVAL 10
+#endif
+
#endif
diff --git a/hw/usb/tinyusb/syscfg.yml b/hw/usb/tinyusb/syscfg.yml
index 726f90c..c76307b 100644
--- a/hw/usb/tinyusb/syscfg.yml
+++ b/hw/usb/tinyusb/syscfg.yml
@@ -34,3 +34,8 @@ syscfg.defs:
description: >
Sysinit stage for USB device functionality.
value: 500
+ USBD_STD_DESCRIPTORS:
+ description: >
+ Include descriptor support. This allows to easily use CDC, MSC, HID device
+ functionality.
+ value: 1