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

[mynewt-core] 04/07: tinyusb: Add hardware initialization for STM32F4xx STM32L4xx

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 fb9576ca090399a50a5b3794cc97e428b2f10674
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Thu Apr 30 14:22:49 2020 +0200

    tinyusb: Add hardware initialization for STM32F4xx STM32L4xx
    
    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/synopsys/include/tusb_hw.h | 31 ++++++++++++++
 hw/usb/tinyusb/synopsys/pkg.yml           | 33 ++++++++++++++
 hw/usb/tinyusb/synopsys/src/synopsys.c    | 71 +++++++++++++++++++++++++++++++
 hw/usb/tinyusb/synopsys/syscfg.yml        | 33 ++++++++++++++
 4 files changed, 168 insertions(+)

diff --git a/hw/usb/tinyusb/synopsys/include/tusb_hw.h b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
new file mode 100755
index 0000000..fe1dd71
--- /dev/null
+++ b/hw/usb/tinyusb/synopsys/include/tusb_hw.h
@@ -0,0 +1,31 @@
+/*
+ * 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__
+
+#include <syscfg/syscfg.h>
+
+#if MYNEWT_VAL(MCU_STM32F4)
+#define CFG_TUSB_MCU OPT_MCU_STM32F4
+#elif MYNEWT_VAL(MCU_STM32L4)
+#define CFG_TUSB_MCU OPT_MCU_STM32L4
+#endif
+
+#endif
diff --git a/hw/usb/tinyusb/synopsys/pkg.yml b/hw/usb/tinyusb/synopsys/pkg.yml
new file mode 100644
index 0000000..0ef48f9
--- /dev/null
+++ b/hw/usb/tinyusb/synopsys/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/synopsys
+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/synopsys/src/synopsys.c b/hw/usb/tinyusb/synopsys/src/synopsys.c
new file mode 100755
index 0000000..2300c10
--- /dev/null
+++ b/hw/usb/tinyusb/synopsys/src/synopsys.c
@@ -0,0 +1,71 @@
+/*
+ * 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/stm32_hal.h>
+
+static void
+OTG_FS_IRQHandler(void)
+{
+    /* TinyUSB provides interrupt handler code */
+    tud_int_handler(0);
+}
+
+void
+tinyusb_hardware_init(void)
+{
+    NVIC_SetVector(OTG_FS_IRQn, (uint32_t)OTG_FS_IRQHandler);
+    NVIC_SetPriority(OTG_FS_IRQn, 2);
+
+    /*
+     * USB Pin Init
+     * PA11- DM, PA12- DP
+     */
+    hal_gpio_init_af(MCU_GPIO_PORTA(11), GPIO_AF10_OTG_FS, GPIO_NOPULL, GPIO_MODE_AF_PP);
+#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), GPIO_AF10_OTG_FS, GPIO_NOPULL, GPIO_MODE_AF_PP);
+
+    /*
+     * Enable USB OTG clock, force device mode
+     */
+    __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+    USB_OTG_FS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD;
+    USB_OTG_FS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
+
+#ifdef USB_OTG_GCCFG_NOVBUSSENS
+#if !MYNEWT_VAL(USB_VBUS_DETECTION_ENABLE)
+    /* PA9- VUSB not used for USB */
+    USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
+    USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
+    USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
+#else
+    USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
+    USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
+    USB_OTG_FS->GCCFG |= ~USB_OTG_GCCFG_VBUSASEN;
+    hal_gpio_init_af(MCU_GPIO_PORTA(9), GPIO_AF10_OTG_FS, GPIO_NOPULL, GPIO_MODE_AF_PP);
+#endif
+#endif
+}
diff --git a/hw/usb/tinyusb/synopsys/syscfg.yml b/hw/usb/tinyusb/synopsys/syscfg.yml
new file mode 100644
index 0000000..5718df3
--- /dev/null
+++ b/hw/usb/tinyusb/synopsys/syscfg.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.
+#
+
+syscfg.defs:
+    USB_DP_HAS_EXTERNAL_PULL_UP:
+        description: >
+            Set this to 1 if hardware has external pull up resistor.
+            Synopsys does have internal pull up that allows to re-enumarate
+            without physical disconnection, but it will not work when
+            external pull up is present (like on on black_vet6 board).
+            Setting this changes pin to GPIO 0 at startup for a fraction
+            then device is discovered by host.
+        value: 0
+    USB_VBUS_DETECTION_ENABLE:
+        description:
+            Set to 1 when PA9 is connected to detect VBus.
+        value: 0