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:55 UTC

[mynewt-core] 03/07: tinyusb: Add hardware initialization for STM32F1xx

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 4012a75cc1bc349519b50ae924de971bd7df7cdc
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 14:15:34 2020 +0200

    tinyusb: Add hardware initialization for STM32F1xx
    
    This provides code for hardware initialization.
    Part of this initialization is present in tinyusb bsps which
    are not used by mynewt since it has own bsps.
---
 hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h | 25 +++++++++++
 hw/usb/tinyusb/stm32_fsdev/pkg.yml           | 33 ++++++++++++++
 hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c | 66 ++++++++++++++++++++++++++++
 hw/usb/tinyusb/stm32_fsdev/syscfg.yml        | 27 ++++++++++++
 4 files changed, 151 insertions(+)

diff --git a/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h b/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
new file mode 100755
index 0000000..e8cbe2a
--- /dev/null
+++ b/hw/usb/tinyusb/stm32_fsdev/include/tusb_hw.h
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+#ifndef __TUSB_HW_H__
+#define __TUSB_HW_H__
+
+#define CFG_TUSB_MCU OPT_MCU_STM32F1
+
+#endif
diff --git a/hw/usb/tinyusb/stm32_fsdev/pkg.yml b/hw/usb/tinyusb/stm32_fsdev/pkg.yml
new file mode 100644
index 0000000..25372e5
--- /dev/null
+++ b/hw/usb/tinyusb/stm32_fsdev/pkg.yml
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+pkg.name: hw/usb/tinyusb/stm32_fsdev
+pkg.description: Hardware initialization for TinyUSB
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - usb
+    - tinyusb
+
+pkg.apis:
+    - TINYUSB_HW_INIT
+
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+    - "@tinyusb/tinyusb"
diff --git a/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c b/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
new file mode 100755
index 0000000..a0f82af
--- /dev/null
+++ b/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+#include <os/mynewt.h>
+#include <mcu/mcu.h>
+
+#include <tusb.h>
+
+#include <mcu/stm32f1_bsp.h>
+#include <mcu/stm32f1xx_mynewt_hal.h>
+#include <bsp/stm32f1xx_hal_conf.h>
+
+static void
+USB_IRQHandler(void)
+{
+    tud_int_handler(0);
+}
+
+void
+tinyusb_hardware_init(void)
+{
+    /* TinyUSB provides interrupt handler, here it is setup the mynewt way */
+    NVIC_SetVector(USB_HP_CAN1_TX_IRQn, (uint32_t)USB_IRQHandler);
+    NVIC_SetPriority(USB_HP_CAN1_TX_IRQn, 2);
+    NVIC_SetVector(USB_LP_CAN1_RX0_IRQn, (uint32_t)USB_IRQHandler);
+    NVIC_SetPriority(USB_LP_CAN1_RX0_IRQn, 2);
+    NVIC_SetVector(USBWakeUp_IRQn, (uint32_t)USB_IRQHandler);
+    NVIC_SetPriority(USBWakeUp_IRQn, 2);
+
+    /*
+     * USB Pin Init
+     * PA11- DM, PA12- DP
+     */
+    hal_gpio_init_af(MCU_GPIO_PORTA(11), 0, GPIO_NOPULL, GPIO_MODE_AF_PP);
+
+    /*
+     * Device needs external PULLUP, following two lines change DP to 0 for a while
+     * to indicated device connection.
+     */
+#if MYNEWT_VAL(USB_DP_HAS_EXTERNAL_PULL_UP)
+    hal_gpio_init_out(MCU_GPIO_PORTA(12), 0);
+    os_time_delay(1);
+#endif
+    hal_gpio_init_af(MCU_GPIO_PORTA(12), 0, GPIO_NOPULL, GPIO_MODE_AF_PP);
+
+    /*
+     * Enable USB clock
+     */
+    __HAL_RCC_USB_CLK_ENABLE();
+}
diff --git a/hw/usb/tinyusb/stm32_fsdev/syscfg.yml b/hw/usb/tinyusb/stm32_fsdev/syscfg.yml
new file mode 100644
index 0000000..37f2fbe
--- /dev/null
+++ b/hw/usb/tinyusb/stm32_fsdev/syscfg.yml
@@ -0,0 +1,27 @@
+#
+# 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:
+    USB_DP_HAS_EXTERNAL_PULL_UP:
+        description: >
+            Set this to 1 if hardware has external pull up resistor.
+            Setting this changes DP pin to 0 at startup for a fraction
+            then device is discovered by host.
+        value: 1
+