Skip to content

arch/risc-v/espressif: Fix build errors on CMake ULP build system#19485

Merged
acassis merged 1 commit into
apache:masterfrom
eren-terzioglu:bugfix/fix_cmake_ulp_build
Jul 20, 2026
Merged

arch/risc-v/espressif: Fix build errors on CMake ULP build system#19485
acassis merged 1 commit into
apache:masterfrom
eren-terzioglu:bugfix/fix_cmake_ulp_build

Conversation

@eren-terzioglu

@eren-terzioglu eren-terzioglu commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • arch/risc-v/espressif: Fix build errors on CMake ULP build system

Fix build errors on ULP usage with CMake (e.g lp_mailbox usage, hal assertions enabled)

Impact

Impact on user: Yes, build error fixed

Impact on build: Yes, ULP build error fixed when using CMake

Impact on hardware: No

Impact on documentation: No

Impact on security: No

Impact on compatibility: No

Testing

esp32p4-function-ev-board:ulp config used to test.

Building

.
└── 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 <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <unistd.h>

#include <nuttx/fs/ioctl.h>
#include <sys/ioctl.h>

#include "ulp/ulp/ulp_main.h"
#include "ulp/ulp/ulp_code.h"


int main(int argc, char *argv[])
{
  int fd;
  int mailbox;
  uint8_t data = 0;
  int ret = OK;
  int prev_data;

  fd = open("/dev/ulp", O_WRONLY);
  if (fd < 0)
    {
      printf("Failed to open ULP: %d\n", errno);
      return -1;
    }

  write(fd, ulp_mailbox_bin, ulp_mailbox_bin_len);

  mailbox = open("/dev/lp_mailbox", O_RDWR);
  if (mailbox < 0)
    {
      printf("Failed to open LP Mailbox: %d\n", errno);
      return -1;
    }

  /* Waiting for a while to let ULP start to run */

  sleep(3);
  for (int i = 0; i < 2; i++)
    {
      ret = write(mailbox, &data, 1);
      if (ret != 1)
        {
          printf("Failed to send data\n");
          return ERROR;
        }

      prev_data = data;
      ret = read(mailbox, &data, 1);
      if (ret != 1 || (prev_data + 1 != data))
        {
          printf("Failed to read data\n");
          return ERROR;
        }
      else
        {
          printf("Read data: %d\n", data);
        }

      sleep(1);
    }

  printf("All done.\n");
  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 "nuttx/config.h"
#include <stdbool.h>
#include <stdint.h>
#include "ulp_lp_core_utils.h"
#include "ulp_lp_core_mailbox.h"

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

static lp_mailbox_t mailbox;

int main(void)
{
  lp_core_mailbox_init(&mailbox, NULL);
  lp_message_t message;
  esp_err_t ret;

  while (1)
    {
      ret = lp_core_mailbox_receive(mailbox, &message, UINT32_MAX);

      if (ret == ESP_OK)
        {
          message = message + 1;
          ret = lp_core_mailbox_send(mailbox, message, UINT32_MAX);
        }

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

  return 0;
}

Command to build ULP example:

cmake -B build -DBOARD_CONFIG=esp32p4-function-ev-board:ulp -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 && kconfig-tweak --file build/.config -e CONFIG_ESPRESSIF_LP_MAILBOX && cmake --build build -t olddefconfig && cmake --build build && ESPTOOL_PORT=/dev/ttyUSB0 cmake --build build -t flash

Running

ulp_test command used to run.

Results

Blink will start on startup

For ULP example:

nsh> ls /dev
/dev:
...
 lp_mailbox
...
nsh> custom_app
Read data: 1
Read data: 2
All done.
nsh> 

Fix build errors on ULP usage with CMake (e.g lp_mailbox usage, hal assertions enabled)

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
@github-actions github-actions Bot added Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Size: XS The size of the change in this PR is very small labels Jul 20, 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 20, 2026 08:01
@acassis
acassis merged commit e26e38f into apache:master Jul 20, 2026
30 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 Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants