XIAO nRF52840, Efficiently Uploads Peripheral On-Board Flash ROM Data to Central

The XIAO nRF52840 has 2MB of flash ROM on board.
In my project, the battery-powered peripheral XIAO stores data collected over a long period of time in the on-board flash ROM. The data will then be uploaded to the central XIAO’s SD card on a regular basis.
I experimented to see if I could upload the data in a short time with as little load on the battery as possible.
I used Bluefruit for the BLE library, but with the default settings, it took over 10 minutes to upload 2MB of data, which was not practical.
So, I considered increasing throughput and reducing battery energy using the article and example sketch in the link below.

Maximizing BLE Throughput on iOS and Android - Punch Through

The points are

  1. Run PHY at 2 MHz
  2. Minimize interval: 7.5mS
  3. Maximize payload: 244 bytes (MTU=243, Data Length=251)
  4. Use Notify mode
  5. Use high speed SD card and set SPI clock to maximum: 32MHz
  6. Implement enough FIFO to allow for the maximum write time to SD: 244*200 bytes
  7. Increase the number of transmissions as much as possible without going below the average write time to SD: 2.8mS
  8. Upload in close proximity and reduce transmit power: 0 dBm

nRF52_XIAO_onBoardFlash_upload.zip (88.4 KB)

The default setting was to send 20 bytes of data three times during 20 mS. I shortened the interval and increased the payload so that 244 bytes of data could be transmitted 2 to 3 times during 7.5 mS. I also set the transmit power to 0 dBm because the distance between the central and peripheral was very close during upload.
As a result, the transmission time, which used to take more than 10 minutes, was reduced to about 30 seconds, and the energy was also reduced to 1/10.

There are several issues to be addressed in the future. I would be glad if someone could give me some tips.

  1. there is a phenomenon that if something is not written to the SD card before connecting BLE, it cannot be written after connection.
  2. if I write the connection parameters only in the peripheral, it works as I expect. Why don’t I have to describe them in the central?
  3. I’m able to achieve a throughput of about 50 kB/sec, is there any way to increase it? Can I use the ‘Connection Event Lengh Extension’?

The XIAO Expansion Board was used as central because it is equipped with an OLED display and an SD card drive.
The following libraries were used
BSP : Seeed nRF52 Borads 1.1.1, Board : Seeed nRF52 Borads / Seeed XIAO nRF52840 Sense
Adafruit SPIFlash by Adafruit 4.1.1
Adafruit GFX Library by Adafruit 1.11.4
AdafruitSSD1306 by Adafruit 2.5.7
RingBuf by D.Aaron Wisner 2.0.0

I hope this will be helpful to those interested.

I’m NOT worthy… :raised_back_of_hand: :innocent: :raised_hand:
from ninja to Master…WOW.
I just poured another cup of coffee to ingest this with. I have seen that SD issue while BLE thing b4.
Are you using a Filter Accept List feature anywhere or "supervision Timeout ?
Really good work here msfujino :ok_hand:
EveryOne should give that The Ultimate Guide to Managing Your BLE Connection a read over.
GL :slight_smile: PJ

are you ? " 1. Choose a connection interval that allows for the maximum # of packets per connection interval." ?

Thanks for the info. I will read carefully “The Ultimate Guide to Managing Your BLE Connection” you mentioned.

I wanted to pack the maximum number of packets per interval, but couldn’t find a way other than trial and error.
I will look into the SD issue with the keywords “a Filter Accept List feature” and “supervision Timeout”.

I managed to get 30MB/s, mainly because iPhone has lower MTU, but it should work for my use case. The issue I have is that bluefruit.h is not found on mbed version of arduino library, which is required for recording PDM mic. Find more info here: PDM Usage for XIAO nRF52840 Sense | Seeed Studio Wiki

Since this is a software issue, I guess it can be solved? Would you have any tips? Simply uploading https://github.com/adafruit/Adafruit_nRF52_Arduino/tree/master/libraries/Bluefruit52Lib this to libraries directory did not work.

If you use “bluefruit.h”, select “Seeed nRF52 Boards 1.1.8” for BoardSercivePackage and “Seeed nRF52 Boards / Seeed XIAO nRF52840 Sense” for Board Select." Example/nRF52840 PDM - Adafruit Fork/PDMSerialPlotter" should work.