Watchdog Timer in ULP
Posted: Fri Mar 24, 2023 1:28 pm
My device program is intermittently getting locked up while in Deep Sleep, running the ulp function (below). I have the watchdog timer running in the main portion of my program and initialize it at the very beginning of the main loop. I add the standard syntax at the beginning of my ulp function and it compiles, but does not seem to be working. Is there another way to call a watchdog timer in ulp? Is there a different watchdog for ulp? This is the last bit of code I need to get our product out. Your help is appreciated.
********************************************************************************************
void ulp_start(uint32_t dutyMeter) {
esp_task_wdt_add(NULL); //add current thread to WDT watch
ulpStarted = 1; //program flag to determine if ulp is started
//// Slow memory initialization
//memset(RTC_SLOW_MEM, 0, 8192); //this sets all RTC memory to Zero
// if LED is connected to GPIO2 (specify by +14)
const gpio_num_t MeterPWMPin = GPIO_NUM_2;
const int MeterPWMBit = RTCIO_GPIO2_CHANNEL + 14;
// GPIOx initialization (set to output and initial value is 0)
rtc_gpio_init(MeterPWMPin);
rtc_gpio_set_direction(MeterPWMPin, RTC_GPIO_MODE_OUTPUT_ONLY);
rtc_gpio_set_level(MeterPWMPin, 0);
// Define ULP program
const ulp_insn_t ulp_prog[] = {
M_LABEL(1),
I_WR_REG(RTC_GPIO_OUT_REG, MeterPWMBit, MeterPWMBit, 1), // on
I_DELAY(dutyMeter),
I_WR_REG(RTC_GPIO_OUT_REG, MeterPWMBit, MeterPWMBit, 0), // off
I_DELAY(900), //factor of meter max duty cycle
M_BX(1),
};
// Run ULP program
size_t size = sizeof(ulp_prog) / sizeof(ulp_insn_t);
ulp_process_macros_and_load(0, ulp_prog, &size);
ulp_run(0);
esp_task_wdt_reset(); //reset WDT for new 3s count
}
********************************************************************************************
void ulp_start(uint32_t dutyMeter) {
esp_task_wdt_add(NULL); //add current thread to WDT watch
ulpStarted = 1; //program flag to determine if ulp is started
//// Slow memory initialization
//memset(RTC_SLOW_MEM, 0, 8192); //this sets all RTC memory to Zero
// if LED is connected to GPIO2 (specify by +14)
const gpio_num_t MeterPWMPin = GPIO_NUM_2;
const int MeterPWMBit = RTCIO_GPIO2_CHANNEL + 14;
// GPIOx initialization (set to output and initial value is 0)
rtc_gpio_init(MeterPWMPin);
rtc_gpio_set_direction(MeterPWMPin, RTC_GPIO_MODE_OUTPUT_ONLY);
rtc_gpio_set_level(MeterPWMPin, 0);
// Define ULP program
const ulp_insn_t ulp_prog[] = {
M_LABEL(1),
I_WR_REG(RTC_GPIO_OUT_REG, MeterPWMBit, MeterPWMBit, 1), // on
I_DELAY(dutyMeter),
I_WR_REG(RTC_GPIO_OUT_REG, MeterPWMBit, MeterPWMBit, 0), // off
I_DELAY(900), //factor of meter max duty cycle
M_BX(1),
};
// Run ULP program
size_t size = sizeof(ulp_prog) / sizeof(ulp_insn_t);
ulp_process_macros_and_load(0, ulp_prog, &size);
ulp_run(0);
esp_task_wdt_reset(); //reset WDT for new 3s count
}