diff --git a/components/esp_hw_support/dma/esp_async_memcpy.c b/components/esp_hw_support/dma/esp_async_memcpy.c index 966ad2371c..c57c92fa12 100644 --- a/components/esp_hw_support/dma/esp_async_memcpy.c +++ b/components/esp_hw_support/dma/esp_async_memcpy.c @@ -22,10 +22,11 @@ esp_err_t esp_async_memcpy(async_memcpy_handle_t asmcp, void *dst, void *src, si return asmcp->memcpy(asmcp, dst, src, n, cb_isr, cb_args); } -#if SOC_GDMA_SUPPORT_ETM +#if SOC_ETM_SUPPORTED esp_err_t esp_async_memcpy_new_etm_event(async_memcpy_handle_t asmcp, async_memcpy_etm_event_t event_type, esp_etm_event_handle_t *out_event) { ESP_RETURN_ON_FALSE(asmcp && out_event, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); + ESP_RETURN_ON_FALSE(asmcp->new_etm_event, ESP_ERR_NOT_SUPPORTED, TAG, "ETM is not supported"); return asmcp->new_etm_event(asmcp, event_type, out_event); } #endif diff --git a/components/esp_hw_support/dma/esp_async_memcpy_priv.h b/components/esp_hw_support/dma/esp_async_memcpy_priv.h index 2d9be6ce77..bf64f83495 100644 --- a/components/esp_hw_support/dma/esp_async_memcpy_priv.h +++ b/components/esp_hw_support/dma/esp_async_memcpy_priv.h @@ -33,10 +33,10 @@ typedef struct async_memcpy_context_t async_memcpy_context_t; struct async_memcpy_context_t { /// @brief Start a new async memcpy transaction esp_err_t (*memcpy)(async_memcpy_context_t *ctx, void *dst, void *src, size_t n, async_memcpy_isr_cb_t cb_isr, void *cb_args); -#if SOC_GDMA_SUPPORT_ETM +#if SOC_ETM_SUPPORTED /// @brief Create ETM event handle of specific event type esp_err_t (*new_etm_event)(async_memcpy_context_t *ctx, async_memcpy_etm_event_t event_type, esp_etm_event_handle_t *out_event); -#endif // SOC_GDMA_SUPPORT_ETM +#endif // SOC_ETM_SUPPORTED /// @brief Delete async memcpy driver context esp_err_t (*del)(async_memcpy_context_t *ctx); }; diff --git a/components/esp_hw_support/dma/gdma.c b/components/esp_hw_support/dma/gdma.c index fe8be64169..602a666c16 100644 --- a/components/esp_hw_support/dma/gdma.c +++ b/components/esp_hw_support/dma/gdma.c @@ -213,9 +213,6 @@ esp_err_t gdma_new_ahb_channel(const gdma_channel_alloc_config_t *config, gdma_c }; return do_allocate_gdma_channel(&search_info, config, ret_chan); } - -esp_err_t gdma_new_channel(const gdma_channel_alloc_config_t *config, gdma_channel_handle_t *ret_chan) -__attribute__((alias("gdma_new_ahb_channel"))); #endif // SOC_AHB_GDMA_SUPPORTED #if SOC_AXI_GDMA_SUPPORTED @@ -232,6 +229,14 @@ esp_err_t gdma_new_axi_channel(const gdma_channel_alloc_config_t *config, gdma_c } #endif // SOC_AXI_GDMA_SUPPORTED +#if SOC_AHB_GDMA_SUPPORTED +esp_err_t gdma_new_channel(const gdma_channel_alloc_config_t *config, gdma_channel_handle_t *ret_chan) +__attribute__((alias("gdma_new_ahb_channel"))); +#elif SOC_AXI_GDMA_SUPPORTED +esp_err_t gdma_new_channel(const gdma_channel_alloc_config_t *config, gdma_channel_handle_t *ret_chan) +__attribute__((alias("gdma_new_axi_channel"))); +#endif + esp_err_t gdma_del_channel(gdma_channel_handle_t dma_chan) { ESP_RETURN_ON_FALSE(dma_chan, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); diff --git a/components/esp_hw_support/dma/gdma_etm.c b/components/esp_hw_support/dma/gdma_etm.c index f849a40e3c..5749c1cc78 100644 --- a/components/esp_hw_support/dma/gdma_etm.c +++ b/components/esp_hw_support/dma/gdma_etm.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -40,11 +40,9 @@ static esp_err_t gdma_del_etm_task(esp_etm_task_t *task) gdma_channel_t *dma_chan = gdma_task->chan; gdma_pair_t *pair = dma_chan->pair; gdma_group_t *group = pair->group; - if (dma_chan->direction == GDMA_CHANNEL_DIRECTION_RX) { - gdma_ll_rx_enable_etm_task(group->hal.dev, pair->pair_id, false); - } else { - gdma_ll_tx_enable_etm_task(group->hal.dev, pair->pair_id, false); - } + gdma_hal_context_t* hal = &group->hal; + + gdma_hal_enable_etm_task(hal, pair->pair_id, dma_chan->direction, false); free(gdma_task); dma_chan->flags.start_stop_by_etm = false; return ESP_OK; @@ -95,14 +93,14 @@ esp_err_t gdma_new_etm_task(gdma_channel_handle_t dma_chan, const gdma_etm_task_ gdma_pair_t *pair = dma_chan->pair; gdma_group_t *group = pair->group; + gdma_hal_context_t* hal = &group->hal; uint32_t task_id = 0; + gdma_hal_enable_etm_task(hal, pair->pair_id, dma_chan->direction, true); if (dma_chan->direction == GDMA_CHANNEL_DIRECTION_RX) { task_id = GDMA_LL_RX_ETM_TASK_TABLE(group->group_id, pair->pair_id, config->task_type); - gdma_ll_rx_enable_etm_task(group->hal.dev, pair->pair_id, true); } else { task_id = GDMA_LL_TX_ETM_TASK_TABLE(group->group_id, pair->pair_id, config->task_type); - gdma_ll_tx_enable_etm_task(group->hal.dev, pair->pair_id, true); } ESP_GOTO_ON_FALSE(task_id != 0, ESP_ERR_NOT_SUPPORTED, err, TAG, "not supported task type"); diff --git a/components/esp_hw_support/include/esp_async_memcpy.h b/components/esp_hw_support/include/esp_async_memcpy.h index 6932aff3fb..033bb9ed91 100644 --- a/components/esp_hw_support/include/esp_async_memcpy.h +++ b/components/esp_hw_support/include/esp_async_memcpy.h @@ -159,7 +159,7 @@ esp_err_t esp_async_memcpy_uninstall(async_memcpy_handle_t mcp); */ esp_err_t esp_async_memcpy(async_memcpy_handle_t mcp, void *dst, void *src, size_t n, async_memcpy_isr_cb_t cb_isr, void *cb_args); -#if SOC_GDMA_SUPPORT_ETM +#if SOC_ETM_SUPPORTED /** * @brief Async memory copy specific events that supported by the ETM module */ @@ -182,7 +182,7 @@ typedef enum { * - ESP_FAIL: Get ETM event failed because of other error */ esp_err_t esp_async_memcpy_new_etm_event(async_memcpy_handle_t mcp, async_memcpy_etm_event_t event_type, esp_etm_event_handle_t *out_event); -#endif // SOC_GDMA_SUPPORT_ETM +#endif // SOC_ETM_SUPPORTED #ifdef __cplusplus } diff --git a/components/esp_hw_support/test_apps/etm/main/test_gdma_etm.c b/components/esp_hw_support/test_apps/etm/main/test_gdma_etm.c index 82f66383c7..3ecedea858 100644 --- a/components/esp_hw_support/test_apps/etm/main/test_gdma_etm.c +++ b/components/esp_hw_support/test_apps/etm/main/test_gdma_etm.c @@ -61,9 +61,9 @@ TEST_CASE("async_memcpy_eof_event", "[etm]") TEST_ESP_OK(esp_etm_dump(stdout)); const uint32_t buffer_size = 1024; - uint8_t *src_buf = heap_caps_malloc(buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL); + uint8_t *src_buf = heap_caps_aligned_alloc(64, buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL); TEST_ASSERT_NOT_NULL(src_buf); - uint8_t *dst_buf = heap_caps_malloc(buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL); + uint8_t *dst_buf = heap_caps_aligned_alloc(64, buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL); TEST_ASSERT_NOT_NULL(dst_buf); printf("start memcpy\r\n"); diff --git a/components/hal/esp32p4/include/hal/gdma_ll.h b/components/hal/esp32p4/include/hal/gdma_ll.h index 9d719c8710..f7573cf1ac 100644 --- a/components/hal/esp32p4/include/hal/gdma_ll.h +++ b/components/hal/esp32p4/include/hal/gdma_ll.h @@ -13,6 +13,7 @@ #include #include #include "soc/hp_sys_clkrst_struct.h" +#include "soc/soc_etm_source.h" #define GDMA_LL_CHANNEL_MAX_PRIORITY 5 // supported priority levels: [0,5] @@ -44,6 +45,46 @@ #define GDMA_LL_AHB_MAX_CRC_BIT_WIDTH 32 // Max CRC bit width supported by AHB GDMA #define GDMA_LL_AXI_MAX_CRC_BIT_WIDTH 16 // Max CRC bit width supported by AXI GDMA +#define GDMA_LL_TX_ETM_EVENT_TABLE(group, chan, event) \ + (uint32_t[2][GDMA_ETM_EVENT_MAX]){ \ + { \ + [GDMA_ETM_EVENT_EOF] = PDMA_AHB_EVT_OUT_EOF_CH0 + (chan), \ + }, \ + { \ + [GDMA_ETM_EVENT_EOF] = PDMA_AXI_EVT_OUT_EOF_CH0 + (chan), \ + }, \ + }[group][event] + +#define GDMA_LL_RX_ETM_EVENT_TABLE(group, chan, event) \ + (uint32_t[2][GDMA_ETM_EVENT_MAX]){ \ + { \ + [GDMA_ETM_EVENT_EOF] = PDMA_AHB_EVT_IN_SUC_EOF_CH0 + (chan), \ + }, \ + { \ + [GDMA_ETM_EVENT_EOF] = PDMA_AXI_EVT_IN_SUC_EOF_CH0 + (chan), \ + }, \ + }[group][event] + +#define GDMA_LL_TX_ETM_TASK_TABLE(group, chan, task) \ + (uint32_t[2][GDMA_ETM_TASK_MAX]){ \ + { \ + [GDMA_ETM_TASK_START] = PDMA_AHB_TASK_OUT_START_CH0 + (chan), \ + }, \ + { \ + [GDMA_ETM_TASK_START] = PDMA_AXI_TASK_OUT_START_CH0 + (chan), \ + }, \ + }[group][task] + +#define GDMA_LL_RX_ETM_TASK_TABLE(group, chan, task) \ + (uint32_t[2][GDMA_ETM_TASK_MAX]){ \ + { \ + [GDMA_ETM_TASK_START] = PDMA_AHB_TASK_IN_START_CH0 + (chan), \ + }, \ + { \ + [GDMA_ETM_TASK_START] = PDMA_AXI_TASK_IN_START_CH0 + (chan), \ + }, \ + }[group][task] + #ifdef __cplusplus extern "C" { #endif diff --git a/components/hal/gdma_hal_ahb_v1.c b/components/hal/gdma_hal_ahb_v1.c index 376828bff9..6964b98790 100644 --- a/components/hal/gdma_hal_ahb_v1.c +++ b/components/hal/gdma_hal_ahb_v1.c @@ -162,6 +162,17 @@ uint32_t gdma_ahb_hal_get_eof_desc_addr(gdma_hal_context_t *hal, int chan_id, gd } } +#if SOC_GDMA_SUPPORT_ETM +void gdma_ahb_hal_enable_etm_task(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir, bool en_or_dis) +{ + if (dir == GDMA_CHANNEL_DIRECTION_RX) { + gdma_ll_rx_enable_etm_task(hal->dev, chan_id, en_or_dis); + } else { + gdma_ll_tx_enable_etm_task(hal->dev, chan_id, en_or_dis); + } +} +#endif // SOC_GDMA_SUPPORT_ETM + void gdma_ahb_hal_init(gdma_hal_context_t *hal, const gdma_hal_config_t *config) { hal->dev = GDMA_LL_GET_HW(config->group_id - GDMA_LL_AHB_GROUP_START_ID); @@ -179,6 +190,9 @@ void gdma_ahb_hal_init(gdma_hal_context_t *hal, const gdma_hal_config_t *config) hal->read_intr_status = gdma_ahb_hal_read_intr_status; hal->get_intr_status_reg = gdma_ahb_hal_get_intr_status_reg; hal->get_eof_desc_addr = gdma_ahb_hal_get_eof_desc_addr; +#if SOC_GDMA_SUPPORT_ETM + hal->enable_etm_task = gdma_ahb_hal_enable_etm_task; +#endif #if SOC_AHB_GDMA_SUPPORT_PSRAM hal->set_ext_mem_align = gdma_ahb_hal_set_ext_mem_align; #endif // SOC_AHB_GDMA_SUPPORT_PSRAM diff --git a/components/hal/gdma_hal_ahb_v2.c b/components/hal/gdma_hal_ahb_v2.c index 5171d7cde1..2b4f7a9e90 100644 --- a/components/hal/gdma_hal_ahb_v2.c +++ b/components/hal/gdma_hal_ahb_v2.c @@ -207,6 +207,17 @@ uint32_t gdma_ahb_hal_get_crc_result(gdma_hal_context_t *hal, int chan_id, gdma_ } #endif // SOC_GDMA_SUPPORT_CRC +#if SOC_GDMA_SUPPORT_ETM +void gdma_ahb_hal_enable_etm_task(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir, bool en_or_dis) +{ + if (dir == GDMA_CHANNEL_DIRECTION_RX) { + ahb_dma_ll_rx_enable_etm_task(hal->ahb_dma_dev, chan_id, en_or_dis); + } else { + ahb_dma_ll_tx_enable_etm_task(hal->ahb_dma_dev, chan_id, en_or_dis); + } +} +#endif // SOC_GDMA_SUPPORT_ETM + void gdma_ahb_hal_init(gdma_hal_context_t *hal, const gdma_hal_config_t *config) { hal->ahb_dma_dev = AHB_DMA_LL_GET_HW(config->group_id - GDMA_LL_AHB_GROUP_START_ID); @@ -230,4 +241,7 @@ void gdma_ahb_hal_init(gdma_hal_context_t *hal, const gdma_hal_config_t *config) hal->set_crc_poly = gdma_ahb_hal_set_crc_poly; hal->get_crc_result = gdma_ahb_hal_get_crc_result; #endif // SOC_GDMA_SUPPORT_CRC +#if SOC_GDMA_SUPPORT_ETM + hal->enable_etm_task = gdma_ahb_hal_enable_etm_task; +#endif // SOC_GDMA_SUPPORT_ETM } diff --git a/components/hal/gdma_hal_axi.c b/components/hal/gdma_hal_axi.c index 493577bc23..67e3aeae40 100644 --- a/components/hal/gdma_hal_axi.c +++ b/components/hal/gdma_hal_axi.c @@ -207,6 +207,17 @@ uint32_t gdma_axi_hal_get_crc_result(gdma_hal_context_t *hal, int chan_id, gdma_ } #endif // SOC_GDMA_SUPPORT_CRC +#if SOC_GDMA_SUPPORT_ETM +void gdma_axi_hal_enable_etm_task(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir, bool en_or_dis) +{ + if (dir == GDMA_CHANNEL_DIRECTION_RX) { + axi_dma_ll_rx_enable_etm_task(hal->axi_dma_dev, chan_id, en_or_dis); + } else { + axi_dma_ll_tx_enable_etm_task(hal->axi_dma_dev, chan_id, en_or_dis); + } +} +#endif // SOC_GDMA_SUPPORT_ETM + void gdma_axi_hal_init(gdma_hal_context_t *hal, const gdma_hal_config_t *config) { hal->axi_dma_dev = AXI_DMA_LL_GET_HW(config->group_id - GDMA_LL_AXI_GROUP_START_ID); @@ -230,4 +241,7 @@ void gdma_axi_hal_init(gdma_hal_context_t *hal, const gdma_hal_config_t *config) hal->set_crc_poly = gdma_axi_hal_set_crc_poly; hal->get_crc_result = gdma_axi_hal_get_crc_result; #endif // SOC_GDMA_SUPPORT_CRC +#if SOC_GDMA_SUPPORT_ETM + hal->enable_etm_task = gdma_axi_hal_enable_etm_task; +#endif // SOC_GDMA_SUPPORT_ETM } diff --git a/components/hal/gdma_hal_top.c b/components/hal/gdma_hal_top.c index c597708698..e3c882b2a2 100644 --- a/components/hal/gdma_hal_top.c +++ b/components/hal/gdma_hal_top.c @@ -106,3 +106,10 @@ uint32_t gdma_hal_get_crc_result(gdma_hal_context_t *hal, int chan_id, gdma_chan return hal->get_crc_result(hal, chan_id, dir); } #endif // SOC_GDMA_SUPPORT_CRC + +#if SOC_GDMA_SUPPORT_ETM +void gdma_hal_enable_etm_task(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir, bool en_or_dis) +{ + hal->enable_etm_task(hal, chan_id, dir, en_or_dis); +} +#endif // SOC_GDMA_SUPPORT_ETM diff --git a/components/hal/include/hal/gdma_hal.h b/components/hal/include/hal/gdma_hal.h index 98dda27228..1eca5ebf3c 100644 --- a/components/hal/include/hal/gdma_hal.h +++ b/components/hal/include/hal/gdma_hal.h @@ -92,6 +92,9 @@ struct gdma_hal_context_t { void (*set_crc_poly)(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir, const gdma_hal_crc_config_t *config); /// Set the CRC polynomial uint32_t (*get_crc_result)(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir); /// Get the CRC result #endif // SOC_GDMA_SUPPORT_CRC +#if SOC_GDMA_SUPPORT_ETM + void (*enable_etm_task)(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir, bool en_or_dis); /// Enable the ETM task +#endif // SOC_GDMA_SUPPORT_ETM }; void gdma_hal_deinit(gdma_hal_context_t *hal); @@ -141,6 +144,10 @@ void gdma_hal_set_crc_poly(gdma_hal_context_t *hal, int chan_id, gdma_channel_di uint32_t gdma_hal_get_crc_result(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir); #endif // SOC_GDMA_SUPPORT_CRC +#if SOC_GDMA_SUPPORT_ETM +void gdma_hal_enable_etm_task(gdma_hal_context_t *hal, int chan_id, gdma_channel_direction_t dir, bool en_or_dis); +#endif + #ifdef __cplusplus } #endif diff --git a/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in b/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in index 535398eab6..c111c04dfd 100644 --- a/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in @@ -375,6 +375,10 @@ config SOC_AXI_GDMA_SUPPORT_PSRAM bool default y +config SOC_GDMA_SUPPORT_ETM + bool + default y + config SOC_ETM_GROUPS int default 1 diff --git a/components/soc/esp32p4/include/soc/soc_caps.h b/components/soc/esp32p4/include/soc/soc_caps.h index d642af7c70..ecf038310b 100644 --- a/components/soc/esp32p4/include/soc/soc_caps.h +++ b/components/soc/esp32p4/include/soc/soc_caps.h @@ -178,7 +178,7 @@ #define SOC_GDMA_NUM_GROUPS_MAX 2 #define SOC_GDMA_PAIRS_PER_GROUP_MAX 3 #define SOC_AXI_GDMA_SUPPORT_PSRAM 1 -// #define SOC_GDMA_SUPPORT_ETM 1 +#define SOC_GDMA_SUPPORT_ETM 1 /*-------------------------- ETM CAPS --------------------------------------*/ #define SOC_ETM_GROUPS 1U // Number of ETM groups