Skip to content

Commit 2571889

Browse files
authored
Merge pull request #2883 from hathach/feature/esp32p4_dma_cache_syncronization
[DCD_DWC2][ESP32P4][HS] Added cache synchronization (cont)
2 parents 9e674d4 + c61b55b commit 2571889

File tree

8 files changed

+181
-61
lines changed

8 files changed

+181
-61
lines changed

hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ list(APPEND compile_definitions
1515
BOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED}
1616
)
1717

18+
if (target STREQUAL esp32p4)
19+
# P4 change alignment to 64 (DCache line size) for possible DMA configuration
20+
list(APPEND compile_definitions
21+
CFG_TUSB_MEM_ALIGN=__attribute__\(\(aligned\(64\)\)\)
22+
)
23+
endif ()
24+
1825
list(APPEND srcs
1926
# common
2027
${tusb_src}/tusb.c
@@ -68,6 +75,7 @@ endif()
6875
idf_component_register(SRCS ${srcs}
6976
INCLUDE_DIRS ${tusb_src}
7077
REQUIRES src
78+
PRIV_REQUIRES esp_mm
7179
)
7280

7381
target_compile_definitions(${COMPONENT_LIB} PUBLIC ${compile_definitions})

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/device/dcd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ typedef struct TU_ATTR_ALIGNED(4) {
9393

9494
// clean/flush data cache: write cache -> memory.
9595
// Required before an DMA TX transfer to make sure data is in memory
96-
void dcd_dcache_clean(void const* addr, uint32_t data_size) TU_ATTR_WEAK;
96+
void dcd_dcache_clean(const void* addr, uint32_t data_size);
9797

9898
// invalidate data cache: mark cache as invalid, next read will read from memory
9999
// Required BOTH before and after an DMA RX transfer
100-
void dcd_dcache_invalidate(void const* addr, uint32_t data_size) TU_ATTR_WEAK;
100+
void dcd_dcache_invalidate(const void* addr, uint32_t data_size);
101101

102102
// clean and invalidate data cache
103103
// Required before an DMA transfer where memory is both read/write by DMA
104-
void dcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_WEAK;
104+
void dcd_dcache_clean_invalidate(const void* addr, uint32_t data_size);
105105

106106
//--------------------------------------------------------------------+
107107
// Controller API

src/device/usbd.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
// Weak stubs: invoked if no strong implementation is available
4747
//--------------------------------------------------------------------+
4848
TU_ATTR_WEAK void tud_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) {
49-
(void) rhport;
50-
(void) eventid;
51-
(void) in_isr;
49+
(void) rhport; (void) eventid; (void) in_isr;
5250
}
5351

5452
TU_ATTR_WEAK void tud_sof_cb(uint32_t frame_count) {
@@ -82,9 +80,7 @@ TU_ATTR_WEAK void tud_resume_cb(void) {
8280
}
8381

8482
TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const* request) {
85-
(void) rhport;
86-
(void) stage;
87-
(void) request;
83+
(void) rhport; (void) stage; (void) request;
8884
return false;
8985
}
9086

@@ -101,6 +97,18 @@ TU_ATTR_WEAK void dcd_disconnect(uint8_t rhport) {
10197
(void) rhport;
10298
}
10399

100+
TU_ATTR_WEAK void dcd_dcache_clean(const void* addr, uint32_t data_size) {
101+
(void) addr; (void) data_size;
102+
}
103+
104+
TU_ATTR_WEAK void dcd_dcache_invalidate(const void* addr, uint32_t data_size) {
105+
(void) addr; (void) data_size;
106+
}
107+
108+
TU_ATTR_WEAK void dcd_dcache_clean_invalidate(const void* addr, uint32_t data_size) {
109+
(void) addr; (void) data_size;
110+
}
111+
104112
//--------------------------------------------------------------------+
105113
// Device Data
106114
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)