From 6e12910f8eca0798f02ede2fbde23e4eb99ec0d3 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Thu, 18 Jun 2026 11:46:23 +0800 Subject: [PATCH 1/3] fix(ulp): use SoC RC_FAST frequency for LP core delay Use the target RC_FAST approximation for LP core delay conversion. This prevents ESP32-S31 from under-delaying when running from RC_FAST. Co-authored-by: Cursor --- .../lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/ulp/lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h b/components/ulp/lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h index 3c0970a6a77..b690a9186a1 100644 --- a/components/ulp/lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h +++ b/components/ulp/lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h @@ -6,13 +6,14 @@ #pragma once #include "sdkconfig.h" +#include "soc/clk_tree_defs.h" #include "soc/soc_caps.h" /* LP_FAST_CLK is not very accurate, for now use a rough estimate */ #if CONFIG_RTC_FAST_CLK_SRC_RC_FAST -#define LP_CORE_CPU_FREQUENCY_HZ 16000000U /* For P4 TRM says 20 MHz by default, but we tune it closer to 16 MHz */ -#define LP_CORE_CYCLES_PER_US_NUM 16U -#define LP_CORE_CYCLES_PER_US_DENOM 1U +#define LP_CORE_CPU_FREQUENCY_HZ SOC_CLK_RC_FAST_FREQ_APPROX +#define LP_CORE_CYCLES_PER_US_NUM (SOC_CLK_RC_FAST_FREQ_APPROX / 500000U) +#define LP_CORE_CYCLES_PER_US_DENOM 2U #elif CONFIG_RTC_FAST_CLK_SRC_XTAL #if SOC_XTAL_SUPPORT_48M #define LP_CORE_CPU_FREQUENCY_HZ 48000000U From a6c7484b53cf802575288d8f8b84715915bc54f6 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Thu, 18 Jun 2026 11:58:40 +0800 Subject: [PATCH 2/3] fix(ulp): use RC_FAST approximation for LP core fallback Use the shared SoC RC_FAST approximation when the target has no RTC_FAST source option. Co-authored-by: Cursor --- .../lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/ulp/lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h b/components/ulp/lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h index b690a9186a1..5a7550af024 100644 --- a/components/ulp/lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h +++ b/components/ulp/lp_core/shared/include/ulp_lp_core_cpu_freq_shared.h @@ -25,9 +25,9 @@ #define LP_CORE_CYCLES_PER_US_DENOM 1U #endif #else // Default value in chip without rtc fast clock sel option -#define LP_CORE_CPU_FREQUENCY_HZ 16000000U -#define LP_CORE_CYCLES_PER_US_NUM 16U -#define LP_CORE_CYCLES_PER_US_DENOM 1U +#define LP_CORE_CPU_FREQUENCY_HZ SOC_CLK_RC_FAST_FREQ_APPROX +#define LP_CORE_CYCLES_PER_US_NUM (SOC_CLK_RC_FAST_FREQ_APPROX / 500000U) +#define LP_CORE_CYCLES_PER_US_DENOM 2U #endif /** From e9d89e85cb879c41d259a6e65cabcc491376079e Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Thu, 18 Jun 2026 12:01:41 +0800 Subject: [PATCH 3/3] test(ulp): check LP core apps avoid soft-float helpers Inspect generated LP core ELF files so accidental floating-point helper linkage is caught in CI. --- .../check_lp_core_no_soft_float.py | 60 +++++++++++++++++++ .../lp_core_basic_tests/main/CMakeLists.txt | 32 ++++++++++ 2 files changed, 92 insertions(+) create mode 100644 components/ulp/test_apps/lp_core/lp_core_basic_tests/check_lp_core_no_soft_float.py diff --git a/components/ulp/test_apps/lp_core/lp_core_basic_tests/check_lp_core_no_soft_float.py b/components/ulp/test_apps/lp_core/lp_core_basic_tests/check_lp_core_no_soft_float.py new file mode 100644 index 00000000000..f4c694bf187 --- /dev/null +++ b/components/ulp/test_apps/lp_core/lp_core_basic_tests/check_lp_core_no_soft_float.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import argparse +from pathlib import Path + +SOFT_FLOAT_SYMBOLS = { + '__adddf3', + '__addsf3', + '__divdf3', + '__divsf3', + '__eqdf2', + '__eqsf2', + '__extendsfdf2', + '__fixdfsi', + '__fixsfsi', + '__fixunsdfsi', + '__fixunssfsi', + '__floatunsidf', + '__floatunsisf', + '__floatsidf', + '__floatsisf', + '__gedf2', + '__gesf2', + '__gtdf2', + '__gtsf2', + '__ledf2', + '__lesf2', + '__ltdf2', + '__ltsf2', + '__muldf3', + '__mulsf3', + '__nedf2', + '__nesf2', + '__subdf3', + '__subsf3', + '__truncdfsf2', +} + + +def main() -> None: + parser = argparse.ArgumentParser(description='Check that an LP core app does not link soft-float helpers') + parser.add_argument('symbol_file', type=Path) + args = parser.parse_args() + + linked_symbols = set() + for line in args.symbol_file.read_text().splitlines(): + fields = line.split() + if fields: + linked_symbols.add(fields[-1]) + + linked_soft_float = sorted(linked_symbols & SOFT_FLOAT_SYMBOLS) + if linked_soft_float: + symbols = ', '.join(linked_soft_float) + raise SystemExit(f'{args.symbol_file}: LP core app links soft-float helper symbols: {symbols}') + + +if __name__ == '__main__': + main() diff --git a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/CMakeLists.txt b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/CMakeLists.txt index 78ec8881201..7a22fcef159 100644 --- a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/CMakeLists.txt +++ b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/CMakeLists.txt @@ -68,19 +68,43 @@ idf_component_register(SRCS ${app_sources} set(lp_core_exp_dep_srcs ${app_sources}) +function(lp_core_test_app_checks) + idf_build_get_property(python PYTHON) + + foreach(app_name ${ARGN}) + set(symbol_file ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.sym) + set(check_output ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name}.no_soft_float) + add_custom_command(OUTPUT ${check_output} + COMMAND ${python} ${CMAKE_CURRENT_LIST_DIR}/../check_lp_core_no_soft_float.py ${symbol_file} + COMMAND ${CMAKE_COMMAND} -E touch ${check_output} + DEPENDS ${symbol_file} ${CMAKE_CURRENT_LIST_DIR}/../check_lp_core_no_soft_float.py + VERBATIM) + add_custom_target(${app_name}_no_soft_float DEPENDS ${check_output}) + add_dependencies(${COMPONENT_LIB} ${app_name}_no_soft_float) + endforeach() +endfunction() + +set(lp_core_test_apps "") + ulp_embed_binary(lp_core_test_app "${lp_core_sources}" "${lp_core_exp_dep_srcs}") +list(APPEND lp_core_test_apps lp_core_test_app) ulp_embed_binary(lp_core_test_app_counter "${lp_core_sources_counter}" "${lp_core_exp_dep_srcs}") +list(APPEND lp_core_test_apps lp_core_test_app_counter) ulp_embed_binary(lp_core_test_app_wake_stub "${lp_core_sources_wake_stub}" "${lp_core_exp_dep_srcs}") +list(APPEND lp_core_test_apps lp_core_test_app_wake_stub) ulp_embed_binary(lp_core_test_app_isr "lp_core/test_main_isr.c" "${lp_core_exp_dep_srcs}") +list(APPEND lp_core_test_apps lp_core_test_app_isr) if(CONFIG_SOC_RTC_TIMER_V2_SUPPORTED) ulp_embed_binary(lp_core_test_app_set_timer_wakeup "${lp_core_sources_set_timer_wakeup}" "${lp_core_exp_dep_srcs}") + list(APPEND lp_core_test_apps lp_core_test_app_set_timer_wakeup) endif() ulp_embed_binary(lp_core_test_app_gpio "${lp_core_sources_gpio}" "${lp_core_exp_dep_srcs}") if(CONFIG_SOC_LP_I2C_SUPPORTED) ulp_embed_binary(lp_core_test_app_i2c "${lp_core_sources_i2c}" "${lp_core_exp_dep_srcs}") + list(APPEND lp_core_test_apps lp_core_test_app_i2c) endif() if(CONFIG_SOC_ULP_LP_UART_SUPPORTED) @@ -90,7 +114,9 @@ endif() if(CONFIG_SOC_LP_SPI_SUPPORTED) ulp_embed_binary(lp_core_test_app_spi_master "${lp_core_sources_spi_master}" "${lp_core_exp_dep_srcs}") + list(APPEND lp_core_test_apps lp_core_test_app_spi_master) ulp_embed_binary(lp_core_test_app_spi_slave "${lp_core_sources_spi_slave}" "${lp_core_exp_dep_srcs}") + list(APPEND lp_core_test_apps lp_core_test_app_spi_slave) endif() if(CONFIG_SOC_LP_ADC_SUPPORTED) @@ -99,9 +125,15 @@ endif() if(CONFIG_SOC_LP_VAD_SUPPORTED) ulp_embed_binary(lp_core_test_app_vad "${lp_core_sources_vad}" "${lp_core_exp_dep_srcs}") + list(APPEND lp_core_test_apps lp_core_test_app_vad) endif() ulp_embed_binary(lp_core_test_app_prefix1 "lp_core/test_main_prefix1.c" "${lp_core_exp_dep_srcs}" PREFIX "ulp1_") +list(APPEND lp_core_test_apps lp_core_test_app_prefix1) ulp_embed_binary(lp_core_test_app_prefix2 "lp_core/test_main_prefix2.c" "${lp_core_exp_dep_srcs}" PREFIX "ulp2_") +list(APPEND lp_core_test_apps lp_core_test_app_prefix2) ulp_embed_binary(lp_core_test_app_exception "lp_core/test_main_exception.c" "${lp_core_exp_dep_srcs}") +list(APPEND lp_core_test_apps lp_core_test_app_exception) + +lp_core_test_app_checks(${lp_core_test_apps})