Page 1 of 1

overwrite weak function not working always

Posted: Fri Feb 15, 2019 12:24 pm
by snahmad75
Hi,

See this thread

viewtopic.php?f=13&t=7583&p=38611#p38611


When I define my overwrite esp_task_wdt_isr_user_handler in main.cpp it works.
but if defined in another files it does not. not 100% reliable make -j and linking on Windows 7 platform which generate .map. I can see in map file. override is not happening.

My project in C++ with all .cpp files.

Is there know issue for it.

Thanks,
Naeem

Re: overwrite weak function not working always

Posted: Fri Feb 15, 2019 6:45 pm
by snahmad75
Can some one reply and share your experience. I guess there are not many people using gcc and msys32on windows platform.

Re: overwrite weak function not working always

Posted: Sat Feb 16, 2019 4:48 am
by ESP_Sprite
Does the overriding function have its own .c/.cpp file? If so, it may be ignored entirely by the linker as it does not contain unresolved symbols.

Re: overwrite weak function not working always

Posted: Sat Feb 16, 2019 2:36 pm
by snahmad75
ESP_Sprite wrote:
Sat Feb 16, 2019 4:48 am
Does the overriding function have its own .c/.cpp file? If so, it may be ignored entirely by the linker as it does not contain unresolved symbols.
Here is example. Do i need to define in .c file instead of .cpp


It is working for when I defined in my C++ main.cpp file as but i define in new file e.g WatchDog.cpp. it gets ignored.

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();
}
}

Re: overwrite weak function not working always

Posted: Sun Feb 17, 2019 12:21 pm
by ESP_Sprite
So yes, that is the issue you have. .c or .cpp shouldn't matter. Can you see if this solves the issue for you?

Re: overwrite weak function not working always

Posted: Sun Feb 17, 2019 5:16 pm
by snahmad75
ESP_Sprite wrote:
Sun Feb 17, 2019 12:21 pm
So yes, that is the issue you have. .c or .cpp shouldn't matter. Can you see if this solves the issue for you?
yes it solve for if define in main.c/main.cpp. not elegant but works.

Can i do esp_restart within this override function. I do not want default behavior which is panic handler just stop device/firmware.
I want to restart when watchdog happens.

Re: overwrite weak function not working always

Posted: Mon Feb 18, 2019 2:24 am
by ESP_Sprite
Erm, you know that you can select panic behaviour in 'make menuconfig'? Restarting quietly is one of the options there.

Re: overwrite weak function not working always

Posted: Mon Feb 18, 2019 9:34 am
by snahmad75
ESP_Sprite wrote:
Mon Feb 18, 2019 2:24 am
Erm, you know that you can select panic behaviour in 'make menuconfig'? Restarting quietly is one of the options there.
I cannot see this option.

Re: overwrite weak function not working always

Posted: Tue Feb 19, 2019 3:14 am
by ESP_Sprite
It's under Component config -> ESP32-specific -> Panic handler behaviour.

Re: overwrite weak function not working always

Posted: Tue Feb 19, 2019 10:22 pm
by snahmad75
ESP_Sprite wrote:
Tue Feb 19, 2019 3:14 am
It's under Component config -> ESP32-specific -> Panic handler behaviour.
ok, got it.