Skip to content

Commit cc19c02

Browse files
committed
dwc2: wait for ahb idle before core reset
1 parent f674561 commit cc19c02

File tree

8 files changed

+85
-7
lines changed

8 files changed

+85
-7
lines changed

.idea/debugServers/AT32F423VCT7.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/debugServers/ST_LINK.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/debugServers/at32f403acgu7.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/debugServers/max32690.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/debugServers/s3.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/debugServers/wch_riscv.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/tusb_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_high(uint16_t ui16) { return
168168
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t ui16) { return TU_U16_LOW(ui16); }
169169

170170
//------------- Bits -------------//
171-
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_bit_set (uint32_t value, uint8_t pos) { return value | TU_BIT(pos); }
172-
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_bit_clear(uint32_t value, uint8_t pos) { return value & (~TU_BIT(pos)); }
171+
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_bit_set (uint32_t value, uint8_t pos) { return value | TU_BIT(pos); }
172+
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_bit_clear(uint32_t value, uint8_t pos) { return value & (~TU_BIT(pos)); }
173173
TU_ATTR_ALWAYS_INLINE static inline bool tu_bit_test (uint32_t value, uint8_t pos) { return (value & TU_BIT(pos)) ? true : false; }
174174

175175
//------------- Min -------------//

src/portable/synopsys/dwc2/dwc2_common.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,26 @@
4545
//
4646
//--------------------------------------------------------------------
4747
static void reset_core(dwc2_regs_t* dwc2) {
48+
// The software must check that bit 31 in this register is set to 1 (AHB Master is Idle) before starting any operation
49+
while (!(dwc2->grstctl & GRSTCTL_AHBIDL)) {
50+
}
51+
4852
// load gsnpsid (it is not readable after reset is asserted)
49-
uint32_t gsnpsid = dwc2->gsnpsid;
53+
const uint32_t gsnpsid = dwc2->gsnpsid;
5054

5155
// reset core
5256
dwc2->grstctl |= GRSTCTL_CSRST;
5357

5458
if ((gsnpsid & DWC2_CORE_REV_MASK) < (DWC2_CORE_REV_4_20a & DWC2_CORE_REV_MASK)) {
55-
// prior v4.20a CSRST is self-clearing
59+
// prior v4.20a: CSRST is self-clearing and the core clears this bit after all the necessary logic is reset in
60+
// the core, which can take several clocks, depending on the current state of the core. Once this bit has been
61+
// cleared, the software must wait at least 3 PHY clocks before accessing the PHY domain (synchronization delay).
5662
while (dwc2->grstctl & GRSTCTL_CSRST) {}
5763
} else {
58-
// From v4.20a CSRST bit is write only, CSRT_DONE (w1c) is introduced for checking.
59-
// CSRST must also be explicitly cleared
64+
// From v4.20a: CSRST bit is write only. The application must clear this bit after checking the bit 29 of this
65+
// register i.e Core Soft Reset Done CSRT_DONE (w1c)
6066
while (!(dwc2->grstctl & GRSTCTL_CSRST_DONE)) {}
61-
dwc2->grstctl = (dwc2->grstctl & ~GRSTCTL_CSRST) | GRSTCTL_CSRST_DONE;
67+
dwc2->grstctl = (dwc2->grstctl & ~GRSTCTL_CSRST) | GRSTCTL_CSRST_DONE;
6268
}
6369

6470
while (!(dwc2->grstctl & GRSTCTL_AHBIDL)) {} // wait for AHB master IDLE

0 commit comments

Comments
 (0)