Hello!!! How can I fix an address of a function ? I'm using the STM32CUBE_IDE with the STM32F103 MCU.
..
..
Hello @INaka.1
To elaborate more on @TDK 's response, it is possible to have a function at a predetermined location (alignment withstanding) by adding a new section in the linker file and place the function there: Linker scripts (haw-hamburg.de), a more beginner friendly guide here: Putting Code of Files into Special Section with the GNU Linker.
Some toolchains have special ways to at least suggest which address a function or a variable should be placed (like __attribute__(at()) for ARMCC/ARMLINK, the @ operator for IAR, etc...). But those should avoided even if you have access to such toolchains for portability's sake.
Otherwise, I'd have to agree with @Tesla DeLorean. An exotic solution for an issue is rarely the good solution. His proposal, which is called a branch table, is more flexible especially in case you have multiple functions which addresses must be fixed it is the way to go. In fact that how interrupt handlers have their fixed (but movable to a certain degree with SCB->VTOR for Cortex M at least) addresses. Beware that if you're targeting MISRA compliance you might run into some issue.
Code placement, and linking in general, is an interesting subject. You can place a function at a given address in more than one suboptimal to disastrous ways. Down-below are some of those *techniques* (it goes without saying that they are not recommended at all:(
Best regards,
@SBEN.2
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.