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

Cannot create PN532_SPI instance. #149

Closed
aloyen07 opened this issue Nov 20, 2024 · 8 comments
Closed

Cannot create PN532_SPI instance. #149

aloyen07 opened this issue Nov 20, 2024 · 8 comments
Assignees
Labels
PN532 Label for PN532 UAY Unassigned yet

Comments

@aloyen07
Copy link

aloyen07 commented Nov 20, 2024

Hello!
I'm have this code:

#define NFC_INTERFACE_SPI

#include <SPI.h>
#include <PN532_SPI.h>
#include "PN532.h"

PN532_SPI pn532spi(SPI, 6);
PN532 nfc(pn532spi);

void setup() {
  nfc.begin();
}

void loop() {

}

But it not works. Compilator throws this error:

/tmp/ccq7arst.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_eee.ino.cpp.o.2087':
<artificial>:(.text.startup+0x62): undefined reference to `PN532_SPI::PN532_SPI(SPIClass&, unsigned char)'
collect2: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

How to fix it?

@reganissu
Copy link

Hello, I have happened to solve this issue a while ago. It was happening because newer arduino rules deprecated a syntax declaration used in SPI include file of that library, if memory serves me well. Sorry for now I am not able to post my solution, only this hint to go toward solution. I rember though that the solution was changing few lines of code regarding that deprecated syntax

@Lesords Lesords added UAY Unassigned yet PN532 Label for PN532 labels Nov 27, 2024
@sduponch
Copy link

sduponch commented Nov 27, 2024

Same issue here with SPI/HSU or whatever, the linker fail on the sample file although the object files are included.
Same issue with ESP32 or AVR.

Linking everything together...
"/usr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections,--relax -mmcu=atmega2560   -o "/tmp/arduino_build_169869/emulate_tag_ndef.ino.elf" "/tmp/arduino_build_169869/sketch/emulate_tag_ndef.ino.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532_HSU.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532_I2C.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532_SPI.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532_SWHSU.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/emulatetag.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/llcp.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/mac_link.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/snep.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/MifareClassic.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/MifareUltralight.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/Ndef.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/NdefMessage.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/NdefRecord.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/NfcAdapter.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/NfcTag.cpp.o" "/tmp/arduino_build_169869/libraries/SPI/SPI.cpp.o"  "/tmp/arduino_build_169869/core/core.a" "-L/tmp/arduino_build_169869" -lm
/tmp/cchaXHjI.ltrans0.ltrans.o: In function `HardwareSerial::read()':
/home/tfury/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/HardwareSerial.cpp:181: undefined reference to `PN532_SPI::PN532_SPI(SPIClass&, unsigned char)'
collect2: erreur: ld a retourné le statut de sortie 1
Linking everything together...
"/home/tfury/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-g++" "-Wl,--Map=/tmp/arduino_build_169869/emulate_tag_ndef.ino.map" "-L/home/tfury/.arduino15/packages/esp32/hardware/esp32/2.0.14/tools/sdk/esp32/lib" "-L/home/tfury/.arduino15/packages/esp32/hardware/esp32/2.0.14/tools/sdk/esp32/ld" "-L/home/tfury/.arduino15/packages/esp32/hardware/esp32/2.0.14/tools/sdk/esp32/qio_qspi" -T esp32.rom.redefined.ld -T memory.ld -T sections.ld -T esp32.rom.ld -T esp32.rom.api.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.peripherals.ld  -mlongcalls -Wno-frame-address -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -Wl,--wrap=esp_log_write -Wl,--wrap=esp_log_writev -Wl,--wrap=log_printf -u ld_include_hli_vectors_bt -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u include_esp_phy_override -u ld_include_highint_hdl -u start_app -u start_app_other_cores -u __ubsan_include -Wl,--wrap=longjmp -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy  -DESP32 -DCORE_DEBUG_LEVEL=0   -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw -DARDUINO_USB_CDC_ON_BOOT=0 -Wl,--start-group "/tmp/arduino_build_169869/sketch/emulate_tag_ndef.ino.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532_HSU.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532_I2C.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532_SPI.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/PN532_SWHSU.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/emulatetag.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/llcp.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/mac_link.cpp.o" "/tmp/arduino_build_169869/libraries/PN532-Arduino/snep.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/MifareClassic.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/MifareUltralight.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/Ndef.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/NdefMessage.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/NdefRecord.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/NfcAdapter.cpp.o" "/tmp/arduino_build_169869/libraries/NDEF/NfcTag.cpp.o" "/tmp/arduino_cache_758568/core/core_esp32_esp32_esp32wroverkit_FlashSize_4M,PSRAM_enabled,PartitionScheme_default,CPUFreq_240,FlashMode_qio,FlashFreq_80,UploadSpeed_921600,DebugLevel_none,EraseFlash_none_6b7e22108de8654f39dd754e8348fd66.a"  -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lasio -lbt -lcbor -lunity -lcmock -lcoap -lnghttp -lesp-tls -lesp_adc_cal -lesp_hid -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lesp_https_server -lesp_lcd -lprotobuf-c -lprotocomm -lmdns -lesp_local_ctrl -lsdmmc -lesp_serial_slave_link -lesp_websocket_client -lexpat -lwear_levelling -lfatfs -lfreemodbus -ljsmn -ljson -llibsodium -lmqtt -lopenssl -lperfmon -lspiffs -lulp -lwifi_provisioning -lrmaker_common -lesp_diagnostics -lrtc_store -lesp_insights -ljson_parser -ljson_generator -lesp_schedule -lespressif__esp_secure_cert_mgr -lesp_rainmaker -lgpio_button -lqrcode -lws2812_led -lesp32-camera -lesp_littlefs -lespressif__esp-dsp -lfb_gfx -lasio -lcmock -lunity -lcoap -lesp_lcd -lesp_websocket_client -lexpat -lfreemodbus -ljsmn -llibsodium -lperfmon -lesp_adc_cal -lesp_hid -lfatfs -lwear_levelling -lopenssl -lspiffs -lesp_insights -lcbor -lesp_diagnostics -lrtc_store -lesp_rainmaker -lesp_local_ctrl -lesp_https_server -lwifi_provisioning -lprotocomm -lbt -lbtdm_app -lprotobuf-c -lmdns -ljson -ljson_parser -ljson_generator -lesp_schedule -lespressif__esp_secure_cert_mgr -lqrcode -lrmaker_common -lmqtt -lcat_face_detect -lhuman_face_detect -lcolor_detect -lmfn -ldl -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls_2 -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls_2 -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls_2 -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls_2 -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lesp_ringbuf -lefuse -lesp_ipc -ldriver -lesp_pm -lmbedtls -lapp_update -lbootloader_support -lspi_flash -lnvs_flash -lpthread -lesp_gdbstub -lespcoredump -lesp_phy -lesp_system -lesp_rom -lhal -lvfs -lesp_eth -ltcpip_adapter -lesp_netif -lesp_event -lwpa_supplicant -lesp_wifi -lconsole -llwip -llog -lheap -lsoc -lesp_hw_support -lxtensa -lesp_common -lesp_timer -lfreertos -lnewlib -lcxx -lapp_trace -lnghttp -lesp-tls -ltcp_transport -lesp_http_client -lesp_http_server -lesp_https_ota -lsdmmc -lesp_serial_slave_link -lulp -lmbedtls_2 -lmbedcrypto -lmbedx509 -lcoexist -lcore -lespnow -lmesh -lnet80211 -lpp -lsmartconfig -lwapi -lphy -lrtc -lesp_phy -lphy -lrtc -lesp_phy -lphy -lrtc -lxt_hal -lc -lm -lnewlib -lstdc++ -lpthread -lgcc -lcxx  -Wl,--end-group -Wl,-EL -o "/tmp/arduino_build_169869/emulate_tag_ndef.ino.elf"
/home/tfury/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino_build_169869/sketch/emulate_tag_ndef.ino.cpp.o:(.literal.startup._GLOBAL__sub_I_pn532hsu+0x8): undefined reference to `PN532_HSU::PN532_HSU(HardwareSerial&)'
/home/tfury/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/arduino_build_169869/sketch/emulate_tag_ndef.ino.cpp.o: in function `_GLOBAL__sub_I_pn532hsu':
/home/tfury/Arduino/TestPN532/emulate_tag_ndef/emulate_tag_ndef.ino:16: undefined reference to `PN532_HSU::PN532_HSU(HardwareSerial&)'
collect2: error: ld returned 1 exit status

