Skip to content

fix(ulp): Ulp core does not start with UlpCoreWakeupSource::HpCpu.#5410

Merged
bugadani merged 5 commits intoesp-rs:mainfrom
puyogo-suzuki:fix/ulp_without_timer
May 2, 2026
Merged

fix(ulp): Ulp core does not start with UlpCoreWakeupSource::HpCpu.#5410
bugadani merged 5 commits intoesp-rs:mainfrom
puyogo-suzuki:fix/ulp_without_timer

Conversation

@puyogo-suzuki
Copy link
Copy Markdown
Contributor

@puyogo-suzuki puyogo-suzuki commented Apr 22, 2026

Pull Request Details 📖

Description

This PR fixes a regression where the ULP core fails to start when using UlpCoreWakeupSource::HpCpu. This issue was introduced in #5134.

Specifically, the lp_blinky example currently hangs because the ULP core never starts. The root cause is that the sleep timer is not enabled within ulp_config_wakeup_source when this wakeup source is selected.

This PR resolves the issue by ensuring the timer is enabled even when UlpCoreWakeupSource::HpCpu is specified. The timer is configured to wake the ULP core immediately.

Detailed explanation

According to Section 2.4 of the ESP32-S3 Technical Reference Manual (v1.8), the sleep timer must be enabled to wake the ULP core, even when triggered by RTC GPIO or software:

  1. Flash the program to be executed by ULP coprocessor into RTC slow memory.
  2. Select the working ULP coprocessor by configuring RTC_CNTL_COCPU_SEL.
  3. If ULP-RISC-V is selected as working ULP coprocessor, please set and reset RTC_CNTL_COCPU_CLK_FO; set RTC_CNTL_COCPU_CLKGATE_EN.
  4. Set sleep cycles for the timer by configuring RTC_CNTL_ULP_CP_TIMER_1_REG.
  5. Enable the timer by software or by RTC GPIO;
  • By software: set RTC_CNTL_ULP_CP_SLP_TIMER_EN.
  • By RTC GPIO: set RTC_CNTL_ULP_CP_GPIO_WAKEUP_ENA.

In ESP-IDF, there is no direct equivalent to our UlpCoreWakeupSource::HpCpu.
Instead, it defaults to ULP_RISCV_WAKEUP_SOURCE_TIMER:
ulp_riscv.h#L32 (esp-idf)

Discussion

I have set the sleep cycles (RTC_CNTL_ULP_CP_TIMER_SLP_CYCLE) to 0 to ensure the ULP core wakes up immediately once the timer is enabled.
However, the hardware default value is 200.
Should I use the hardware default?

Testing

Tested with the lp_blinky example on an ESP32-S3-DevKitC-1:

  • Before this PR: The LED does not blink, and the counter remains at 0 (stuck).
  • After this PR: The ULP core starts correctly, the LED blinks, and the counter increments as expected.

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the latest Migration Guide.
  • My changes are in accordance to the esp-rs developer guidelines

Extra:

Copilot AI review requested due to automatic review settings April 22, 2026 06:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a regression in the ESP32-S2/S3 ULP core bring-up path where UlpCoreWakeupSource::HpCpu would not start the ULP core because the ULP sleep timer wasn’t enabled (regression introduced by the timer-support work in #5134).

Changes:

  • Refactors ULP wakeup-source configuration to share timer setup via a local helper.
  • Ensures UlpCoreWakeupSource::HpCpu also enables the ULP sleep timer (configured for immediate wake) so the ULP core actually starts.
  • Applies the same fix to both ESP32-S2 and ESP32-S3 implementations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
esp-hal/src/soc/esp32s3/ulp_core.rs Enables/configures the ULP sleep timer even for HpCpu wakeup to avoid ULP start hang on ESP32-S3.
esp-hal/src/soc/esp32s2/ulp_core.rs Mirrors the same wakeup-source/timer enabling fix for ESP32-S2.

Comment thread esp-hal/src/soc/esp32s3/ulp_core.rs
Comment thread esp-hal/src/soc/esp32s2/ulp_core.rs
@puyogo-suzuki puyogo-suzuki force-pushed the fix/ulp_without_timer branch from 789a806 to e4c0018 Compare April 27, 2026 02:57
Copilot AI review requested due to automatic review settings April 27, 2026 07:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread esp-hal/CHANGELOG.md Outdated
Comment thread esp-hal/CHANGELOG.md Outdated
Copilot AI review requested due to automatic review settings April 27, 2026 07:30
@puyogo-suzuki puyogo-suzuki force-pushed the fix/ulp_without_timer branch from 161fc2c to 7f2c28c Compare April 27, 2026 07:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@puyogo-suzuki
Copy link
Copy Markdown
Contributor Author

I don't know why the changelog check fails.

Caused by:
    Changelog line This release was made possible via the following pre-releases: starts with unexpected character

I verified that the added line starts as same as the other lines.

@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 27, 2026
@github-actions
Copy link
Copy Markdown

New commits in main has made this PR unmergable. Please resolve the conflicts.

Comment thread esp-hal/src/soc/esp32s2/ulp_core.rs
@bjoernQ
Copy link
Copy Markdown
Contributor

bjoernQ commented Apr 29, 2026

There was a problem with the changelog format - it's fixed on main and a rebase should fix it

I guess otherwise this is fine

Comment thread esp-hal/CHANGELOG.md Outdated
@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 29, 2026
@bugadani
Copy link
Copy Markdown
Contributor

@leighleighleigh could you please take a look at this PR?

@puyogo-suzuki
Copy link
Copy Markdown
Contributor Author

Thank you for the review.
I have updated CHANGELOG based on your suggestion.

Do you have any further suggestions?

@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 30, 2026
@github-actions
Copy link
Copy Markdown

New commits in main have made this PR unmergeable. Please resolve the conflicts.

@leighleighleigh
Copy link
Copy Markdown
Contributor

@bugadani I have reproduced this, and confirmed the changes fix the regression.
Thanks @puyogo-suzuki ! :)

Copilot AI review requested due to automatic review settings May 2, 2026 09:13
@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label May 2, 2026
Copy link
Copy Markdown
Contributor

@bugadani bugadani left a comment

Choose a reason for hiding this comment

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

Thank you both!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@bugadani bugadani added this pull request to the merge queue May 2, 2026
Merged via the queue into esp-rs:main with commit c651f80 May 2, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants