XIAO BLE Sense Firmware Update (UF2)

Mithun Das
3 min readOct 28, 2022

--

When you are dealing with microcontrollers, you often come across with the use-case of updating device software (aka firmware). I was working on a project using XIAO BLE Sense and I needed to distribute the firmware. My target users were not technical and were not familiar with Arduino IDE to upload the sketch. So I was looking for an easier way for them to update firmware.

Luckily, XIAO BLE ships with the Adafruit nRF52 Bootloader which supports flashing using UF2. Doing so allows easy flashing of new firmwares. I am going to walk you through how I created uf2 file and flashed the board.

Arduino IDE

I am assuming you have Arduino IDE installed and also installed the board to program XIAO on Arduino IDE. If not, please read this wiki to get started. I am using a very simple program to demonstrate. The program blinks GREEN led light every second.

#define USER_LED LEDGvoid setup() {pinMode(USER_LED, OUTPUT);}void loop() {digitalWrite(USER_LED, HIGH);delay(1000);digitalWrite(USER_LED, LOW);delay(1000);}

Now from the menu, go to Sketch -> Export Compiled Binary

This should create few files including a .bin and .hex

To view them, go to Sketch -> Show Sketch Folder

Generate UF2

Before you can start making your own uf2 files, you need to install few softwares. Assuming you have python 3 installed on your computer, install adafruit nrfutil package.

pip3 install --user adafruit-nrfutil

Then clone the repo

git clone https://github.com/adafruit/Adafruit_nRF52_Bootloader
cd Adafruit_nRF52_Bootloader
git submodule update --init
cd lib/uf2/utils

Now issue below command to make uf2 file. Make sure to change the filename and path of your .hex file. This will generate a .uf2 file with name flash.uf2

python uf2conv.py ~/Documents/Arduino/XIAO_DFU/build/Seeeduino.nrf52.xiaonRF52840Sense/XIAO_DFU.ino.hex -c -f 0xADA52840

PS: If you are on windows, read Brendan’s comment below if you face any issues. I did not have access to windows machine to test.

UF2 Flashing

To enter the bootloader, connect the USB port of the XIAO BLE to your computer, and double tap the reset button (labelled RST) on the device. A mass storage device named XIAO BLE should appear on the host. Drag and drop flash.u2 file to the storage drive. The XIAO BLE will automatically reset and launch the newly flashed application.

Happy coding!!! 👋

--

--

Mithun Das

Sr Principal Engineer | Designing & Building Softwares for 20 years