This is an automated email from the ASF dual-hosted git repository. kasjer pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 5044251ba46d1e490e1a96dfb6375858f7c9f6a1 Author: Jerzy Kasenberg <[email protected]> AuthorDate: Tue Apr 7 11:46:29 2026 +0200 tinyusb: Add support for STM32H5 devices Signed-off-by: Jerzy Kasenberg <[email protected]> --- hw/usb/tinyusb/pkg.yml | 2 + .../tinyusb/stm32_fsdev/stm32h5/include/tusb_hw.h | 89 ++++++++++++++++++++++ hw/usb/tinyusb/stm32_fsdev/stm32h5/pkg.yml | 33 ++++++++ .../tinyusb/stm32_fsdev/stm32h5/src/stm32_fsdev.c | 60 +++++++++++++++ hw/usb/tinyusb/stm32_fsdev/stm32h5/syscfg.yml | 36 +++++++++ 5 files changed, 220 insertions(+) diff --git a/hw/usb/tinyusb/pkg.yml b/hw/usb/tinyusb/pkg.yml index 0f5e94145..2555cb688 100644 --- a/hw/usb/tinyusb/pkg.yml +++ b/hw/usb/tinyusb/pkg.yml @@ -48,6 +48,8 @@ pkg.deps.MCU_LPC55XX: - "@apache-mynewt-core/hw/usb/tinyusb/lpc55" pkg.deps.MCU_STM32F4: - "@apache-mynewt-core/hw/usb/tinyusb/synopsys" +pkg.deps.MCU_STM32H5: + - "@apache-mynewt-core/hw/usb/tinyusb/stm32_fsdev/stm32h5" pkg.deps.MCU_STM32H7: - "@apache-mynewt-core/hw/usb/tinyusb/synopsys" pkg.deps.MCU_STM32F7: diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32h5/include/tusb_hw.h b/hw/usb/tinyusb/stm32_fsdev/stm32h5/include/tusb_hw.h new file mode 100644 index 000000000..61df1fba7 --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32h5/include/tusb_hw.h @@ -0,0 +1,89 @@ +/* + * 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_STM32H5 + +#include <syscfg/syscfg.h> + +#define CFG_TUSB_RHPORT0_SPEED OPT_MODE_FULL_SPEED + +#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 + +#if defined(MYNEWT_VAL_USBD_MSC_DATA_IN_EP) +#define USBD_MSC_DATA_IN_EP MYNEWT_VAL(USBD_MSC_DATA_IN_EP) +#else +#define USBD_MSC_DATA_IN_EP 0x86 +#endif + +#if defined(MYNEWT_VAL_USBD_MSC_DATA_OUT_EP) +#define USBD_MSC_DATA_OUT_EP MYNEWT_VAL(USBD_MSC_DATA_OUT_EP) +#else +#define USBD_MSC_DATA_OUT_EP 0x06 +#endif + +#endif diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32h5/pkg.yml b/hw/usb/tinyusb/stm32_fsdev/stm32h5/pkg.yml new file mode 100644 index 000000000..7e314a2e0 --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32h5/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/stm32h5 +pkg.description: Hardware initialization for TinyUSB +pkg.author: "Apache Mynewt <[email protected]>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + - usb + - tinyusb + +pkg.apis: + - TINYUSB_HW_INIT + +pkg.deps: + - "@apache-mynewt-core/kernel/os" + - "@apache-mynewt-core/hw/usb/tinyusb" diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32h5/src/stm32_fsdev.c b/hw/usb/tinyusb/stm32_fsdev/stm32h5/src/stm32_fsdev.c new file mode 100644 index 000000000..6be1a0b62 --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32h5/src/stm32_fsdev.c @@ -0,0 +1,60 @@ +/* + * 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/stm32h5_bsp.h> +#include <mcu/stm32h5xx_mynewt_hal.h> +#include <bsp/stm32h5xx_hal_conf.h> +#include <stm32h5xx_hal_rcc_ex.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_DRD_FS_IRQn, (uint32_t)USB_IRQHandler); + NVIC_SetPriority(USB_DRD_FS_IRQn, 2); + + if (MYNEWT_VAL_CHOICE(USB_CLOCK_SOURCE, hsi48_ker_ck)) { + RCC->CCIPR4 = RCC->CCIPR4 | RCC_USBCLKSOURCE_HSI48; + } else if (MYNEWT_VAL_CHOICE(USB_CLOCK_SOURCE, pll1_q_ck)) { + RCC->CCIPR4 = (RCC->CCIPR4 & ~RCC_CCIPR4_USBSEL) | RCC_USBCLKSOURCE_PLL1Q; + } else if (MYNEWT_VAL_CHOICE(USB_CLOCK_SOURCE, pll3_q_ck)) { + RCC->CCIPR4 = (RCC->CCIPR4 & ~RCC_CCIPR4_USBSEL) | RCC_USBCLKSOURCE_PLL3Q; + } + + /* + * Enable USB clock + */ + __HAL_RCC_USB_CLK_ENABLE(); + +#if defined(PWR_USBSCR_USB33DEN) + /* Enable VDDUSB */ + HAL_PWREx_EnableVddUSB(); +#endif +} diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32h5/syscfg.yml b/hw/usb/tinyusb/stm32_fsdev/stm32h5/syscfg.yml new file mode 100644 index 000000000..51a52af1d --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32h5/syscfg.yml @@ -0,0 +1,36 @@ +# +# 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: 0 + + USB_CLOCK_SOURCE: + description: > + Source of USB clock. + choices: + - pll1_q_ck + - pll3_q_ck + - hsi48_ker_ck + value: hsi48_ker_ck +
