Seeed-Studio / PN532

NFC library using PN532 to read/write card and communicate with android
420 stars 174 forks source link

Can't enable debug on esp32. #137

Open TECH7Fox opened 1 year ago

TECH7Fox commented 1 year ago

Using a ESP32 Dev Module. If I uncomment #define DEBUG to enable debug I get this:

In file included from C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/newlib/stdio.h:47:0,
                 from C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32/Arduino.h:27,
                 from C:\Users\Jordy\Documents\Arduino\libraries\PN532\PN532_debug.h:6,
                 from C:\Users\Jordy\Documents\Arduino\libraries\PN532\emulatetag.cpp:10:
C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/newlib/sys/reent.h:463:10: error: #if with no expression
In file included from C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/newlib/stdio.h:47:0,
                 from C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32/Arduino.h:27,
                 from C:\Users\Jordy\Documents\Arduino\libraries\PN532\PN532_debug.h:6,
                 from C:\Users\Jordy\Documents\Arduino\libraries\PN532\llcp.cpp:3:
C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/newlib/sys/reent.h:463:10: error: #if with no expression
In file included from C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/newlib/stdio.h:47:0,
                 from C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32/Arduino.h:27,
                 from C:\Users\Jordy\Documents\Arduino\libraries\PN532\PN532_debug.h:6,
                 from C:\Users\Jordy\Documents\Arduino\libraries\PN532\mac_link.cpp:3:
C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/newlib/sys/reent.h:463:10: error: #if with no expression
In file included from C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/newlib/stdio.h:47:0,
                 from C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\cores\esp32/Arduino.h:27,
                 from C:\Users\Jordy\Documents\Arduino\libraries\PN532\PN532_debug.h:6,
                 from C:\Users\Jordy\Documents\Arduino\libraries\PN532\snep.cpp:3:
C:\Users\Jordy\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6/tools/sdk/include/newlib/sys/reent.h:463:10: error: #if with no expression

exit status 1

Compilation error: exit status 1

Anyone else got this?

qbonenfant commented 1 year ago

Hi, I got the same issue on a CubeCell HTCC-AB02. In my case, there was a conflict with the board library, which also use a DEBUG statement in its debug.h, with a IFNDEF DEBUG to avoid redundancy. Using such common names in a library is poor practice and should be fixed ASAP (on both side really).

To solve the issue, you can modify the redundancy checks in PN532_debug.h

Here is what my file looks like:

#ifndef __DEBUG_PN532_H_
#define __DEBUG_PN532_H_

#define DEBUG_532

#include "Arduino.h"

#ifdef DEBUG_532
#define DMSG(args...)       Serial.print(args)
#define DMSG_STR(str)       Serial.println(str)
#define DMSG_HEX(num)       Serial.print(' '); Serial.print((num>>4)&0x0F, HEX); Serial.print(num&0x0F, HEX)
#define DMSG_INT(num)       Serial.print(' '); Serial.print(num)
#else
#define DMSG(args...)
#define DMSG_STR(str)
#define DMSG_HEX(num)
#define DMSG_INT(num)
#endif

#endif

I hope it will work for you too. This fix may need to be propagated to other files if there is an update of the library, but should work for now. I should really make a PR to fix this, but don't have time RN (maybe later... if i remember)

alireza-tabatabaee commented 1 year ago

As a quick and dirty fix you can comment out

define SERIAL 0x0

in line 50 of Arduino.h which is located at %localappdata%/Arduino15/packages/esp32/hardware/esp32/2.0.8/cores/esp32/Arduino.h