cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431 - how to use interrupts within library

mrox
Associate II

Hi,

I'd like to create a library for fast handling the USART2 and TIMER. Unfortunately, when I move the USART2_IRQHandler() to the library, the linker do not include this function in a final application, and the program crashes by ending up in the endless loop of the Default_Handler. When I move the function back to main.c or other file within a target project - it works. How to update the interrupt vector table for external function?

 

Cheers,

Mike

1 ACCEPTED SOLUTION

Accepted Solutions
mrox
Associate II

The issue is already solved - extern "C" was missing in the library code.

View solution in original post

5 REPLIES 5

What functions are you using that would cause the library to be pulled in?

Are the library components being build from .cpp files or compiled as C++?

How is the project aware of the library?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

This is a toolchain-specific issue, so I am now assuming you are using a gcc suite i.e. the binutils ld linker.

The weak/(strong) mechanism is an afterthough and a not that well thought out too; and then the way how the linker treats them is not well defined either. ld treats objects in libraries differently from "plain" objects and simply ignores the weak marker when it links libraries, see e.g. here.

JW

Pavel A.
Evangelist III

when I move the USART2_IRQHandler() to the library, the linker do not include this function in a final application

IMHO this is only to the better. Define a custom function name for your library and call it from USART2_IRQHandler in your app source - similar to how cube-generated code calls HAL libraries.

mrox
Associate II

The issue is already solved - extern "C" was missing in the library code.

Thanks for coming back with the solution... so @Tesla DeLorean  was right that you're using C++...

JW