Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delay(0) behavior changed #8947

Closed
6 tasks done
mhightower83 opened this issue Jun 26, 2023 · 2 comments · Fixed by #8960 · May be fixed by #8949
Closed
6 tasks done

delay(0) behavior changed #8947

mhightower83 opened this issue Jun 26, 2023 · 2 comments · Fixed by #8960 · May be fixed by #8949

Comments

@mhightower83
Copy link
Contributor

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12
  • Core Version: 521ae60
  • Development Env: Arduino IDE 1.8.19
  • Operating System: Ubuntu

Settings in IDE

  • Module: Adafruit Feather HUZZAH ESP8266
  • Flash Mode: qio
  • Flash Size: 4MB
  • lwip Variant: v2 Higher Bandwidth
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 460800

Problem Description

A blocking library function that uses delay(0) will fail with Software WDT Reset.

This last worked in Core version 3.1.0

Changes made in commit 39080e3 altered this behavior

MCVE Sketch

#include <Arduino.h>

// Last worked with Core v3.1.0

void setup() {
  Serial.begin(115200);
  delay(200);
}

void loop() {
  Serial.printf("\r\n\r\ndelay(0) test - should never WDT reset\r\n");

  while(true) {
    delay(0);
  }
}

Debug Messages


--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

Exception (4):
epc1=0x40100249 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffe20 end: 3fffffd0 offset: 0160
3fffff80:  00000000 3fffff60 3fffff90 3ffee5a8 <
3fffff90:  3fffdad0 00000000 00000000 40201f3c  
3fffffa0:  3fffdad0 00000cc1 3ffee57c 40201069  
3fffffb0:  feefeffe 00000042 3ffee57c 4020199c  
3fffffc0:  feefeffe feefeffe 3fffdab0 40100c05  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

Exception 4: Level1Interrupt: Level-1 interrupt as indicated by set level-1 bits in the INTERRUPT register
PC: 0x40100249: millis() at /home/mhightow/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring.cpp line 176
EXCVADDR: 0x00000000

Decoding stack results
0x40201f3c: __delay(unsigned long) at /home/mhightow/Arduino/hardware/esp8266com/esp8266/cores/esp8266/coredecls.h line 77
0x40201069: loop() at /home/mhightow/Arduino/Debug/DelayZero/DelayZero.ino line 11
0x4020199c: loop_wrapper() at /home/mhightow/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp line 258

@mcspr
Copy link
Collaborator

mcspr commented Jun 27, 2023

A blocking library function that uses delay(0) will fail with Software WDT Reset.

Any examples outside of Core?

Unintentionally (?) broken in #8802, since esp_try_delay never bothers to do anything with timeout of 0 and treats it as end of usual delay cycle that happens after yield happened.

while (!esp_try_delay(start_ms, timeout_ms, intvl_ms) && blocked()) {

bool esp_try_delay(const uint32_t start_ms, const uint32_t timeout_ms, const uint32_t intvl_ms) {
uint32_t expired = millis() - start_ms;
if (expired >= timeout_ms) {
return true; // expired
}

Suppose the fix is to wire this even earlier

esp_delay(ms, [](){ return true; });

So it calls esp_delay(0) instead of the blocking variant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants