Skip to content

Commit a52ebd2

Browse files
committed
update(port/dwc2): add dcache api for esp & st
Signed-off-by: sakumisu <[email protected]>
1 parent 0422bb8 commit a52ebd2

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

osal/idf/usb_config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,15 @@
334334
#define CONFIG_USB_HS
335335
#else
336336
#error "Unsupported SoC"
337+
#endif
338+
339+
#if CONFIG_IDF_TARGET_ESP32P4
340+
#define CONFIG_USB_DCACHE_ENABLE
341+
342+
#undef CONFIG_USB_ALIGN_SIZE
343+
#define CONFIG_USB_ALIGN_SIZE 32
344+
345+
void usb_dcache_clean(uintptr_t addr, uint32_t size);
346+
void usb_dcache_invalidate(uintptr_t addr, uint32_t size);
347+
void usb_dcache_flush(uintptr_t addr, uint32_t size);
337348
#endif

port/dwc2/usb_glue_esp.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
#include "usbh_core.h"
1515

1616
#ifdef CONFIG_IDF_TARGET_ESP32S2
17-
#define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
17+
#define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
1818
#define DEFAULT_USB_INTR_SOURCE ETS_USB_INTR_SOURCE
1919
#elif CONFIG_IDF_TARGET_ESP32S3
20-
#define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
20+
#define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
2121
#define DEFAULT_USB_INTR_SOURCE ETS_USB_INTR_SOURCE
2222
#elif CONFIG_IDF_TARGET_ESP32P4
23-
#define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
23+
#define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
2424
#define DEFAULT_USB_INTR_SOURCE ETS_USB_OTG_INTR_SOURCE
2525
#else
2626
#define DEFAULT_CPU_FREQ_MHZ 160
@@ -56,7 +56,7 @@ void usb_dc_low_level_init(uint8_t busid)
5656
USB_LOG_ERR("USB Interrupt Init Failed!\r\n");
5757
return;
5858
}
59-
USB_LOG_INFO("cherryusb, version: "CHERRYUSB_VERSION_STR"\r\n");
59+
USB_LOG_INFO("cherryusb, version: " CHERRYUSB_VERSION_STR "\r\n");
6060
}
6161

6262
void usb_dc_low_level_deinit(uint8_t busid)
@@ -106,7 +106,7 @@ void usb_hc_low_level_init(struct usbh_bus *bus)
106106
USB_LOG_ERR("USB Interrupt Init Failed!\r\n");
107107
return;
108108
}
109-
USB_LOG_INFO("cherryusb, version: "CHERRYUSB_VERSION_STR"\r\n");
109+
USB_LOG_INFO("cherryusb, version: " CHERRYUSB_VERSION_STR "\r\n");
110110
}
111111

112112
void usb_hc_low_level_deinit(struct usbh_bus *bus)
@@ -129,4 +129,23 @@ uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
129129
void usbd_dwc2_delay_ms(uint8_t ms)
130130
{
131131
vTaskDelay(pdMS_TO_TICKS(ms));
132-
}
132+
}
133+
134+
#ifdef CONFIG_USB_DCACHE_ENABLE
135+
#include "esp_cache.h"
136+
137+
void usb_dcache_clean(uintptr_t addr, size_t size)
138+
{
139+
esp_cache_msync((void *)addr, size, ESP_CACHE_MSYNC_FLAG_TYPE_DATA | ESP_CACHE_MSYNC_FLAG_DIR_C2M);
140+
}
141+
142+
void usb_dcache_invalidate(uintptr_t addr, size_t size)
143+
{
144+
esp_cache_msync((void *)addr, size, ESP_CACHE_MSYNC_FLAG_TYPE_DATA | ESP_CACHE_MSYNC_FLAG_DIR_M2C);
145+
}
146+
147+
void usb_dcache_flush(uintptr_t addr, size_t size)
148+
{
149+
esp_cache_msync((void *)addr, size, ESP_CACHE_MSYNC_FLAG_TYPE_DATA | ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_DIR_M2C);
150+
}
151+
#endif

port/dwc2/usb_glue_st.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,21 @@ void OTG_FS_IRQHandler(void)
235235
void OTG_HS_IRQHandler(void)
236236
{
237237
g_usb_dwc2_irq[1](g_usb_dwc2_busid[1]);
238-
}
238+
}
239+
240+
#ifdef CONFIG_USB_DCACHE_ENABLE
241+
void usb_dcache_clean(uintptr_t addr, size_t size)
242+
{
243+
SCB_CleanDCache_by_Addr((void *)addr, size);
244+
}
245+
246+
void usb_dcache_invalidate(uintptr_t addr, size_t size)
247+
{
248+
SCB_InvalidateDCache_by_Addr((void *)addr, size);
249+
}
250+
251+
void usb_dcache_flush(uintptr_t addr, size_t size)
252+
{
253+
SCB_CleanInvalidateDCache_by_Addr((void *)addr, size);
254+
}
255+
#endif

0 commit comments

Comments
 (0)