Skip to content

Commit a6efc7d

Browse files
authored
Merge pull request #3319 from peppapighs/dwc2-usbsuspm
dcd/dwc2: fix suspend interrupt indefinitely disabled on AT32F405
2 parents 96d5109 + 80309e4 commit a6efc7d

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,8 @@ void dcd_int_handler(uint8_t rhport) {
10541054
if (gintsts & GINTSTS_ENUMDNE) {
10551055
// ENUMDNE is the end of reset where speed of the link is detected
10561056
dwc2->gintsts = GINTSTS_ENUMDNE;
1057+
// There may be a pending suspend event, so we clear it first
1058+
dwc2->gintsts = GINTSTS_USBSUSP;
10571059
dwc2->gintmsk |= GINTMSK_USBSUSPM;
10581060
handle_enum_done(rhport);
10591061
}

src/portable/synopsys/dwc2/dwc2_at32.h

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -64,58 +64,59 @@
6464
#endif
6565

6666
#ifdef __cplusplus
67-
extern "C" {
67+
extern "C" {
6868
#endif
6969

70-
static const dwc2_controller_t _dwc2_controller[] = {
71-
{.reg_base = DWC2_OTG1_REG_BASE, .irqnum = OTG1_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = OTG1_FIFO_SIZE},
70+
static const dwc2_controller_t _dwc2_controller[] = {
71+
{.reg_base = DWC2_OTG1_REG_BASE, .irqnum = OTG1_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = OTG1_FIFO_SIZE},
7272
#if defined DWC2_OTG2_REG_BASE
73-
{.reg_base = DWC2_OTG2_REG_BASE, .irqnum = OTG2_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = OTG2_FIFO_SIZE}
73+
{.reg_base = DWC2_OTG2_REG_BASE, .irqnum = OTG2_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = OTG2_FIFO_SIZE}
7474
#endif
75-
};
75+
};
7676

77-
TU_ATTR_ALWAYS_INLINE static inline void dwc2_int_set(uint8_t rhport, tusb_role_t role, bool enabled) {
78-
(void) role;
79-
const IRQn_Type irqn = (IRQn_Type) _dwc2_controller[rhport].irqnum;
80-
if (enabled) {
81-
NVIC_EnableIRQ(irqn);
82-
} else {
83-
NVIC_DisableIRQ(irqn);
84-
}
85-
}
77+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_int_set(uint8_t rhport, tusb_role_t role, bool enabled) {
78+
(void) role;
79+
const IRQn_Type irqn = (IRQn_Type) _dwc2_controller[rhport].irqnum;
80+
if (enabled) {
81+
NVIC_EnableIRQ(irqn);
82+
} else {
83+
NVIC_DisableIRQ(irqn);
84+
}
85+
}
8686

87-
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_enable(uint8_t rhport) { NVIC_EnableIRQ(_dwc2_controller[rhport].irqnum);
88-
}
87+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_enable(uint8_t rhport) {
88+
NVIC_EnableIRQ(_dwc2_controller[rhport].irqnum);
89+
}
8990

90-
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_disable(uint8_t rhport) {
91-
NVIC_DisableIRQ(_dwc2_controller[rhport].irqnum);
92-
}
91+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_disable(uint8_t rhport) {
92+
NVIC_DisableIRQ(_dwc2_controller[rhport].irqnum);
93+
}
9394

94-
TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
95-
// try to delay for 1 ms
96-
uint32_t count = system_core_clock / 1000;
97-
while (count--) __asm volatile("nop");
98-
}
95+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
96+
// try to delay for 1 ms
97+
uint32_t count = system_core_clock / 1000;
98+
while (count--) __asm volatile("nop");
99+
}
99100

100-
// MCU specific PHY init, called BEFORE core reset
101-
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t *dwc2, uint8_t hs_phy_type) {
102-
(void) dwc2;
103-
// Enable on-chip HS PHY
104-
if (hs_phy_type == GHWCFG2_HSPHY_UTMI || hs_phy_type == GHWCFG2_HSPHY_UTMI_ULPI) {
105-
} else if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) {
106-
}
107-
}
101+
// MCU specific PHY init, called BEFORE core reset
102+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t *dwc2, uint8_t hs_phy_type) {
103+
(void) dwc2;
104+
// Enable on-chip HS PHY
105+
if (hs_phy_type == GHWCFG2_HSPHY_UTMI || hs_phy_type == GHWCFG2_HSPHY_UTMI_ULPI) {
106+
} else if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) {
107+
}
108+
}
108109

109-
// MCU specific PHY update, it is called AFTER init() and core reset
110-
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_update(dwc2_regs_t *dwc2, uint8_t hs_phy_type) {
111-
(void) dwc2;
112-
(void) hs_phy_type;
110+
// MCU specific PHY update, it is called AFTER init() and core reset
111+
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_update(dwc2_regs_t *dwc2, uint8_t hs_phy_type) {
112+
(void) dwc2;
113+
(void) hs_phy_type;
113114

114-
dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN | STM32_GCCFG_DCDEN | STM32_GCCFG_PDEN;
115-
}
115+
dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN | STM32_GCCFG_DCDEN | STM32_GCCFG_PDEN;
116+
}
116117

117118
#ifdef __cplusplus
118119
}
119120
#endif
120121

121-
#endif /* DWC2_GD32_H_ */
122+
#endif /* DWC2_AT32_H_ */

0 commit comments

Comments
 (0)