Skip to content

Commit ca7a940

Browse files
committed
Added _Error_Handler(const char *, int)
Allow to use the SystemClock_Config() from STM32CubeMX without any change. It could be redefined by user at sketch level (weak) extern "C" void _Error_Handler(const char * file, int line) { ... } Fix stm32duino#66 Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 22f42a8 commit ca7a940

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

cores/arduino/pins_arduino.h

-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@
2020

2121
#include "PeripheralPins.h"
2222

23-
/**
24-
* Libc porting layers
25-
*/
26-
#if defined ( __GNUC__ ) /* GCC CS3 */
27-
#include <syscalls.h> /** RedHat Newlib minimal stub */
28-
#define WEAK __attribute__ ((weak))
29-
#endif
30-
3123
// Arduino digital pin alias
3224
// GPIO port (A to K) * 16 pins: 176
3325
enum {

cores/arduino/stm32/stm32_def.c

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "stm32_def.h"
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
/**
8+
* @brief This function is executed in case of error occurrence.
9+
* @param None
10+
* @retval None
11+
*/
12+
WEAK void _Error_Handler(const char * msg, int val)
13+
{
14+
/* User can add his own implementation to report the HAL error return state */
15+
printf("Error: %s (%i)\n", msg, val);
16+
while(1)
17+
{
18+
}
19+
}
20+
21+
#ifdef __cplusplus
22+
}
23+
#endif

cores/arduino/stm32/stm32_def.h

+14
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,25 @@
7474
#define CAN1 CAN
7575
#endif
7676

77+
/**
78+
* Libc porting layers
79+
*/
80+
#if defined ( __GNUC__ ) /* GCC CS3 */
81+
#include <syscalls.h> /** RedHat Newlib minimal stub */
82+
#define WEAK __attribute__ ((weak))
83+
#endif
84+
7785
#ifdef __cplusplus
7886
extern "C"{
7987
#endif // __cplusplus
88+
8089
// weaked functions declaration
8190
void SystemClock_Config(void);
91+
92+
void _Error_Handler(const char *, int);
93+
94+
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
95+
8296
#ifdef __cplusplus
8397
} // extern "C"
8498
#endif // __cplusplus

0 commit comments

Comments
 (0)