adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.07k stars 1.2k forks source link

ESP32-S3 crashes when a client subscribes to the Notify characteristic of the AccelerationService #9304

Closed tyeth closed 3 months ago

tyeth commented 4 months ago

Sorry @tannewt I've not managed to get a good debug output as it goes straight to safemode, but when a debug build I didn't see that it just stalled and serial eventually disconnected.

I was testing on the LilyGo T-Display-S3 (as the 4mb flash builds dont have BLEIO), and then eventually on the ESP32v2 Feather (8mb Flash / 2mb PSRAM). Testing against the Web Bluetooth Dashboard https://adafruit.github.io/Adafruit_WebBluetooth_Dashboard/ with an SHT3x (sht30/31/35 temp+humidity sensor but not required) or BMP280 worked fine, but not with an accelerometer.

The code example linked below has been adapted to optionally ignore all non-present sensors, and accept one of 3 accelerometers (lsm9ds1 or lsm303 or lsm6ds33)

Copied from discord #: It's a reliable hard-fault 😄 Using an LSM303AGR (accelerometer) with the BLE Web Dashboard, hard fault as soon as it tries to start notifications from the AccelerationService, although I'm also seeing a console message claiming the web dashboard is attempting to update the measurement period which happens before notify start (I set it to 500 ms period instead of 100 in code so shouldn't be required, but maybe not part of broadcast info so writes desired value rather than read then write if incorrect). Modified example to skip non-available sensors and have 3 Accelerometer options, https://github.com/tyeth/Adafruit_CircuitPython_BLE/blob/web-bluetooth-dashboard/examples/ble_bluefruit_web_dashboard.py, I'll try to capture more details before filing an issue. BLE Web Dashboard: https://kind-decisive-paw.glitch.me/

Original learn guide: https://learn.adafruit.com/bluefruit-dashboard-web-bluetooth-chrome

Adafruit BLE Web Dashboard: https://adafruit.github.io/Adafruit_WebBluetooth_Dashboard/

tannewt commented 3 months ago

It'd be easier to debug this if we had CircuitPython client code that trigger the issue.

tyeth commented 3 months ago

@dhalbert you'll be relieved to hear your work on #9374 has fixed it. Thank you both for tackling the BLE stuff. I initially thought ah-almost, as the T-Display S3 just didn't crash this time but no accelerometer data appeared in browser, but reading the console I saw it moan about a missing service (0000180f-0000-1000-8000-00805f9b34fb battery service it turned out), which the T-Display won't/doesn't have. Tried again on feather s3 reverse tft, but not enough space for BLE, so ran a custom debug build using CIRCUITPY_BLEIO=1 FLASH_SIZE_SDKCONFIG=esp-idf-config/sdkconfig-flash-4MB-no-ota.defaults for build flags (inspired by memento def) and hey presto I see acceleration service data (and battery with a ? as none attached which I'd never thought about really as the code doesn't mention one in the imports) image

dhalbert commented 3 months ago

@tyeth Fantastic, thank you for testing!

dhalbert commented 3 months ago

Fixed by #9374.