@sduponch
Copy link

Adding -DNFC_INTERFACE_I2C / -DNFC_INTERFACE_SPI to compiler.cpreprocessor.flags.esp32s3= in platform.txt fix the issue (Yes i have "#define NFC_INTERFACE_I2C" at start of my code).

@BenEspinoza10
Copy link

@reganissu Im having the exactly same problem, have you remembered the solution?

@reganissu
Copy link

@reganissu Im having the exactly same problem, have you remembered the solution?

Ok, I have found the workaround I have done and that made everything work for me. I am not totally sure it is on topic for your issue, but I am posting the solution below and you can judge for yourself.

In the PN532_SPI folder, in PN532_SPI.cpp file, in the void PN532_SPI::begin() function in the first 30 lines of code, you have to make the following mod, since SetDataMode and SetBitOrder have been deprecated a long ago (by arduino SPI library I think - not sure):
` _spi->begin();
_spi->beginTransaction(SPISettings(2000000, LSBFIRST, SPI_MODE0));
// _spi->setDataMode(SPI_MODE0); // PN532 only supports mode0 // MOD SPISettings
//_spi->setBitOrder(LSBFIRST); //

// SPISettings(2000000, LSBFIRST, SPI_MODE0);
`
as you can see I have commented out the deprecated declaration, using the "new" accepted SPIsettings declaration.
Hope this helps

@sduponch
Copy link

sduponch commented Dec 3, 2024

The issue is that #define NFC_INTERFACE_SPI is not set when the compiler build the PN532 lib.

The #define in the ".ino" file seems out of scope : A workaround is to manually edit the compiler args by adding -DNFC_INTERFACE_SPI in the compiler command line (ex: by editing the "platform.txt" in the Arduino "hardware" directory).

@Cincinnatu
Copy link

Hello,I just tested this issue and found that adding #include <PN532_SPI.cpp> allows it to run normally.

@Lesords Lesords assigned Lesords and unassigned Cincinnatu Dec 24, 2024
@ackPeng
Copy link

ackPeng commented Dec 26, 2024

This issue has been fixed and will be closed soon. If you still have any doubts, please reopen one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PN532 Label for PN532 UAY Unassigned yet
Projects
Status: Done
Development

No branches or pull requests

7 participants