GCC alias to function outside of translation unit -AKA- is this even the right tool for the job?

前端 未结 4 658
野趣味
野趣味 2020-12-10 15:08

I\'m working with FreeRTOS on an STM32 (Cortex-M3), and using the CMSIS library from ST to bootstrap everything.

The CMSIS library defines the weak symbol SV

相关标签:
4条回答
  • 2020-12-10 15:10

    Another solution that I gleaned from one of the FreeRTOS examples is to add the following to your FreeRTOSConfig.h ...

    /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
    standard names - or at least those used in the unmodified vector table. */
    #define vPortSVCHandler SVC_Handler
    #define xPortPendSVHandler PendSV_Handler
    #define xPortSysTickHandler SysTick_Handler
    

    The original file is from FreeRTOS/Demo/CORTEX_M0_LPC1114_LPCXpresso/RTOSDemo/Source/FreeRTOSConfig.h which also integrates the CMSIS system clock into the config. A very nice starting point for a CMSIS/FreeRTOS project.

    0 讨论(0)
  • 2020-12-10 15:20

    You should be able to do this either with a linker script, or by passing the appropriate option to the linker, eg. for ld, --defsym=SVC_Handler=vPortSVCHandler

    See the binutils documentation for more information on the ld --defsym option, and assignments in linker scripts

    0 讨论(0)
  • 2020-12-10 15:31

    I think the problem with alias is, that it expects a declared and defined function, since it is just an alias. You want to use it as a forward-declaration of another function. I got a similar thing to work like that:

    void SVC_Handler(void) asm("vPortSVCHandler");
    

    This renames the entry point of the SVC_Handler, and if you then do not define it, it should find vPortSVCHandler.

    See: https://gcc.gnu.org/onlinedocs/gcc/Asm-Labels.html

    0 讨论(0)
  • 2020-12-10 15:33

    I'm pretty sure SVC handler is only used by FreeRTOS at initial startup, so adding an indirection exception handler isn't going to hurt performance (but its ugly). Best ask this on the FreeRTOS forum, response there is usually great.

    Hope this helps, Best Regards, Dave

    0 讨论(0)
提交回复
热议问题