Electronic – What does [WEAK] mean in STM32 startup assembly code

assemblykeilstm32

I was reading the STM32F407 startup file in Keil software to gather some information. I faced this problem: What is the [WEAK] symbol used for?

A part of the code that this symbol has been used in is:

Reset_Handler    PROC
                 EXPORT  Reset_Handler             [WEAK]
        IMPORT  SystemInit
        IMPORT  __main

                 LDR     R0, =SystemInit
                 BLX     R0
                 LDR     R0, =__main
                 BX      R0
                 END

Best Answer

It says the implementation of the function should be weakly linked (as opposed to strongly linked, which is the usual).

This allows providing a "fallback" implementation of a function, in case no other (strongly linked) is found.

This is often used for default interrupt handlers in bare-metal MCU frameworks. This way, when you implement an interrupt, you just have to write your function, without having to remove the default one from the sources, and the linker does the job.

See https://en.wikipedia.org/wiki/Weak_symbol

Related Topic