Crash Report

danieltsz

Well-known member
Hi, I'm trying to use the Audio Library for Teensy 4.1. During testing, my board stacks, and watchdog resets it.
Then this is the crash report I'm getting.

Code:
CrashReport:
  A problem occurred at (system time) 16:57:36
  Code was executing from address 0x2C8C
  CFSR: 82
    (DACCVIOL) Data Access Violation
    (MMARVALID) Accessed Address: 0x20003B60 (Stack problem)
      Check for stack overflows, array bounds, etc.
  Temperature inside the chip was 46.70 °C
  Startup CPU clock speed is 151MHz
  Reboot was caused by auto reboot after fault or bad interrupt detected
  Reboot was caused by watchdog 1 or 2

This is the code I'm trying to run:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlaySdWav warningpost;   //xy=364,308
AudioOutputI2S2 audioOutput;  //xy=561,309
AudioConnection patchCord1(warningpost, 0, audioOutput, 0);
AudioConnection patchCord2(warningpost, 1, audioOutput, 1);
// GUItool: end automatically generated code
String SerialValue;
#include "Watchdog_t4.h"
//WatchDog_1
WDT_T4<WDT1> wdt;
time_t getTeensyTime() {
  return Teensy3Clock.get();
}
#include <TimeLib.h>
#define time_offset 8
time_t datetime;
int Year;
int Month;
int Day;
int Hour;
int Minute;
int Second;
int PreviousSecond;
#include <SPI.h>
#include <SD.h>
File DataLogger;
char Logfile[23];
void setup() {
  Serial.begin(9600);
  Serial.setTimeout(10);
  setSyncProvider(getTeensyTime);
  if (timeStatus() != timeSet) {
    Serial.println("Unable to sync with the RTC");
    Serial.flush();
  }
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(8);
  if (!SD.begin(BUILTIN_SDCARD)) {
    Serial.println(F("SD card Module failed, or not present"));
    Serial.flush();
    while (1)
      ;
  }
  SD.mkdir("LOGFILE");
  DataLogger.setTimeout(16);
  WDT_timings_t config;
  //WatchDog_1
  config.trigger = 5;  /* in seconds, 0->128 */
  config.timeout = 10; /* in seconds, 0->128 */
  wdt.begin(config);
  Serial.println("Warning Post Test Begin");
  delay(1000);
}
void loop() {
  datetime = now();
  Month = month(datetime);
  Day = day(datetime);
  Year = year(datetime);
  Hour = hour(datetime);
  Minute = minute(datetime);
  Second = second(datetime);
  if (Serial && CrashReport) {    // Make sure Serial is alive and there is a CrashReport stored.
    Serial.println(CrashReport);  // Once called any crash data is cleared
    Serial.println();
    Serial.flush();
    // In this case USB Serial is used - but any Stream capable output will work : SD Card or other UART Serial
  }
  if (Serial.available() > 0) {
    while (Serial.available()) {
      SerialValue = Serial.readString();
      Serial.clear();
    }
    if (SerialValue == "1\r") {
      warningpost.play("WARNING/ALERT1.WAV");  // filenames are always uppercase 8.3 format
      Serial.println("playing Alert");
      GetFileName();
      DataLogger = SD.open(Logfile, FILE_WRITE);
      if (DataLogger) {
        DataLogger.println("Playing Alert1.wav");
        DataLogger.close();
      } else {
        Serial.print(F("error opening "));
        Serial.print(Logfile);
        Serial.println();
        Serial.flush();
      }
    }
    else if (SerialValue == "2\r") {
      warningpost.play("WARNING/ALERT2.WAV");  // filenames are always uppercase 8.3 format
      Serial.println("playing Alarm");
      GetFileName();
      DataLogger = SD.open(Logfile, FILE_WRITE);
      if (DataLogger) {
        DataLogger.println("Playing Alert2.wav");
        DataLogger.close();
      } else {
        Serial.print(F("error opening "));
        Serial.print(Logfile);
        Serial.println();
        Serial.flush();
      }
    }
    else if (SerialValue == "3\r") {
      warningpost.play("WARNING/ALERT3.WAV");  // filenames are always uppercase 8.3 format
      Serial.println("playing Critical");
      GetFileName();
      DataLogger = SD.open(Logfile, FILE_WRITE);
      if (DataLogger) {
        DataLogger.println("Playing Alert3.wav");
        DataLogger.close();
      } else {
        Serial.print(F("error opening "));
        Serial.print(Logfile);
        Serial.println();
        Serial.flush();
      }
    }
    else if (SerialValue == "4\r") {
      warningpost.play("WARNING/ALERT4.WAV");  // filenames are always uppercase 8.3 format
      Serial.println("playing Recession");
      GetFileName();
      DataLogger = SD.open(Logfile, FILE_WRITE);
      if (DataLogger) {
        DataLogger.println("Playing Alert4.wav");
        DataLogger.close();
      } else {
        Serial.print(F("error opening "));
        Serial.print(Logfile);
        Serial.println();
        Serial.flush();
      }
    }
    else if (SerialValue == "5\r") {
      warningpost.play("WARNING/ALERT5.WAV");  // filenames are always uppercase 8.3 format
      Serial.println("playing Termination");
      GetFileName();
      DataLogger = SD.open(Logfile, FILE_WRITE);
      if (DataLogger) {
        DataLogger.println("Playing Alert5.wav");
        DataLogger.close();
      } else {
        Serial.print(F("error opening "));
        Serial.print(Logfile);
        Serial.println();
        Serial.flush();
      }
    }
    else if (SerialValue == "stop\r") {
      warningpost.stop();
      Serial.println("stop");
      GetFileName();
      DataLogger = SD.open(Logfile, FILE_WRITE);
      if (DataLogger) {
        DataLogger.println("Stop Playing");
        DataLogger.close();
      } else {
        Serial.print(F("error opening "));
        Serial.print(Logfile);
        Serial.println();
        Serial.flush();
      }
    }
    SerialValue = "";
  }
  if (Second % 5 == 0 && PreviousSecond != Second) {
    wdt.feed();
  }
}
void GetFileName() {
  sprintf(Logfile, "LOGFILE/%04u%02u%02u.txt", Year, Month, Day);
}

Upon observation, I noticed that when saving to an SD card, sometimes it never finishes that's why watchdog resets my board. Do you have any suggestions with this problem? Thank you
 
The stock audio / SDFAT libraries do not allow you to play back audio from SD while simultaneously accessing it from your sketch. See this thread for discussions and links to a new set of audio objects which do allow this (because no file access is attempted from interrupt code).
 
hi again sir @h4yn0nnym0u5e, I already tested the library, just had some problems installing it earlier but now I have it.
Thank you for the modification of the Audio Library.

I just had some questions, for the createBuffer(****, AudioBuffer::inHeap), how to compute the most optimal value I can use? Thank you hoping for your response on this.
 
You need a buffer big enough for twice the longest interval between yield() calls, plus some margin. It looks as if your code exits loop() often, so if you monitor the loop interval and print the maximum value, that’s going to help a lot.

Say your loop takes 15ms. In twice that time 1323 samples will play, which take 2646 bytes; the buffer needs to be a multiple of 1024 bytes, so you’d set it to 3072, or maybe 4096. Even if your loop is a lot faster, I’d advise not going below 2048 bytes.

if your loop gets slower as you develop your code, rather than increasing the buffer size, you could consider putting in calls to yield() just after any time-consuming sections, to give the buffers a chance to re-load.

The reason you use twice the longest interval is that after the initial buffer load, only half of it at a time is re-loaded, as the other half is in use being played back.
 
Back
Top