Skip to content

Invalid macro name if Arduino is used as a component in esp-idf and the board name contains a dash #7499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
supcik opened this issue Nov 20, 2022 · 3 comments · Fixed by #7500
Closed
1 task done
Labels
Area: Arduino as ESP-IDF component Issues about Arduino used as component in ESP-IDF Status: Solved

Comments

@supcik
Copy link
Contributor

supcik commented Nov 20, 2022

Board

ttgo-lora32-v1 (and on all boards with a dash in the name)

Device Description

Plain module. This issue is not related to a specific device.

Hardware Configuration

This issue is not related to a specific configuration

Version

latest master (checkout manually)

IDE Name

VS Code

Operating System

macOS 13.0.1

Flash frequency

40 Mhz

PSRAM enabled

no

Upload speed

115200

Description

This problem occurs when arduino-esp32 is used as a component in esp-idf (as described here) and when the name of the board (the "variant") contains a dash (for example ttgo-lora32-v1).

In this case, the CMakeList.txt of arduino-esp32 defines the symbol ARDUINO_${idf_target_caps}_DEV where idf_target_caps is the capitalized board name (or the variant).

When the board name contains a dash (-), the symbol is not valid and the compiler issues plenty of warnings :

<command-line>: warning: ISO C++11 requires whitespace after the macro name

If, inside the C++ code, you want to use conditional compilation, such as :

#ifdef ARDUINO_TTGO-LORA32-V1_DEV
...
#endif

the code still compiles, but it seems to ignore everything starting from the first dash. So it is not possible to distinguish ARDUINO_TTGO-LORA32-V1_DEV from ARDUINO_TTGO-LORA32-V2_DEV. Note that the compiler also issues a warning:

main/main.cpp:3:20: warning: extra tokens at end of #ifdef directive
 #ifdef ARDUINO_TTGO-LORA32-V1_DEV
                    ^

and the clang-format adds spaces around the dashes.

So to my opinion, the dashes should be replaced by underscores for the macro defined by the CMakeList.txt. Something like this:

string(REPLACE "-" "_" idf_target_for_macro "${idf_target_caps}")
target_compile_options(${COMPONENT_TARGET} PUBLIC
    ...
    -DARDUINO_${idf_target_for_macro}_DEV
    ...

... but this is already part of the solution and I will provide a Pull Request for this.

Sketch

#include <Arduino.h>

#ifdef ARDUINO_TTGO-LORA32-V1_DEV
#define DELAY 1000
#endif

void setup() { Serial.begin(115200); }

void loop() {
    Serial.println("Hello World!");
    delay(DELAY);
}

Debug Message

The error messages (warnings) are given in the description.

This warning comes from the command line because of the `-DARDUINO_TTGO-LORA32-V1_DEV` flag :

    <command-line>: warning: ISO C++11 requires whitespace after the macro name

This warning comes when you try to test for the symbol:

    main/main.cpp:3:20: warning: extra tokens at end of #ifdef directive
     #ifdef ARDUINO_TTGO-LORA32-V1_DEV
                        ^

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@supcik supcik added the Status: Awaiting triage Issue is waiting for triage label Nov 20, 2022
@SuGlider SuGlider self-assigned this Nov 21, 2022
@SuGlider
Copy link
Collaborator

that seems interesting....
Let me look at that.

@SuGlider SuGlider added Status: Needs investigation We need to do some research before taking next steps on this issue Area: Arduino as ESP-IDF component Issues about Arduino used as component in ESP-IDF and removed Status: Awaiting triage Issue is waiting for triage labels Nov 21, 2022
@supcik
Copy link
Contributor Author

supcik commented Nov 21, 2022

I made the Pull Request #7500 with the changes described in this issue.

@VojtechBartoska
Copy link
Contributor

Hello @supcik, thank you for the issue and PR as well. We'll review it as soon as possible.

@VojtechBartoska VojtechBartoska added Status: In Progress ⚠️ Issue is in progress and removed Status: Needs investigation We need to do some research before taking next steps on this issue labels Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Arduino as ESP-IDF component Issues about Arduino used as component in ESP-IDF Status: Solved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants