Browse Source

nRF52 BLE: wait for LFXO crystal before enabling SoftDevice

The Adafruit framework starts the LFXO in init() but never waits for
EVENTS_LFCLKSTARTED. On first boot the filesystem format (~600ms of page
erases) gives the crystal time to stabilize. On subsequent boots only
quick mounts happen, so sd_softdevice_enable() inside Bluefruit.begin()
can be called while the crystal is still starting, which hangs
indefinitely.

Poll EVENTS_LFCLKSTARTED before Bluefruit.begin() so the wait is exact
rather than a blind delay.

fixes: #1780
pull/1939/head
Wessel Nieboer 3 months ago
parent
commit
fc9e0b3c7b
No known key found for this signature in database GPG Key ID: 929C8E45E33B5FD2
  1. 9
      src/helpers/nrf52/SerialBLEInterface.cpp

9
src/helpers/nrf52/SerialBLEInterface.cpp

@ -129,6 +129,15 @@ void SerialBLEInterface::begin(const char* prefix, char* name, uint32_t pin_code
char charpin[20];
snprintf(charpin, sizeof(charpin), "%lu", (unsigned long)pin_code);
// Ensure LFXO crystal is fully started before enabling SoftDevice.
// The framework starts LFXO in init() but doesn't wait for it.
// On fast boots (filesystem already formatted), Bluefruit.begin() can
// be called before the crystal is stable, hanging sd_softdevice_enable().
// See: https://github.com/meshcore-dev/MeshCore/issues/1780
while (!NRF_CLOCK->EVENTS_LFCLKSTARTED) {
delay(1);
}
// If we want to control BLE LED ourselves, uncomment this:
// Bluefruit.autoConnLed(false);
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);

Loading…
Cancel
Save