cancel
Showing results for 
Search instead for 
Did you mean: 

Where to put the "overwritten" of a "weak" function ?

hhuyn.1
Associate II

The function "__weak void HAL_SYSTICK_Callback()" is implemented in "stm32f4xx_hal_cortex.c"

I overwrite it in the "main.c", I compiled project, but my project still does not work.

void HAL_SYSTICK_Callback(void)
{
	HAL_IncTick();
}

Why am I wrong ?

Where should I put the function ?

6 REPLIES 6
Pavel A.
Evangelist III

> Why am I wrong ?

Because you're trusting somebody else's code without re-checking ;)

HAL_SYSTICK_Callback likely is not called if your code is Cube-generated, and HAL_SYSTICK_IRQHandler is not called.

Rather, in the generated code and examples, the low level Systick_Handler in stm32f4xx_it.c calls directly HAL_IncTick().

So it's no need to implement HAL_SYSTICK_Callback at all.

hhuyn.1
Associate II

I don't use STM32CUBE MX to generate code. I do it myself for learning C and embedded hardware.

In Keil C project, I see one file stm32_hal_cortex.c that services NVIC, SYSTICK and MPU.

But I don't see file "stm32f4_it.c" in the project. Which software component do I need to include ?.

There is one component : "EXTI". It seems not the case.

> But I don't see file "stm32f4_it.c" in the project.

Then you need to implement the Systick_Handler somewhere. From there, call either  HAL_IncTick() or HAL_SYSTICK_IRQHandler with your HAL_SYSTICK_Callback .

hhuyn.1
Associate II

I put an define of HAL_SYSTICK_Callback() in main.c that just call HAL_IncTick();

I don't know how to let my project aware of the new function.

When debugging, it jump to a weak SysTick_Handler() define in stm32f411xe.s that seems doing nothing.

S.Ma
Principal

Well, to answer the generic question, your project can have anywhere one weak and optionally one user define function sharing the same definition, because the decision to put which one in flash memory is the linker which concatenate all the compiled files of the project.

Nikita91
Lead II

Do you have this handler in your code ?

void	SysTick_Handler (void)
{
	HAL_IncTick () ;
}

No need of callback.