This is an automated email from the ASF dual-hosted git repository.

simbit18 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 70dc59a5e6cedcdc67ed1b656f5bf9b7e4ef56b5
Author: Eren Terzioglu <[email protected]>
AuthorDate: Wed Jul 23 14:52:42 2025 +0200

    arch/risc-v/esp32c6: Add lpcore support
    
    Add lpcore support for esp32c6
    
    Signed-off-by: Eren Terzioglu <[email protected]>
---
 arch/risc-v/src/common/espressif/Kconfig    |  45 +++++
 arch/risc-v/src/common/espressif/Make.defs  |  13 +-
 arch/risc-v/src/common/espressif/esp_ulp.c  |  85 ++++++++++
 arch/risc-v/src/common/espressif/esp_ulp.h  |  70 ++++++++
 arch/risc-v/src/common/espressif/esp_ulp.mk | 254 ++++++++++++++++++++++++++++
 arch/risc-v/src/esp32c6/.gitignore          |   1 +
 arch/risc-v/src/esp32c6/hal_esp32c6.mk      |   7 +
 7 files changed, 474 insertions(+), 1 deletion(-)

diff --git a/arch/risc-v/src/common/espressif/Kconfig 
b/arch/risc-v/src/common/espressif/Kconfig
index d15a9a2ae76..548af621e56 100644
--- a/arch/risc-v/src/common/espressif/Kconfig
+++ b/arch/risc-v/src/common/espressif/Kconfig
@@ -251,6 +251,51 @@ endif # ESPRESSIF_HAVE_OTA_PARTITION
 
 endmenu # Bootloader and Image Configuration
 
+menu "LP Core (Low-power core) Coprocessor Configuration"
+
+config ESPRESSIF_USE_LP_CORE
+       bool "Enable LP Coprocessor"
+       depends on ESPRESSIF_ESP32C6
+       ---help---
+               Enable LP core (Low-power core) coprocessor
+
+config ESPRESSIF_ULP_PROJECT_PATH
+       string "Path to ULP project (relative to nuttx root folder)"
+       depends on ESPRESSIF_USE_LP_CORE
+       default ""
+       ---help---
+               Path to ULP project to include build system and run on LP core.
+               This path can either be a .bin file or a project folder
+
+config ESPRESSIF_ULP_COPROC_RESERVE_MEM_SIZE
+       int "RTC slow memory reserved for coprocessor"
+       depends on ESPRESSIF_USE_LP_CORE
+       default 4096
+       range 32 16352
+       ---help---
+               Bytes of memory to reserve for ULP Co-processor firmware & data.
+               Data is reserved at the beginning of RTC slow memory.
+
+config ESPRESSIF_ULP_SHARED_MEM_SIZE
+       int "Size of the shared memory for ULP core"
+       depends on ESPRESSIF_USE_LP_CORE
+       default 16
+       ---help---
+               Size of the shared memory defined in bytes.
+
+config ESPRESSIF_ULP_ENABLE_UBSAN
+       bool "Enable UBSan (undefined behavior sanitizer) for LP core 
application"
+       depends on ESPRESSIF_USE_LP_CORE
+       depends on DEBUG_SYMBOLS
+       default n
+       ---help---
+               LP core supports limited set of HW exceptions. This can be 
overcome
+               by enabling undefined behavior sanitizer for LP core 
application to catch some errors.
+               But note that it will increase code size significantly and it 
can happen that
+               application will not fit into RTC RAM
+
+endmenu # LP Core (Low-power core) Coprocessor Configuration
+
 menu "Peripheral Support"
 
 config ESPRESSIF_RTC
diff --git a/arch/risc-v/src/common/espressif/Make.defs 
b/arch/risc-v/src/common/espressif/Make.defs
index 60b1ed1865d..6202e988842 100644
--- a/arch/risc-v/src/common/espressif/Make.defs
+++ b/arch/risc-v/src/common/espressif/Make.defs
@@ -179,6 +179,10 @@ ifeq ($(CONFIG_CRYPTO_CRYPTODEV_HARDWARE),y)
        CHIP_CSRCS += esp_crypto.c
 endif
 
