@@ -101,19 +101,6 @@ static uint16_t _allocated_fifo_words_tx; // TX FIFO size in words (IN EPs)
101
101
// SOF enabling flag - required for SOF to not get disabled in ISR when SOF was enabled by
102
102
static bool _sof_en ;
103
103
104
- static inline void fifo_flush (uint8_t rhport )
105
- {
106
- dwc2_regs_t * dwc2 = DWC2_REG (rhport );
107
-
108
- // flush all TX fifo and wait for it cleared
109
- dwc2 -> grstctl = GRSTCTL_TXFFLSH | (0x10u << GRSTCTL_TXFNUM_Pos );
110
- while (dwc2 -> grstctl & GRSTCTL_TXFFLSH_Msk ) {}
111
-
112
- // flush RX fifo and wait for it cleared
113
- dwc2 -> grstctl = GRSTCTL_RXFFLSH ;
114
- while (dwc2 -> grstctl & GRSTCTL_RXFFLSH_Msk ) {}
115
- }
116
-
117
104
// Calculate the RX FIFO size according to minimum recommendations from reference manual
118
105
// RxFIFO = (5 * number of control endpoints + 8) +
119
106
// ((largest USB packet used / 4) + 1 for status information) +
@@ -125,6 +112,17 @@ static inline uint16_t calc_grxfsiz(uint16_t max_ep_size, uint8_t ep_count) {
125
112
return 15 + 2 * (max_ep_size / 4 ) + 2 * ep_count ;
126
113
}
127
114
115
+ TU_ATTR_ALWAYS_INLINE static inline void fifo_flush_tx (dwc2_regs_t * dwc2 , uint8_t epnum ) {
116
+ // flush TX fifo and wait for it cleared
117
+ dwc2 -> grstctl = GRSTCTL_TXFFLSH | (epnum << GRSTCTL_TXFNUM_Pos );
118
+ while (dwc2 -> grstctl & GRSTCTL_TXFFLSH_Msk ) {}
119
+ }
120
+ TU_ATTR_ALWAYS_INLINE static inline void fifo_flush_rx (dwc2_regs_t * dwc2 ) {
121
+ // flush RX fifo and wait for it cleared
122
+ dwc2 -> grstctl = GRSTCTL_RXFFLSH ;
123
+ while (dwc2 -> grstctl & GRSTCTL_RXFFLSH_Msk ) {}
124
+ }
125
+
128
126
static bool fifo_alloc (uint8_t rhport , uint8_t ep_addr , uint16_t packet_size ) {
129
127
dwc2_regs_t * dwc2 = DWC2_REG (rhport );
130
128
uint8_t const ep_count = _dwc2_controller [rhport ].ep_count ;
@@ -238,8 +236,7 @@ static void edpt_disable(uint8_t rhport, uint8_t ep_addr, bool stall) {
238
236
}
239
237
240
238
// Flush the FIFO, and wait until we have confirmed it cleared.
241
- dwc2 -> grstctl = ((epnum << GRSTCTL_TXFNUM_Pos ) | GRSTCTL_TXFFLSH );
242
- while ((dwc2 -> grstctl & GRSTCTL_TXFFLSH_Msk ) != 0 ) {}
239
+ fifo_flush_tx (dwc2 , epnum );
243
240
} else {
244
241
dwc2_epout_t * epout = dwc2 -> epout ;
245
242
@@ -283,7 +280,8 @@ static void bus_reset(uint8_t rhport) {
283
280
dwc2 -> epout [n ].doepctl |= DOEPCTL_SNAK ;
284
281
}
285
282
286
- fifo_flush (rhport );
283
+ fifo_flush_tx (dwc2 , 0x10 ); // all tx fifo
284
+ fifo_flush_rx (dwc2 );
287
285
288
286
// 2. Set up interrupt mask
289
287
dwc2 -> daintmsk = TU_BIT (DAINTMSK_OEPM_Pos ) | TU_BIT (DAINTMSK_IEPM_Pos );
@@ -591,7 +589,8 @@ void dcd_init(uint8_t rhport) {
591
589
// (non zero-length packet), send STALL back and discard.
592
590
dwc2 -> dcfg |= DCFG_NZLSOHSK ;
593
591
594
- fifo_flush (rhport );
592
+ fifo_flush_tx (dwc2 , 0x10 ); // all tx fifo
593
+ fifo_flush_rx (dwc2 );
595
594
596
595
// Clear all interrupts
597
596
uint32_t int_mask = dwc2 -> gintsts ;
@@ -714,7 +713,8 @@ void dcd_edpt_close_all(uint8_t rhport) {
714
713
// reset allocated fifo IN
715
714
_allocated_fifo_words_tx = 16 ;
716
715
717
- fifo_flush (rhport );
716
+ fifo_flush_tx (dwc2 , 0x10 ); // all tx fifo
717
+ fifo_flush_rx (dwc2 );
718
718
}
719
719
720
720
bool dcd_edpt_iso_alloc (uint8_t rhport , uint8_t ep_addr , uint16_t largest_packet_size ) {
0 commit comments