Skip to content

Commit b3b8bd8

Browse files
committed
add CFG_TUD_MEM_DCACHE_ENABLE, CFG_TUD_MEM_DCACHE_LINE_SIZE option
1 parent 4da5de7 commit b3b8bd8

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

src/common/tusb_mcu.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,18 @@
361361
#define TUP_USBIP_DWC2_ESP32
362362
#define TUP_RHPORT_HIGHSPEED 1 // port0 FS, port1 HS
363363
#define TUP_DCD_ENDPOINT_MAX 16 // FS 7 ep, HS 16 ep
364+
365+
#if defined(CFG_TUD_DWC2_DMA_ENABLE) && CFG_TUD_DWC2_DMA_ENABLE == 1
366+
#define CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT 1
367+
#endif
368+
369+
#if defined(CFG_TUH_DWC2_DMA_ENABLE) && CFG_TUH_DWC2_DMA_ENABLE == 1
370+
#define CFG_TUH_MEM_DCACHE_ENABLE_DEFAULT 1
371+
#endif
372+
373+
#define CFG_TUD_MEM_DCACHE_LINE_SIZE 64
374+
#define CFG_TUH_MEM_DCACHE_LINE_SIZE 64
375+
364376
#define CFG_TUH_DWC2_DMA_ENABLE_DEFAULT 0 // TODO currently have issue with buffer DMA with espressif
365377

366378
#elif TU_CHECK_MCU(OPT_MCU_ESP32, OPT_MCU_ESP32C2, OPT_MCU_ESP32C3, OPT_MCU_ESP32C6, OPT_MCU_ESP32H2)

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static bool _sof_en;
7272
//--------------------------------------------------------------------
7373
// DMA
7474
//--------------------------------------------------------------------
75-
#if DWC2_ENABLE_MEM_CACHE
75+
#if CFG_TUD_MEM_DCACHE_ENABLE
7676
void dcd_dcache_clean(const void* addr, uint32_t data_size) {
7777
if (addr && data_size) {
7878
dwc2_dcache_clean(addr, data_size);

src/portable/synopsys/dwc2/dwc2_esp32.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint
114114
//--------------------------------------------------------------------+
115115
// Data Cache
116116
//--------------------------------------------------------------------+
117+
#if CFG_TUD_DWC2_DMA_ENABLE || CFG_TUH_DWC2_DMA_ENABLE
117118
#if defined(SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE) && SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
118-
#include "sdkconfig.h"
119119
#include "hal/cache_hal.h"
120120
#include "esp_cache.h"
121-
#include "esp_log.h"
122121

123-
#define DWC2_MEM_CACHE_LINE_SIZE CONFIG_CACHE_L1_CACHE_LINE_SIZE
124-
#define DWC2_ENABLE_MEM_CACHE 1
122+
#if CFG_TUD_MEM_DCACHE_LINE_SIZE != CONFIG_CACHE_L1_CACHE_LINE_SIZE || \
123+
CFG_TUH_MEM_DCACHE_LINE_SIZE != CONFIG_CACHE_L1_CACHE_LINE_SIZE
124+
#error "CFG_TUD/TUH_MEM_DCACHE_LINE_SIZE must match CONFIG_CACHE_L1_CACHE_LINE_SIZE"
125+
#endif
125126

126127
TU_ATTR_ALWAYS_INLINE static inline uint32_t round_up_to_cache_line_size(uint32_t size) {
127128
if (size & (CONFIG_CACHE_L1_CACHE_LINE_SIZE-1)) {
@@ -131,29 +132,25 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t round_up_to_cache_line_size(uint32_
131132
}
132133

133134
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcache_clean(const void* addr, uint32_t data_size) {
134-
// round up to cache line size
135135
const int flag = ESP_CACHE_MSYNC_FLAG_TYPE_DATA | ESP_CACHE_MSYNC_FLAG_DIR_C2M;
136136
data_size = round_up_to_cache_line_size(data_size);
137-
//ESP_EARLY_LOGI("ESP32_DWC", "dcache clean, addr 0x%"PRIx32", size %d (%s)", (uintptr_t)addr, data_size);
138137
assert(ESP_OK == esp_cache_msync((void*)addr, data_size, flag));
139138
}
140139

141140
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcache_invalidate(const void* addr, uint32_t data_size) {
142141
const int flag = ESP_CACHE_MSYNC_FLAG_TYPE_DATA | ESP_CACHE_MSYNC_FLAG_DIR_M2C;
143142
data_size = round_up_to_cache_line_size(data_size);
144-
//ESP_EARLY_LOGI("ESP32_DWC", "dcache invalidate, addr 0x%"PRIx32", size %d (%s)", (uintptr_t)addr, data_size);
145143
assert(ESP_OK == esp_cache_msync((void*)addr, data_size, flag));
146144
}
147145

148146
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcache_clean_invalidate(const void* addr, uint32_t data_size) {
149147
const int flag = ESP_CACHE_MSYNC_FLAG_TYPE_DATA | ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_DIR_M2C;
150148
data_size = round_up_to_cache_line_size(data_size);
151-
//ESP_EARLY_LOGI("ESP32_DWC", "dcache clean_invalidate, addr 0x%"PRIx32", size %d (%s)", (uintptr_t)addr, data_size);
152149
assert(ESP_OK == esp_cache_msync((void*)addr, data_size, flag));
153150
}
154151

155-
#endif // SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
156-
152+
#endif
153+
#endif
157154

158155
#ifdef __cplusplus
159156
}

src/tusb_option.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
#ifndef CFG_TUH_DWC2_SLAVE_ENABLE_DEFAULT
267267
#define CFG_TUH_DWC2_SLAVE_ENABLE_DEFAULT 1
268268
#endif
269+
269270
#define CFG_TUH_DWC2_SLAVE_ENABLE CFG_TUH_DWC2_SLAVE_ENABLE_DEFAULT
270271
#endif
271272

@@ -274,6 +275,7 @@
274275
#ifndef CFG_TUH_DWC2_DMA_ENABLE_DEFAULT
275276
#define CFG_TUH_DWC2_DMA_ENABLE_DEFAULT 1
276277
#endif
278+
277279
#define CFG_TUH_DWC2_DMA_ENABLE CFG_TUH_DWC2_DMA_ENABLE_DEFAULT
278280
#endif
279281

@@ -422,6 +424,18 @@
422424
#define CFG_TUD_MEM_ALIGN CFG_TUSB_MEM_ALIGN
423425
#endif
424426

427+
#ifndef CFG_TUD_MEM_DCACHE_ENABLE
428+
#ifndef CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT
429+
#define CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT 0
430+
#endif
431+
432+
#define CFG_TUD_MEM_DCACHE_ENABLE CFG_TUD_MEM_DCACHE_ENABLE_DEFAULT
433+
#endif
434+
435+
#ifndef CFG_TUD_MEM_DCACHE_LINE_SIZE
436+
#define CFG_TUD_MEM_DCACHE_LINE_SIZE 32
437+
#endif
438+
425439
#ifndef CFG_TUD_ENDPOINT0_SIZE
426440
#define CFG_TUD_ENDPOINT0_SIZE 64
427441
#endif

0 commit comments

Comments
 (0)