+ifeq ($(CONFIG_ESPRESSIF_USE_LP_CORE), y)
+       CHIP_CSRCS += esp_ulp.c
+endif
+
 ifeq ($(CONFIG_ESPRESSIF_EFUSE),y)
        LDFLAGS += -u esp_efuse_startup_include_func
 endif
@@ -191,7 +195,7 @@ endif
 
 ESP_HAL_3RDPARTY_REPO   = esp-hal-3rdparty
 ifndef ESP_HAL_3RDPARTY_VERSION
-       ESP_HAL_3RDPARTY_VERSION = 8d7f4177afafdb7941182d8997d3589b1152aec0
+       ESP_HAL_3RDPARTY_VERSION = b6fa6c9098318007a61acc7c9f0f180443bb80c2
 endif
 
 ifndef ESP_HAL_3RDPARTY_URL
@@ -242,6 +246,10 @@ CHIP_SERIES = $(patsubst 
"%",%,$(CONFIG_ESPRESSIF_CHIP_SERIES))
 
 include chip/hal_${CHIP_SERIES}.mk
 
+ifeq ($(CONFIG_ESPRESSIF_USE_LP_CORE), y)
+       include common$(DELIM)espressif$(DELIM)/esp_ulp.mk
+endif
+
 ifeq ($(CONFIG_ESP_WIRELESS),y)
        include common$(DELIM)espressif$(DELIM)Wireless.mk
 endif
@@ -255,6 +263,9 @@ distclean::
        $(call DELFILE,../include/chip/irq.h)
        $(call DELFILE,../../../vefuse.bin)
        $(call DELDIR,chip/$(ESP_HAL_3RDPARTY_REPO))
+ifeq ($(CONFIG_ESPRESSIF_USE_LP_CORE),y)
+       $(call DELDIR,chip/ulp)
+endif
 
 INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)common$(DELIM)espressif
 INCLUDES += 
