task watchdog user handler

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

task watchdog user handler

Postby urbanze » Mon Oct 08, 2018 5:47 pm

I trying to handle tsk wdt user function with

Code: Select all

void esp_task_wdt_isr_user_handler(void)
{
ets_printf("\n\n\nABCDEFG\n\n\n");
ets_delay_us(10000);
}
but doesnt work, however, I write this code in original function in task_wdt.c and work perfecly. Why my custom function in main.c doesnt working?

snahmad75
Posts: 445
Joined: Wed Jan 24, 2018 6:32 pm

Re: task watchdog user handler

Postby snahmad75 » Fri Feb 15, 2019 12:20 pm

It is working for when I defined in my C++ main.cpp file as

extern "C" {
/***************************************************************************//**
\brief This function is called by task_wdt_isr function (ISR for when TWDT times out).
\details It can be redefined in user code to handle twdt events.
Note: It has the same limitations as the interrupt function.
Do not use ESP_LOGI functions inside.
*******************************************************************************/
void esp_task_wdt_isr_user_handler(void)
{
/* restart firmware */
esp_restart();
}
}

I can see it appears in map file as override. but If define in seperate watchdog.cpp file. It does not overwrite weak function. confused.

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: task watchdog user handler

Postby urbanze » Tue May 14, 2019 5:05 pm

Well, I using .cpp file in main esp32, then, weak function will not work without 'extern "C"'

this work's nicelly:

Code: Select all

extern "C" void esp_task_wdt_isr_user_handler(void)
	{
		ets_printf("lol\r\n");
	}
But, how can I get task name that not-feed task wdt in this handler()?

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: task watchdog user handler

Postby ESP_Sprite » Wed May 15, 2019 7:07 am

It's because c/cpp files will be left out entirely if they don't contain any symbols that are unresolved, and the linker sees the availability of a 'weak' function as 'resolved'. Solution is to create a symbol in the c file somehow (e.g. void wdt_handler_dummy_symbol { }) and then add ing a linker flag to force it as unresolved (in component.mk. add -COMPONENT_ADD_LDFLAGS += u wdt_handler_dummy_symbol)

EDIT: Also, sorry, the information about what tasks did or did not reset the watchdog is not currently propagated to the callback.

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: task watchdog user handler

Postby urbanze » Wed May 15, 2019 1:16 pm

ESP_Sprite wrote:
Wed May 15, 2019 7:07 am
It's because c/cpp files will be left out entirely if they don't contain any symbols that are unresolved, and the linker sees the availability of a 'weak' function as 'resolved'. Solution is to create a symbol in the c file somehow (e.g. void wdt_handler_dummy_symbol { }) and then add ing a linker flag to force it as unresolved (in component.mk. add -COMPONENT_ADD_LDFLAGS += u wdt_handler_dummy_symbol)

EDIT: Also, sorry, the information about what tasks did or did not reset the watchdog is not currently propagated to the callback.
All right, this (very useful) information about tasks state in TWDT is a good feature!

Then, can I get any handler to catch task stack overflow? I need this 2 features to make internal LOG to remote debug.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: task watchdog user handler

Postby ESP_Sprite » Thu May 16, 2019 2:02 am

Not really... usually, when a stack overflow happens, it is detected after the fact and random data from other tasks or the OS already has been overwritten. This means the stability of the system can't be relied upon anymore and it would not be a smart idea to do complicated stuff like uploading logs. Instead, I'd suggest you just allow the ESP32 to crash but to configure the panic handler in such a way that it writes a core dump to flash. Then, after the reboot, detect that the core dump is there and upload it to a server.

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: task watchdog user handler

Postby urbanze » Thu May 16, 2019 2:26 pm

ESP_Sprite wrote:
Thu May 16, 2019 2:02 am
Not really... usually, when a stack overflow happens, it is detected after the fact and random data from other tasks or the OS already has been overwritten. This means the stability of the system can't be relied upon anymore and it would not be a smart idea to do complicated stuff like uploading logs. Instead, I'd suggest you just allow the ESP32 to crash but to configure the panic handler in such a way that it writes a core dump to flash. Then, after the reboot, detect that the core dump is there and upload it to a server.
I only need to save it in variable to AFTER reboot, log. Please, tell me if this can interfere in something.

I did some test's and worked nicelly, but if you know something interference (in panic handler/etc) what this can do in, tell me.

Code: Select all

volatile RTC_NOINIT_ATTR int16_t 	lt_sys_reset;//Global var
RTC_NOINIT_ATTR char lt_sys_tsk_ovf[16];//Global var
		 	
extern "C" void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
	{
		snprintf(lt_sys_tsk_ovf, 16, "%s", pcTaskName);
		lt_sys_reset = 21;

		ets_printf("***ERROR*** A stack overflow in task ");
		ets_printf((char *)pcTaskName);
		ets_printf(" has been detected.\r\n");

		abort();
	}
1. When overflow occur, this hook (I found in panic.c) is called and has weak attribute, then, I modified to my main.c .
2. Changed panicPutStr() to ets_printf()
3. Added 2 lines to copy task name and reset reason to RTC_NOINIT_ATTR global vars (21 = task overflow in my code).
4. After restart (abort()), RTC_NOINIT still intact (by my CRC) and will LOG in flash reset reason is task overflow and name. See image bellow that all worked:

Image

This changeds lines can bug sw DURING panic handler?

Who is online

Users browsing this forum: Baldhead and 131 guests