cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a keil driver library out of HAL source. Weak definitions gets selected unexpectedly.

PeterL
Associate III

When doing generating a project from STM32CubeMX (for F4 family) and converting it to a library in keil, then when keeping main in executable project and linking to library wrong implementation of *MspInit gets selected. The weak ones are selected even though there is a "strong" one in library too.

Problem is how compilers work. They don't look extensively in librarys so they don't even bother to find the strong one if first stumbled upon a weak symbol.

    i.HAL_UART_Init                          0x08001260   Section        0  stm32f4xx_hal_uart.o(i.HAL_UART_Init)
    i.HAL_UART_MspInit                       0x080012c2   Section        0  stm32f4xx_hal_uart.o(i.HAL_UART_MspInit)

See keil map file above. The weak MspInit were selected despite the "strong" version is in library too.

For IAR there is an linker option --whole_archive that forces linker to actually look in all object files and then the strong one is selected.

For Keil I haven't fond similar option (neither old or clang based version).

1 REPLY 1
Pavel A.
Evangelist III