|
16 | 16 | #include "esp_err.h" |
17 | 17 | #include "esp_log.h" |
18 | 18 |
|
| 19 | +#include "soc/soc_caps.h" |
19 | 20 | #include "soc/usb_dwc_periph.h" |
20 | 21 | #include "hal/usb_dwc_hal.h" |
21 | 22 | #include "hcd.h" |
22 | 23 | #include "usb_private.h" |
23 | 24 | #include "usb/usb_types_ch9.h" |
24 | 25 |
|
25 | | -#include "soc/soc_caps.h" |
26 | | -#if SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE |
27 | 26 | #include "esp_cache.h" |
28 | | -#endif // SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE |
| 27 | +#include "esp_private/esp_cache_private.h" |
29 | 28 |
|
30 | 29 | // ----------------------------------------------------- Macros -------------------------------------------------------- |
31 | 30 |
|
| 31 | +#define ALIGN_UP(num, align) ((align) == 0 ? (num) : (((num) + ((align) - 1)) & ~((align) - 1))) |
| 32 | + |
32 | 33 | // --------------------- Constants ------------------------- |
33 | 34 |
|
| 35 | +#define XFER_DESC_LIST_CAPS (MALLOC_CAP_DMA | MALLOC_CAP_CACHE_ALIGNED | MALLOC_CAP_INTERNAL) |
| 36 | + |
34 | 37 | #define INIT_DELAY_MS 30 // A delay of at least 25ms to enter Host mode. Make it 30ms to be safe |
35 | 38 | #define DEBOUNCE_DELAY_MS CONFIG_USB_HOST_DEBOUNCE_DELAY_MS |
36 | 39 | #define RESET_HOLD_MS CONFIG_USB_HOST_RESET_HOLD_MS |
@@ -1518,16 +1521,18 @@ static dma_buffer_block_t *buffer_block_alloc(usb_transfer_type_t type) |
1518 | 1521 | } |
1519 | 1522 |
|
1520 | 1523 | // Transfer descriptor list: Must be 512 aligned and DMA capable (USB-DWC requirement) and its size must be cache aligned |
1521 | | - void *xfer_desc_list = heap_caps_aligned_calloc(USB_DWC_QTD_LIST_MEM_ALIGN, desc_list_len * sizeof(usb_dwc_ll_dma_qtd_t), 1, MALLOC_CAP_DMA | MALLOC_CAP_CACHE_ALIGNED | MALLOC_CAP_INTERNAL); |
| 1524 | + void *xfer_desc_list = heap_caps_aligned_calloc(USB_DWC_QTD_LIST_MEM_ALIGN, desc_list_len * sizeof(usb_dwc_ll_dma_qtd_t), 1, XFER_DESC_LIST_CAPS); |
1522 | 1525 | if (xfer_desc_list == NULL) { |
1523 | 1526 | free(buffer); |
1524 | 1527 | heap_caps_free(xfer_desc_list); |
1525 | 1528 | return NULL; |
1526 | 1529 | } |
1527 | 1530 | buffer->xfer_desc_list = xfer_desc_list; |
1528 | | - // For targets with L1CACHE, the allocated size might be bigger than requested, this value is than used during memory sync |
1529 | | - // We save this value here, so we don't have to call 'heap_caps_get_allocated_size()' during every memory sync |
1530 | | - buffer->xfer_desc_list_len_bytes = heap_caps_get_allocated_size(xfer_desc_list); |
| 1531 | + |
| 1532 | + // Note for developers: We do not use heap_caps_get_allocated_size() because it is broken with HEAP_POISONING=COMPREHENSIVE |
| 1533 | + size_t cache_align = 0; |
| 1534 | + esp_cache_get_alignment(XFER_DESC_LIST_CAPS, &cache_align); |
| 1535 | + buffer->xfer_desc_list_len_bytes = ALIGN_UP(desc_list_len * sizeof(usb_dwc_ll_dma_qtd_t), cache_align); |
1531 | 1536 | return buffer; |
1532 | 1537 | } |
1533 | 1538 |
|
|
0 commit comments