Compilation error using Arduino/ESP32-S2/Nimble

I’ve been using platformio for ESP32 DevKit development using the Arduino framework with great success. I’ve recently gotten the Adafruit Qt Py (which I believe uses the ESP32-S2) and am trying to use it with the Arduino framework and Arduino NimBLE library.

When I try to build my project, I get the compiler error message at the end of this message. I’ve also put a minimal project that should make the error reproducible here: GitHub - devalbo/test-qtpy-pio-nimble-arduino .

Does anyone know what’s going on or what would be a good way to proceed with this error?

Thanks!

Processing adafruit_qtpy_esp32s2 (platform: espressif32; board: adafruit_qtpy_esp32s2; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/adafruit_qtpy_esp32s2.html
PLATFORM: Espressif 32 (4.3.0+sha.b1b44fe) > Adafruit QT Py ESP32-S2
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20003.0 (2.0.3) 
 - tool-esptoolpy @ 1.30300.0 (3.3.0) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch3 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- NimBLE-Arduino @ 1.3.8
|-- ESP32 BLE Arduino @ 2.0.0
Building in release mode
Compiling .pio/build/adafruit_qtpy_esp32s2/src/bluetooth.cpp.o
In file included from src/bluetooth.cpp:2:
src/bluetooth.h:8:1: error: 'NimBLEServer' does not name a type
 NimBLEServer * initBluetoothServer(const char * deviceName);
 ^~~~~~~~~~~~
src/bluetooth.h:9:27: error: variable or field 'startBluetoothServer' declared void
 void startBluetoothServer(NimBLEServer * server);
                           ^~~~~~~~~~~~
src/bluetooth.h:9:27: error: 'NimBLEServer' was not declared in this scope
Compiling .pio/build/adafruit_qtpy_esp32s2/lib2b7/NimBLE-Arduino/esp-hci/src/esp_nimble_hci.c.o
src/bluetooth.h:9:42: error: 'server' was not declared in this scope
 void startBluetoothServer(NimBLEServer * server);
                                          ^~~~~~
src/bluetooth.h:9:42: note: suggested alternative: 'perror'
 void startBluetoothServer(NimBLEServer * server);
                                          ^~~~~~
                                          perror
src/bluetooth.cpp:8:1: error: 'NimBLEServer' does not name a type
 NimBLEServer * initBluetoothServer(const char * deviceName) {
 ^~~~~~~~~~~~
src/bluetooth.cpp:32:27: error: variable or field 'startBluetoothServer' declared void
 void startBluetoothServer(NimBLEServer * server) {
                           ^~~~~~~~~~~~
src/bluetooth.cpp:32:27: error: 'NimBLEServer' was not declared in this scope
src/bluetooth.cpp:32:42: error: 'server' was not declared in this scope
 void startBluetoothServer(NimBLEServer * server) {
                                          ^~~~~~
src/bluetooth.cpp:32:42: note: suggested alternative: 'perror'
 void startBluetoothServer(NimBLEServer * server) {
                                          ^~~~~~
                                          perror
Compiling .pio/build/adafruit_qtpy_esp32s2/lib2b7/NimBLE-Arduino/ext/tinycrypt/src/ctr_mode.c.o
Compiling .pio/build/adafruit_qtpy_esp32s2/lib2b7/NimBLE-Arduino/ext/tinycrypt/src/ctr_prng.c.o
Compiling .pio/build/adafruit_qtpy_esp32s2/lib2b7/NimBLE-Arduino/ext/tinycrypt/src/ecc.c.o
Compiling .pio/build/adafruit_qtpy_esp32s2/lib2b7/NimBLE-Arduino/ext/tinycrypt/src/ecc_dh.c.o
Compiling .pio/build/adafruit_qtpy_esp32s2/lib2b7/NimBLE-Arduino/ext/tinycrypt/src/ecc_dsa.c.o
*** [.pio/build/adafruit_qtpy_esp32s2/src/bluetooth.cpp.o] Error 1
Compiling .pio/build/adafruit_qtpy_esp32s2/lib2b7/NimBLE-Arduino/ext/tinycrypt/src/ecc_platform_specific.c.o
In file included from /Users/ajb/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/esp_hw_support/include/soc/compare_set.h:12,
                 from /Users/ajb/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/esp_hw_support/include/soc/spinlock.h:13,
                 from /Users/ajb/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/freertos/port/xtensa/include/freertos/portmacro.h:42,
                 from /Users/ajb/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/freertos/include/freertos/portable.h:51,
                 from /Users/ajb/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/freertos/include/freertos/FreeRTOS.h:63,
                 from .pio/libdeps/adafruit_qtpy_esp32s2/NimBLE-Arduino/src/nimble/nimble_npl_os.h:26,
                 from .pio/libdeps/adafruit_qtpy_esp32s2/NimBLE-Arduino/src/nimble/nimble_npl.h:54,
                 from .pio/libdeps/adafruit_qtpy_esp32s2/NimBLE-Arduino/src/os/os.h:38,
                 from .pio/libdeps/adafruit_qtpy_esp32s2/NimBLE-Arduino/src/nimble/ble.h:26,
                 from .pio/libdeps/adafruit_qtpy_esp32s2/NimBLE-Arduino/src/nimble/hci_common.h:23,
                 from .pio/libdeps/adafruit_qtpy_esp32s2/NimBLE-Arduino/src/esp-hci/src/esp_nimble_hci.c:24:
/Users/ajb/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/soc/include/soc/soc_memory_types.h: In function 'esp_ptr_in_iram':
/Users/ajb/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/soc/include/soc/soc_memory_types.h:105:28: error: 'SOC_CACHE_APP_LOW' undeclared (first use in this function); did you mean 'SOC_RTC_DRAM_LOW'?
     return ((intptr_t)p >= SOC_CACHE_APP_LOW && (intptr_t)p < SOC_IRAM_HIGH);
                            ^~~~~~~~~~~~~~~~~
                            SOC_RTC_DRAM_LOW
/Users/ajb/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s2/include/soc/include/soc/soc_memory_types.h:105:28: note: each undeclared identifier is reported only once for each function it appears in
.pio/libdeps/adafruit_qtpy_esp32s2/NimBLE-Arduino/src/esp-hci/src/esp_nimble_hci.c: At top level:
.pio/libdeps/adafruit_qtpy_esp32s2/NimBLE-Arduino/src/esp-hci/src/esp_nimble_hci.c:30:10: fatal error: esp_bt.h: No such file or directory

Ctrl+Click’ing to follow the #include <NimBLEServer.h> line in bluetooth.h and VSCode shows me

so the file is all disabled becacuse the sdkconfig.h, which comes from the Arduino-ESP32 core, does not have the CONFIG_BT_ENABLED macro set.

And as ESP32 S2 fails to compile · Issue #375 · h2zero/NimBLE-Arduino · GitHub shows that is because…

thorrak: Doesn’t the S2 not have a Bluetooth radio?
joostbijl: doh, it does not :frowning: !

This is further confirmed by https://maker.pro/esp8266/tutorial/a-comparison-of-the-new-esp32-s2-to-the-esp32

So what you want is impossible on your ESP32S2 board.

Note that there are 4 different Adafruit Qt Py boards, for ESP32, ESP32-S2, ESP32-C3 and ESP32-S3

all but the ESP32-S2 are bluetooth capable, and so e.g., changing your project to board = adafruit_qtpy_esp32s3 in the platformio.ini with zero code modifications, …

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   6.5% (used 21216 bytes from 327680 bytes)
Flash: [=         ]  12.4% (used 259285 bytes from 2097152 bytes)
Building .pio\build\adafruit_qtpy_esp32s3\firmware.bin
esptool.py v3.3
Creating esp32s3 image...
Merged 2 ELF sections
Successfully created esp32s3 image.
========= [SUCCESS] Took 35.43 seconds =========

Thank you - in hindsight, I got hung up on the wrong board configuration and didn’t think enough about it (I was following an Adafruit tutorial for the S2, but have the C3). Then, I saw the deeper compiler errors in
soc_memory_types.h and didn’t backtrack the right way. Thankfully it’s a quick fix (since you figured it out), so I will be on my way. Thanks again!