-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
extmod/nimble: Support pairing/bonding on the ESP32. #13258
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
Conversation
Code size report:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #13258 +/- ##
=======================================
Coverage 98.36% 98.36%
=======================================
Files 161 161
Lines 21091 21091
=======================================
Hits 20746 20746
Misses 345 345 ☔ View full report in Codecov by Sentry. |
efd5455
to
5862647
Compare
Rebased to include the explanations in the commit messages. |
Thanks, this looks good. But I'm having trouble testing it. Using IDF 5.0.4 and a normal ESP32 without SPIRAM, running the What IDF version and hardware set up do you use for the testing? Can you try running the multitests with two ESP32's, like this:
(You may need to adjust u0 and u1 to match your serial ports.) |
When testing BLE for the Arduino Nanoc connect 2040 and the SAMD extension @iabdalkader and me have seen a largely inconsistent test coverage. Some tests always failed, some tests always succeeded, and some tests succeeded sometimes. Arduino Nano Connect 2040
SAMD ItsyBitsyM4 with Airlift hat
The pass rates vary somewhat if the test are changed, especially the timeout settings. BLE testing works fine with the PYBD-SF6, and it works as well fine for ESP32 devices as BLE modem running the esp-hosted firmware. Then we get about 100% pass rates for the test. |
I currently build against IDFv5.0.5 (using DvdGiessen@a4bec6a). Most of my development and testing was done on an ESP32-S3 and connecting to it with an Android app, but I've just ran the testsuite between a regular ESP32 (with 4MB SPIRAM) and ESP32-S3 (with 8MB SPIRAM). Tests from esp32 to esp32s3 succeed:
However, I ran again with
I poked around for a bit but haven't seen what's different there yet, maybe I'll find some time to dive into that later. |
I've recently upgraded to IDF v5.2 (see #13775), so just decided to re-run these tests against that version. It seems all the issues I saw previously are gone:
So perhaps a BLE issue was fixed upstream? |
Testing latest master as at a30c293, with ESP32_GENERIC and PYBD_SF6, the 14 standard BLE multitests pass reliably now, still using IDF 5.0.4. |
This moves the runtime initialisation of `ble_hs_cfg` to happen after `nimble_port_init()`. That is consistent with the order used in NimBLE examples. On the ESP32 port this is needed because the ESP-IDF sets up the default RAM secret store callbacks in its implementation of `nimble_port_init()` (specifically, it calls `esp_nimble_init()` which in turn calls `ble_store_ram_init()`). We want to override those with our own callbacks to implement the `IRQ_[GS]ET_SECRET` events in Python. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This sets the BLE key distribution parameters at runtime. This isn't needed in most ports since we already set the default values in `extmod/nimble/syscfg/syscfg.h`; however in the ESP32 port that headerfile is not used, and the default values in the ESP-IDF don't enable key distribution nor can we change those defaults via `sdkconfig`. Thus we're setting these values explicitly at runtime. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Pairing and bonding was fixed for the ESP32 in the two previous commits. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
5862647
to
678707c
Compare
Testing this PR with IDF 5.0.4, it works reliably (with a ESP32_GENERIC and PYBD_SF6). |
Two fixes to NimBLE to fix compatibility with the ESP-IDF.
The first commit moves the runtime initialisation of
ble_hs_cfg
to happen afternimble_port_init()
. That is consistent with the order used in NimBLE examples. On the ESP32 port this is needed because the ESP-IDF sets up the default RAM secret store callbacks in its implementation ofnimble_port_init()
(specifically, it callsesp_nimble_init()
which in turn callsble_store_ram_init()
). We want to override those callbacks with our own so used to implement theIRQ_[GS]ET_SECRET
events in Python.The second commit sets the BLE key distribution parameters at runtime. This isn't needed in most ports since we already set the default values in
extmod/nimble/syscfg/syscfg.h
; however in the ESP32 port that headerfile is not used, and the default values in the ESP-IDF don't enable key distribution nor can we change those defaults viasdkconfig
. Setting the values explicitly at runtime seems like a reasonable solution.These two commits together make persistent pairing/bonding work on the ESP32 in my own local tests.
Third commit updates the documentation to mention that the ESP32 now also supports pairing/bonding.
Fixes #12958.