-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add Bluetooth support to Pico W #10739
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:
|
a790e12
to
25256dd
Compare
Codecov Report
@@ Coverage Diff @@
## master #10739 +/- ##
=======================================
Coverage 98.40% 98.40%
=======================================
Files 155 155
Lines 20543 20543
=======================================
Hits 20215 20215
Misses 328 328 |
25256dd
to
ac3c9e1
Compare
ports/rp2/boards/PICO_W/manifest.py
Outdated
@@ -1,3 +1,6 @@ | |||
include("$(PORT_DIR)/boards/manifest.py") | |||
|
|||
require("bundle-networking") | |||
|
|||
# Bluetooth | |||
require("aioble", client=True, central=True, l2cap=True, security=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to remember there are some BT examples that need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary (only needed for aioble examples), but might be good to include it by default.
@jimmo what do you think?
bf78a12
to
3e4244f
Compare
Note: I think I addressed the review comments so far. We're still waiting for some news on a fix for an issue from Infineon, so we'd prefer if this was not merged yet. |
OK. But note that this is blocking #10635 because that PR needs to update cyw43-driver as well, which in turn requires pico-sdk 1.5.0. Will pico-sdk need updating with the fix from Infineon? If yes then we can wait. If no then would be good to just update pico-sdk to 1.5.0 (and cyw43-driver) and do the minimal changes to the rp2 port to work with the new pico-sdk (that's hopefully very minimal work). Then BT can be added as a second step, as done in this PR. |
See #10764 which updates pico-sdk to 1.5.0 and cyw43-driver to the latest. That's a very simple change, then this PR can be easily rebased on that once it's merged. |
@peterharperuk Impersonating my little one, are we there yet? |
@samveen We're still waiting to see if we can get an update from Infineon. In the meantime, feel free to try this PR out for yourself. |
@peterharperuk can you provide any clarity as to what this issue is? I've been able to get this PR working on my Pico but not quite up to feature parity with the ESP32 stack and I'm wondering if that's related... |
It's just a stability issue. What features are missing? |
It seems that remote writes to a characteristic ( I've also been able to get pairing and pairing with a passkey working in "Legacy Pairing" mode but enabling "LE Secure" mode so as to allow for bonding does not work, it just seems to get stuck. I realize those options are disabled in this PR so I totally understand if that's too in the weeds for you right now. |
@FlantasticDan Could you point me towards an example that demonstrates the problem with gattc_write mode set to zero? I believe you, but the ble_simple_central.py example seems to work okay and that appears to be using write-without-response. |
@peterharperuk I think I have gotten to the bottom of this and I fear I may have steered you a little off course. My apologies. I was seeing that my writes were erroring and assumed it was because of that write mode. Both write modes are working as expected. What's actually happening is the write response handler (only used when mode = To test this I'm running ble_simple_peripheral.py on a TinyS3 and ble_simple_central.py on a Pico W using this PR's build of micropython. I've made a few changes to ble_simple_central.py to test this bug: # ble_simple_central.py
elif event == _IRQ_GATTC_WRITE_DONE:
conn_handle, value_handle, status = data
print("TX complete", value_handle) # line 147 modified print statement to see the value_handle of the response event
# . . .
with_response = True # line 228, was False, changed to True
i = 0 # line 230
print("RX Handle:", central._rx_handle) # added this statement to confirm outbound write value_handle
while central.is_connected():
# . . . Running this test sees all writes successfully reach the TinyS3 but where it's interesting is in the Pico W stdout:
The writes occur at |
@FlantasticDan this is a known issue with our btstack bindings. I have been working on this in the past week (in between other things). v1.20 will include feature parity with NimBLE for all the GATT functionality (and hopefully also l2cap channels), which will mean that aioble will work identically. |
@FlantasticDan the background is that btstack doesn't provide the value handle in the event, so it's up to us to track it. It would be nice if we could make btstack do this but I'll have a PR for this ready soon. @peterharperuk Yes, just to confirm this is completely unrelated to the issue you're tracking with infineon. |
@jimmo that's awesome, thanks for all your work on that. I think I just came across that issue in the source code 😅 micropython/extmod/btstack/modbluetooth_btstack.c Lines 432 to 439 in 2e4dda3
Sorry for steering you astray @peterharperuk |
np |
Hi there, I've tried out this PR, and noticed two bugs/instabilities, that could be addressed here or resolved as separate PRs/issues, as they are closely related but not strictly implied by this change:
void mp_bluetooth_hci_poll_in_ms(uint32_t ms) {
+ if(poll_timer_id != 0){
+ cancel_alarm(poll_timer_id);
+ }
poll_timer_id = add_alarm_in_ms(ms, mp_bluetooth_hci_timer_callback, NULL, true);
}
@@ -592,26 +601,26 @@ STATIC void set_random_address(void) {
bd_addr_t static_addr;
#if MICROPY_BLUETOOTH_USE_MP_HAL_GET_MAC_STATIC_ADDRESS
DEBUG_printf("set_random_address: Generating static address using mp_hal_get_mac\n");
mp_hal_get_mac(MP_HAL_MAC_BDADDR, static_addr);
- // Mark it as STATIC (not RPA or NRPA).
- static_addr[0] |= 0xc0;
#else
DEBUG_printf("set_random_address: Generating random static address.\n");
btstack_crypto_random_t sm_crypto_random_request;
volatile bool ready = false;
btstack_crypto_random_generate(&sm_crypto_random_request, static_addr, 6, &btstack_static_address_ready, (void *)&ready);
while (!ready) {
MICROPY_EVENT_POLL_HOOK
}
#endif // MICROPY_BLUETOOTH_USE_MP_HAL_GET_MAC_STATIC_ADDRESS
+ // Mark it as STATIC (not RPA or NRPA).
+ static_addr[0] |= 0xc0;
DEBUG_printf("set_random_address: Address generated.\n");
gap_random_address_set(static_addr);
} |
@peterharperuk I think we can now drop the commits that prevent the use of WiFi and BT together. Do you want me to do that? We also need to wait for releases/tags of pico-sdk and btstack. |
@dpgeorge I've reverted the two commits that stopped bt and wifi working. Yes - we have to wait for btstack and pico-sdk. Are you going to wait to update cyw43-driver? |
Thanks @peterharperuk. I've now cleaned up the commits here (squashing the relevant ones), and have also added commits to update to the latest submodules for pico-sdk, cyw43-driver and btstack. I tested it and everything works as far as I can tell. In particular there are no more issues with BT and WiFi running at the same time on Pico W. Apart from waiting for tags on the three submodules, this is ready to go in. |
e0383f0
to
7a0857b
Compare
Includes a fix for combined BT+WiFi when using SPI transport. Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Using BTstack with CYW43 for Pico W. Signed-off-by: Damien George <damien@micropython.org>
Cancel any existing poll alarm before add a new one. Signed-off-by: Damien George <damien@micropython.org>
Marking address as static was not applied to all code paths. Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
This is now merged! |
Thanks for your help, and all the work! |
Thank you for all the hard work. I have a question. When updating the submodules with that PR, commit 825a957 shows a diff:
However,. git submodules lists: |
I'm not sure where v1.4-2373 is coming from. |
Guys, while I just sat here observing progress, thanks for all the hard and pro work. Really appreciated! Well deserved official praise on The official Site, BTW |
You probably just need to run |
The Pico W firmware nightly builds include this work from version v1.20.0-206-g33b403dfb onward. Thank you for the Music et. al. |
That's what I did, and git tags returns all tags:
I tried as well a deinit of btstack and a new init. No change. |
@robert-hh my repo also shows that same line when running |
Thanks. I was just a little bit nervous about the state of my local clone. |
Add Bluetooth support to Pico W. Using BTstack with CYW43