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

Compilation error when enabling debug in Adafruit_PN532 lib #118

Open
jsiobj opened this issue Jul 9, 2023 · 3 comments
Open

Compilation error when enabling debug in Adafruit_PN532 lib #118

jsiobj opened this issue Jul 9, 2023 · 3 comments

Comments

@jsiobj
Copy link

jsiobj commented Jul 9, 2023

  • Arduino board: Adafruit M0 Proto

  • Arduino IDE version (found in Arduino -> About Arduino menu): Using VSCode + PlatformIO

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):

When enabling debugging in Adafruit_PN532 lib uncommenting line 71/72

// #define PN532DEBUG
// #define MIFAREDEBUG

I get 2 compilation errors :
.pio\libdeps\adafruit_feather_m0\Adafruit PN532\Adafruit_PN532.cpp:957:28: error: invalid conversion from 'int8_t*' {aka 'signed char*'} to 'const byte*' {aka 'const unsigned char*'} [-fpermissive]

For compilation to succeed, I forced conversion to (const uint8_t*) for _uid and _key when calling PrintHex here :

#ifdef MIFAREDEBUG
PN532DEBUGPRINT.print(F("Trying to authenticate card "));
Adafruit_PN532::PrintHex(_uid, _uidLen);
PN532DEBUGPRINT.print(F("Using authentication KEY "));
PN532DEBUGPRINT.print(keyNumber ? 'B' : 'A');
PN532DEBUGPRINT.print(F(": "));
Adafruit_PN532::PrintHex(_key, 6);
#endif

With the change :

#ifdef MIFAREDEBUG
  PN532DEBUGPRINT.print(F("Trying to authenticate card "));
  Adafruit_PN532::PrintHex((const uint8_t*)_uid, _uidLen);
  PN532DEBUGPRINT.print(F("Using authentication KEY "));
  PN532DEBUGPRINT.print(keyNumber ? 'B' : 'A');
  PN532DEBUGPRINT.print(F(": "));
  Adafruit_PN532::PrintHex((const uint8_t*)_key, 6);
#endif

Not sure how to contribute / make a PR (code of conduct link in readme is broken)
and not even sure this is the proper way to solve this issue anyway.

Regards
Jean-Sébastien

@caternuson
Copy link
Contributor

Also able to recreate this using Arduino IDE. Compiling the readMifareClassic library example for a target board of Feather M0:

Arduino/libraries/Adafruit-PN532/Adafruit_PN532.cpp:883:28: error: invalid conversion from 'int8_t*' {aka 'signed char*'} to 'const byte*' {aka 'const unsigned char*'} [-fpermissive]
  883 |   Adafruit_PN532::PrintHex(_uid, _uidLen);
      |                            ^~~~
      |                            |
      |                            int8_t* {aka signed char*}

@caternuson
Copy link
Contributor

Not sure int8_t is a good choice for these in the first place. Not seeing any reasons for them being signed.

@jsiobj Try removing the casts. Then change the declarations in Adafruit_PN532.h to:

  uint8_t _uid[7];      // ISO14443A uid
  uint8_t _uidLen;      // uid len
  uint8_t _key[6];      // Mifare Classic key

That will most likely get past the compilation issue. But do other issue then arise? Like run time issues, etc?

@jsiobj
Copy link
Author

jsiobj commented Sep 10, 2023

Hello @caternuson,

Indeed, it passes compilation successfully. I'll do some tests, hopefully next week and give the results.

I did not want to change variables types in the first place as just debugging code was not working and I was not sure of the implications. But I agree that changing the type should be the way to go.

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

No branches or pull requests

2 participants