Jump to content
Sign in to follow this  

declare ISR to be weak

Recommended Posts

Actually, it's a little trickier, since you actually want this thing to be a second weak definition: there's the one in crt0 that's the default, and the one provided by the alias.


My expectation is that which weak one wins depends on the order they're encountered by the linker; you need to do a link with -v to see exactly what gets passed to collect. If you play with the order of the files you can get the right one to be selected. It'll be a bit fragile, though.


In your case, mspgcc provides a weak definition for when no other implementation is available (case A). You want to provide a second weak definition, but have it take priority over mspgcc's (case B), but to be ignored if the user provides one (case C). Case A is automatic; case C happens if you make either your implementation or the user one not weak; case B can be obtained only by controlling the order the object files and archives are made visible to the linker in order to do that.


Another way to do it is to move the alias out of the implementation file and provide it as a linker parameter. Here's what I do in BSPACM to make _sbrk be a specific implementation defined by the user through a make flag that's normally not set:

BSPACM_LDFLAGS += -Wl,--undefined=_bspacm_sbrk_$(NEWLIB_SBRK),--defsym=_sbrk=_bspacm_sbrk_$(NEWLIB_SBRK)
There's two steps here: first, you need to make the real symbol (in your case, TA0_CCR_updater) explicitly undefined so that the function gets pulled out of the first object file/archive that provides it even if there had been no prior reference to it. Then you need to provide the alias that's used to access it in the non-relocatable executable (in your case, __isr_53) and specify that it's equivalent to the real symbol.


The case of sbrk for BSPACM which I've been using as an example is a particularly tricky one, which I'll explain in case it helps: If there's no reference at all, I want only weak symbols with no reference, so -Wl,-gc-sections causes the implementation to be dropped from the final link. If there's a reference to sbrk but the application developer didn't select a policy, I want it to find a default one (through the weak alias). If the application developer selected a particular policy, I want that to supersede the default one. There's more discussion in the BSPACM build infrastructure.


To get a robust solution you'll probably have to both control the order of the object files and archives and use linker flags to force resolution. You may need to use a start-group trick to ensure everything works out.

Share this post

Link to post
Share on other sites

I'm don't know how you're getting multiple definitions (unless you still have that declaration in a header, in which case get rid of it or at least its interrupt attribute). However, I just tried a more complete example and AFAICT mspgcc is going to put the default weak definition before anything else in the link line (it comes from crt0ivtbl*.o). It's not obvious how to get the application/energia-specific object file before that, so I think you'd probably have to use -Wl,--undefined=__isr_53,--defsym=__isr_53=TA0_CCR_updater, which is not a weak definition, to override it.


At that point you're probably better off requiring a user who wants to override the PWM interrupt normally provided by energia to pass a flag (e.g. -DNO_ENERGIA_PWM) which just inhibits generation of the strong definition you've already got.


The techniques I've described are probably more likely to be successful with the RH msp430-elf compiler and with the TM4C ones. Because it's embedded in the compiler mspgcc's mechanism for specifying interrupts doesn't work so well when providing a three-alternative solution.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...