${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)common$(DELIM)espressif$(DELIM)platform_include
diff --git a/arch/risc-v/src/common/espressif/esp_ulp.c 
b/arch/risc-v/src/common/espressif/esp_ulp.c
new file mode 100644
index 00000000000..3ac3fd8b1e4
--- /dev/null
+++ b/arch/risc-v/src/common/espressif/esp_ulp.c
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * arch/risc-v/src/common/espressif/esp_ulp.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include "ulp_lp_core.h"
+#include "ulp/ulp_code.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp_ulp_init
+ *
+ * Description:
+ *   Initialize ULP co-processor
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void esp_ulp_init(void)
+{
+  ulp_lp_core_cfg_t cfg =
+    {
+      .wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_HP_CPU,
+    };
+
+  ulp_lp_core_load_binary(esp_ulp_bin,
+                          sizeof(esp_ulp_bin));
+
+  ulp_lp_core_run(&cfg);
+}
diff --git a/arch/risc-v/src/common/espressif/esp_ulp.h 
b/arch/risc-v/src/common/espressif/esp_ulp.h
new file mode 100644
index 00000000000..3a97e253af8
--- /dev/null
+++ b/arch/risc-v/src/common/espressif/esp_ulp.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+ * arch/risc-v/src/common/espressif/esp_ulp.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_ULP_H
+#define __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_ULP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+
+#ifndef __ASSEMBLY__
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp_ulp_init
+ *
+ * Description:
+ *   Initialize ULP co-processor
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void esp_ulp_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+#undef EXTERN
+
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_RISCV_SRC_COMMON_ESPRESSIF_ESP_ULP_H */
diff --git a/arch/risc-v/src/common/espressif/esp_ulp.mk 
b/arch/risc-v/src/common/espressif/esp_ulp.mk
new file mode 100644
index 00000000000..d4761429213
--- /dev/null
+++ b/arch/risc-v/src/common/espressif/esp_ulp.mk
@@ -0,0 +1,254 @@
+############################################################################
+# arch/risc-v/src/common/espressif/esp_ulp.mk
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+ifeq ($(CONFIG_ESPRESSIF_USE_LP_CORE),y)
+
+# Include header paths
+
+ULP_INCLUDES += $(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)
+ULP_INCLUDES += $(INCDIR_PREFIX)chip$(DELIM)ulp
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_common$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)port$(DELIM)$(CHIP_SERIES)$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)port$(DELIM)$(CHIP_SERIES)$(DELIM)private_include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_rom
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_rom$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_rom$(DELIM)$(CHIP_SERIES)
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_rom$(DELIM)$(CHIP_SERIES)$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_rom$(DELIM)$(CHIP_SERIES)$(DELIM)include$(DELIM)$(CHIP_SERIES)
+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)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
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)$(CHIP_SERIES)$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)register
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)register
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)register$(DELIM)soc
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)ulp_common
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)ulp_common$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)$(CHIP_SERIES)$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)src$(DELIM)components$(DELIM)esp_driver_gpio$(DELIM)include
+ULP_INCLUDES += 
$(INCDIR_PREFIX)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)src$(DELIM)components$(DELIM)esp_driver_uart$(DELIM)include
+
+# Linker scripts
+
+ULP_LDINCLUDES += 
-Tchip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)ld$(DELIM)$(CHIP_SERIES).peripherals.ld
+ULP_LDINCLUDES += -Tchip$(DELIM)ulp$(DELIM)ulp_sections.ld
+
+# Source files
+
+ULP_ASOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)port$(DELIM)${CHIP_SERIES}$(DELIM)vector_table.S
+ULP_ASOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)start.S
+ULP_ASOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)vector.S
+
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_spi.c
+# ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)src$(DELIM)components$(DELIM)esp_driver_uart$(DELIM)src$(DELIM)uart_wakeup.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_memory_shared.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_lp_uart_shared.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_lp_timer_shared.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)uart_hal_iram.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)uart_hal.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_i2c.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_startup.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_utils.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_uart.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_print.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_panic.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_interrupt.c
+ULP_CSOURCES += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_ubsan.c
+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
+
+# Add ULP app source files and directories
+
+ULP_FOLDER = chip$(DELIM)ulp
+ULP_CODE_HEADER = $(ULP_FOLDER)$(DELIM)ulp_code.h
+ULP_PROJECT_PATH = $(shell echo $(CONFIG_ESPRESSIF_ULP_PROJECT_PATH))
+
+ifeq ($(suffix $(ULP_PROJECT_PATH)),.bin)
+       ULP_BIN_FILE_PATH = 
$(TOPDIR)$(DELIM)$(CONFIG_ESPRESSIF_ULP_PROJECT_PATH)
+       ULP_BIN_FILE = "skip"
+else
+       ARCHSCRIPT += $(ULP_FOLDER)$(DELIM)ulp_main.ld
+
+       ULP_BIN_FILE = $(ULP_FOLDER)$(DELIM)ulp.bin
+       ULP_BIN_FILE_PATH = $(ULP_BIN_FILE)
+
+       ULP_APP_DIR = $(shell echo $(CONFIG_ESPRESSIF_ULP_PROJECT_PATH))
+       ULP_APP_PATH = $(TOPDIR)$(DELIM)$(ULP_APP_DIR)
+
+       ULP_APP_C_SRCS = $(wildcard $(ULP_APP_PATH)/*.c $(ULP_APP_PATH)/**/*.c)
+       ULP_APP_ASM_SRCS = $(wildcard $(ULP_APP_PATH)/*.s 
$(ULP_APP_PATH)/**/*.S)
+       ULP_APP_HEADERS = $(wildcard $(ULP_APP_PATH)/**/*.h 
$(ULP_APP_PATH)/**/*.h)
+       ULP_APP_INCLUDES = $(addprefix -I,$(sort $(dir $(ULP_APP_HEADERS))))
+       ULP_APP_OBJS = $(ULP_APP_ASM_SRCS:.S=_ulp.o)
+       ULP_APP_OBJS += $(ULP_APP_C_SRCS:.c=_ulp.o)
+
+       ULP_INCLUDES += $(ULP_APP_INCLUDES)
+       ULP_CSOURCES += $(ULP_APP_C_SRCS)
+       ULP_ASOURCES += $(ULP_APP_ASM_SRCS)
+
+       # Object file format for ULP will be FILE_NAME_ulp.o to distinguish it 
from HP core files
+
+       ULP_COBJS = $(ULP_CSOURCES:.c=_ulp.o)
+       ULP_AOBJS = $(ULP_ASOURCES:.S=_ulp.o)
+       ULP_OBJS = $(ULP_COBJS) $(ULP_AOBJS)
+
+       ULP_ELF_FILE = $(ULP_FOLDER)$(DELIM)ulp.elf
+       ULP_MAP_FILE = $(ULP_FOLDER)$(DELIM)ulp.map
+       ULP_SYM_FILE = $(ULP_FOLDER)$(DELIM)ulp.sym
+
+endif
+
+# Toolchain and output paths definitions
+
+ULP_AS = $(CC)
+
+ULP_READELF = $(CROSSDEV)readelf
+ULP_MAPGEN_TOOL_PATH = 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)esp32ulp_mapgen.py
+ULP_PREFIX = ulp_
+ULP_BASE = 0
+
+# To prevent redefining error of other header files in nuttx folder, 
nuttx/config.h file
+# will be moved during ULP compilation. This step will only effect ULP
+
+ULP_NUTTX_CONFIG = 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)config.h
+
+# Compiler and linker flags
+
+ULP_CFLAGS :=                                                                  
        \
