34#ifdef __PROJECT_MIKROSDK_MIKROE__
41#if CFG_TUSB_MCU == OPT_MCU_STM32F1
44 #define EP_FIFO_SIZE_FS 1280
46#elif CFG_TUSB_MCU == OPT_MCU_STM32F2
48 #define EP_MAX_FS USB_OTG_FS_MAX_IN_ENDPOINTS
49 #define EP_FIFO_SIZE_FS USB_OTG_FS_TOTAL_FIFO_SIZE
51 #define EP_MAX_HS USB_OTG_HS_MAX_IN_ENDPOINTS
52 #define EP_FIFO_SIZE_HS USB_OTG_HS_TOTAL_FIFO_SIZE
54#elif CFG_TUSB_MCU == OPT_MCU_STM32F4
56 #define EP_MAX_FS USB_OTG_FS_MAX_IN_ENDPOINTS
57 #define EP_FIFO_SIZE_FS USB_OTG_FS_TOTAL_FIFO_SIZE
59 #define EP_MAX_HS USB_OTG_HS_MAX_IN_ENDPOINTS
60 #define EP_FIFO_SIZE_HS USB_OTG_HS_TOTAL_FIFO_SIZE
62#elif CFG_TUSB_MCU == OPT_MCU_STM32H7
65 #define EP_FIFO_SIZE_FS 4096
68 #define EP_FIFO_SIZE_HS 4096
72 #if (! defined USB2_OTG_FS)
73 #define USB_OTG_FS_PERIPH_BASE USB1_OTG_HS_PERIPH_BASE
74 #define OTG_FS_IRQn OTG_HS_IRQn
77#elif CFG_TUSB_MCU == OPT_MCU_STM32F7
80 #define EP_FIFO_SIZE_FS 1280
83 #define EP_FIFO_SIZE_HS 4096
85#elif CFG_TUSB_MCU == OPT_MCU_STM32L4
86 #ifndef __PROJECT_MIKROSDK_MIKROE__
88 #include "stm32l4xx.h"
91 #define EP_FIFO_SIZE_FS 1280
93#elif CFG_TUSB_MCU == OPT_MCU_STM32U5
94 #include "stm32u5xx.h"
95 #define USB_OTG_FS_PERIPH_BASE USB_OTG_FS_BASE
97 #define EP_FIFO_SIZE_FS 1280
100 #error "Unsupported MCUs"
104#ifdef USB_OTG_HS_PERIPH_BASE
105 #define DWC2_EP_MAX EP_MAX_HS
107 #define DWC2_EP_MAX EP_MAX_FS
114#ifdef USB_OTG_FS_PERIPH_BASE
115 { .reg_base = USB_OTG_FS_PERIPH_BASE, .irqnum =
OTG_FS_IRQn, .ep_count = EP_MAX_FS, .ep_fifo_size = EP_FIFO_SIZE_FS },
118#ifdef USB_OTG_HS_PERIPH_BASE
119 { .reg_base = USB_OTG_HS_PERIPH_BASE, .irqnum =
OTG_HS_IRQn, .ep_count = EP_MAX_HS, .ep_fifo_size = EP_FIFO_SIZE_HS },
131static inline void dwc2_dcd_int_enable(uint8_t rhport)
133 NVIC_EnableIRQ((
IRQn_Type)_dwc2_controller[rhport].irqnum);
137static inline void dwc2_dcd_int_disable (uint8_t rhport)
139 NVIC_DisableIRQ((
IRQn_Type)_dwc2_controller[rhport].irqnum);
143static inline void dwc2_remote_wakeup_delay(
void)
146 uint32_t count = SystemCoreClock / 1000;
147 while ( count-- )
__NOP();
151static inline void dwc2_phy_init(
dwc2_regs_t * dwc2, uint8_t hs_phy_type)
153 if ( hs_phy_type == HS_PHY_TYPE_NONE )
156 dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN;
160 dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN;
163 if (hs_phy_type == HS_PHY_TYPE_UTMI || hs_phy_type == HS_PHY_TYPE_UTMI_ULPI)
167 dwc2->stm32_gccfg |= STM32_GCCFG_PHYHSEN;
170 USB_HS_PHYC->USB_HS_PHYC_LDO |= USB_HS_PHYC_LDO_ENABLE;
173 while ( 0 == (USB_HS_PHYC->USB_HS_PHYC_LDO & USB_HS_PHYC_LDO_STATUS) ) {}
175 uint32_t phyc_pll = 0;
180 case 12000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12MHZ ;
break;
181 case 12500000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12_5MHZ ;
break;
182 case 16000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_16MHZ ;
break;
183 case 24000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_24MHZ ;
break;
184 case 25000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_25MHZ ;
break;
185 case 32000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_Msk ;
break;
189 USB_HS_PHYC->USB_HS_PHYC_PLL = phyc_pll;
193 USB_HS_PHYC->USB_HS_PHYC_TUNE |= 0x00000F13U;
196 USB_HS_PHYC->USB_HS_PHYC_PLL |= USB_HS_PHYC_PLL_PLLEN;
203static inline void dwc2_phy_update(
dwc2_regs_t * dwc2, uint8_t hs_phy_type)
206 if ( hs_phy_type == HS_PHY_TYPE_NONE )
211 if ( SystemCoreClock >= 32000000u )
213 else if ( SystemCoreClock >= 27500000u )
215 else if ( SystemCoreClock >= 24000000u )
217 else if ( SystemCoreClock >= 21800000u )
219 else if ( SystemCoreClock >= 20000000u )
221 else if ( SystemCoreClock >= 18500000u )
223 else if ( SystemCoreClock >= 17200000u )
225 else if ( SystemCoreClock >= 16000000u )
227 else if ( SystemCoreClock >= 15000000u )
232 dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_TRDT_Msk) | (turnaround << GUSBCFG_TRDT_Pos);
#define __NOP()
No Operation.
Definition cmsis_gcc.h:903
IRQn_Type
STM32F10x Interrupt Number Definition, according to the selected device in Library_configuration_sect...
Definition stm32f107xc.h:70
@ OTG_FS_IRQn
Definition stm32f107xc.h:143
@ OTG_HS_IRQn
Definition stm32f207xx.h:155
CMSIS STM32F1xx Device Peripheral Access Layer Header File.
#define HSE_VALUE
Adjust the value of External High Speed oscillator (HSE) used in your application....
Definition stm32f1xx_hal_conf.h:95
CMSIS STM32F2xx Device Peripheral Access Layer Header File.
CMSIS STM32F4xx Device Peripheral Access Layer Header File.
CMSIS STM32F7xx Device Peripheral Access Layer Header File.
CMSIS STM32H7xx Device Peripheral Access Layer Header File.
Definition dwc2_type.h:28
Definition dwc2_type.h:191