mikroSDK Reference Manual
dwc2_efm32.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2021 Rafael Silva (@perigoso)
5 * Copyright (c) 2021, Ha Thach (tinyusb.org)
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 * This file is part of the TinyUSB stack.
26 */
27
28#ifndef _DWC2_EFM32_H_
29#define _DWC2_EFM32_H_
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35#include "em_device.h"
36
37// EFM32 has custom control register before DWC registers
38#define DWC2_REG_BASE (USB_BASE + offsetof(USB_TypeDef, GOTGCTL))
39#define DWC2_EP_MAX 7
40
41static const dwc2_controller_t _dwc2_controller[] =
42{
43 { .reg_base = DWC2_REG_BASE, .irqnum = USB_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 2048 }
44};
45
46TU_ATTR_ALWAYS_INLINE
47static inline void dwc2_dcd_int_enable(uint8_t rhport)
48{
49 NVIC_EnableIRQ(_dwc2_controller[rhport].irqnum);
50}
51
52TU_ATTR_ALWAYS_INLINE
53static inline void dwc2_dcd_int_disable (uint8_t rhport)
54{
55 NVIC_DisableIRQ(_dwc2_controller[rhport].irqnum);
56}
57
58static inline void dwc2_remote_wakeup_delay(void)
59{
60 // try to delay for 1 ms
61// uint32_t count = SystemCoreClock / 1000;
62// while ( count-- ) __NOP();
63}
64
65// MCU specific PHY init, called BEFORE core reset
66static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
67{
68 (void) dwc2;
69 (void) hs_phy_type;
70
71 // Enable PHY
72 USB->ROUTE = USB_ROUTE_PHYPEN;
73}
74
75// MCU specific PHY update, it is called AFTER init() and core reset
76static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
77{
78 (void) dwc2;
79 (void) hs_phy_type;
80
81 // EFM32 Manual: turn around must be 5 (reset & default value)
82 // dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_TRDT_Msk) | (5u << GUSBCFG_TRDT_Pos);
83}
84
85#ifdef __cplusplus
86}
87#endif
88
89#endif
Definition dwc2_type.h:28
Definition dwc2_type.h:191