diff --git a/components/driver/sdm.c b/components/driver/sdm.c index 6a0830ca3a..fb98b6ca24 100644 --- a/components/driver/sdm.c +++ b/components/driver/sdm.c @@ -26,6 +26,7 @@ #include "hal/sdm_ll.h" #include "soc/sdm_periph.h" #include "esp_private/esp_clk.h" +#include "esp_private/io_mux.h" #if CONFIG_SDM_CTRL_FUNC_IN_IRAM #define SDM_MEM_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) @@ -209,6 +210,7 @@ esp_err_t sdm_new_channel(const sdm_config_t *config, sdm_channel_handle_t *ret_ ESP_GOTO_ON_FALSE(group->clk_src == 0 || group->clk_src == config->clk_src, ESP_ERR_INVALID_ARG, err, TAG, "clock source conflict"); uint32_t src_clk_hz = 0; switch (config->clk_src) { +#if SOC_SDM_CLK_SUPPORT_APB case SDM_CLK_SRC_APB: src_clk_hz = esp_clk_apb_freq(); #if CONFIG_PM_ENABLE @@ -217,12 +219,31 @@ esp_err_t sdm_new_channel(const sdm_config_t *config, sdm_channel_handle_t *ret_ ESP_RETURN_ON_ERROR(ret, TAG, "create APB_FREQ_MAX lock failed"); #endif break; +#endif // SOC_SDM_CLK_SUPPORT_APB +#if SOC_SDM_CLK_SUPPORT_XTAL + case SDM_CLK_SRC_XTAL: + src_clk_hz = esp_clk_xtal_freq(); + break; +#endif // SOC_SDM_CLK_SUPPORT_XTAL +#if SOC_SDM_CLK_SUPPORT_PLL_F80M + case SDM_CLK_SRC_PLL_F80M: + src_clk_hz = 80 * 1000 * 1000; +#if CONFIG_PM_ENABLE + sprintf(chan->pm_lock_name, "sdm_%d_%d", group->group_id, chan_id); // e.g. sdm_0_0 + ret = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, chan->pm_lock_name, &chan->pm_lock); + ESP_RETURN_ON_ERROR(ret, TAG, "create NO_LIGHT_SLEEP lock failed"); +#endif + break; +#endif // SOC_SDM_CLK_SUPPORT_PLL_F80M default: ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "clock source %d is not support", config->clk_src); break; } group->clk_src = config->clk_src; + // SDM clock comes from IO MUX, but IO MUX clock might be shared with other submodules as well + ESP_GOTO_ON_ERROR(io_mux_set_clock_source((soc_module_clk_t)(group->clk_src)), err, TAG, "set IO MUX clock source failed"); + // GPIO configuration gpio_config_t gpio_conf = { .intr_type = GPIO_INTR_DISABLE, diff --git a/components/soc/esp32/include/soc/Kconfig.soc_caps.in b/components/soc/esp32/include/soc/Kconfig.soc_caps.in index 3c1e3ebb8b..b231f66e3e 100644 --- a/components/soc/esp32/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32/include/soc/Kconfig.soc_caps.in @@ -523,6 +523,10 @@ config SOC_SDM_CHANNELS_PER_GROUP int default 8 +config SOC_SDM_CLK_SUPPORT_APB + bool + default y + config SOC_SPI_HD_BOTH_INOUT_SUPPORTED bool default y diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index c99948a251..9ea655428a 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -261,6 +261,7 @@ /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ #define SOC_SDM_GROUPS 1U #define SOC_SDM_CHANNELS_PER_GROUP 8 +#define SOC_SDM_CLK_SUPPORT_APB 1 /*-------------------------- SPI CAPS ----------------------------------------*/ #define SOC_SPI_HD_BOTH_INOUT_SUPPORTED 1 //Support enabling MOSI and MISO phases together under Halfduplex mode diff --git a/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in index 871bb7d359..761e4eb823 100644 --- a/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in @@ -551,6 +551,10 @@ config SOC_SDM_CHANNELS_PER_GROUP int default 4 +config SOC_SDM_CLK_SUPPORT_APB + bool + default y + config SOC_SPI_PERIPH_NUM int default 2 diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index e8b25f27ca..6b17c23afc 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -262,6 +262,7 @@ /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ #define SOC_SDM_GROUPS 1U #define SOC_SDM_CHANNELS_PER_GROUP 4 +#define SOC_SDM_CLK_SUPPORT_APB 1 /*-------------------------- SPI CAPS ----------------------------------------*/ #define SOC_SPI_PERIPH_NUM 2 diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 085a860374..0840ff0105 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -659,6 +659,14 @@ config SOC_SDM_CHANNELS_PER_GROUP int default 4 +config SOC_SDM_CLK_SUPPORT_PLL_F80M + bool + default y + +config SOC_SDM_CLK_SUPPORT_XTAL + bool + default y + config SOC_SPI_PERIPH_NUM int default 2 diff --git a/components/soc/esp32c6/include/soc/clk_tree_defs.h b/components/soc/esp32c6/include/soc/clk_tree_defs.h index 422a77f6fd..86ec1608c0 100644 --- a/components/soc/esp32c6/include/soc/clk_tree_defs.h +++ b/components/soc/esp32c6/include/soc/clk_tree_defs.h @@ -101,7 +101,7 @@ typedef enum { } soc_rtc_fast_clk_src_t; // Naming convention: SOC_MOD_CLK_{[upstream]clock_name}_[attr] -// {[upstream]clock_name}: APB, (BB)PLL, etc. +// {[upstream]clock_name}: XTAL, (BB)PLL, etc. // [attr] - optional: FAST, SLOW, D, F /** * @brief Supported clock sources for modules (CPU, peripherals, RTC, etc.) @@ -115,7 +115,6 @@ typedef enum { SOC_MOD_CLK_RTC_FAST, /*!< RTC_FAST_CLK can be sourced from XTAL_D2 or RC_FAST by configuring soc_rtc_fast_clk_src_t */ SOC_MOD_CLK_RTC_SLOW, /*!< RTC_SLOW_CLK can be sourced from RC_SLOW, XTAL32K, or RC_FAST_D256 by configuring soc_rtc_slow_clk_src_t */ // For digital domain: peripherals, WIFI, BLE - SOC_MOD_CLK_APB, /*!< APB_CLK is highly dependent on the CPU_CLK source */ // TODO: IDF-6343 This should be removed on ESP32C6! Impacts on all following peripheral drivers! SOC_MOD_CLK_PLL_F80M, /*!< PLL_F80M_CLK is derived from PLL, and has a fixed frequency of 80MHz */ SOC_MOD_CLK_PLL_F160M, /*!< PLL_F160M_CLK is derived from PLL, and has a fixed frequency of 160MHz */ SOC_MOD_CLK_PLL_F240M, /*!< PLL_F240M_CLK is derived from PLL, and has a fixed frequency of 240MHz */ @@ -291,14 +290,15 @@ typedef enum { /** * @brief Array initializer for all supported clock sources of SDM */ -#define SOC_SDM_CLKS {SOC_MOD_CLK_APB} +#define SOC_SDM_CLKS {SOC_MOD_CLK_PLL_F80M, SOC_MOD_CLK_XTAL} /** * @brief Sigma Delta Modulator clock source */ typedef enum { - SDM_CLK_SRC_APB = SOC_MOD_CLK_APB, /*!< Select APB as the source clock */ - SDM_CLK_SRC_DEFAULT = SOC_MOD_CLK_APB, /*!< Select APB as the default clock choice */ + SDM_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< Select XTAL clock as the source clock */ + SDM_CLK_SRC_PLL_F80M = SOC_MOD_CLK_PLL_F80M, /*!< Select PLL_F80M clock as the source clock */ + SDM_CLK_SRC_DEFAULT = SOC_MOD_CLK_PLL_F80M, /*!< Select PLL_F80M clock as the default clock choice */ } soc_periph_sdm_clk_src_t; //////////////////////////////////////////////////TWAI///////////////////////////////////////////////////////////////// diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index 4b78381fb4..4e65652589 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -309,8 +309,10 @@ #define SOC_SHA_SUPPORT_SHA256 (1) /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ -#define SOC_SDM_GROUPS 1U -#define SOC_SDM_CHANNELS_PER_GROUP 4 +#define SOC_SDM_GROUPS 1U +#define SOC_SDM_CHANNELS_PER_GROUP 4 +#define SOC_SDM_CLK_SUPPORT_PLL_F80M 1 +#define SOC_SDM_CLK_SUPPORT_XTAL 1 // TODO: IDF-5334 (Copy from esp32c3, need check) /*-------------------------- SPI CAPS ----------------------------------------*/ diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index 58be5ab21a..f727b2e4d8 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -511,6 +511,14 @@ config SOC_SDM_CHANNELS_PER_GROUP int default 4 +config SOC_SDM_CLK_SUPPORT_PLL_F80M + bool + default y + +config SOC_SDM_CLK_SUPPORT_XTAL + bool + default y + config SOC_SPI_PERIPH_NUM int default 2 diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index 562fdbbc81..bd3ba808fc 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -292,8 +292,10 @@ // TODO: IDF-6220 /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ -#define SOC_SDM_GROUPS 1U -#define SOC_SDM_CHANNELS_PER_GROUP 4 +#define SOC_SDM_GROUPS 1U +#define SOC_SDM_CHANNELS_PER_GROUP 4 +#define SOC_SDM_CLK_SUPPORT_PLL_F80M 1 +#define SOC_SDM_CLK_SUPPORT_XTAL 1 // TODO: IDF-6245 (Copy from esp32c6, need check) /*-------------------------- SPI CAPS ----------------------------------------*/ diff --git a/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in index 6fba2353c0..8332c22713 100644 --- a/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in @@ -531,6 +531,10 @@ config SOC_SDM_CHANNELS_PER_GROUP int default 4 +config SOC_SDM_CLK_SUPPORT_APB + bool + default y + config SOC_SPI_PERIPH_NUM int default 2 diff --git a/components/soc/esp32h4/include/soc/soc_caps.h b/components/soc/esp32h4/include/soc/soc_caps.h index da112d4597..743b02647a 100644 --- a/components/soc/esp32h4/include/soc/soc_caps.h +++ b/components/soc/esp32h4/include/soc/soc_caps.h @@ -270,6 +270,7 @@ /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ #define SOC_SDM_GROUPS 1U #define SOC_SDM_CHANNELS_PER_GROUP 4 +#define SOC_SDM_CLK_SUPPORT_APB 1 /*-------------------------- SPI CAPS ----------------------------------------*/ #define SOC_SPI_PERIPH_NUM 2 diff --git a/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in index 352f0622dd..2fe4d9a5ae 100644 --- a/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in @@ -547,6 +547,10 @@ config SOC_SDM_CHANNELS_PER_GROUP int default 8 +config SOC_SDM_CLK_SUPPORT_APB + bool + default y + config SOC_SPI_HD_BOTH_INOUT_SUPPORTED bool default y diff --git a/components/soc/esp32s2/include/soc/soc_caps.h b/components/soc/esp32s2/include/soc/soc_caps.h index 5fc78fd97d..106f17885c 100644 --- a/components/soc/esp32s2/include/soc/soc_caps.h +++ b/components/soc/esp32s2/include/soc/soc_caps.h @@ -244,6 +244,7 @@ /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ #define SOC_SDM_GROUPS 1U #define SOC_SDM_CHANNELS_PER_GROUP 8 +#define SOC_SDM_CLK_SUPPORT_APB 1 /*-------------------------- SPI CAPS ----------------------------------------*/ #define SOC_SPI_HD_BOTH_INOUT_SUPPORTED 1 //Support enabling MOSI and MISO phases together under Halfduplex mode diff --git a/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in index 7a108d03ca..b0bdeb62e5 100644 --- a/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in @@ -667,6 +667,10 @@ config SOC_SDM_CHANNELS_PER_GROUP int default 8 +config SOC_SDM_CLK_SUPPORT_APB + bool + default y + config SOC_SPI_PERIPH_NUM int default 3 diff --git a/components/soc/esp32s3/include/soc/soc_caps.h b/components/soc/esp32s3/include/soc/soc_caps.h index 0ae868a7f5..c454eec821 100644 --- a/components/soc/esp32s3/include/soc/soc_caps.h +++ b/components/soc/esp32s3/include/soc/soc_caps.h @@ -275,6 +275,7 @@ /*-------------------------- Sigma Delta Modulator CAPS -----------------*/ #define SOC_SDM_GROUPS 1 #define SOC_SDM_CHANNELS_PER_GROUP 8 +#define SOC_SDM_CLK_SUPPORT_APB 1 /*-------------------------- SPI CAPS ----------------------------------------*/ #define SOC_SPI_PERIPH_NUM 3 diff --git a/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c b/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c index 30710ab61b..f747b25fed 100644 --- a/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c +++ b/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c @@ -33,11 +33,11 @@ #define REF_CLOCK_GPIO 0 // GPIO used to combine RMT out signal with PCNT input signal #define REF_CLOCK_PRESCALER_MS 30 // PCNT high threshold interrupt fired every 30ms +// peripheral driver handles static pcnt_unit_handle_t s_pcnt_unit; static pcnt_channel_handle_t s_pcnt_chan; static rmt_channel_handle_t s_rmt_chan; static rmt_encoder_handle_t s_rmt_encoder; -static volatile uint32_t s_milliseconds; void ref_clock_init(void) {