File tree Expand file tree Collapse file tree 4 files changed +34
-10
lines changed Expand file tree Collapse file tree 4 files changed +34
-10
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,12 @@ STATIC void sync_cb(void) {
183
183
int rc ;
184
184
(void )rc ;
185
185
186
+ DEBUG_printf ("sync_cb: state=%d\n" , mp_bluetooth_nimble_ble_state );
187
+
188
+ if (mp_bluetooth_nimble_ble_state != MP_BLUETOOTH_NIMBLE_BLE_STATE_WAITING_FOR_SYNC ) {
189
+ return ;
190
+ }
191
+
186
192
if (has_public_address ()) {
187
193
nimble_address_mode = BLE_OWN_ADDR_PUBLIC ;
188
194
} else {
@@ -390,14 +396,16 @@ void mp_bluetooth_deinit(void) {
390
396
return ;
391
397
}
392
398
393
- mp_bluetooth_gap_advertise_stop ();
394
- #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
395
- mp_bluetooth_gap_scan_stop ();
396
- #endif
397
-
398
399
// Must call ble_hs_stop() in a port-specific way to stop the background
399
400
// task. Default implementation provided above.
400
401
if (mp_bluetooth_nimble_ble_state == MP_BLUETOOTH_NIMBLE_BLE_STATE_ACTIVE ) {
402
+ mp_bluetooth_gap_advertise_stop ();
403
+ #if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
404
+ mp_bluetooth_gap_scan_stop ();
405
+ #endif
406
+
407
+ DEBUG_printf ("trying port shutdown\n" );
408
+
401
409
mp_bluetooth_nimble_port_shutdown ();
402
410
assert (mp_bluetooth_nimble_ble_state == MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF );
403
411
} else {
Original file line number Diff line number Diff line change @@ -9,9 +9,12 @@ CONFIG_BT_NIMBLE_ENABLED=y
9
9
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=4
10
10
11
11
# Pin to the same core as MP.
12
- CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=n
13
- CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y
14
- CONFIG_BT_NIMBLE_PINNED_TO_CORE=1
12
+ # Until we move to IDF 4.2+, we need NimBLE on core 0, and for synchronisation
13
+ # with the ringbuffer and scheduler MP needs to be on the same core.
14
+ # See https://github.com/micropython/micropython/issues/5489
15
+ CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y
16
+ CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=n
17
+ CONFIG_BT_NIMBLE_PINNED_TO_CORE=0
15
18
16
19
# v3.3-only (renamed in 4.0)
17
20
CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY=y
Original file line number Diff line number Diff line change 35
35
#include "freertos/FreeRTOS.h"
36
36
#include "freertos/task.h"
37
37
38
- // The core that the MicroPython task(s) are pinned to
39
- #define MP_TASK_COREID (1)
38
+ // The core that the MicroPython task(s) are pinned to.
39
+ // Until we move to IDF 4.2+, we need NimBLE on core 0, and for synchronisation
40
+ // with the ringbuffer and scheduler MP needs to be on the same core.
41
+ // See https://github.com/micropython/micropython/issues/5489
42
+ #define MP_TASK_COREID (0)
40
43
41
44
extern TaskHandle_t mp_main_task_handle ;
42
45
Original file line number Diff line number Diff line change 30
30
31
31
#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE
32
32
33
+ #define DEBUG_printf (...) // printf("nimble (esp32): " __VA_ARGS__)
34
+
33
35
#include "esp_nimble_hci.h"
34
36
#include "nimble/nimble_port.h"
35
37
#include "nimble/nimble_port_freertos.h"
36
38
37
39
#include "extmod/nimble/modbluetooth_nimble.h"
38
40
39
41
STATIC void ble_host_task (void * param ) {
42
+ DEBUG_printf ("ble_host_task\n" );
40
43
nimble_port_run (); // This function will return only when nimble_port_stop() is executed.
41
44
nimble_port_freertos_deinit ();
42
45
}
43
46
44
47
void mp_bluetooth_nimble_port_hci_init (void ) {
48
+ DEBUG_printf ("mp_bluetooth_nimble_port_hci_init\n" );
45
49
esp_nimble_hci_and_controller_init ();
46
50
}
47
51
48
52
void mp_bluetooth_nimble_port_hci_deinit (void ) {
53
+ DEBUG_printf ("mp_bluetooth_nimble_port_hci_deinit\n" );
54
+
49
55
esp_nimble_hci_and_controller_deinit ();
50
56
}
51
57
52
58
void mp_bluetooth_nimble_port_start (void ) {
59
+ DEBUG_printf ("mp_bluetooth_nimble_port_start\n" );
53
60
nimble_port_freertos_init (ble_host_task );
54
61
}
55
62
56
63
void mp_bluetooth_nimble_port_shutdown (void ) {
64
+ DEBUG_printf ("mp_bluetooth_nimble_port_shutdown\n" );
65
+
57
66
// Despite the name, these is an ESP32-specific (no other NimBLE ports have these functions).
58
67
// Calls ble_hs_stop() and waits for stack shutdown.
59
68
nimble_port_stop ();
69
+
60
70
// Shuts down the event queue.
61
71
nimble_port_deinit ();
62
72
You can’t perform that action at this time.
0 commit comments