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.
This is the code I'm trying to run:
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
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