Skip to content

Synchronize the ESP32 BLE receive queue - #3007

Merged
ripplebiz merged 2 commits into
meshcore-dev:devfrom
axhoff:agent/synchronize-ble-receive-queue
Jul 21, 2026
Merged

Synchronize the ESP32 BLE receive queue#3007
ripplebiz merged 2 commits into
meshcore-dev:devfrom
axhoff:agent/synchronize-ble-receive-queue

Conversation

@axhoff

@axhoff axhoff commented Jul 20, 2026

Copy link
Copy Markdown

Summary

  • replace the ESP32 BLE receive array with a statically allocated FreeRTOS queue
  • use non-blocking queue send/receive operations and reset the queue when buffers are cleared
  • keep send-queue behavior unchanged

Root cause

The BLE callback task appended to recv_queue while the Arduino loop task read, decremented, shifted, and cleared the same array without synchronization. Closely spaced frames could therefore observe partially published state or race with draining and clearing.

Scope

Only the receive queue is changed. xQueueSend(..., 0) retains the existing drop-newest behavior when all four slots are occupied, xQueueReceive(..., 0) keeps reads non-blocking, and xQueueReset handles clear/reset. Static allocation avoids introducing heap allocation or queue-lifetime management.

Validation

  • git diff --check
  • pio test -e native — 13/13 tests passed
  • pio run -e Xiao_S3_WIO_companion_radio_ble

Fixes #2923

@axhoff
axhoff marked this pull request as ready for review July 20, 2026 14:51
@ripplebiz

Copy link
Copy Markdown
Member

Wow, I did a bit of research and it's news to me that the Arduino BLE classes don't wrap the operations/callbacks into thread-safe accessors. Yoiks! So, in that case, we should just use an RTOS Queue, eg
dataQueue = xQueueCreate(FRAME_QUEUE_SIZE, sizeof(Frame));
...
onWrite() { ... xQueueSend(dataQueue, ...) }
...
in checkRecvFrame() { ... if (xQueueReceive(dataQueue, ... }

@axhoff

axhoff commented Jul 21, 2026

Copy link
Copy Markdown
Author

Thanks @ripplebiz — good call on using the RTOS primitive. I replaced the custom queue and critical section with a statically allocated FreeRTOS queue using xQueueSend, xQueueReceive, and xQueueReset in 4d4d7c3. The BLE target and native tests both pass.

@ripplebiz
ripplebiz merged commit 8b048ab into meshcore-dev:dev Jul 21, 2026
15 checks passed
hermes-gadget added a commit to gadgethd/MeshCore-MQTT that referenced this pull request Jul 22, 2026
Upstream dev: 7ecb2cb..78240e9 (6 commits)
3885c67 fix: synchronize BLE receive queue
9fd6b41 fix: preserve bonded BLE reconnects
4d4d7c3 refactor: use FreeRTOS BLE receive queue
8b048ab Merge pull request meshcore-dev#3007
4157e43 Merge pull request meshcore-dev#3005
78240e9 optimised: value-init not needed

Clean auto-merge (no conflicts). MQTT additions preserved.
dl9sau pushed a commit to dl9sau/MeshCore-fork-DL9SAU that referenced this pull request Aug 10, 2026
…er adoptiert)

Merge companion-v1.17.0 in den DL9SAU-Fork. Core-Protokoll 0-Diff (kein Wire-Bruch).

Config (Weg B -- binaer behalten, JSON meshcore-dev#2982 NICHT adoptiert):
- NodePrefs.h / DataStore.{cpp,h} / MyMesh.h savePrefs auf --ours (2-arg, unser
  feldweises Binaerformat). ConfigSerializer.* liegt ungenutzt (nur native-Test).
  Bestandsgeraete: null Migration (/new_prefs binaer weiter).
- MyMesh.cpp: unsere Logik (client_repeat statt isRepeatEn/setRepeatEn, memset+
  Sentinels, cad_enabled, 2-arg loadPrefs). Upstreams MCU-Temperatur-Telemetrie
  (onContactRequest + handleCmdFrame) BEHALTEN.

Adoptiert:
- interface_manager (MultiSerialInterface, multi-interface: USB-CLI + BLE-App
  gleichzeitig). main.cpp setup()/loop() rekonstruiert mit unseren Boot-Anpassungen
  (DIAG / earlyShutdownCheck / OTA-Skip / configureBatteryWake +
  applyShutdownPendingCheck NACH BLE = SoftDevice-up).
- esp32 SerialBLEInterface: FreeRTOS thread-safe recv-Queue (meshcore-dev#3007) + unsere
  Diagnostik/Overflow-Counter + FRAME_QUEUE_SIZE 16.
- USE_CC310_HW_CRYPTO (meshcore-dev#2824), listen-before-talk configSideDetectors (meshcore-dev#3036/meshcore-dev#2977).

Auto-Merge-Fixes (Upstream-Refactors trafen unsere Andock-Zeilen):
- AbstractUITask _serial -> _interfaceManager (ui-orig / ui-tiny).
- DisplayDriver enum Color -> UIColor-Klasse (meshcore-dev#3034): YELLOW -> warning_txt (ui-new).

CI: action.yml unsere -DL9SAU-Prefix-Strip + upstream dispatch-branch; build.sh
unser Build-Tracking (kein set -e) + upstream Matrix-get-*-firmwares-Commands.

FIRMWARE_VERSION -> v1.17.0-DL9SAU (dl9sau_version.py-Sync beim Release).

Builds gruen: t1000e_companion_radio_ble (nRF52), Heltec_v3_companion_radio_ble (esp32).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants