I have a project where I use code generated by HalCoGen, and I'm only able to override some of the weakly defined functions. I posted in the HalCoGen forum, but it looks like there's a compiler issue here. https://e2e.ti.com/support/microcontrollers/hercules/f/312/p/510723/1853529
I'm using the TI compiler 5.2.0 and HalCoGen 4.05.02. The problem is illustrated with 3 files :
sys_selftest.c (generated by HalcoGen)
#pragma WEAK(selftestFailNotification)
void selftestFailNotification(uint32 flag) { }
void ccmSelfCheck(void)
{
[code]
selftestFailNotification(CCMSELFCHECK_FAIL1);
[code]
}
notification.c (generated by HalCoGen):
#pragma WEAK(spiNotification)
void spiNotification(spiBASE_t *spi, uint32 flags) { }
myFile.c (written by me)
void selftestFailNotification(uint32 flag) { }
void spiNotification(spiBASE_t *spi, uint32 flags) { }
[call spi and self-test functions]
In this setup, my overridden spiNotification() gets called, but selftestFailNotification does not. If I move selftestFailNotification to notification.c, then my overridden one gets called. It appears that calls to selftestFailNotification from the same file as the definition, causes it to be resolved immediately, not at link time, like with spiNotification.
According to the manual: A weak definition does not change the rules by which object files are selected from libraries. However, if a link set contains both a weak definition and a non-weak definition, the non-weak definition is always used.
In my case the non-weak definition is not used for calls from sys_selftest.c. While trying things out, I discovered that calls to selftestFailNotification from outside of sys_selftest.c will use the definition in myFile.c, even while calls from within sys_selftest.c use the one in the same file.