diff --git a/components/ulp/Kconfig b/components/ulp/Kconfig index 5b8a7c5ce1..29b1e5ff00 100644 --- a/components/ulp/Kconfig +++ b/components/ulp/Kconfig @@ -80,4 +80,16 @@ menu "Ultra Low Power (ULP) Co-processor" Size of the shared memory defined in ulp_lp_core_memory_shared.c. Size should be kept in-sync with the size of the struct defined there. + config ULP_ROM_PRINT_ENABLE + depends on ULP_COPROC_TYPE_LP_CORE && ESP_ROM_HAS_LP_ROM + bool + prompt "Enable print utilities from LP ROM" + default "y" + help + Set this option to enable printf functionality from LP ROM. This option + can help reduce the LP core binary size by not linking printf functionality + from RAM code. + Note: For LP ROM prints to work properly, make sure that the LP core boots + from the LP ROM. + endmenu # Ultra Low Power (ULP) Co-processor diff --git a/components/ulp/cmake/CMakeLists.txt b/components/ulp/cmake/CMakeLists.txt index e396502853..d35f517966 100644 --- a/components/ulp/cmake/CMakeLists.txt +++ b/components/ulp/cmake/CMakeLists.txt @@ -54,6 +54,7 @@ target_link_options(${ULP_APP_NAME} PRIVATE SHELL:-T ${CMAKE_CURRENT_BINARY_DIR} # To avoid warning "Manually-specified variables were not used by the project" set(bypassWarning "${IDF_TARGET}") +set(bypassWarning "${CONFIG_ESP_ROM_HAS_LP_ROM}") if(ULP_COCPU_IS_RISCV) #risc-v ulp uses extra files for building: list(APPEND ULP_S_SOURCES diff --git a/components/ulp/lp_core/lp_core/include/ulp_lp_core_print.h b/components/ulp/lp_core/lp_core/include/ulp_lp_core_print.h index 43a956b9be..4c0b214528 100644 --- a/components/ulp/lp_core/lp_core/include/ulp_lp_core_print.h +++ b/components/ulp/lp_core/lp_core/include/ulp_lp_core_print.h @@ -1,8 +1,9 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" /** * @brief Print from the LP core @@ -14,4 +15,21 @@ * @param ... variable argument list * */ +#if CONFIG_ULP_ROM_PRINT_ENABLE +extern int ets_printf(const char* format, ...); +int (*lp_core_printf)(const char* format, ...) = ets_printf; +#else +//TODO: Change return type from void to int in IDF 6.0 void lp_core_printf(const char* format, ...); +#endif /* CONFIG_ULP_ROM_PRINT_ENABLE */ + +#if CONFIG_ULP_ROM_PRINT_ENABLE +/** + * @brief Install LP ROM UART printf function as standard putc handler to enable prints + * + * @note This function must be called before printing anything when the LP core boots from LP ROM but does not install + * putc handler. This is possible when the LP ROM is instructed so by setting bit#1 in the LP_SYSTEM_REG_LP_STORE9_REG register. + */ +extern void ets_install_uart_printf(void); +void (*lp_core_install_uart_printf)(void) = ets_install_uart_printf; +#endif /* CONFIG_ULP_ROM_PRINT_ENABLE */ diff --git a/components/ulp/lp_core/lp_core/lp_core_print.c b/components/ulp/lp_core/lp_core/lp_core_print.c index d010f68328..785d59e6c4 100644 --- a/components/ulp/lp_core/lp_core/lp_core_print.c +++ b/components/ulp/lp_core/lp_core/lp_core_print.c @@ -6,6 +6,8 @@ #include #include "ulp_lp_core_uart.h" +#if !CONFIG_ULP_ROM_PRINT_ENABLE + #define LP_UART_PORT_NUM LP_UART_NUM_0 #define BINARY_SUPPORT 1 @@ -271,3 +273,5 @@ int lp_core_printf(const char* format, ...) return ret; } + +#endif /* !CONFIG_ULP_ROM_PRINT_ENABLE */ diff --git a/components/ulp/project_include.cmake b/components/ulp/project_include.cmake index 47df252e01..b3e35dca96 100644 --- a/components/ulp/project_include.cmake +++ b/components/ulp/project_include.cmake @@ -49,6 +49,9 @@ function(ulp_embed_binary app_name s_sources exp_dep_srcs) elseif(CONFIG_ULP_COPROC_TYPE_LP_CORE) set(TOOLCHAIN_FLAG ${idf_path}/components/ulp/cmake/toolchain-lp-core-riscv.cmake) set(ULP_IS_LP_CORE_RISCV ON) + if(CONFIG_ESP_ROM_HAS_LP_ROM) + set(CONFIG_ESP_ROM_HAS_LP_ROM ON) + endif() endif() externalproject_add(${app_name} @@ -67,6 +70,7 @@ function(ulp_embed_binary app_name s_sources exp_dep_srcs) -DPYTHON=${python} -DULP_COCPU_IS_RISCV=${ULP_IS_RISCV} -DULP_COCPU_IS_LP_CORE=${ULP_IS_LP_CORE_RISCV} + -DCONFIG_ESP_ROM_HAS_LP_ROM=${CONFIG_ESP_ROM_HAS_LP_ROM} ${extra_cmake_args} BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/${app_name} --target build BUILD_BYPRODUCTS ${ulp_artifacts} ${ulp_artifacts_extras} ${ulp_ps_sources}