Skip to content

Conversation

@eren-terzioglu
Copy link
Contributor

Note: Please merge #17235 first

Summary

  • arch/xtensa/esp32[-s3]: Add ULP RISCV coprocessor wakeup board support

Add ULP RISC-V coprocessor wakeup board support for esp32s3

  • arch/xtensa/esp32[-s3]: Add ULP RISCV coprocessor wakeup

Add ULP RISCV coprocessor wakeup support for esp32s3

Impact

Impact on user: Yes, ULP RISC-V coprocessor can wake up HP core

Impact on build: No

Impact on hardware: No

Impact on documentation: No

Impact on security: No

Impact on compatibility: No

Testing

esp32s3-devkit:pm used as a base with these options added:

CONFIG_ESP32S3_ULP_COPROC_ENABLED=y
CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=8000
CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM=8000
CONFIG_PM_ULP_WAKEUP=y
CONFIG_PM_SLEEP_WAKEUP_SEC=25

To test this feature an example created, here are the snippets:

// HP core application
#include <nuttx/config.h>
#include <nuttx/power/pm.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <inttypes.h>
#include "ulp/ulp/ulp_main.h"
#include "ulp/ulp/ulp_code.h"
#include "esp32s3_pm.h"

void load_ulp_wakeup_binary(void)
{
  int fd;
  fd = open("/dev/ulp", O_WRONLY);
  if (fd < 0)
    {
      printf("Failed to open ULP: %d\n", errno);
      return;
    }
  write(fd, ulp_wakeup_bin, ulp_wakeup_bin_len);
}

int main(int argc, char *argv[])
{
  int ulp_fd;

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

  load_ulp_wakeup_binary();

  // esp32s3_pmsleep can be used for deep sleep as well
  esp32s3_pmstandby(CONFIG_PM_ALARM_SEC * 1000000 +
                    CONFIG_PM_ALARM_NSEC / 1000);

  return OK;
}
// LP core application
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include "ulp_riscv.h"
#include "ulp_riscv_utils.h"
#include "ulp_riscv_print.h"
#include "sdkconfig.h"

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

int main(void)
{
    while (1)
        {
            /* Delay */

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

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

    return 0;
}

Building

NuttX build process applied to related config. Assuming we updated pm config with related options

make -j distclean && ./tools/configure.sh esp32s3-devkit:pm && make -j && make download ESPTOOL_PORT=/dev/ttyUSB0 ESPTOOL_BAUD=921600 ESPTOOL_BINDIR=./

Running

Example run

Results

Device should got into sleep and nsh would be unresponsive for a few seconds but it needs to return back less than 25 seconds (or whatever assigned to CONFIG_PM_SLEEP_WAKEUP_SEC)

Fix exception issue when PM and DEBUG_ASSERTIONS enabled for esp32 and esp32s3.
This error happens due to PM system workflow, when system gets into sleep-modes with
removing PM_NORMAL count, system is raising an exception for not having
enough number of PM_NORMAL state count if DEBUG_ASSERTIONS enabled.

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
Add ULP RISCV coprocessor wakeup support for esp32s3

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
Add ULP RISC-V coprocessor wakeup board support for esp32s3

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation Arch: xtensa Issues related to the Xtensa architecture Board: xtensa Size: S The size of the change in this PR is small labels Oct 23, 2025
linguini1
linguini1 previously approved these changes Oct 23, 2025
Copy link
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eren-terzioglu suggestion: please include the test example in to Documentation/ and explain the steps to test it. This way people could use this feature easily

@eren-terzioglu
Copy link
Contributor Author

eren-terzioglu commented Oct 23, 2025

@eren-terzioglu suggestion: please include the test example in to Documentation/ and explain the steps to test it. This way people could use this feature easily

ULP example has only one line difference than documentation which is mentioned on Kconfig option and defconfig doc. Also PM defconfig doc should include tricks to let device sleep. Should we add it? I thought it will be unnecessary repeating.

@acassis
Copy link
Contributor

acassis commented Oct 23, 2025

@eren-terzioglu suggestion: please include the test example in to Documentation/ and explain the steps to test it. This way people could use this feature easily

ULP example has only one line difference than documentation which is mentioned on Kconfig option and defconfig doc. Also PM defconfig doc should include tricks to let device sleep. Should we add it? I thought it will be unnecessary repeating.

Is this only one line necessary to get ULP working correctly on NuttX? If so I think it is important to document it, even if you decide not to include this sample source code.

@eren-terzioglu
Copy link
Contributor Author

@eren-terzioglu suggestion: please include the test example in to Documentation/ and explain the steps to test it. This way people could use this feature easily

ULP example has only one line difference than documentation which is mentioned on Kconfig option and defconfig doc. Also PM defconfig doc should include tricks to let device sleep. Should we add it? I thought it will be unnecessary repeating.

Is this only one line necessary to get ULP working correctly on NuttX? If so I think it is important to document it, even if you decide not to include this sample source code.

Only different line is ulp_riscv_wakeup_main_processor and it is waking up the HP core but I can add it into ULP example with a comment, it will be efficient and informational.

@eren-terzioglu
Copy link
Contributor Author

Thanks @acassis, updated

Add ULP RISCV coprocessor wakeup docs for esp32s3

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
@xiaoxiang781216 xiaoxiang781216 merged commit 3893350 into apache:master Oct 24, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: xtensa Issues related to the Xtensa architecture Area: Documentation Improvements or additions to documentation Board: xtensa Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants