diff --git a/Documentation/platforms/risc-v/esp32c6/index.rst b/Documentation/platforms/risc-v/esp32c6/index.rst index 976fc53bb67b0..84f139f1e0f1f 100644 --- a/Documentation/platforms/risc-v/esp32c6/index.rst +++ b/Documentation/platforms/risc-v/esp32c6/index.rst @@ -842,6 +842,9 @@ Makefile/CMake Variables for ULP Core Build: - ``ULP_APP_C_SRCS``: Lists all C source files (.c) that need to be compiled for the ULP application. - ``ULP_APP_ASM_SRCS``: Lists all assembly source files (.S or .s) to be assembled. - ``ULP_APP_INCLUDES``: Specifies additional include directories for the compiler and assembler. +- ``ULP_CUSTOM_SECTIONS_LD``: Optional. Replaces the default ``${CHIP_SERIES}_lpcore_sections.ld`` linker template. +- ``ULP_EXTRA_DEFINES``: Optional. Extra compile definitions for the ULP firmware +- ``ULP_POST_LINK``: Optional (Make only). Commands run after linking. Here is an Makefile example when using prebuilt binary for ULP core: diff --git a/Documentation/platforms/risc-v/esp32p4/index.rst b/Documentation/platforms/risc-v/esp32p4/index.rst index 04a982445e2c9..08764b0944dfc 100644 --- a/Documentation/platforms/risc-v/esp32p4/index.rst +++ b/Documentation/platforms/risc-v/esp32p4/index.rst @@ -470,6 +470,9 @@ Makefile/CMake Variables for ULP Core Build: - ``ULP_APP_C_SRCS``: Lists all C source files (.c) that need to be compiled for the ULP application. - ``ULP_APP_ASM_SRCS``: Lists all assembly source files (.S or .s) to be assembled. - ``ULP_APP_INCLUDES``: Specifies additional include directories for the compiler and assembler. +- ``ULP_CUSTOM_SECTIONS_LD``: Optional. Replaces the default ``${CHIP_SERIES}_lpcore_sections.ld`` linker template. +- ``ULP_EXTRA_DEFINES``: Optional. Extra compile definitions for the ULP firmware +- ``ULP_POST_LINK``: Optional (Make only). Commands run after linking. Here is an Makefile example when using prebuilt binary for ULP core: diff --git a/arch/risc-v/src/common/espressif/Kconfig b/arch/risc-v/src/common/espressif/Kconfig index e4df0a5c2ebb1..cbdbd04bd04c3 100644 --- a/arch/risc-v/src/common/espressif/Kconfig +++ b/arch/risc-v/src/common/espressif/Kconfig @@ -1732,7 +1732,7 @@ config ESPRESSIF_ANA_COMPR1 config ESPRESSIF_LP_MAILBOX bool "LP Mailbox" default n - depends on ARCH_CHIP_ESP32P4 && ESPRESSIF_USE_LP_CORE + depends on ESPRESSIF_USE_LP_CORE ---help--- Enable lp mailbox support for data passing between cores. diff --git a/arch/risc-v/src/common/espressif/esp_lp_mailbox.c b/arch/risc-v/src/common/espressif/esp_lp_mailbox.c index 18a785378530a..5ef4af6696871 100644 --- a/arch/risc-v/src/common/espressif/esp_lp_mailbox.c +++ b/arch/risc-v/src/common/espressif/esp_lp_mailbox.c @@ -30,6 +30,7 @@ #include #include "lp_core_mailbox.h" +#include "soc/soc_caps.h" /**************************************************************************** * Pre-processor Definitions @@ -52,6 +53,7 @@ struct esp_lp_mailbox_priv_s * Private Function Prototypes ****************************************************************************/ +static int esp_lp_mailbox_open(struct file *filep); static int esp_lp_mailbox_read(struct file *filep, char *buffer, size_t buflen); @@ -68,7 +70,7 @@ static int esp_lp_mailbox_ioctl(struct file *filep, static const struct file_operations g_esp_lp_mailbox_fops = { - .open = NULL, /* open */ + .open = esp_lp_mailbox_open, /* open */ .close = NULL, /* close */ .read = esp_lp_mailbox_read, /* read */ .write = esp_lp_mailbox_write, /* write */ @@ -91,6 +93,31 @@ struct esp_lp_mailbox_priv_s esp_lp_mailbox_priv = * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: esp_lp_mailbox_open + * + * Description: + * Handler for the LP Mailbox initializer. + * + * Input Parameters: + * filep - Pointer to the file structure. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static int esp_lp_mailbox_open(struct file *filep) +{ + int ret = OK; +#ifndef SOC_LP_MAILBOX_SUPPORTED + ret = lp_core_mailbox_init(&esp_lp_mailbox_priv.mailbox, + &esp_lp_mailbox_priv.config); +#endif + + return ret; +} + /**************************************************************************** * Name: esp_lp_mailbox_rcv_callback * @@ -312,6 +339,7 @@ static int esp_lp_mailbox_ioctl(struct file *filep, int esp_lp_mailbox_init(void) { +#ifdef SOC_LP_MAILBOX_SUPPORTED int ret = lp_core_mailbox_init(&esp_lp_mailbox_priv.mailbox, &esp_lp_mailbox_priv.config); @@ -320,6 +348,7 @@ int esp_lp_mailbox_init(void) ferr("Failed to initialize LP Mailbox driver: %d\n", ret); return ret; } +#endif register_driver("/dev/lp_mailbox", esp_lp_mailbox_priv.ops, 0600, (void *)&esp_lp_mailbox_priv); diff --git a/arch/risc-v/src/common/espressif/esp_ulp.cmake b/arch/risc-v/src/common/espressif/esp_ulp.cmake index 95a1de9593332..9fbef1708e2cd 100644 --- a/arch/risc-v/src/common/espressif/esp_ulp.cmake +++ b/arch/risc-v/src/common/espressif/esp_ulp.cmake @@ -74,6 +74,9 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) set(ULP_LPCORE_SECTIONS_LD ${ULP_BOARD_SCRIPTS_DIR}/${CHIP_SERIES}_lpcore_sections.ld) + if(ULP_CUSTOM_SECTIONS_LD) + set(ULP_LPCORE_SECTIONS_LD ${ULP_CUSTOM_SECTIONS_LD}) + endif() set(ULP_SECTIONS_LD ${ULP_FOLDER}/ulp_sections.ld) set(ULP_MAPGEN_TOOL ${HAL}/components/ulp/esp32ulp_mapgen.py) @@ -116,6 +119,8 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) ${HAL}/components/esp_rom/${CHIP_SERIES}/include/${CHIP_SERIES} ${HAL}/components/hal/include ${HAL}/components/hal/platform_port/include + ${HAL}/components/esp_hal_wdt/include + ${HAL}/components/esp_hal_wdt/${CHIP_SERIES}/include ${HAL}/components/log ${HAL}/components/log/include ${HAL}/components/riscv/include @@ -201,6 +206,7 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) ${HAL}/components/ulp/lp_core/lp_core/lp_core_startup.c ${HAL}/components/ulp/lp_core/lp_core/lp_core_utils.c ${HAL}/components/ulp/lp_core/lp_core/lp_core_uart.c + ${HAL}/components/ulp/lp_core/lp_core/lp_core_mailbox.c ${HAL}/components/ulp/lp_core/lp_core/lp_core_print.c ${HAL}/components/ulp/lp_core/lp_core/lp_core_panic.c ${HAL}/components/ulp/lp_core/lp_core/lp_core_interrupt.c @@ -211,10 +217,14 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) ) if(CONFIG_ARCH_CHIP_ESP32P4) - list( - APPEND ULP_CSOURCES ${HAL}/components/ulp/lp_core/lp_core/lp_core_touch.c - ${HAL}/components/ulp/lp_core/lp_core/port/lp_core_mailbox_impl_hw.c - ${HAL}/components/ulp/lp_core/lp_core/lp_core_mailbox.c) + list(APPEND ULP_CSOURCES + ${HAL}/components/ulp/lp_core/lp_core/lp_core_touch.c + ${HAL}/components/ulp/lp_core/lp_core/port/lp_core_mailbox_impl_hw.c) + endif() + + if(CONFIG_ARCH_CHIP_ESP32C6) + list(APPEND ULP_CSOURCES + ${HAL}/components/ulp/lp_core/lp_core/port/lp_core_mailbox_impl_sw.c) endif() # ############################################################################ @@ -311,17 +321,29 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) set(ULP_NUTTX_CONFIG_COPY ${ULP_FOLDER}/nuttx/config.h) foreach(_ulp_csrc ${ULP_APP_C_SRCS}) - list(APPEND ULP_APP_C_SOURCES ${ULP_APP_FOLDER}/${_ulp_csrc}) + if(IS_ABSOLUTE "${_ulp_csrc}") + list(APPEND ULP_APP_C_SOURCES ${_ulp_csrc}) + else() + list(APPEND ULP_APP_C_SOURCES ${ULP_APP_FOLDER}/${_ulp_csrc}) + endif() endforeach() foreach(_ulp_asrc ${ULP_APP_ASM_SRCS}) - list(APPEND ULP_APP_ASM_SOURCES ${ULP_APP_FOLDER}/${_ulp_asrc}) + if(IS_ABSOLUTE "${_ulp_asrc}") + list(APPEND ULP_APP_ASM_SOURCES ${_ulp_asrc}) + else() + list(APPEND ULP_APP_ASM_SOURCES ${ULP_APP_FOLDER}/${_ulp_asrc}) + endif() endforeach() if(ULP_APP_INCLUDES) foreach(_ulp_incl ${ULP_APP_INCLUDES}) - get_filename_component(_ulp_incl_dir ${_ulp_incl} DIRECTORY) - list(APPEND ULP_APP_INCLUDE_DIRS ${_ulp_incl_dir}) + if(IS_DIRECTORY "${_ulp_incl}") + list(APPEND ULP_APP_INCLUDE_DIRS ${_ulp_incl}) + else() + get_filename_component(_ulp_incl_dir ${_ulp_incl} DIRECTORY) + list(APPEND ULP_APP_INCLUDE_DIRS ${_ulp_incl_dir}) + endif() endforeach() list(REMOVE_DUPLICATES ULP_APP_INCLUDE_DIRS) list(APPEND ULP_INCLUDE_DIRS ${ULP_APP_INCLUDE_DIRS}) @@ -375,6 +397,10 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) target_include_directories(${ULP_FIRMWARE_TARGET} PRIVATE ${ULP_INCLUDE_DIRS}) target_compile_definitions(${ULP_FIRMWARE_TARGET} PRIVATE IS_ULP_COCPU) + if(ULP_EXTRA_DEFINES) + target_compile_definitions(${ULP_FIRMWARE_TARGET} + PRIVATE ${ULP_EXTRA_DEFINES}) + endif() target_compile_options( ${ULP_FIRMWARE_TARGET} PRIVATE ${ULP_COMPILE_OPTS} @@ -399,6 +425,13 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) COMMENT "Linking ULP firmware" VERBATIM) + set(_ulp_postprocess_sw_mailbox_alias + [=[if grep -q 'g_lp_core_mailbox_impl_sw_ctx' "@ULP_MAIN_LD@"; then addr=$(grep 'g_lp_core_mailbox_impl_sw_ctx' "@ULP_MAIN_LD@" | head -1 | sed -E 's/.*=[[:space:]]*([0x0-9a-fA-F]+);.*/\1/'); if ! grep -qE '^[[:space:]]*ulp_g_lp_core_mailbox_impl_sw_ctx[[:space:]]*=' "@ULP_MAIN_LD@"; then echo "ulp_g_lp_core_mailbox_impl_sw_ctx = ${addr};" >> "@ULP_MAIN_LD@"; fi; fi]=] + ) + string(REPLACE "@ULP_MAIN_LD@" "${ULP_MAIN_LD}" + _ulp_postprocess_sw_mailbox_alias + "${_ulp_postprocess_sw_mailbox_alias}") + set(_ulp_postprocess_aliases [=[grep -E '^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*=[[:space:]]*[0x]*[0-9a-fA-F]+;' "@ULP_MAIN_LD@" | while IFS= read -r line; do var_name=$(echo "$line" | sed -E 's/^[[:space:]]*([a-zA-Z_][a-zA-Z0-9_]*).*/\1/'); existing_line=$(grep -E "^[[:space:]]*${var_name}[[:space:]]*=" "@ULP_ALIASES_LD@" 2>/dev/null || true); if [ -n "$existing_line" ]; then if [ "$existing_line" != "$line" ]; then sed -i "/${existing_line}/c\\${line}" "@ULP_ALIASES_LD@"; fi; else echo "$line" >> "@ULP_ALIASES_LD@"; fi; done]=] ) @@ -408,7 +441,7 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) _ulp_postprocess_aliases "${_ulp_postprocess_aliases}") set(_ulp_postprocess_var_map - [=[if ! grep -q "struct ulp_var_map_s ulp_var_map" "@ULP_VAR_MAP_HEADER@"; then printf '%s\n' '#include "nuttx/symtab.h"' '#include "ulp/ulp_vars.h"' '' 'struct ulp_var_map_s' '{' ' struct symtab_s sym;' ' size_t size;' '};' '' 'struct ulp_var_map_s ulp_var_map[] =' '{ };' > "@ULP_VAR_MAP_HEADER@"; fi; sed -i "/@ULP_PREFIX@/d" "@ULP_VAR_MAP_HEADER@"; flock -x "@ULP_LOCKFILE@" -c 'grep "@ULP_PREFIX@" "@ULP_MAIN_HEADER@" | while IFS= read -r line; do var=$(echo "$line" | grep -oP "@ULP_PREFIX@\w+(?=[;\[])" ); if [ -n "$var" ]; then size=$(echo "$line" | grep -oP "\[\d+\]" | grep -oP "\d+"); if [ -n "$size" ]; then size=$(( size * 4 )); else size=4; fi; sed -i "s/ };//" "@ULP_VAR_MAP_HEADER@"; echo -ne " { .sym.sym_name = \"${var}\", .sym.sym_value = &${var}, .size = ${size}},\n };" >> "@ULP_VAR_MAP_HEADER@"; fi; done']=] + [=[if ! grep -q "struct ulp_var_map_s ulp_var_map" "@ULP_VAR_MAP_HEADER@"; then printf '%s\n' '#include "nuttx/symtab.h"' '#include "ulp/ulp_vars.h"' '' 'struct ulp_var_map_s' '{' ' struct symtab_s sym;' ' size_t size;' '};' '' 'struct ulp_var_map_s ulp_var_map[] =' '{ };' > "@ULP_VAR_MAP_HEADER@"; fi; sed -i "/@ULP_PREFIX@/d" "@ULP_VAR_MAP_HEADER@"; flock -x "@ULP_LOCKFILE@" -c 'grep "@ULP_PREFIX@" "@ULP_MAIN_HEADER@" | while IFS= read -r line; do var=$(echo "$line" | grep -oP "@ULP_PREFIX@\w+(?=[;\[])" ); if [ -n "$var" ]; then size=$(echo "$line" | grep -oP "\[\d+\]" | grep -oP "\d+"); if [ -n "$size" ]; then size=$(( size * 4 )); else size=4; fi; sed -i "s/ };//" "@ULP_VAR_MAP_HEADER@"; printf " { .sym.sym_name = \"%s\", .sym.sym_value = &%s, .size = %s},\n };" "${var}" "${var}" "${size}" >> "@ULP_VAR_MAP_HEADER@"; fi; done']=] ) string(REPLACE "@ULP_VAR_MAP_HEADER@" "${ULP_VAR_MAP_HEADER}" _ulp_postprocess_var_map "${_ulp_postprocess_var_map}") @@ -427,6 +460,7 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE) COMMAND ${ULP_READELF} -sW ${ULP_ELF_FILE} > ${ULP_SYM_FILE} COMMAND ${Python3_EXECUTABLE} ${ULP_MAPGEN_TOOL} -s ${ULP_SYM_FILE} -o ${ULP_FOLDER}/ulp_main --base ${ULP_BASE} --prefix ${ULP_PREFIX} + COMMAND bash -c "${_ulp_postprocess_sw_mailbox_alias}" COMMAND bash -c "${_ulp_postprocess_aliases}" COMMAND sed -i "/${ULP_PREFIX}/d" ${ULP_VARS_HEADER} COMMAND diff --git a/arch/risc-v/src/common/espressif/esp_ulp.mk b/arch/risc-v/src/common/espressif/esp_ulp.mk index 26db0f2d42bc2..4f1a5d64840b3 100644 --- a/arch/risc-v/src/common/espressif/esp_ulp.mk +++ b/arch/risc-v/src/common/espressif/esp_ulp.mk @@ -63,6 +63,8 @@ ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)c ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)include ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)include ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)platform_port$(DELIM)include +ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hal_wdt$(DELIM)include +ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hal_wdt$(DELIM)$(CHIP_SERIES)$(DELIM)include ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)log ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)log$(DELIM)include ULP_INCLUDES += $(INCDIR_PREFIX)$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)riscv$(DELIM)include @@ -141,10 +143,12 @@ ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_lp_adc_shared.c ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_lp_vad_shared.c ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_critical_section_shared.c +ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_mailbox.c ifeq ($(CONFIG_ARCH_CHIP_ESP32P4),y) ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_touch.c ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)port$(DELIM)lp_core_mailbox_impl_hw.c - ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_mailbox.c +else + ULP_CSOURCES += $(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)port$(DELIM)lp_core_mailbox_impl_sw.c endif # Add ULP app source files and directories @@ -159,8 +163,8 @@ else ULP_BIN_FILE = $(ULP_FOLDER)$(DELIM)ulp.bin ULP_BIN_FILE_PATH = $(ULP_BIN_FILE) - ULP_C_SRCS = $(addprefix $(ULP_APP_FOLDER)/,$(sort $(ULP_APP_C_SRCS))) - ULP_ASM_SRCS = $(addprefix $(ULP_APP_FOLDER)/,$(sort $(ULP_APP_ASM_SRCS))) + ULP_C_SRCS = $(foreach s,$(sort $(ULP_APP_C_SRCS)),$(if $(filter /%,$(s)),$(s),$(ULP_APP_FOLDER)/$(s))) + ULP_ASM_SRCS = $(foreach s,$(sort $(ULP_APP_ASM_SRCS)),$(if $(filter /%,$(s)),$(s),$(ULP_APP_FOLDER)/$(s))) ULP_APP_OBJS = $(ULP_ASM_SRCS:.S=_ulp.o) ULP_APP_OBJS += $(ULP_C_SRCS:.c=_ulp.o) @@ -250,6 +254,17 @@ ULP_LDFLAGS := \ -Xlinker -Map=$(ULP_MAP_FILE) \ $(ULP_LDINCLUDES) +# Optional compile defines (e.g. -DNUTTX_ESP_BIST_MODULE) — after := above +ULP_CFLAGS += $(ULP_EXTRA_DEFINES) +ULP_ASFLAGS += $(ULP_EXTRA_DEFINES) + +# Default LP sections linker template; apps may override with ULP_CUSTOM_SECTIONS_LD +ifeq ($(ULP_CUSTOM_SECTIONS_LD),) + ULP_SECTIONS_TEMPLATE = $(BOARD)$(DELIM)scripts$(DELIM)${CHIP_SERIES}_lpcore_sections.ld +else + ULP_SECTIONS_TEMPLATE = $(ULP_CUSTOM_SECTIONS_LD) +endif + # Build rules .PHONY: context depend @@ -261,15 +276,18 @@ checkpython3: exit 1; \ fi -%_ulp.o: %.c $(ULP_NUTTX_CONFIG) +%_ulp.o: %.c $(ULP_NUTTX_CONFIG) $(ULP_FOLDER)$(DELIM)ulp_sections.ld $(Q) echo "Compiling $< for ULP" $(Q) $(CC) $(ULP_CFLAGS) -c $< -o $@ - $(Q) $(CC) $(ULP_INCLUDES) -E -P -xc -o $(ULP_FOLDER)$(DELIM)ulp_sections.ld $(BOARD)$(DELIM)scripts$(DELIM)${CHIP_SERIES}_lpcore_sections.ld %_ulp.o: %.S $(ULP_NUTTX_CONFIG) $(Q) echo "Compiling $< for ULP" $(Q) $(CC) $(ULP_ASFLAGS) -c $< -o $@ +$(ULP_FOLDER)$(DELIM)ulp_sections.ld: $(ULP_NUTTX_CONFIG) $(ULP_SECTIONS_TEMPLATE) + $(Q) echo "Preprocessing ULP linker sections from $(ULP_SECTIONS_TEMPLATE)" + $(Q) $(CC) $(ULP_INCLUDES) -E -P -xc -o $@ $(ULP_SECTIONS_TEMPLATE) + $(ULP_NUTTX_CONFIG): $(ULP_FOLDER) $(Q) echo "Copying nuttx$(DELIM)config.h into $(ULP_FOLDER)$(DELIM)nuttx" $(Q) cp $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)config.h $(ULP_FOLDER)$(DELIM)nuttx @@ -277,6 +295,7 @@ $(ULP_NUTTX_CONFIG): $(ULP_FOLDER) $(ULP_ELF_FILE): $(ULP_OBJS) $(Q) echo "Linking for ULP" $(Q) $(CC) $(ULP_LDFLAGS) $(ULP_OBJS) -o $@ + $(ULP_POST_LINK) $(ULP_BIN_FILE): $(ULP_ELF_FILE) checkpython3 $(Q) \ @@ -288,6 +307,13 @@ ifneq ($(suffix $(ULP_APP_BIN)),.bin) $(Q) $(OBJCOPY) -O binary $(ULP_ELF_FILE) $(ULP_BIN_FILE) $(Q) $(ULP_READELF) -sW $(ULP_ELF_FILE) > $(ULP_SYM_FILE) $(Q) python3 $(ULP_MAPGEN_TOOL_PATH) -s $(ULP_SYM_FILE) -o $(ULP_FOLDER)$(DELIM)ulp_main --base $(ULP_BASE) --prefix $(ULP_PREFIX) + $(Q) if grep -q 'g_lp_core_mailbox_impl_sw_ctx' $(ULP_FOLDER)$(DELIM)ulp_main.ld; then \ + addr=$$(grep 'g_lp_core_mailbox_impl_sw_ctx' $(ULP_FOLDER)$(DELIM)ulp_main.ld | head -1 | \ + sed -E 's/.*=[[:space:]]*([0x0-9a-fA-F]+);.*/\1/'); \ + if ! grep -qE '^[[:space:]]*ulp_g_lp_core_mailbox_impl_sw_ctx[[:space:]]*=' $(ULP_FOLDER)$(DELIM)ulp_main.ld; then \ + echo "ulp_g_lp_core_mailbox_impl_sw_ctx = $$addr;" >> $(ULP_FOLDER)$(DELIM)ulp_main.ld; \ + fi; \ + fi # Checking ULP linker script output and adding/changing related lines on common linker for HP core to access ULP core variables on HP core. $(Q) grep -E '^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*=[[:space:]]*[0x]*[0-9a-fA-F]+;' $(ULP_FOLDER)$(DELIM)ulp_main.ld | while IFS= read -r line; do \ out_file=$(BOARD)$(DELIM)scripts$(DELIM)ulp_aliases.ld; \ @@ -317,7 +343,7 @@ ifneq ($(suffix $(ULP_APP_BIN)),.bin) size=4; \ fi; \ sed -i "s/ };//" $(ULP_VAR_MAP_HEADER); \ - echo -ne " { .sym.sym_name = \"$${var}\", .sym.sym_value = &$${var}, .size = $${size}},\n };" >> $(ULP_VAR_MAP_HEADER); \ + printf " { .sym.sym_name = \"%s\", .sym.sym_value = &%s, .size = %s},\n };" "$${var}" "$${var}" "$${size}" >> $(ULP_VAR_MAP_HEADER); \ fi; \ done' endif diff --git a/arch/risc-v/src/esp32c6/hal_esp32c6.cmake b/arch/risc-v/src/esp32c6/hal_esp32c6.cmake index 897a290a7e532..994bc313e2d95 100644 --- a/arch/risc-v/src/esp32c6/hal_esp32c6.cmake +++ b/arch/risc-v/src/esp32c6/hal_esp32c6.cmake @@ -270,6 +270,7 @@ list( ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/mac_addr.c ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/modem_clock.c ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/periph_ctrl.c + ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/pmu_share_hw.c ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/regi2c_ctrl.c ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/rtc_module.c ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/sleep_console.c @@ -504,6 +505,9 @@ list( HAL_SRCS ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/lp_core_i2c.c ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/lp_core.c + ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/lp_core_mailbox.c + ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/lp_core_mailbox_impl_sw.c + ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/shared/ulp_lp_core_critical_section_shared.c ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/shared/ulp_lp_core_memory_shared.c ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/shared/ulp_lp_core_lp_timer_shared.c ) diff --git a/arch/risc-v/src/esp32c6/hal_esp32c6.mk b/arch/risc-v/src/esp32c6/hal_esp32c6.mk index 6da49a12d2a7d..c3dbd8d66d0ad 100644 --- a/arch/risc-v/src/esp32c6/hal_esp32c6.mk +++ b/arch/risc-v/src/esp32c6/hal_esp32c6.mk @@ -213,6 +213,7 @@ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)mac_addr.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)modem_clock.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)periph_ctrl.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)pmu_share_hw.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)regi2c_ctrl.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)rtc_module.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)sleep_console.c @@ -364,6 +365,9 @@ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)spi_ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)spi_flash$(DELIM)cache_utils.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core_i2c.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core_mailbox.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core_mailbox_impl_sw.c +CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_critical_section_shared.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_memory_shared.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_lp_timer_shared.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)upper_hal_rmt$(DELIM)src$(DELIM)rmt_common.c diff --git a/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c b/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c index d44081a652ffc..d50b9e0a34165 100644 --- a/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c +++ b/boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c @@ -158,6 +158,10 @@ # endif #endif +# ifdef CONFIG_ESPRESSIF_LP_MAILBOX +# include "espressif/esp_lp_mailbox.h" +# endif + #include "esp32c6-devkitc.h" /**************************************************************************** @@ -549,6 +553,10 @@ int esp_bringup(void) #ifdef CONFIG_ESPRESSIF_USE_LP_CORE +# ifdef CONFIG_ESPRESSIF_LP_MAILBOX + esp_lp_mailbox_init(); +# endif + /* ULP initialization should be the handled later than * peripherals to use supported peripherals properly on ULP core */