+       -Os                                                                     
                                        \
+       -ggdb                                                                   
                                \
+       -march=rv32imac_zicsr_zifencei  \
+       -mdiv                                                                   
                                \
+       -fdata-sections                                                         
        \
+       -ffunction-sections                                             \
+       -DIS_ULP_COCPU                                                          
        \
+       $(ULP_INCLUDES)
+
+ULP_ASFLAGS :=                                                                 
        \
+       -Os                                                                     
                                                \
+       -ggdb                                                                   
                                        \
+       -march=rv32imac_zicsr_zifencei  \
+       -x assembler-with-cpp                                   \
+       -D__ASSEMBLER__                                                         
        \
+       -DIS_ULP_COCPU                                                          
        \
+       $(ULP_INCLUDES)
+
+ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
+ULP_CFLAGS += -O0
+ULP_ASFLAGS += -O0
+
+ifeq ($(CONFIG_ESPRESSIF_ULP_ENABLE_UBSAN),y)
+ULP_CFLAGS +=                                                          \
+       -fno-sanitize=shift-base        \
+       -fsanitize=undefined
+
+ULP_ASFLAGS +=                                                 \
+       -fno-sanitize=shift-base        \
+       -fsanitize=undefined
+endif
+endif
+
+ULP_LDFLAGS :=                                                                 
        \
+       -march=rv32imac_zicsr_zifencei  \
+       --specs=nano.specs                                                      
\
+       --specs=nosys.specs                                             \
+       -nostartfiles                                                           
                \
+       -Wl,--no-warn-rwx-segments                      \
+       -Wl,--gc-sections                                                       
        \
