← index #7798Issue #17973
Off-topic · high · value 0.160
QUERY · ISSUE

pwm caused crash on esp8266 generic version

openby yunfanopened 2021-09-15updated 2021-09-16
port-esp8266

mpy ver: v1.17 generic esp8266
board: dmini

description:

the board has a builtin rgb light, which could be control by pin (15, 12, 13)
i want it to do blink over and over, but the code only work for about 2 or 3 times, then the whole program will crash and reboot

here is the code in boot.py

import time
from machine import Pin, Timer, PWM

print("boot start")

def rgbBlink(rv, gv, bv, onTime):
    r, g, b = PWM(Pin(15)), PWM(Pin(12)), PWM(Pin(13))

    r.init(duty=rv)
    g.init(duty=gv)
    b.init(duty=bv)

    time.sleep_ms(onTime)

    r.deinit()
    g.deinit()
    b.deinit()
    
print("before doBlink")
def doBlink():
    tim = Timer(-1)
    tim.init(
            period=3000,
            mode=Timer.PERIODIC,
            callback=lambda t: rgbBlink(255, 128, 128, 1500)
    )

doBlink()
print("after doBlink")

gc.collect()
CANDIDATE · ISSUE

ESP32-S3 PWM in lightsleep mode does not works as expected

openby yoann-darcheopened 2025-08-22updated 2025-08-23
bug

Port, board and/or hardware

ESP32S3

MicroPython version

MicroPython v1.26.0 on 2025-08-09; Generic ESP32S3 module with ESP32S3

Reproduction

import esp32
from machine import Pin, I2C, ADC, Timer, PWM, deepsleep, lightsleep
from neopixel import NeoPixel
import time

# Internal Led
INTERNAL_LED = const(47)

PWM_PIN_NORMAL = 1
PWM_PIN_SLEEP  = 12

# Init
LED = NeoPixel(Pin(INTERNAL_LED, Pin.OUT), 1)



# Test 26 Version
#    On ESP32-S3 : the pwm_ligthsleep goes to 1 when ligthsleep


pwm1 = PWM(Pin(PWM_PIN_SLEEP), freq=5000, duty_u16=32768, lightsleep=True)
pwm0 = PWM(Pin(PWM_PIN_NORMAL), freq=5000, duty_u16=32768)


# Init : LED = Blue
LED[0] = (0,0,32)
LED.write()

time.sleep_ms(10*1000) # Wait 10 Sec

while True:
    
    LED[0] = (32,0,0) # Green
    LED.write()
    time.sleep_ms(10*1000) # Wait 10 Sec
    
    LED[0] = (0,64,0) # Red
    LED.write()
    lightsleep(10*1000)

Expected behaviour

The option set on the pwm1 instance (lightsleep=True) should keep the pwm signal on while the ESP32 is in ligthsleep.
But when performing the test we see that the pwm1 pin goes to high value when the ESP32 enter in ligthsleep.

Observed behaviour

I've worked on this subject (https://github.com/micropython/micropython/pull/10854) and (https://github.com/micropython/micropython/pull/16102). On my local repository, I reloaded an old firmware with the same machine_pwm.c (ESP port) code as in the current repository, and it is working as expected! I haven’t yet found the difference - maybe it’s related to the IDF framework version ?

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied