Code: Select all
rtc_wdt_protect_off();
rtc_wdt_disable();
disableCore0WDT();
disableLoopWDT();
Code: Select all
static portMUX_TYPE my_mutex; (below #includes)
vPortCPUInitializeMutex(&my_mutex); (in setup)
portENTER_CRITICAL(&my_mutex); (in task)
I'm looking to disable the watchdog so I can stay in portENTER_CRITICAL indefinitely on one core because I'm successfully bitbanging at decently fast speeds, but the FreeRTOS ticks and background stuff ends up throwing random 1-2us delays that wreck it. I realize this sacrifices the ability to use timers and extra tasks on that core, but I can accept that. I can't use interrupts in this case, as ESP32 takes +2us to handle the interrupt.
Here's some minimal example code, if I uncomment the portENTER/portEXIT code, it errors out.
Code: Select all
#include "soc/rtc_wdt.h"
#include "esp_int_wdt.h"
#include "esp_task_wdt.h"
static portMUX_TYPE my_mutex;
IRAM_ATTR void setup() {
rtc_wdt_protect_off();
rtc_wdt_disable();
disableCore0WDT();
disableLoopWDT();
vPortCPUInitializeMutex(&my_mutex);
Serial.begin(115200);
TaskHandle_t Task2;
xTaskCreatePinnedToCore(
Select, /* Function to implement the task */
"Select", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
configMAX_PRIORITIES, /* Priority of the task */
&Task2, /* Task handle. */
0); /* Core where the task should run */
}
IRAM_ATTR void Select( void * parameter) {
unsigned long sincePrint = millis();
portENTER_CRITICAL(&my_mutex);
for(int i = 0; i < 10000000; i++) {
digitalWrite(22, 1);
digitalWrite(22, 0);
esp_task_wdt_reset();
}
portEXIT_CRITICAL(&my_mutex);
Serial.print(millis() - sincePrint);
vTaskDelete(0);
}
void loop() {
vTaskDelay(portMAX_DELAY);
}