Skip to main content
Visitor II
September 2, 2022
Question

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

  • September 2, 2022
  • 5 replies
  • 3859 views

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 ?

    This topic has been closed for replies.

    5 replies

    Super User
    September 2, 2022

    > 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.1Author
    Visitor II
    September 3, 2022

    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.

    Super User
    September 3, 2022

    > 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.1Author
    Visitor II
    September 4, 2022

    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.

    Visitor II
    September 5, 2022

    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.

    Explorer II
    September 5, 2022

    Do you have this handler in your code ?

    void	SysTick_Handler (void)
    {
    	HAL_IncTick () ;
    }

    No need of callback.