Skip to content

Commit 40ea42a

Browse files
committed
feature(dcd_dwc): Proceed implment cache synchronization
1 parent 321b66e commit 40ea42a

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ TU_ATTR_ALWAYS_INLINE static inline dwc2_regs_t* DWC2_REG(uint8_t rhport) {
7979
// MACRO TYPEDEF CONSTANT ENUM
8080
//--------------------------------------------------------------------+
8181

82-
#include "esp_attr.h"
83-
84-
// static CFG_TUD_MEM_SECTION TU_ATTR_ALIGNED(4) uint32_t _setup_packet[2];
85-
static DRAM_DMA_ALIGNED_ATTR TU_ATTR_ALIGNED(4) uint32_t _setup_packet[2];
82+
static CFG_TUD_MEM_SECTION TU_ATTR_ALIGNED(4) uint32_t _setup_packet[2];
8683

8784
typedef struct {
8885
uint8_t* buffer;
@@ -510,7 +507,9 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
510507

511508
if(dma_enabled(dwc2)) {
512509
dep->doepdma = (uintptr_t)xfer->buffer;
513-
// dwc2_dcd_sync_cache_to_memory(xfer->buffer, total_bytes);
510+
if (total_bytes != 0) {
511+
dwc2_dcd_sync_cache_to_memory(xfer->buffer, total_bytes);
512+
}
514513
}
515514

516515
dep->doepctl |= DOEPCTL_EPENA | DOEPCTL_CNAK;
@@ -1083,7 +1082,9 @@ static void handle_epout_irq(uint8_t rhport) {
10831082
if(epnum == 0 && xfer->total_len == 0) {
10841083
dma_setup_prepare(rhport);
10851084
}
1086-
1085+
if (xfer->total_len) {
1086+
dwc2_dcd_sync_memory_to_cache(xfer->buffer, xfer->total_len);
1087+
}
10871088
dcd_event_xfer_complete(rhport, epnum, xfer->total_len, XFER_RESULT_SUCCESS, true);
10881089
}
10891090
} else {

src/portable/synopsys/dwc2/dwc2_esp32.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#if TU_CHECK_MCU(OPT_MCU_ESP32P4)
4343
#if SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
44+
#include "sdkconfig.h"
4445
#include "hal/cache_hal.h"
4546
#include "esp_cache.h"
4647
#define DWC2_ENABLE_MEM_CACHE 1
@@ -106,7 +107,7 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint
106107
// MCU specific cache synchronization call
107108
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_sync_cache_to_memory(void *addr, size_t size) {
108109
#if DWC2_ENABLE_MEM_CACHE
109-
ESP_EARLY_LOGW("dwc2_esp32", "cache to mem sync, addr 0x%"PRIx32", size %d", (uintptr_t)addr, size);
110+
ESP_EARLY_LOGV("dwc2_esp32", "cache to mem sync, addr 0x%"PRIx32", size %d", (uintptr_t)addr, size);
110111
int flags = ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_UNALIGNED;
111112
esp_err_t ret = esp_cache_msync(addr, size, flags);
112113
assert(ret == ESP_OK);
@@ -120,8 +121,9 @@ TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_sync_cache_to_memory(void *add
120121
TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_sync_memory_to_cache(void *addr, size_t size) {
121122
#if DWC2_ENABLE_MEM_CACHE
122123
int flags = ESP_CACHE_MSYNC_FLAG_DIR_M2C;
123-
size = (size < 0x40)? 0x40 : size;
124-
ESP_EARLY_LOGW("dwc2", "mem to cache sync, addr 0x%"PRIx32", size %d", (uintptr_t)addr, size);
124+
ESP_EARLY_LOGV("dwc2", "mem to cache sync, addr 0x%"PRIx32", size %d", (uintptr_t)addr, size);
125+
// TODO: size should be multiply of CONFIG_CACHE_L1_CACHE_LINE_SIZE?
126+
size = (size < CONFIG_CACHE_L1_CACHE_LINE_SIZE)? CONFIG_CACHE_L1_CACHE_LINE_SIZE : size;
125127
esp_err_t ret = esp_cache_msync(addr, size, flags);
126128
assert(ret == ESP_OK);
127129
#else

src/tusb_option.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
// For example, on Cortex-M7 the MPU region can be configured as normal
251251
// non-cacheable, with RASR register value: TEX=1 C=0 B=0 S=0.
252252
#ifndef CFG_TUD_DWC2_DMA
253-
#define CFG_TUD_DWC2_DMA 1
253+
#define CFG_TUD_DWC2_DMA 0
254254
#endif
255255

256256
// Enable PIO-USB software host controller

0 commit comments

Comments
 (0)