8
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\begingroup\$ Are IMPORT SystemInit and IMPORT __main really indented as shown here? \$\endgroup\$ Commented Oct 27, 2018 at 9:56

1 Answer 1

20
\$\begingroup\$

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

\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.