Skip to content

ledcFade can lead to dead-lock on ESP32-classic #9212

Closed
@TD-er

Description

@TD-er

Board

ESP32 (classic)

Device Description

ESP32-classic

Hardware Configuration

Nothing attached to the board

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Windows 11

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

115200

Description

Several calls to ledcAttach followed by ledcFade on the same pin without calling ledcDetach for that pin will lead to a completely frozen system on ESP32.

N.B. the same code on ESP32-C2 does not show this behavior. Not tested on other ESP32-variants.

Since there doesn't seem to be a simple check to see if a pin is already attached, I added a simple ledcWrite check first to set the start duty cycle for the upcoming fade.
If this returns false, I run ledcAttach on that pin.

So either of these 2 variants do work:

    if (!ledcWrite(gpio, start_duty)) {
      // Pin not yet attached
      if (!ledcAttach(gpio, frequency, resolution)) {
        return false;
      }
    }

    if (!ledcFade(gpio, start_duty, target_duty, fadeDuration_ms)) {
      return false;
    }
    ledcDetach(gpio);
    if (!ledcAttach(gpio, frequency, resolution)) {
      return false;
    }

    if (!ledcFade(gpio, start_duty, target_duty, fadeDuration_ms)) {
      return false;
    }

Sketch

// Not working code
while (true) {
    if (ledcAttach(gpio, frequency, resolution)) {
      ledcFade(gpio, start_duty, target_duty, fadeDuration_ms);
    }
    delay(2*fadeDuration_ms);
}

Debug Message

Node just freezes after a few calls
Probably due to the semaphore code in ledcFadeConfig

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Status: Needs investigationWe need to do some research before taking next steps on this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions