Skip to content

Instantly share code, notes, and snippets.

@intx82
Last active June 23, 2024 16:14
Show Gist options
  • Save intx82/ee35c7724cb8d4328ca0588c48dfbebd to your computer and use it in GitHub Desktop.
Save intx82/ee35c7724cb8d4328ca0588c48dfbebd to your computer and use it in GitHub Desktop.
How to create USB bluetooth dongle (BLE-only) from NRF52840 USB dongle

How to create USB bluetooth dongle (BLE-only) from NRF52840 USB dongle

Downloading and installing ZEPHYR-OS

This paragraph mostly follow the https://docs.zephyrproject.org/latest/develop/getting_started/index.html

You may need up to 15 GB of space

First of all download 'west'

python3 -m pip install west

Then create some directory and initialize west-zephyr project

mkdir -p ble-zephyr-hci
cd ble-zephyr-hci
west init
west update

After download the zephyr-sdk package

wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.8/zephyr-sdk-0.16.8_linux-x86_64.tar.xz
tar xvf zephyr-sdk-0.16.8_linux-x86_64.tar.xz
cd zephyr-sdk-0.16.8
./setup.sh

After such steps you should have something like:

drwxr-xr-x  8 intl intl     4096 июн 23 17:48 .  
drwxr-xr-x 13 intl intl     4096 июн 23 04:20 ..  
drwxr-xr-x  3 intl intl     4096 июн 23 06:09 bootloader  
drwxr-xr-x  9 intl intl     4096 июн 23 06:14 modules  
drwxr-xr-x  4 intl intl     4096 июн 23 06:09 tools  
drwxr-xr-x  2 intl intl     4096 июн 23 04:34 .west  
drwxr-xr-x 24 intl intl     4096 июн 23 07:36 zephyr  
drwxr-xr-x 27 intl intl     4096 июн 23 15:29 zephyr-sdk-0.16.8

Building example HCI-USB firmware

To build firmware run next commands:

cd zephyr
west build -p always -b nrf52840_mdk_usb_dongle samples/bluetooth/hci_usb

If everything goes successfully, in zephyr/build/zephyr should be located zephyr.hex - which is our firmware itself

Preparing NRFUTIL

Next step - download nrfutil tool, which is located: https://www.nordicsemi.com/Products/Development-tools/nRF-Util After downloading need to assign appropriate permissions to run this tool, and (sic!) install via it other tools

chmod 0755 ./nrfutil
./nrfutil install device
./nrfutil install completion
./nrfutil install nrf5sdk-tools

Then on the dongle need to push 'boot' button (there is only one button) - and put it to the USB, dongle should blink red (that's means DFU mode)

If run:

./nrfutil device device-info  
       serial_number: <SERIAL>
       deviceFamily: NRF52  
       deviceVersion: NRF52840_AAD0  
       ramSize: 262144  
       romPageSize: 4096  
       romSize: 1048576

Device should be visible in output

Flashing firmware to the dongle

To flash already built firmware, first need to convert it to DFU zip file. To do it run:

./nrfutil pkg generate --hw-version 52 --sd-req=0x00 --application zephyr/build/zephyr/zephyr.hex --application-version 1 ble-hci.zip

After this ZIP file could be easily written to the device with:

./nrfutil dfu usb-serial -pkg ble-hci.zip -p /dev/ttyACM0

Done!

Now you may use any BLE (not a classic bluetooth) tools

sudo hcitool -i hci1 lescan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment