Skip to content

Commit 65f00a6

Browse files
committed
Fixed weak-symbol issue with system interrupt handlers.
1 parent ddd35a2 commit 65f00a6

File tree

6 files changed

+167
-183
lines changed

6 files changed

+167
-183
lines changed

hardware/arduino/sam/cores/arduino/cortex_handlers.c

Lines changed: 89 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,109 @@
1717
*/
1818

1919
#include "Arduino.h"
20+
#include "Reset.h"
2021

2122
#ifdef __cplusplus
2223
extern "C" {
2324
#endif
2425

25-
void NMI_Handler( void )
26-
{
27-
for ( ;; ) ;
28-
}
29-
30-
void HardFault_Handler( void )
31-
{
32-
for ( ;; ) ;
26+
static void __halt() {
27+
// Halts
28+
while (1)
29+
;
3330
}
3431

35-
void MemManage_Handler( void )
36-
{
37-
for ( ;; ) ;
38-
}
32+
extern void svcHook(void);
33+
extern void pendSVHook(void);
34+
extern int sysTickHook(void);
3935

40-
void BusFault_Handler( void )
41-
{
42-
for ( ;; ) ;
43-
}
36+
/* Cortex-M3 core handlers */
37+
void NMI_Handler (void) __attribute__ ((weak, alias("__halt")));
38+
void HardFault_Handler (void) __attribute__ ((weak, alias("__halt")));
39+
void MemManage_Handler (void) __attribute__ ((weak, alias("__halt")));
40+
void BusFault_Handler (void) __attribute__ ((weak, alias("__halt")));
41+
void UsageFault_Handler(void) __attribute__ ((weak, alias("__halt")));
42+
void DebugMon_Handler (void) __attribute__ ((weak, alias("__halt")));
43+
void SVC_Handler (void) { svcHook(); }
44+
void PendSV_Handler (void) { pendSVHook(); }
4445

45-
void UsageFault_Handler( void )
46+
void SysTick_Handler(void)
4647
{
47-
for ( ;; ) ;
48-
}
48+
if (sysTickHook())
49+
return;
4950

50-
void SVC_Handler( void )
51-
{
52-
for ( ;; ) ;
53-
}
51+
tickReset();
5452

55-
void DebugMon_Handler( void )
56-
{
57-
for ( ;; ) ;
53+
// Increment tick count each ms
54+
TimeTick_Increment();
5855
}
5956

60-
void PendSV_Handler( void )
61-
{
62-
for ( ;; ) ;
63-
}
57+
/* Peripherals handlers */
58+
void SUPC_Handler (void) __attribute__ ((weak, alias("__halt")));
59+
void RSTC_Handler (void) __attribute__ ((weak, alias("__halt")));
60+
void RTC_Handler (void) __attribute__ ((weak, alias("__halt")));
61+
void RTT_Handler (void) __attribute__ ((weak, alias("__halt")));
62+
void WDT_Handler (void) __attribute__ ((weak, alias("__halt")));
63+
void PMC_Handler (void) __attribute__ ((weak, alias("__halt")));
64+
void EFC0_Handler (void) __attribute__ ((weak, alias("__halt")));
65+
void EFC1_Handler (void) __attribute__ ((weak, alias("__halt")));
66+
void UART_Handler (void) __attribute__ ((weak, alias("__halt")));
67+
#ifdef _SAM3XA_SMC_INSTANCE_
68+
void SMC_Handler (void) __attribute__ ((weak, alias("__halt")));
69+
#endif
70+
#ifdef _SAM3XA_SDRAMC_INSTANCE_
71+
void SDRAMC_Handler (void) __attribute__ ((weak, alias("__halt")));
72+
#endif
73+
void PIOA_Handler (void) __attribute__ ((weak, alias("__halt")));
74+
void PIOB_Handler (void) __attribute__ ((weak, alias("__halt")));
75+
#ifdef _SAM3XA_PIOC_INSTANCE_
76+
void PIOC_Handler (void) __attribute__ ((weak, alias("__halt")));
77+
#endif
78+
#ifdef _SAM3XA_PIOD_INSTANCE_
79+
void PIOD_Handler (void) __attribute__ ((weak, alias("__halt")));
80+
#endif
81+
#ifdef _SAM3XA_PIOE_INSTANCE_
82+
void PIOE_Handler (void) __attribute__ ((weak, alias("__halt")));
83+
#endif
84+
#ifdef _SAM3XA_PIOF_INSTANCE_
85+
void PIOF_Handler (void) __attribute__ ((weak, alias("__halt")));
86+
#endif
87+
void USART0_Handler (void) __attribute__ ((weak, alias("__halt")));
88+
void USART1_Handler (void) __attribute__ ((weak, alias("__halt")));
89+
void USART2_Handler (void) __attribute__ ((weak, alias("__halt")));
90+
#ifdef _SAM3XA_USART3_INSTANCE_
91+
void USART3_Handler (void) __attribute__ ((weak, alias("__halt")));
92+
#endif
93+
void HSMCI_Handler (void) __attribute__ ((weak, alias("__halt")));
94+
void TWI0_Handler (void) __attribute__ ((weak, alias("__halt")));
95+
void TWI1_Handler (void) __attribute__ ((weak, alias("__halt")));
96+
void SPI0_Handler (void) __attribute__ ((weak, alias("__halt")));
97+
#ifdef _SAM3XA_SPI1_INSTANCE_
98+
void SPI1_Handler (void) __attribute__ ((weak, alias("__halt")));
99+
#endif
100+
void SSC_Handler (void) __attribute__ ((weak, alias("__halt")));
101+
void TC0_Handler (void) __attribute__ ((weak, alias("__halt")));
102+
void TC1_Handler (void) __attribute__ ((weak, alias("__halt")));
103+
void TC2_Handler (void) __attribute__ ((weak, alias("__halt")));
104+
void TC3_Handler (void) __attribute__ ((weak, alias("__halt")));
105+
void TC4_Handler (void) __attribute__ ((weak, alias("__halt")));
106+
void TC5_Handler (void) __attribute__ ((weak, alias("__halt")));
107+
#ifdef _SAM3XA_TC2_INSTANCE_
108+
void TC6_Handler (void) __attribute__ ((weak, alias("__halt")));
109+
void TC7_Handler (void) __attribute__ ((weak, alias("__halt")));
110+
void TC8_Handler (void) __attribute__ ((weak, alias("__halt")));
111+
#endif
112+
void PWM_Handler (void) __attribute__ ((weak, alias("__halt")));
113+
void ADC_Handler (void) __attribute__ ((weak, alias("__halt")));
114+
void DACC_Handler (void) __attribute__ ((weak, alias("__halt")));
115+
void DMAC_Handler (void) __attribute__ ((weak, alias("__halt")));
116+
void UOTGHS_Handler (void) __attribute__ ((weak, alias("__halt")));
117+
void TRNG_Handler (void) __attribute__ ((weak, alias("__halt")));
118+
#ifdef _SAM3XA_EMAC_INSTANCE_
119+
void EMAC_Handler (void) __attribute__ ((weak, alias("__halt")));
120+
#endif
121+
void CAN0_Handler (void) __attribute__ ((weak, alias("__halt")));
122+
void CAN1_Handler (void) __attribute__ ((weak, alias("__halt")));
64123

65124
#ifdef __cplusplus
66125
}

hardware/arduino/sam/cores/arduino/hooks.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,30 @@ static void __empty() {
2929
// Empty
3030
}
3131
void yield(void) __attribute__ ((weak, alias("__empty")));
32+
33+
/**
34+
* SysTick hook
35+
*
36+
* This function is called from SysTick handler, before the default
37+
* handler provided by Arduino.
38+
*/
39+
static int __false() {
40+
// Return false
41+
return 0;
42+
}
43+
int sysTickHook(void) __attribute__ ((weak, alias("__false")));
44+
45+
/**
46+
* SVC hook
47+
* PendSV hook
48+
*
49+
* These functions are called from SVC handler, and PensSV handler.
50+
* Default action is halting.
51+
*/
52+
static void __halt() {
53+
// Halts
54+
while (1)
55+
;
56+
}
57+
void svcHook(void) __attribute__ ((weak, alias("__halt")));
58+
void pendSVHook(void) __attribute__ ((weak, alias("__halt")));

hardware/arduino/sam/cores/arduino/wiring.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "Arduino.h"
20-
#include "Reset.h"
2120

2221
#ifdef __cplusplus
2322
extern "C" {
@@ -57,17 +56,6 @@ void delayMicroseconds( uint32_t us )
5756
;
5857
}
5958

60-
/*
61-
* Cortex-M3 Systick IT handler: MOVED TO MAIN DUE TO WEAK SYMBOL ISSUE NOT RESOLVED
62-
*/
63-
void SysTick_Handler( void )
64-
{
65-
tickReset();
66-
67-
// Increment tick count each ms
68-
TimeTick_Increment() ;
69-
}
70-
7159
#if defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
7260
extern signed int putchar( signed int c ) ;
7361
/**

hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/source/gcc/startup_sam3xa.c

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -47,86 +47,7 @@ int main(void);
4747
// Arduino: we must setup hardware before doing this
4848
// void __libc_init_array(void);
4949

50-
/* Default empty handler */
51-
void Dummy_Handler(void);
52-
53-
/* Cortex-M3 core handlers */
54-
void NMI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
55-
void HardFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
56-
void MemManage_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
57-
void BusFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
58-
void UsageFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
59-
void SVC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
60-
void DebugMon_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
61-
void PendSV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
62-
void SysTick_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
63-
64-
/* Peripherals handlers */
65-
void SUPC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
66-
void RSTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
67-
void RTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
68-
void RTT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
69-
void WDT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
70-
void PMC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
71-
void EFC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
72-
void EFC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
73-
void UART_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
74-
#ifdef _SAM3XA_SMC_INSTANCE_
75-
void SMC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
76-
#endif /* _SAM3XA_SMC_INSTANCE_ */
77-
#ifdef _SAM3XA_SDRAMC_INSTANCE_
78-
void SDRAMC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
79-
#endif /* _SAM3XA_SDRAMC_INSTANCE_ */
80-
void PIOA_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
81-
void PIOB_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
82-
#ifdef _SAM3XA_PIOC_INSTANCE_
83-
void PIOC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
84-
#endif /* _SAM3XA_PIOC_INSTANCE_ */
85-
#ifdef _SAM3XA_PIOD_INSTANCE_
86-
void PIOD_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
87-
#endif /* _SAM3XA_PIOD_INSTANCE_ */
88-
#ifdef _SAM3XA_PIOE_INSTANCE_
89-
void PIOE_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
90-
#endif /* _SAM3XA_PIOE_INSTANCE_ */
91-
#ifdef _SAM3XA_PIOF_INSTANCE_
92-
void PIOF_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
93-
#endif /* _SAM3XA_PIOF_INSTANCE_ */
94-
void USART0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
95-
void USART1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
96-
void USART2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
97-
#ifdef _SAM3XA_USART3_INSTANCE_
98-
void USART3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
99-
#endif /* _SAM3XA_USART3_INSTANCE_ */
100-
void HSMCI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
101-
void TWI0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
102-
void TWI1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
103-
void SPI0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
104-
#ifdef _SAM3XA_SPI1_INSTANCE_
105-
void SPI1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
106-
#endif /* _SAM3XA_SPI1_INSTANCE_ */
107-
void SSC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
108-
void TC0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
109-
void TC1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
110-
void TC2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
111-
void TC3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
112-
void TC4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
113-
void TC5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
114-
#ifdef _SAM3XA_TC2_INSTANCE_
115-
void TC6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
116-
void TC7_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
117-
void TC8_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
118-
#endif /* _SAM3XA_TC2_INSTANCE_ */
119-
void PWM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
120-
void ADC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
121-
void DACC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
122-
void DMAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
123-
void UOTGHS_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
124-
void TRNG_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
125-
#ifdef _SAM3XA_EMAC_INSTANCE_
126-
void EMAC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
127-
#endif /* _SAM3XA_EMAC_INSTANCE_ */
128-
void CAN0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
129-
void CAN1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
50+
// Arduino: handlers weak symbols moved into main
13051

13152
/* Exception Table */
13253
__attribute__ ((section(".vectors")))
@@ -283,13 +204,3 @@ void Reset_Handler(void)
283204
/* Infinite loop */
284205
while (1);
285206
}
286-
287-
/**
288-
* \brief Default interrupt handler for unused IRQs.
289-
*/
290-
void Dummy_Handler(void)
291-
{
292-
while (1) {
293-
}
294-
}
295-
Binary file not shown.

0 commit comments

Comments
 (0)