Skip to content

Commit 61b70c5

Browse files
committed
freertos: Use the standard assert() function for configASSERT
Unless the option for "assert and keep running" is enabled. This means that silent asserts now work for FreeRTOS, and disabling asserts now also disables them in FreeRTOS without needing a separate config change. Related to #6306
1 parent cfde7ad commit 61b70c5

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

components/freertos/Kconfig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,25 @@ menu "FreeRTOS"
141141

142142
choice FREERTOS_ASSERT
143143
prompt "FreeRTOS assertions"
144-
default FREERTOS_ASSERT_FAIL_ABORT
144+
default FREERTOS_ASSERT_FAIL_ABORT if !COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE
145+
default FREERTOS_ASSERT_DISABLE if COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE
145146
help
146147
Failed FreeRTOS configASSERT() assertions can be configured to
147148
behave in different ways.
148149

150+
By default these behave the same as the global project assert settings.
151+
149152
config FREERTOS_ASSERT_FAIL_ABORT
150153
bool "abort() on failed assertions"
154+
depends on !COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE
151155
help
152156
If a FreeRTOS configASSERT() fails, FreeRTOS will abort() and
153157
halt execution. The panic handler can be configured to handle
154158
the outcome of an abort() in different ways.
155159

160+
If assertions are disabled for the entire project, they are also
161+
disabled in FreeRTOS and this option is unavailable.
162+
156163
config FREERTOS_ASSERT_FAIL_PRINT_CONTINUE
157164
bool "Print and continue failed assertions"
158165
help

components/freertos/port/riscv/include/freertos/FreeRTOSConfig.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888

8989
/* configASSERT behaviour */
9090
#ifndef __ASSEMBLER__
91-
#include <stdlib.h> /* for abort() */
91+
#include <assert.h>
9292
#include "esp32c3/rom/ets_sys.h"
9393

9494
// If CONFIG_FREERTOS_ASSERT_DISABLE is set then configASSERT is defined empty later in FreeRTOS.h and the macro
@@ -100,11 +100,7 @@
100100
__FUNCTION__); \
101101
}
102102
#elif defined(CONFIG_FREERTOS_ASSERT_FAIL_ABORT)
103-
#define configASSERT(a) if (unlikely(!(a))) { \
104-
esp_rom_printf("%s:%d (%s)- assert failed!\n", __FILE__, __LINE__, \
105-
__FUNCTION__); \
106-
abort(); \
107-
}
103+
#define configASSERT(a) assert(a)
108104
#endif
109105

110106
#if CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION

components/freertos/port/xtensa/include/freertos/FreeRTOSConfig.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int xt_clock_freq(void) __attribute__((deprecated));
119119

120120
/* configASSERT behaviour */
121121
#ifndef __ASSEMBLER__
122-
#include <stdlib.h> /* for abort() */
122+
#include <assert.h>
123123
#include "esp_rom_sys.h"
124124
#if CONFIG_IDF_TARGET_ESP32
125125
#include "esp32/rom/ets_sys.h" // will be removed in idf v5.0
@@ -140,11 +140,7 @@ int xt_clock_freq(void) __attribute__((deprecated));
140140
__FUNCTION__); \
141141
}
142142
#elif defined(CONFIG_FREERTOS_ASSERT_FAIL_ABORT)
143-
#define configASSERT(a) if (unlikely(!(a))) { \
144-
esp_rom_printf("%s:%d (%s)- assert failed!\n", __FILE__, __LINE__, \
145-
__FUNCTION__); \
146-
abort(); \
147-
}
143+
#define configASSERT(a) assert(a)
148144
#endif
149145

150146
#if CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION

0 commit comments

Comments
 (0)