2025-08-31 8:44 AM
in app_freertos.c, the hook prototypes are not all defined as __weak. This requires either deleting those prototypes or rewriting them with the __weak attribute to avoid multiple definitions when they're actually used in user code.
I generally do not like to modify the IOC provided code unless it's main.c. Even though there are user sections, I'd like to have to modify as few things as possible to get a working project
I do use the hook prototypes frequently, but the hook definitions are autogenerated and not in a user area.
Please change your code to add the __weak attribute, as shown in the segment below. I've got them commented out because I transplanted the definitions into the user area so I would at least keep them.
/* Hook prototypes */
//__weak void configureTimerForRunTimeStats(void);
//__weak unsigned long getRunTimeCounterValue(void);
//__weak void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName);
//__weak void vApplicationMallocFailedHook(void);
This would have no impact if the functions were not used, since the prototypes exist and would not be overridden. For someone who defines those routines and uses them, the multiple definition problems would be eliminated.
thanks.
2025-08-31 4:52 PM
Most implementations I can find on ST's GitHub already have __weak and/or a relevant USER CODE section.
How are you generating these? Chip family? Can you share the IOC?
2025-08-31 8:22 PM
L562 processor. I'm letting the IOC configurator generate the file. The problem is what you've generated. The function prototypes do not need the __weak attribute,
The actual functions as you define them, though, need that attribute. Note that the vApplicationStackOverflowHook does *not* have the __weak attribute, while the other two links do.
I've included the L562 IOC file, but I'm not sure if it will be all that useful.
The problem I have is when I decide to add a stack overflow check, I get a multiple definition. Adding the __weak attribute in the user code definition will fix the problem, but I'd rather not have to beat on the software to make it well behave.
What I did (however right or wrong, but it was reflexive), was to move all the function prototypes inside the user code section, which isn't really needed.
Thanks.
2025-09-01 5:31 AM
They're all within USER CODE blocks. Add the __weak if that's what you want. It won't change on code regeneration.
I don't think adding two "__weak" statements within USER CODE sections qualifies as "beating on the software".
Here's a snippet of the code as generated by the IOC. All within USER CODE.
/* USER CODE BEGIN 1 */
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
__weak void configureTimerForRunTimeStats(void)
{
}
__weak unsigned long getRunTimeCounterValue(void)
{
return 0;
}
/* USER CODE END 1 */
/* USER CODE BEGIN 4 */
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)
{
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
called if a stack overflow is detected. */
}
/* USER CODE END 4 */
/* USER CODE BEGIN 5 */
void vApplicationMallocFailedHook(void)
{
2025-09-01 8:33 AM
My philosophy is that if I do something normal (use this, for instance)
vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)
I should not have to fix the code to allow it to work. Why the other functions are defined as __weak, and this one isn't, well.... I regard it as an error, and when it's in code that ST generates, it's in code that ST ought to fix.
Yes, when fixed it will stay fixed, but it's an annoyance at best.
Oh, unless you remove FreeRTOS for some reason and then decide to put it back....
Thanks.
2025-09-02 6:35 AM
@Harvey White wrote:Please change your code to add the __weak attribute, as shown in the segment below.
Does it make sense to put a weak qualifier on a prototype ?
Surely, the weak qualifier only makes sense on a definition ?
https://blog.feabhas.com/2013/01/weak-linkage-in-c-programming/
2025-09-02 8:50 AM
Does it make sense to put a weak qualifier on a prototype ?
Surely, the weak qualifier only makes sense on a definition ?
Yep, please correct concept to put __weak on all implementations in the user code section so I don't have to fix it.