I found the problem.
The xTask "blink_led()" was not in an infinite loop. It will execute once and exit thus, when RTOS want to schedule it again, it does not exists and crashes.
I found the problem.
The xTask "blink_led()" was not in an infinite loop. It will execute once and exit thus, when RTOS want to schedule it again, it does not exists and crashes.
My blink_function looks like this:
void blink_led(void *parameter)
{
digitalWrite(LED_PIN, HIGH);
vTaskDelay(10);
digitalWrite(LED_PIN, LOW);
read_high_water_mark("blink_led");
vTaskDelay(1000);
}
and the read_high_water_mark()
void read_high_water_mark(String funct)
{
// Inspect our own high water mark on entering the task.
UBaseType_t uxHighWaterMark;
uxHighWaterMark = uxTaskGetStackHighWaterMark(NULL);
Serial.print("***uxHighWaterMark (" + funct + ") = ");
Serial.println(uxHighWaterMark);
}
This is my first time I am using any MCU so, I realize I no expert. I slowly build up my code from normal blink, to Wi-Fi, to ESP_NOW, and to multi-tasking. It all worked very well until I added a xSemaphoreHandle with
// Create a mutex type semaphore
sisuDataMutex = xSemaphoreCreateMutex();
I then wrapped the data write and read blocks as follows:
if (xSemaphoreTake(sisuDataMutex, portMAX_DELAY) == pdTRUE)
{
sisuData.levelFwd += 20;
if (sisuData.levelFwd > 100)
sisuData.levelFwd = 0;
sisuData.levelAft += 10;
if (sisuData.levelAft > 100)
sisuData.levelAft = 0;
sisuData.levelBattery -= 1;
if (sisuData.levelBattery < 0)
sisuData.levelBattery = 5;
// Release the mutex (unlock)
xSemaphoreGive(sisuDataMutex);
}
Then I implemented OTA and it eventually worked too. And somewhere here, disaster struck. These following print() function started to print half sentence or skipped sentences. It was working before and all printed very good. But I did something wrong and the Serial.print() functions below started to print missing parts of the text.
Serial.print("Aft Level Voltage: ");
vTaskDelay(500 / portTICK_PERIOD_MS);
Serial.println(sisuData.levelAft);
Serial.print("Fwd Level Voltage: ");
Serial.println(sisuData.levelFwd);
Serial.print("Batt Level Voltage: ");
Serial.println(sisuData.levelBattery);
Serial.println();
In fact, every Serial.println() started to skip parts when printing.
I started to eliminate parts of code until I was back a simple blink sketch, and Serial.println() functions, which worked perfectly. However, the moment I put that same working blink() function in a xTaskCreate(), the Serial.println() functions start to misbehave.
I have tried to pin it to the non-Wifi core, but still the same.
// xTaskCreate(blink_led, "Blink", 2048, NULL, 1, NULL);
xTaskCreatePinnedToCore(blink_led, "Blink", 1024, NULL, 1, NULL,1);
At this moment, the T7 S3 crashes and reboot like this:
Reconnecting to /dev/cu.usbmodem1101 Connected!
Hello from Sisu Freshwater!
***uxHighWaterMark (blink_led) = 360
Guru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x42002304: 1ed2a520 0000f01d 21006136
Guru Meditation Error: Core 1 panic'ed (Unhandled debug exception).
Debug exception reason: Stack canary watchpoint triggered (Blink)
Core 1 register dump:
PC : 0x40056f60 PS : 0x00060036 A0 : 0x8200b0a6 A1 : 0x3fcec610
A2 : 0x3fcec620 A3 : 0x3c043a90 A4 : 0x00000060 A5 : 0x3fcec620
A6 : 0x3c0439b7 A7 : 0x3c0439c0 A8 : 0x00000000 A9 : 0x00000001
A10 : 0x60000000 A11 : 0x00000001 A12 : 0x42002308 A13 : 0x3fcec7c0
A14 : 0x00000001 A15 : 0x3fc93128 SAR : 0x0000000a EXCCAUSE: 0x00000001
EXCVADDR: 0x00000000 LBEG : 0x40056f5c LEND : 0x40056f72 LCOUNT : 0x00000005
Backtrace: 0x40056f5d:0x3fcec610 0x4200b0a3:0x3fcec620 0x4200ae65:0x3fcec6a0 0x4200ae95:0x3fcec6c0 0x4200aa8a:0x3fcec6e0 0x4200ae16:0x3fcec750 0x40377965:0x3fcec7a0 0x40378790:0x3fcec7c0 0x42002305:0x3fcec880
ELF file SHA256: 22d9db3c5b226676
Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x2b (SPI_FAST_FLASH_BOOT)
Saved PC:0x42031176
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x4bc
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a0c
entry 0x403c98d0
[ 109][I][esp32-hal-psram.c:96] psramInit(): PSRAM enabled
Disconnected (read failed: [Errno 6] Device not configured)
Reconnecting to /dev/cu.usbmodem1101 Connected!
What am I doing wrong?