Skip to content

arch/risc-v/espressif: Add CMake ULP support#19457

Merged
xiaoxiang781216 merged 3 commits into
apache:masterfrom
eren-terzioglu:feature/esp_ulp_cmake
Jul 17, 2026
Merged

arch/risc-v/espressif: Add CMake ULP support#19457
xiaoxiang781216 merged 3 commits into
apache:masterfrom
eren-terzioglu:feature/esp_ulp_cmake

Conversation

@eren-terzioglu

Copy link
Copy Markdown
Contributor

Summary

  • Docs/platforms/risc-v: Add CMake ULP build system docs

Add CMake ULP build system docs for esp32[-c6|-p4]

  • boards/risc-v/espressif: Add CMake ULP board support

Add CMake ULP board support for esp32[-c6|-p4]

  • arch/risc-v/espressif: Add CMake ULP support

Add CMake support for ULP build

Impact

Impact on user: Yes, users can build ULP app with using CMake build system

Impact on build: Yes, ULP application can be built with CMake

Impact on hardware: Yes, ULP can be built with using CMake

Impact on documentation: Yes, related docs added

Impact on security: No

Impact on compatibility: No

Testing

esp32c6-devkitc:ulp and esp32p4-function-ev-board:ulp configs used to test.

Building

ULP processor can be used with 2 ways:

  • Using Pre-Built binary
  • Using NuttX ULP build system for Espressif

Using Pre-Built binary

These commands can be used for pre-built binary example

cmake -B build -DBOARD_CONFIG=esp32c6-devkitc:ulp -GNinja && cmake --build build && ESPTOOL_PORT=/dev/ttyUSB0 cmake --build build -t flash

Feature included a pre-built binary which is a blink example. After these commands it will include .bin file under boards/risc-v/esp32c6/common/etc/ and GPIO0 will blink after flashing.

Using NuttX ULP build system for Espressif

.
└── nuttxspace/
    ├── nuttx
    └── apps/
        └── external/
            ├── ...
            └── ulp_test/
                ├── Kconfig
                ├── CMakeLists.txt
                ├── ulp_test_main.c
                └── ulp/
                    ├── CMakeLists.txt
                    └── ulp_blink.c

Contents of the files:

  • Kconfig:
config ULP_TEST_APP
	bool "ULP test app"
	default n
  • CMakeLists.txt:
   include(ulp/CMakeLists.txt)
   nuttx_add_application(
      NAME
      ${CONFIG_EXAMPLES_ULP_EXAMPLE_PROGNAME}
      PRIORITY
      ${SCHED_PRIORITY_DEFAULT}
      STACKSIZE
      ${CONFIG_DEFAULT_TASK_STACKSIZE}
      MODULE
      ${CONFIG_EXAMPLES_ULP_EXAMPLE}
      INCLUDE_DIRECTORIES
      ${CMAKE_CURRENT_BINARY_DIR}
      SRCS
      ulp_example.c
      DEPENDS
      ${_ulp_example_deps})
  • ulp_test_main.c:
#include <nuttx/config.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <nuttx/fs/ioctl.h>
#include <sys/ioctl.h>
#include "ulp/ulp/ulp_main.h"
#include "ulp/ulp/ulp_code.h"
#include "nuttx/symtab.h"

#define PIN 0

int main(int argc, char *argv[])
{
  int fd;
  uint32_t read_result;
  struct symtab_s sym =
  {
    .sym_name = "ulp_blink_gpio_level_previous",
    .sym_value = &read_result,
  };

  fd = open("/dev/ulp", O_WRONLY);
  if (fd < 0)
    {
      printf("Failed to open ULP: %d\n", errno);
      return -1;
    }
  int ret = write(fd, ulp_blink_bin, ulp_blink_bin_len);
  if (ret != OK)
    {
      printf("Write failed \n");
      return ERROR;
    }
  ioctl(fd, FIONREAD, &sym);

  /* Chaging LP GPIO status from a variable on HP core */

  printf("First GPIO level: %ld\n", read_result);
  printf("Expected GPIO level: %ld\n", !read_result);
  read_result = !read_result;
  ioctl(fd, FIONWRITE, &sym);
  return OK;

}
  • ulp/CMakeLists.txt:
    set(_ulp_example_deps)
    set(ULP_APP_NAME ulp_example)
    set(ULP_APP_FOLDER ${CMAKE_CURRENT_LIST_DIR}/ulp)
    set(ULP_APP_C_SRCS ulp_main.c)
    include(${NUTTX_DIR}/arch/risc-v/src/common/espressif/esp_ulp.cmake)
    list(APPEND _ulp_example_deps ulp_example_ulp_bin)
  • ulp/ulp_blink.c
#include <stdint.h>
#include <stdbool.h>
#include "ulp_lp_core_gpio.h"

#define GPIO_PIN 0

#define nop()   __asm__ __volatile__ ("nop")

bool gpio_level_previous = true;

int main(void)
{
    while (1)
        {
            ulp_lp_core_gpio_set_level(GPIO_PIN, gpio_level_previous);

            /* Delay */

            for (int i = 0; i < 10000; i++)
                {
                    nop();
                }
        }

    /* ulp_lp_core_halt() is called automatically when main exits */

    return 0;
}

Command to build ULP example:

cmake -B build -DBOARD_CONFIG=esp32c6-devkitc:nsh -GNinja && kconfig-tweak --file build/.config -e CONFIG_ESPRESSIF_GPIO_IRQ && kconfig-tweak --file build/.config -e CONFIG_DEV_GPIO && kconfig-tweak --file build/.config -e CONFIG_ESPRESSIF_USE_LP_CORE && kconfig-tweak --file build/.config -e CONFIG_EXAMPLES_ULP_EXAMPLE && cmake --build build -t olddefconfig && cmake --build build && ESPTOOL_PORT=/dev/ttyUSB0 cmake --build build -t flash

Running

Test bin will start to run at startup. Logic analyzer connected to GPIO0. For ULP example ulp_test command used to run.

Results

Blink will start on startup

For ULP example:

nsh> ulp_blink
First GPIO level: 1
Expected GPIO level: 0
Pin status: 1
Pin status: 0
Cheking done. Exiting.
nsh> 

Add CMake support for ULP build

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
Add CMake ULP board support for esp32[-c6|-p4]

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
Add CMake ULP build system docs for esp32[-c6|-p4]

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Size: L The size of the change in this PR is large Board: risc-v labels Jul 16, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@eren-terzioglu eren-terzioglu marked this pull request as ready for review July 16, 2026 12:43
@xiaoxiang781216 xiaoxiang781216 merged commit 20c2807 into apache:master Jul 17, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Area: Documentation Improvements or additions to documentation Board: risc-v Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants