Skip to main content
Associate II
July 12, 2023
Solved

STM32G431 - how to use interrupts within library

  • July 12, 2023
  • 5 replies
  • 2610 views

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

This topic has been closed for replies.
Best answer by mrox

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

5 replies

Tesla DeLorean
Guru
July 13, 2023

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
waclawek.jan
Super User
July 13, 2023

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.
July 13, 2023

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.

mroxAuthorBest answer
Associate II
July 18, 2023

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

waclawek.jan
Super User
July 18, 2023

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

JW