From e58dabe7a71462fac74dd97b802a4c17d647d936 Mon Sep 17 00:00:00 2001 From: morris Date: Tue, 12 May 2026 11:38:45 +0800 Subject: [PATCH] feat(etm): add modem ETM support on esp32s31 Enable modem ETM capability on esp32s31 and add a dedicated modem_etm LL implementation with the correct event/task status register mapping. --- .../hal/esp32s31/include/hal/modem_etm_ll.h | 95 +++++++++++++++++++ .../esp32s31/include/soc/Kconfig.soc_caps.in | 4 + .../soc/esp32s31/include/soc/soc_caps.h | 3 + 3 files changed, 102 insertions(+) create mode 100644 components/hal/esp32s31/include/hal/modem_etm_ll.h diff --git a/components/hal/esp32s31/include/hal/modem_etm_ll.h b/components/hal/esp32s31/include/hal/modem_etm_ll.h new file mode 100644 index 00000000000..f4a4c3ab45d --- /dev/null +++ b/components/hal/esp32s31/include/hal/modem_etm_ll.h @@ -0,0 +1,95 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include "soc/soc.h" +#include "hal/assert.h" +#include "soc/soc_etm_struct.h" +#include "soc/soc_etm_reg.h" +#include "soc/soc_etm_source.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MODEM_LL_ETM_EVENT_TABLE(event_type) \ + (uint32_t[4]){ \ + [0] = MODEM_EVT_G0, \ + [1] = MODEM_EVT_G1, \ + [2] = MODEM_EVT_G2, \ + [3] = MODEM_EVT_G3, \ + }[event_type] + +#define MODEM_LL_ETM_TASK_TABLE(task_type) \ + (uint32_t[4]){ \ + [0] = MODEM_TASK_G0, \ + [1] = MODEM_TASK_G1, \ + [2] = MODEM_TASK_G2, \ + [3] = MODEM_TASK_G3, \ + }[task_type] + +static inline bool modem_etm_ll_get_group_event_status(int group_id) +{ + switch (group_id) { + case 0: + return SOC_ETM.evt_st12.modem_evt_g0_st; + case 1: + return SOC_ETM.evt_st12.modem_evt_g1_st; + case 2: + return SOC_ETM.evt_st12.modem_evt_g2_st; + case 3: + return SOC_ETM.evt_st12.modem_evt_g3_st; + default: + HAL_ASSERT(false); + } + return false; +} + +static inline bool modem_etm_ll_get_group_task_status(int group_id) +{ + switch (group_id) { + case 0: + return SOC_ETM.task_st10.modem_task_g0_st; + case 1: + return SOC_ETM.task_st10.modem_task_g1_st; + case 2: + return SOC_ETM.task_st10.modem_task_g2_st; + case 3: + return SOC_ETM.task_st11.modem_task_g3_st; + default: + HAL_ASSERT(false); + } + return false; +} + +static inline void modem_etm_ll_clear_group_event_status(int group_id) +{ + SOC_ETM.evt_st12_clr.val = SOC_ETM_MODEM_EVT_G0_ST_CLR << group_id; +} + +static inline void modem_etm_ll_clear_group_task_status(int group_id) +{ + switch (group_id) { + case 0: + case 1: + case 2: + SOC_ETM.task_st10_clr.val = SOC_ETM_MODEM_TASK_G0_ST_CLR << group_id; + break; + case 3: + SOC_ETM.task_st11_clr.val = SOC_ETM_MODEM_TASK_G3_ST_CLR; + break; + default: + HAL_ASSERT(false); + break; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in index 86e61f285af..4f20d6895c2 100644 --- a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in @@ -515,6 +515,10 @@ config SOC_GDMA_EXT_MEM_ENC_ALIGNMENT int default 16 +config SOC_MODEM_SUPPORT_ETM + bool + default y + config SOC_APM_CTRL_FILTER_SUPPORTED bool default y diff --git a/components/soc/esp32s31/include/soc/soc_caps.h b/components/soc/esp32s31/include/soc/soc_caps.h index 1f41cb26397..558c6d6b729 100644 --- a/components/soc/esp32s31/include/soc/soc_caps.h +++ b/components/soc/esp32s31/include/soc/soc_caps.h @@ -194,6 +194,9 @@ // #define SOC_GDMA_SUPPORT_SLEEP_RETENTION 1 // TODO: [ESP32S31] IDF-14760 #define SOC_GDMA_EXT_MEM_ENC_ALIGNMENT (16) +/*-------------------------- MODEM CAPS --------------------------------------*/ +#define SOC_MODEM_SUPPORT_ETM 1 + /*-------------------------- APM CAPS ----------------------------------------*/ #define SOC_APM_CTRL_FILTER_SUPPORTED 1 /*!< Support for APM control filter */