Skip to main content
Adalgiso
Associate III
February 22, 2017
Question

Define interrupt handler as weak

  • February 22, 2017
  • 3 replies
  • 1592 views
Posted on February 22, 2017 at 10:31

I need to define my own interrupt handler. Cube not not generate the ISR as weak so everytime I regenerate the code with cube, I have to modify the code to hide the interrupt handler generated by cube.

Would it be possible to define them as weakß

    This topic has been closed for replies.

    3 replies

    AvaTar
    Senior III
    February 22, 2017
    Posted on February 22, 2017 at 10:51

    Would it be possible to define them as weakß

    If I remember correctly, no. There are only two definitions allowed, one 'weak' and one none-weak (i.e. without the weak attribute).

    And the weak definition of interrupt handlers usually comes from the startup code.

    That would make two 'weak' definitions, confusing the linker.

    Tesla DeLorean
    Guru
    February 22, 2017
    Posted on February 22, 2017 at 20:02

    I think you need to use a development method that doesn't require CubeMX to constantly update your code. Have Cube generate into a sandbox project if you must use this method, and then merge the new code into your development branch so you don't constant break your code, or have Cube inadvertently nuke it by accident. A lot of people have lost critical project code by expecting CubeMX to tread lightly, or recognize users intentions.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    hbarta
    Associate II
    February 23, 2017
    Posted on February 23, 2017 at 05:18

    Doesn't MX create stubs for the interrupts in the <processor>_it.c file? Those then call HAL drivers or user interrupt handlers which are both defined with the weak keyword.

    Or am I mistaken?

    Adalgiso
    AdalgisoAuthor
    Associate III
    February 23, 2017
    Posted on February 23, 2017 at 08:19

    CubeMX as a similar process for freertos: task entry function can be defined as weak default or external.

    Idea behind this is to have a similar process for interrupt handler, In some situation there is no stub (hardfaulthandler...) and in this situation we need to modify the startup file, or we may not want to use the stubs and HAL drivers defined as weak and managed directly interrupts.

    Goal is to have a clean separation between code generated by cube and application specific code and like this avoid to mess up project when regenerating code with cubeMX.

    From my side I solved this by relocating interrupt in RAM and remapping to my own specific interrupt handler (only the ones requiring specific management).