From 01f08c4638e30fe3f1b2d242938a63914de5e1b5 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Tue, 17 Nov 2015 20:31:17 -0500 Subject: [PATCH] Remove WEAK from handler prototypes These prototypes affect functions defined by application code. Only the implementations in libopencm3 are supposed to be weak; the functions in application code should definitely not be. Otherwise, you'll end up with two weak symbols being linked together, and it's luck as to which one the linker picks. --- include/libopencm3/cm3/nvic.h | 22 ++++++++++------------ lib/cm3/vector.c | 2 +- lib/stm32/common/gpio_common_all.c | 2 -- scripts/irq2nvic_h | 2 +- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/include/libopencm3/cm3/nvic.h b/include/libopencm3/cm3/nvic.h index 09a402b4..216833e3 100644 --- a/include/libopencm3/cm3/nvic.h +++ b/include/libopencm3/cm3/nvic.h @@ -130,8 +130,6 @@ IRQ numbers -3 and -6 to -9 are reserved * specific header file in the corresponding subfolder. */ -#define WEAK __attribute__((weak)) - #include /* --- NVIC functions ------------------------------------------------------ */ @@ -152,19 +150,19 @@ uint8_t nvic_get_active_irq(uint8_t irqn); void nvic_generate_software_interrupt(uint16_t irqn); #endif -void WEAK reset_handler(void); -void WEAK nmi_handler(void); -void WEAK hard_fault_handler(void); -void WEAK sv_call_handler(void); -void WEAK pend_sv_handler(void); -void WEAK sys_tick_handler(void); +void reset_handler(void); +void nmi_handler(void); +void hard_fault_handler(void); +void sv_call_handler(void); +void pend_sv_handler(void); +void sys_tick_handler(void); /* Those defined only on ARMv7 and above */ #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) -void WEAK mem_manage_handler(void); -void WEAK bus_fault_handler(void); -void WEAK usage_fault_handler(void); -void WEAK debug_monitor_handler(void); +void mem_manage_handler(void); +void bus_fault_handler(void); +void usage_fault_handler(void); +void debug_monitor_handler(void); #endif END_DECLS diff --git a/lib/cm3/vector.c b/lib/cm3/vector.c index 2da43016..b9c22a25 100644 --- a/lib/cm3/vector.c +++ b/lib/cm3/vector.c @@ -60,7 +60,7 @@ vector_table_t vector_table = { } }; -void WEAK __attribute__ ((naked)) reset_handler(void) +void __attribute__ ((weak, naked)) reset_handler(void) { volatile unsigned *src, *dest; funcp_t *fp; diff --git a/lib/stm32/common/gpio_common_all.c b/lib/stm32/common/gpio_common_all.c index f75491d9..d77c2f3d 100644 --- a/lib/stm32/common/gpio_common_all.c +++ b/lib/stm32/common/gpio_common_all.c @@ -23,8 +23,6 @@ * along with this library. If not, see . */ -#define WEAK __attribute__((weak)) - #include /**@{*/ diff --git a/scripts/irq2nvic_h b/scripts/irq2nvic_h index 95728cd2..e3aeea00 100755 --- a/scripts/irq2nvic_h +++ b/scripts/irq2nvic_h @@ -121,7 +121,7 @@ def convert(infile, outfile_nvic, outfile_vectornvic, outfile_cmsis): data['irqcount'] = max([int(x) for x in data['irqs'].keys()]) + 1 data['irqdefinitions'] = "\n".join('#define NVIC_%s_IRQ %d'%(v.upper(),int(k)) for (k,v) in irq2name) - data['isrprototypes'] = "\n".join('void WEAK %s_isr(void);'%name.lower() for name in irqnames) + data['isrprototypes'] = "\n".join('void %s_isr(void);'%name.lower() for name in irqnames) data['isrpragmas'] = "\n".join('#pragma weak %s_isr = blocking_handler'%name.lower() for name in irqnames) data['vectortableinitialization'] = ', \\\n '.join('[NVIC_%s_IRQ] = %s_isr'%(name.upper(), name.lower()) for name in irqnames) data['cmsisbends'] = "\n".join("#define %s_IRQHandler %s_isr"%(name.upper(), name.lower()) for name in irqnames)