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 fe0060f13bf4c643626114d07b0dad30cd5568f5 Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> AuthorDate: Thu Feb 1 08:55:20 2024 +0100 tinyusb: Add support for STM32G0 and STM32G4 Code adds hardware specific initialization for STM32G0 and STM32G4 to be used in TinyUSB stack. Signed-off-by: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> --- hw/usb/tinyusb/pkg.yml | 4 + .../tinyusb/stm32_fsdev/stm32g0/include/tusb_hw.h | 89 ++++++++++++++++++++++ hw/usb/tinyusb/stm32_fsdev/stm32g0/pkg.yml | 33 ++++++++ .../tinyusb/stm32_fsdev/stm32g0/src/stm32_fsdev.c | 53 +++++++++++++ hw/usb/tinyusb/stm32_fsdev/stm32g0/syscfg.yml | 27 +++++++ .../tinyusb/stm32_fsdev/stm32g4/include/tusb_hw.h | 89 ++++++++++++++++++++++ hw/usb/tinyusb/stm32_fsdev/stm32g4/pkg.yml | 33 ++++++++ .../tinyusb/stm32_fsdev/stm32g4/src/stm32_fsdev.c | 64 ++++++++++++++++ hw/usb/tinyusb/stm32_fsdev/stm32g4/syscfg.yml | 27 +++++++ 9 files changed, 419 insertions(+) diff --git a/hw/usb/tinyusb/pkg.yml b/hw/usb/tinyusb/pkg.yml index 09a567cb1..187deead1 100644 --- a/hw/usb/tinyusb/pkg.yml +++ b/hw/usb/tinyusb/pkg.yml @@ -58,6 +58,10 @@ pkg.deps.MCU_STM32L0: - "@apache-mynewt-core/hw/usb/tinyusb/stm32_fsdev/stm32l0" pkg.deps.MCU_STM32WB: - "@apache-mynewt-core/hw/usb/tinyusb/stm32_fsdev/stm32wb55" +pkg.deps.MCU_STM32G0: + - "@apache-mynewt-core/hw/usb/tinyusb/stm32_fsdev/stm32g0" +pkg.deps.MCU_STM32G4: + - "@apache-mynewt-core/hw/usb/tinyusb/stm32_fsdev/stm32g4" pkg.deps.'(MCU_TARGET == "DA14691" || MCU_TARGET == "DA14695" || MCU_TARGET == "DA14697" || MCU_TARGET == "DA14699")': - "@apache-mynewt-core/hw/usb/tinyusb/da146xx" pkg.deps.MCU_PIC32MZ: diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32g0/include/tusb_hw.h b/hw/usb/tinyusb/stm32_fsdev/stm32g0/include/tusb_hw.h new file mode 100644 index 000000000..7b879e9b1 --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32g0/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_STM32G0 + +#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/stm32g0/pkg.yml b/hw/usb/tinyusb/stm32_fsdev/stm32g0/pkg.yml new file mode 100644 index 000000000..60e5717b5 --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32g0/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/stm32g0 +pkg.description: Hardware initialization for TinyUSB +pkg.author: "Apache Mynewt <d...@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" + - "@apache-mynewt-core/hw/usb/tinyusb" diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32g0/src/stm32_fsdev.c b/hw/usb/tinyusb/stm32_fsdev/stm32g0/src/stm32_fsdev.c new file mode 100644 index 000000000..dbae7494b --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32g0/src/stm32_fsdev.c @@ -0,0 +1,53 @@ +/* + * 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/stm32g0_bsp.h> +#include <mcu/stm32g0xx_mynewt_hal.h> +#include <bsp/stm32g0xx_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_UCPD1_2_IRQn, (uint32_t)USB_IRQHandler); + NVIC_SetPriority(USB_UCPD1_2_IRQn, 2); + + if (MYNEWT_VAL(STM32_CLOCK_HSI48)) { + RCC->CCIPR2 = RCC->CCIPR2 & ~RCC_CCIPR2_USBSEL; + } + + /* + * Enable USB clock + */ + __HAL_RCC_USB_CLK_ENABLE(); + + /* Enable VDDUSB */ + HAL_PWREx_EnableVddUSB(); +} diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32g0/syscfg.yml b/hw/usb/tinyusb/stm32_fsdev/stm32g0/syscfg.yml new file mode 100644 index 000000000..8b3d626be --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32g0/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: 0 + diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32g4/include/tusb_hw.h b/hw/usb/tinyusb/stm32_fsdev/stm32g4/include/tusb_hw.h new file mode 100644 index 000000000..ab8fae2bc --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32g4/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_STM32G4 + +#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/stm32g4/pkg.yml b/hw/usb/tinyusb/stm32_fsdev/stm32g4/pkg.yml new file mode 100644 index 000000000..4a7e671e7 --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32g4/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/stm32g4 +pkg.description: Hardware initialization for TinyUSB +pkg.author: "Apache Mynewt <d...@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" + - "@apache-mynewt-core/hw/usb/tinyusb" diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32g4/src/stm32_fsdev.c b/hw/usb/tinyusb/stm32_fsdev/stm32g4/src/stm32_fsdev.c new file mode 100644 index 000000000..f618c5316 --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32g4/src/stm32_fsdev.c @@ -0,0 +1,64 @@ +/* + * 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/stm32g4_bsp.h> +#include <mcu/stm32g4xx_mynewt_hal.h> +#include <bsp/stm32g4xx_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_IRQn, (uint32_t)USB_IRQHandler); + NVIC_SetPriority(USB_HP_IRQn, 2); + NVIC_SetVector(USB_LP_IRQn, (uint32_t)USB_IRQHandler); + NVIC_SetPriority(USB_LP_IRQn, 2); + NVIC_SetVector(USBWakeUp_IRQn, (uint32_t)USB_IRQHandler); + NVIC_SetPriority(USBWakeUp_IRQn, 2); + NVIC_SetVector(UCPD1_IRQn, (uint32_t)USB_IRQHandler); + NVIC_SetPriority(UCPD1_IRQn, 2); + + if (MYNEWT_VAL(STM32_CLOCK_HSI48)) { + RCC->CCIPR = RCC->CCIPR & ~RCC_CCIPR_CLK48SEL; + } + + /* + * Enable USB clock + */ + __HAL_RCC_USB_CLK_ENABLE(); + + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_CRC_CLK_ENABLE(); + __HAL_RCC_UCPD1_CLK_ENABLE(); + + /* Enable DMA for USB PD */ + __HAL_RCC_DMAMUX1_CLK_ENABLE(); + __HAL_RCC_DMA1_CLK_ENABLE(); +} diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32g4/syscfg.yml b/hw/usb/tinyusb/stm32_fsdev/stm32g4/syscfg.yml new file mode 100644 index 000000000..8b3d626be --- /dev/null +++ b/hw/usb/tinyusb/stm32_fsdev/stm32g4/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: 0 +