-
Notifications
You must be signed in to change notification settings - Fork 654
Description
When compiling with the -DSIMPLEFOC_DISABLE_DEBUG flag on ESP32-S3, the build fails with SimpleFOCDebug has not been declared errors. The issue occurs in esp32_mcu.h where the macro SIMPLEFOC_ESP32_CS_DEBUG attempts to use SimpleFOCDebug::println() even though the debug class is disabled.
error message:
.pio/libdeps/esp32s3/Simple FOC/src/current_sense/hardware_specific/esp32/esp32_mcu.h:24:4: error: 'SimpleFOCDebug' has not been declared 24 | SimpleFOCDebug::println( "ESP32-CS: "+ String(str)); | ^~~~~~~~~~~~~~
This error appears multiple times:
In esp32_adc_driver.cpp at line 107 and 156
In esp32_mcu.cpp during ADC configuration
Current behavior: Compilation fails with -DSIMPLEFOC_DISABLE_DEBUG enabled.
Expected behavior: The code should compile successfully with -DSIMPLEFOC_DISABLE_DEBUG, since this flag is intended to disable debug output and reduce firmware size.
Root cause
In src/current_sense/hardware_specific/esp32/esp32_mcu.h (around line 20-25), the macro SIMPLEFOC_ESP32_CS_DEBUG is conditionally defined:
#if defined(SIMPLEFOC_ESP32_DEBUG) #define SIMPLEFOC_ESP32_CS_DEBUG(str)\ SimpleFOCDebug::println( "ESP32-CS: "+ String(str));\ #else #define SIMPLEFOC_ESP32_CS_DEBUG(str) #endif
The problem: when -DSIMPLEFOC_DISABLE_DEBUG is set globally, the SimpleFOCDebug class is not compiled/included, but the SIMPLEFOC_ESP32_CS_DEBUG macro still tries to use it if SIMPLEFOC_ESP32_DEBUG is defined elsewhere or in specific compilation units.
Platform information:
Platform: espressif32 @ 55.03.34 Board: esp32-s3-devkitm-1 Framework: arduino SimpleFOC: v2.3.5
Minimal reproducible example
platformio.ini:
`[env:esp32s3]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.34/platform-espressif32.zip
board = esp32-s3-devkitm-1
framework = arduino
lib_deps =
askuric/Simple [email protected]
build_flags =
-Os
-fno-exceptions
-fno-rtti
-DSIMPLEFOC_DISABLE_DEBUG
`
Proposed solution
The macro definition in esp32_mcu.h should check for both SIMPLEFOC_ESP32_DEBUG AND ensure that SIMPLEFOC_DISABLE_DEBUG is not set:
#if defined(SIMPLEFOC_ESP32_DEBUG) && !defined(SIMPLEFOC_DISABLE_DEBUG) #define SIMPLEFOC_ESP32_CS_DEBUG(str)\ SimpleFOCDebug::println( "ESP32-CS: "+ String(str));\ #else #define SIMPLEFOC_ESP32_CS_DEBUG(str) #endif
This ensures the macro expands to an empty statement when debug is disabled, preventing the undefined reference error.