Skip to content

Commit 10bec59

Browse files
committed
1 parent 54ea855 commit 10bec59

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

cores/arduino/core_debug.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef _CORE_DEBUG_H
22
#define _CORE_DEBUG_H
3-
#ifdef CORE_DEBUG
3+
#if !defined(NDEBUG)
44
#include <stdio.h>
55
#include <stdarg.h>
6-
#endif /* CORE_DEBUG */
6+
#endif /* NDEBUG */
77

88
#ifdef __cplusplus
99
extern "C" {
@@ -18,14 +18,14 @@ extern "C" {
1818
*/
1919
static inline void core_debug(const char *format, ...)
2020
{
21-
#ifdef CORE_DEBUG
21+
#if !defined(NDEBUG)
2222
va_list args;
2323
va_start(args, format);
2424
vfprintf(stderr, format, args);
2525
va_end(args);
2626
#else
2727
(void)(format);
28-
#endif /* CORE_DEBUG */
28+
#endif /* NDEBUG */
2929
}
3030

3131
#ifdef __cplusplus

cores/arduino/stm32/stm32_def.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,22 @@ extern "C" {
7777
// weaked functions declaration
7878
void SystemClock_Config(void);
7979

80-
void _Error_Handler(const char *, int);
80+
#if defined(NDEBUG)
81+
#if !defined(_Error_Handler)
82+
#define _Error_Handler(str, value); \
83+
while (1) {\
84+
}
85+
#endif
86+
#if !defined(Error_Handler)
87+
#define Error_Handler() \
88+
while (1) {\
89+
}
90+
#endif
91+
#else
92+
void _Error_Handler(const char *, int);
8193

82-
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
94+
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
95+
#endif
8396

8497
#ifdef __cplusplus
8598
} // extern "C"

libraries/SrcWrapper/src/stm32/stm32_def.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#include "stm32_def.h"
23
#include "core_debug.h"
34

@@ -10,13 +11,15 @@ extern "C" {
1011
* @param None
1112
* @retval None
1213
*/
14+
#if !defined(NDEBUG)
1315
WEAK void _Error_Handler(const char *msg, int val)
1416
{
1517
/* User can add his own implementation to report the HAL error return state */
1618
core_debug("Error: %s (%i)\n", msg, val);
1719
while (1) {
1820
}
1921
}
22+
#endif
2023

2124
#ifdef __cplusplus
2225
}

platform.txt

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ build.enable_virtio=
9999
build.startup_file=
100100
build.flags.fp=
101101
build.flags.optimize=-Os
102+
build.flags.debug=-DNDEBUG
102103
build.flags.ldspecs=--specs=nano.specs
103104
build.flash_offset=0
104105

system/extras/prebuild.sh

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
BUILD_PATH="$1"
44
BUILD_SOURCE_PATH="$2"
5+
BOARD_PLATFORM_PATH="$3"
56

67
# Create sketch dir if not exists
78
if [ ! -f "$BUILD_PATH/sketch" ]; then
@@ -13,5 +14,10 @@ if [ ! -f "$BUILD_SOURCE_PATH/build_opt.h" ]; then
1314
touch "$BUILD_PATH/sketch/build_opt.h"
1415
fi
1516

17+
# Append -fmacro-prefix-map option to change __FILE__ absolute path of the board
18+
# platform folder to a relative path by using '.'.
19+
# (i.e. the folder containing boards.txt)
20+
printf '\n-fmacro-prefix-map=%s=.' "${BOARD_PLATFORM_PATH//\\/\\\\}" > "$BUILD_PATH/sketch/build.opt"
21+
1622
# Force include of SrcWrapper library
1723
echo "#include <SrcWrapper.h>" >"$BUILD_PATH/sketch/SrcWrapper.cpp"

0 commit comments

Comments
 (0)