+       -Xlinker -Map=$(ULP_MAP_FILE)           \
+       $(ULP_LDINCLUDES)
+
+# Build rules
+
+.PHONY: context depend
+
+checkpython3:
+       $(Q) if [ -z "$$(which python3)" ]; then \
+               $(Q) echo "ERROR: python3 not found in PATH"; \
+               $(Q) echo "       Please install python3 or fix the PATH"; \
+               exit 1; \
+       fi
+
+%_ulp.o: %.c $(ULP_NUTTX_CONFIG)
+       $(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_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
+
+$(ULP_ELF_FILE): $(ULP_OBJS)
+       $(Q) echo "Linking for ULP"
+       $(Q) $(CC) $(ULP_LDFLAGS) $(ULP_OBJS) -o $@
+
+$(ULP_BIN_FILE): $(ULP_ELF_FILE) checkpython3
+ifneq ($(suffix $(ULP_PROJECT_PATH)),.bin)
+       $(Q) echo "Creating bin for ULP"
+       $(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)
+endif
+       $(Q) echo "Converting bin for ULP into header file"
+       $(Q) xxd -i $(ULP_BIN_FILE_PATH) >$(ULP_CODE_HEADER) || { echo "xxd of 
$< failed" ; exit 1 ; }
+       $(Q) sed -i 's/unsigned char[^[]*\[[^]]*\]/unsigned char 
esp_ulp_bin[]/g' $(ULP_CODE_HEADER)
+       $(Q) sed -i 's/unsigned int[^=]* =/unsigned int esp_ulp_bin_len =/g' 
$(ULP_CODE_HEADER)
+
+$(ULP_FOLDER):
+       $(Q) echo "Creating $(ULP_FOLDER) folder"
+       $(Q) mkdir $(ULP_FOLDER)
+       $(Q) mkdir $(ULP_FOLDER)$(DELIM)nuttx
+
+context:: $(ULP_FOLDER)
+       $(Q) touch $(ULP_CODE_HEADER)
+       $(Q) touch $(ULP_FOLDER)$(DELIM)ulp_main.h
+
+depend: $(ULP_BIN_FILE)
+
+distclean::
+ifneq ($(suffix $(ULP_PROJECT_PATH)),.bin)
+       $(Q) rm $(ULP_APP_OBJS) || true
+endif
+
+endif # CONFIG_ESPRESSIF_USE_LP_CORE
diff --git a/arch/risc-v/src/esp32c6/.gitignore 
b/arch/risc-v/src/esp32c6/.gitignore
index d40b86f3a0d..4f35cf6fd45 100644
--- a/arch/risc-v/src/esp32c6/.gitignore
+++ b/arch/risc-v/src/esp32c6/.gitignore
@@ -2,3 +2,4 @@
 /esp-nuttx-bootloader
 /*.zip
 /esp-hal-3rdparty
+/ulp
diff --git a/arch/risc-v/src/esp32c6/hal_esp32c6.mk 
b/arch/risc-v/src/esp32c6/hal_esp32c6.mk
index 4bc082ed27a..9544771e19d 100644
--- a/arch/risc-v/src/esp32c6/hal_esp32c6.mk
+++ b/arch/risc-v/src/esp32c6/hal_esp32c6.mk
@@ -77,7 +77,11 @@ INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY
 INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)spi_flash$(DELIM)include$(DELIM)spi_flash
 INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp
 INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core
+INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared
+INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)include
 INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)include
+INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)ulp_common
+INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)ulp_common$(DELIM)include
 
 ifeq ($(CONFIG_ESPRESSIF_SIMPLE_BOOT),y)
   INCLUDES += 
$(INCDIR_PREFIX)$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)spi_flash$(DELIM)include
@@ -214,6 +218,9 @@ CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)temperature_sensor_periph.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)${CHIP_SERIES}$(DELIM)uart_periph.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)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)nuttx$(DELIM)src$(DELIM)components$(DELIM)esp_driver_gpio$(DELIM)src$(DELIM)gpio.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)src$(DELIM)components$(DELIM)esp_driver_gpio$(DELIM)src$(DELIM)rtc_io.c

Reply via email to