4646//--------------------------------------------------------------------+
4747// MACRO TYPEDEF CONSTANT ENUM
4848//--------------------------------------------------------------------+
49-
50- static CFG_TUD_MEM_SECTION TU_ATTR_ALIGNED (4 ) uint32_t _setup_packet [2 ];
49+ static CFG_TUD_MEM_SECTION CFG_TUD_MEM_ALIGN uint32_t _setup_packet [2 ];
5150
5251typedef struct {
5352 uint8_t * buffer ;
@@ -73,6 +72,25 @@ static bool _sof_en;
7372//--------------------------------------------------------------------
7473// DMA
7574//--------------------------------------------------------------------
75+ #if DWC2_ENABLE_MEM_CACHE
76+ void dcd_dcache_clean (const void * addr , uint32_t data_size ) {
77+ if (addr && data_size ) {
78+ dwc2_dcache_clean (addr , data_size );
79+ }
80+ }
81+
82+ void dcd_dcache_invalidate (const void * addr , uint32_t data_size ) {
83+ if (addr && data_size ) {
84+ dwc2_dcache_invalidate (addr , data_size );
85+ }
86+ }
87+
88+ void dcd_dcache_clean_invalidate (const void * addr , uint32_t data_size ) {
89+ if (addr && data_size ) {
90+ dwc2_dcache_clean_invalidate (addr , data_size );
91+ }
92+ }
93+ #endif
7694
7795TU_ATTR_ALWAYS_INLINE static inline bool dma_device_enabled (const dwc2_regs_t * dwc2 ) {
7896 (void ) dwc2 ;
@@ -180,7 +198,7 @@ static bool dfifo_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t packet_size) {
180198 // Check if free space is available
181199 TU_ASSERT (_dfifo_top >= fifo_size + dwc2 -> grxfsiz );
182200 _dfifo_top -= fifo_size ;
183- TU_LOG (DWC2_DEBUG , " TX FIFO %u: allocated %u words at offset %u\r\n" , epnum , fifo_size , _dfifo_top );
201+ // TU_LOG(DWC2_DEBUG, " TX FIFO %u: allocated %u words at offset %u\r\n", epnum, fifo_size, _dfifo_top);
184202
185203 // Both TXFD and TXSA are in unit of 32-bit words.
186204 if (epnum == 0 ) {
@@ -348,14 +366,18 @@ static void edpt_schedule_packets(uint8_t rhport, const uint8_t epnum, const uin
348366
349367 const bool is_dma = dma_device_enabled (dwc2 );
350368 if (is_dma ) {
369+ if (dir == TUSB_DIR_IN && total_bytes != 0 ) {
370+ dcd_dcache_clean (xfer -> buffer , total_bytes );
371+ }
351372 dep -> diepdma = (uintptr_t ) xfer -> buffer ;
352- }
353-
354- dep -> diepctl = depctl .value ; // enable endpoint
373+ dep -> diepctl = depctl . value ; // enable endpoint
374+ } else {
375+ dep -> diepctl = depctl .value ; // enable endpoint
355376
356- // Slave: enable tx fifo empty interrupt only if there is data. Note must after depctl enable
357- if (!is_dma && dir == TUSB_DIR_IN && total_bytes != 0 ) {
358- dwc2 -> diepempmsk |= (1 << epnum );
377+ // Enable tx fifo empty interrupt only if there is data. Note must after depctl enable
378+ if (dir == TUSB_DIR_IN && total_bytes != 0 ) {
379+ dwc2 -> diepempmsk |= (1 << epnum );
380+ }
359381 }
360382}
361383
@@ -847,6 +869,7 @@ static void handle_epout_dma(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepi
847869
848870 if (doepint_bm .setup_phase_done ) {
849871 dma_setup_prepare (rhport );
872+ dcd_dcache_invalidate (_setup_packet , 8 );
850873 dcd_event_setup_received (rhport , (uint8_t * ) _setup_packet , true);
851874 return ;
852875 }
@@ -873,6 +896,7 @@ static void handle_epout_dma(uint8_t rhport, uint8_t epnum, dwc2_doepint_t doepi
873896 dma_setup_prepare (rhport );
874897 }
875898
899+ dcd_dcache_invalidate (xfer -> buffer , xfer -> total_len );
876900 dcd_event_xfer_complete (rhport , epnum , xfer -> total_len , XFER_RESULT_SUCCESS , true);
877901 }
878902 }
0 commit comments