From b90a2795879159f832521b77976fa061a68b3254 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 11 Mar 2024 12:15:09 +0100 Subject: [PATCH] feat(lp-core): Added ability to print from LP ROM on the LP core This commit adds the ability to use LP ROM functions from the LP core. This allows the LP core code to utilize standard functions such as those for printing from the LP ROM and therefore help reduce the code size on the LP core. --- components/ulp/Kconfig | 12 +++++++++++ components/ulp/cmake/CMakeLists.txt | 1 + .../lp_core/include/ulp_lp_core_print.h | 20 ++++++++++++++++++- .../ulp/lp_core/lp_core/lp_core_print.c | 4 ++++ components/ulp/project_include.cmake | 4 ++++ 5 files changed, 40 insertions(+), 1 deletion(-) 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}