openwch / arduino_core_ch32

Core library for CH32duino
244 stars 42 forks source link

unwanted DEBUG macro is defined by default #125

Open lyusupov opened 2 months ago

lyusupov commented 2 months ago

Build platform

Linux

Core version

current 'main' branch

Target

CH32V30x_EVT

To reproduce

Make an empty sketch like that:

#if defined(DEBUG)
#error DEBUG is defined by default
#endif

void setup() { }
void loop() { }

Then try to build it

$ export BOARD=WCH:ch32v:CH32V30x_EVT
$ arduino-cli compile -v --build-path=/tmp/arduino -b "$BOARD" debug/
FQBN: WCH:ch32v:CH32V30x_EVT
Using board 'CH32V30x_EVT' from platform in folder: /home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4
Using core 'arduino' from platform in folder: /home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4

Detecting libraries used...
/home/codespace/.arduino15/packages/WCH/tools/riscv-none-embed-gcc/8.2.0/bin/riscv-none-embed-g++ -DSYSCLK_FREQ_144MHz_HSI=144000000 -march=rv32imafcxw -mabi=ilp32f -msmall-data-limit=8 -msave-restore -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -c -Os -DNDEBUG -Wunused -Wuninitialized -std=gnu++14 -fno-threadsafe-statics -fno-rtti -fno-exceptions -fno-use-cxa-atexit -I/tmp/debug -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino/avr/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino/ch32/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino/ch32/lib/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/USER/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Core/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Debug/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Startup/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Peripheral/inc/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Peripheral/src/ -fpermissive -w -x c++ -E -CC -DARDUINO_ARCH_CH32 -DCH32V30x -DARDUINO=10607 -DCH32V30x_C -DVARIANT_H="variant_CH32V307VCT6.h" -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/variants/CH32V30x/CH32V307VCT6 -o /dev/null -c /tmp/arduino/sketch/debug.ino.cpp
Error while detecting libraries included by /tmp/arduino/sketch/debug.ino.cpp
Generating function prototypes...
/home/codespace/.arduino15/packages/WCH/tools/riscv-none-embed-gcc/8.2.0/bin/riscv-none-embed-g++ -DSYSCLK_FREQ_144MHz_HSI=144000000 -march=rv32imafcxw -mabi=ilp32f -msmall-data-limit=8 -msave-restore -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -c -Os -DNDEBUG -Wunused -Wuninitialized -std=gnu++14 -fno-threadsafe-statics -fno-rtti -fno-exceptions -fno-use-cxa-atexit -I/tmp/debug -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino/avr/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino/ch32/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino/ch32/lib/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/USER/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Core/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Debug/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Startup/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Peripheral/inc/ -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/system/CH32V30x/SRC/Peripheral/src/ -fpermissive -w -x c++ -E -CC -DARDUINO_ARCH_CH32 -DCH32V30x -DARDUINO=10607 -DCH32V30x_C -DVARIANT_H="variant_CH32V307VCT6.h" -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/cores/arduino -I/home/codespace/.arduino15/packages/WCH/hardware/ch32v/1.0.4/variants/CH32V30x/CH32V307VCT6 -o /tmp/1384001371/sketch_merged.cpp -c /tmp/arduino/sketch/debug.ino.cpp
/tmp/debug/debug.ino:2:2: error: #error DEBUG is defined by default
 #error DEBUG is defined by default
  ^~~~~

Expected behavior

'DEBUG' symbol name is too much generic one. It can easily cause namespace conflict with user application or a third-party library.

https://github.com/openwch/arduino_core_ch32/blob/b2c30eef490c189dc5923ae1a562c6574a983e9e/system/CH32V30x/SRC/Debug/debug.h#L28-L31

My suggestion is to use other name ( such as CH32_DEBUG or something similar ) for internal purpose of the Core.

Let's make DEBUG macro to be inactive by default in order to avoid namespace conflicts with other source codes.

A user may set it manually in Arduino IDE or by altering content of 1) boards.txt 2) platform.txt 3) variants folder

maxgerhardt commented 2 months ago

While I do agree, the system/CH32V30x/SRC/ etc files come from the official WCH SDK. as e.g. posted at https://github.com/openwch/ch32v307/tree/main/EVT/EXAM/SRC. So to change that, you would have to file a change request with WCH, not the Arduino croe.