Skip to content
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

UNO R4 WiFi issue and IS_PIN_PWM variable declaration conflict #167

Closed
julesmoretti opened this issue Sep 12, 2024 · 1 comment · Fixed by #168
Closed

UNO R4 WiFi issue and IS_PIN_PWM variable declaration conflict #167

julesmoretti opened this issue Sep 12, 2024 · 1 comment · Fixed by #168

Comments

@julesmoretti
Copy link

In the following thread over the Arduino Forum we identified that ConfigurableFirmata did not upload properly onto an UNO R4 Wifi board. At first a DHT sensor library dependency was flagged as being needed to be installed which I did separately. But then the following error came about:

In file included from /Users/jules/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.2.0/cores/arduino/Arduino.h:124:0,
                 from /Users/jules/Documents/Arduino/libraries/ConfigurableFirmata/src/utility/Boards.h:23,
                 from /Users/jules/Documents/Arduino/libraries/ConfigurableFirmata/src/ConfigurableFirmata.h:18,
                 from /Users/jules/Documents/Arduino/libraries/ConfigurableFirmata/src/AnalogOutputFirmata.cpp:19:
/Users/jules/Documents/Arduino/libraries/ConfigurableFirmata/src/AnalogOutputFirmata.cpp: In member function 'virtual boolean AnalogOutputFirmata::handlePinMode(byte, int)':
/Users/jules/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.2.0/variants/UNOWIFIR4/pins_arduino.h:93:30: error: 'IS_PIN_PWM' was not declared in this scope
 #define digitalPinHasPWM(p) (IS_PIN_PWM(getPinCfgs(p, PIN_CFG_REQ_PWM)[0]))
                              ^
/Users/jules/Documents/Arduino/libraries/ConfigurableFirmata/src/utility/Boards.h:817:33: note: in expansion of macro 'digitalPinHasPWM'
 #define IS_PIN_PWM(p)           digitalPinHasPWM(p)
                                 ^~~~~~~~~~~~~~~~
/Users/jules/Documents/Arduino/libraries/ConfigurableFirmata/src/AnalogOutputFirmata.cpp:41:33: note: in expansion of macro 'IS_PIN_PWM'
     if (mode == PIN_MODE_PWM && IS_PIN_PWM(pin)) {
                                 ^~~~~~~~~~
/Users/jules/Documents/Arduino/libraries/ConfigurableFirmata/src/AnalogOutputFirmata.cpp: In member function 'virtual void AnalogOutputFirmata::handleCapability(byte)':
/Users/jules/Library/Arduino15/packages/arduino/hardware/renesas_uno/1.2.0/variants/UNOWIFIR4/pins_arduino.h:93:30: error: 'IS_PIN_PWM' was not declared in this scope
 #define digitalPinHasPWM(p) (IS_PIN_PWM(getPinCfgs(p, PIN_CFG_REQ_PWM)[0]))
                              ^
/Users/jules/Documents/Arduino/libraries/ConfigurableFirmata/src/utility/Boards.h:817:33: note: in expansion of macro 'digitalPinHasPWM'
 #define IS_PIN_PWM(p)           digitalPinHasPWM(p)

Thanks to @ptillisch on the Arduino Forum, they provided me with a temporary patch to correct the issue which was:

  1. within the Arduino/libraries/ConfigurableFirmata/src/utility/Boards.h
  2. replace line 817 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
  3. with:
#define ARDUINO_IS_PIN_PWM(x)   (((x & PIN_USE_MASK) ==  PIN_PWM_GPT) || ((x & PIN_USE_MASK) ==  PIN_PWM_AGT))
#define ARDUINO_digitalPinHasPWM(p) (ARDUINO_IS_PIN_PWM(getPinCfgs(p, PIN_CFG_REQ_PWM)[0]))
#define IS_PIN_PWM(p)           ARDUINO_digitalPinHasPWM(p)

This helped unblock the issue but not a good permanent fix as they explained:
The problem is that there is a macro named IS_PIN_PWM in the UNO R4 WiFi board's [Arduino core library]
(https://arduino.github.io/arduino-cli/latest/platform-specification/#cores):
line 76: #define IS_PIN_PWM(x) (((x & PIN_USE_MASK) == PIN_PWM_GPT) || ((x & PIN_USE_MASK) == PIN_PWM_AGT))

but the ConfigurableFirmata library also uses a macro of the same name:
line 817: #define IS_PIN_PWM(p) digitalPinHasPWM(p)

The person who added support for the UNO R4 WiFi board attempted to work around that macro name collision by undefining the core's macro before defining the library's macro:
line 811: // These have conflicting(?) definitions in the core for this CPU
line 812: #undef IS_PIN_PWM

However, that doesn't work because the digitalPinHasPWM macro uses the IS_PIN_PWM macro:
line 93: #define digitalPinHasPWM(p) (IS_PIN_PWM(getPinCfgs(p, PIN_CFG_REQ_PWM)[0]))

@ptillisch worked around this by duplicating all the code from the core for the digitalPinHasPWM macro definition, including the code for the core's IS_PIN_PWM macro.

@ptillisch thinks that a better solution would be to change the name of the ConfigurableFirmata library's IS_PIN_PWM macro to something more unique (e.g., CONFIGURABLE_FIRMATA_IS_PIN_PWM) so that it won't collide with the macro of the same name in the UNO R4 WiFi board's core. However, this solution does require updating all references to the macro throughout the library so it is more complex to apply to the library.

Hope this helps :)

Thank you for the help

@pgrawehr
Copy link
Contributor

The issue is known already, thanks for the report. It was probably caused by a change in the UnoR4 toolchain. PR #168 should fix it.

@pgrawehr pgrawehr linked a pull request Sep 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants