earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
2.03k stars 422 forks source link

BTstack examples won't compile #1356

Closed noahbaron closed 1 year ago

noahbaron commented 1 year ago

Thanks for making an Arduino wrapper for the Pico W bluetooth functionality. I am trying to compile iBeaconScanner.ino in the BTstack folder with board v.3.1.0, which I understand is beta/alpha however I did note that it should compile. I haven't modified the example and in looking at BTstack.h I don't see any reason why these errors would occur.

Here are the errors:

/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:37:6: error: variable or field 'advertisementCallback' declared void
   37 | void advertisementCallback(BLEAdvertisement *adv) {
      |      ^~~~~~~~~~~~~~~~~~~~~
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:37:28: error: 'BLEAdvertisement' was not declared in this scope
   37 | void advertisementCallback(BLEAdvertisement *adv) {
      |                            ^~~~~~~~~~~~~~~~
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:37:46: error: 'adv' was not declared in this scope
   37 | void advertisementCallback(BLEAdvertisement *adv) {
      |                                              ^~~
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino: In function 'void setup()':
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:17:3: error: 'BTstack' was not declared in this scope
   17 |   BTstack.setup();
      |   ^~~~~~~
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:18:39: error: 'advertisementCallback' was not declared in this scope
   18 |   BTstack.setBLEAdvertisementCallback(advertisementCallback);
      |                                       ^~~~~~~~~~~~~~~~~~~~~
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino: In function 'void loop()':
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:24:3: error: 'BTstack' was not declared in this scope
   24 |   BTstack.loop();
      |   ^~~~~~~
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino: At global scope:
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:37:6: error: variable or field 'advertisementCallback' declared void
   37 | void advertisementCallback(BLEAdvertisement *adv) {
      |      ^~~~~~~~~~~~~~~~~~~~~
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:37:28: error: 'BLEAdvertisement' was not declared in this scope
   37 | void advertisementCallback(BLEAdvertisement *adv) {
      |                            ^~~~~~~~~~~~~~~~
/private/var/folders/2w/n4f1n28573345fr4zwssdkmc0000gn/T/.arduinoIDE-unsaved202335-73470-gxhntz.rwt4/iBeaconScanner/iBeaconScanner.ino:37:46: error: 'adv' was not declared in this scope
   37 | void advertisementCallback(BLEAdvertisement *adv) {
      |                                              ^~~

exit status 1

Compilation error: variable or field 'advertisementCallback' declared void
earlephilhower commented 1 year ago

To be clear, I just added the Arduino library that the BTStack folks wrote themselves (with simple compilation fixes) so I really do mean the "unsupported" part of the commit. I think it may have been abandoned at some point because the version that's distributed in their repo actually has the wrong number of parameters in a callback (fixed in the copy of the lib here) which is basically fatal to any GCC never than ~7.0.

How did you install the core? I'm able to build all of the examples without incident via my own git version. Maybe the ZIP (IDE boards manager) install is munged somehow.

lyusupov commented 1 year ago

I am trying to compile iBeaconScanner.ino in the BTstack folder with board v.3.1.0

https://github.com/earlephilhower/arduino-pico/releases/tag/3.1.1

earlephilhower commented 1 year ago

Sorry, I cannot reproduce this.

I just

It built fine, ending with:

Linking everything together...
/home/earle/.arduino15/packages/rp2040/tools/pqt-python3/1.0.1-base-3a57aed/python3 -I /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/tools/simplesub.py --input /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/lib/memmap_default.ld --out /tmp/arduino_build_392412/memmap_default.ld --sub __FLASH_LENGTH__ 2093056 --sub __EEPROM_START__ 270528512 --sub __FS_START__ 270528512 --sub __FS_END__ 270528512 --sub __RAM_LENGTH__ 256k
/home/earle/.arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/bin/arm-none-eabi-gcc -Werror=return-type -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSBD_PID=0xf00a -DUSBD_VID=0x2e8a -DUSBD_MAX_POWER_MA=250 "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico W\"" -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_LWIP=1 -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DENABLE_CLASSIC=1 -DENABLE_BLE=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 "-DARDUINO_VARIANT=\"rpipicow\"" -DTARGET_RP2040 -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -DARM_MATH_CM0_FAMILY -DARM_MATH_CM0_PLUS -Os -u _printf_float -u _scanf_float -c /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/boot2/boot2_w25q080_2_padded_checksum.S -I/home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/pico-sdk/src/rp2040/hardware_regs/include/ -I/home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/pico-sdk/src/common/pico_binary_info/include -o /tmp/arduino_build_392412/boot2.o
/home/earle/.arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/bin/arm-none-eabi-g++ -L/tmp/arduino_build_392412 -Wall -Wextra -Werror=return-type -Wno-ignored-qualifiers -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSBD_PID=0xf00a -DUSBD_VID=0x2e8a -DUSBD_MAX_POWER_MA=250 "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico W\"" -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_LWIP=1 -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DENABLE_CLASSIC=1 -DENABLE_BLE=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 "-DARDUINO_VARIANT=\"rpipicow\"" -DTARGET_RP2040 -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -DARM_MATH_CM0_FAMILY -DARM_MATH_CM0_PLUS -Os -u _printf_float -u _scanf_float @/home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/lib/platform_wrap.txt -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--script=/tmp/arduino_build_392412/memmap_default.ld -Wl,-Map,/tmp/arduino_build_392412/iBeaconScanner.ino.map -o /tmp/arduino_build_392412/iBeaconScanner.ino.elf -Wl,--start-group /tmp/arduino_build_392412/sketch/iBeaconScanner.ino.cpp.o /tmp/arduino_build_392412/libraries/BTstack/BTstack.a /tmp/arduino_build_392412/libraries/SPI/SPI.a /tmp/arduino_build_392412/core/picow_digital.cpp.o /tmp/arduino_build_392412/core/picow_init.cpp.o /tmp/arduino_build_392412/core/core.a /tmp/arduino_build_392412/boot2.o /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/lib/ota.o /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/lib/libpico.a /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/lib/libpicow-noipv6-btc-ble.a /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/lib/libbearssl.a -lm -lc -lstdc++ -lc -Wl,--end-group
/home/earle/.arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/bin//arm-none-eabi-objcopy -Obinary /tmp/arduino_build_392412/iBeaconScanner.ino.elf /tmp/arduino_build_392412/iBeaconScanner.ino.bin
/home/earle/.arduino15/packages/rp2040/tools/pqt-python3/1.0.1-base-3a57aed/python3 -I /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/tools/signing.py --mode sign --privatekey /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/libraries/BTstack/examples/iBeaconScanner/private.key --bin /tmp/arduino_build_392412/iBeaconScanner.ino.bin --out /tmp/arduino_build_392412/iBeaconScanner.ino.bin.signed
/home/earle/.arduino15/packages/rp2040/tools/pqt-elf2uf2/1.5.0-b-c7bab52/elf2uf2 /tmp/arduino_build_392412/iBeaconScanner.ino.elf /tmp/arduino_build_392412/iBeaconScanner.ino.uf2
Using library BTstack at version 1.0 in folder: /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/libraries/BTstack 
Using library SPI at version 1.0 in folder: /home/earle/.arduino15/packages/rp2040/hardware/rp2040/3.1.1/libraries/SPI 
/home/earle/.arduino15/packages/rp2040/tools/pqt-gcc/1.5.0-b-c7bab52/bin/arm-none-eabi-size -A /tmp/arduino_build_392412/iBeaconScanner.ino.elf
Sketch uses 440588 bytes (21%) of program storage space. Maximum is 2093056 bytes.
Global variables use 87780 bytes (33%) of dynamic memory, leaving 174364 bytes for local variables. Maximum is 262144 bytes.

Are you maybe trying to compile the files in pico-sdk/lib/btstack ? If so, that won't work. Like I said, the example code they had in their repo had compile problems in modern GCCs and so I had to fix it to include in the normal libraries directory.

noahbaron commented 1 year ago

Same procedure as you have outlined. I have a screenshot showing all the settings with the error output pasted previously. I have also tried with a dfferent Windows 11 PC laptop using the latest Arduino v1.8 and v2.0.4. I verified the location of the header files is:

btstack.h /Users/noahneibaron/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.1/pico-sdk/lib/btstack/src/btstack.h

spi.h /Users/noahneibaron/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.1/libraries/SPI/src/SPI.h

Not sure what else to check. The other examples are compiling, just not btstack. I understand it's not supported, however I was hoping to use the Pico W as a customized iBeacon to WiFi and iBeacon to serial adapter.

image
earlephilhower commented 1 year ago

@lyusupov are you doing this on a Mac, too? There might be a case sensitive filename issue, but afaik only Win32 NTFS has that problem, not Unix derived OSes like Linux and MacOS.

I'm away from the computer now, but I think the Arduino lib has a CAP BTStack.h while the internal header is all lowercase. For case sensitive OSesi might need to rename the lib to BTStackLib and adjust the header to match to avoid this problem...

noahbaron commented 1 year ago

I tried different cases on my Mac laptop with latest OS v13.1 vs. both seemed ok.

One thing I noticed is Arduino is referencing the location for in possibly the wrong location since on further inspection, it appeared to have the SDK version of this file that as you said won't compile.

/Users/noahneibaron/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.1/pico-sdk/lib/btstack/src/btstack.h (This location is the SDK version and Arduino 2.0.4 is showing this file is being referenced)

image

/Users/noahneibaron/Library/Arduino15/packages/rp2040/hardware/rp2040/3.1.1/pico-sdk/lib/btstack/port/arduino/btstack.h (This location has your Arduino wrapper version)

earlephilhower commented 1 year ago

No, that's the problem. Per https://discussions.apple.com/thread/251191099 "BTStack.h" (the library header) and "btstack.h" (the internal file you as a user should never include) will both resolve (incorrectly) to the same filename.

So, looks like I need to rename their library too (in addition to fixing all the compilation errors already done) to make it work anywhere but Linux and the odd Windows w/NTFS case-sensitivity turned on.

earlephilhower commented 1 year ago

Also, as for your use case, I did test the iBeacon.ino sketch and detected the PicoW with my cell phone, but I didn't have any other beacons to test so did not try your iBeaconScanner side. to verify it could properly detect any modern beacons (the library is ~8yrs old IIRC!).

noahbaron commented 1 year ago

Great to hear the iBeacon transmitter is working. iBeacon is 10 years old at this point but is still an active standard and still useful (for example Tesla model 3 transmits an iBeacon and the Pico W could potentially detect it now). Most low cost iBeacon to WiFi capable boards are based on ESP32 so the Pico W might be a great alternative to the popular Espressif ecosystem.

On Thu, Apr 6, 2023 at 4:27 PM Earle F. Philhower, III < @.***> wrote:

Also, as for your use case, I did test the iBeacon.ino sketch and detected the PicoW with my cell phone, but I didn't have any other beacons to test so did not try your iBeaconScanner side. to verify it could properly detect any modern beacons (the library is ~8yrs old IIRC!).

— Reply to this email directly, view it on GitHub https://github.com/earlephilhower/arduino-pico/issues/1356#issuecomment-1499753669, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ3FBLGQVAV4E3FB7KQ6Y3W75GPXANCNFSM6AAAAAAWUYBJE4 . You are receiving this because you authored the thread.Message ID: @.***>

lyusupov commented 1 year ago

@lyusupov are you doing this on a Mac, too?

Debian Linux