ESP8266Audio icon indicating copy to clipboard operation
ESP8266Audio copied to clipboard

Divide by Zero exception raised by AudioOutputULP::begin() after a watchdog reset.

Open WayneKeenan opened this issue 3 years ago • 0 comments

Hi,

The following sketch is a minimal test case which demonstrates a DIV0 exception occurring within the AudioOutputULP::begin() function after a watchdog reset has occurred.

Sketch:

#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputULP.h"

// Sample taken from this library's example: 
// https://github.com/earlephilhower/ESP8266Audio/blob/master/examples/PlayWAVFromPROGMEM/viola.h

#include "viola.h"

AudioGeneratorWAV *wav;
AudioOutputULP *out;
AudioFileSourcePROGMEM *file;


void setup() {
  out = new AudioOutputULP(2);
  wav = new AudioGeneratorWAV();
  file = new AudioFileSourcePROGMEM( viola, sizeof(viola) );

  wav->begin(file, out);
  bool isPlaying = true;
  while (isPlaying) {
    if (wav->isRunning()) {
      if (!wav->loop()) wav->stop();
    } else {
      isPlaying = false;
    }
  }

  enableLoopWDT();
}

void loop() {
  while (1);      // Triggers watchdog
}

The exception raised on the reboot triggered by the watchdog is:

Guru Meditation Error: Core  1 panic'ed (IntegerDivideByZero). Exception was unhandled.
Core 1 register dump:
PC      : 0x4000d099  PS      : 0x00060930  A0      : 0x800d1a08  A1      : 0x3ffb1ec0  
A2      : 0x00000000  A3      : 0x00007a12  A4      : 0x00000000  A5      : 0x00000000  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x00000001  A9      : 0x00007a12  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00004e1f  
A14     : 0x00000000  A15     : 0x00000001  SAR     : 0x00000010  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

ELF file SHA256: 0000000000000000

Backtrace: 0x4000d099:0x3ffb1ec0 0x400d1a05:0x3ffb1ee0 0x400d16c2:0x3ffb1f70 0x400d108f:0x3ffb1f90 0x400d37c2:0x3ffb1fb0 0x40085db9:0x3ffb1fd0

Rebooting...

The decoded backtrace:

0x400d1a05: AudioOutputULP::begin() at /Users/wayne/Documents/Arduino/libraries/ESP8266Audio/src/AudioOutputULP.cpp line 59
0x400d16c2: AudioGeneratorWAV::begin(AudioFileSource*, AudioOutput*) at /Users/wayne/Documents/Arduino/libraries/ESP8266Audio/src/AudioGeneratorWAV.cpp line 308
0x400d108f: setup() at /Users/wayne/Documents/Arduino/ESP8266Audio_wdt_div0_error/ESP8266Audio_wdt_div0_error.ino line 21
0x400d37c2: loopTask(void*) at /Users/wayne/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/main.cpp line 18
0x40085db9: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

Line in question: https://github.com/earlephilhower/ESP8266Audio/blob/a72bee6d739f2d245deb245a04c8d3cf5f51ef08/src/AudioOutputULP.cpp#L55

The rtc_clk_cal(RTC_CAL_8MD256, 1000) call returns 0.

All the best Wayne

WayneKeenan avatar Jun 10 '21 09:06 WayneKeenan