# hci-dongle
This is the source code used for the nRF52840 used in my [bachelor
thesis](https://sr.ht/~witcher/bachelor-thesis).
It is taken *verbatim* from
https://github.com/zephyrproject-rtos/zephyr/tree/f393e2205c2c71d05dcefeffddc4bc429911e12e/samples/bluetooth/hci_usb.
The only changes made here are to the `prj.conf` to allow:
* a DLE of 251 bytes
* 2M PHY mode
## Compiling
Install the [Zephyr
toolchain](https://docs.zephyrproject.org/latest/develop/getting_started/index.html).
After compiling, the output files will be in `$(OUTDIR)/zephyr/` in various
formats.
### Using the Makefile
To compile the image using the Makefile use
```sh
make
```
Flashing is done with
```sh
make flash FLASH_PORT=/path/to/device
```
where `/path/to/device` is the path the device that should be flashed can be
accessed from, e.g. `/dev/ttyACM2`.
The variable `FLASH_PORT` can also be set in `config.mk`. If set it doesn't need
to be given as a parameter anymore.
### Using CMake/Ninja
Simply invoke the following commands:
```sh
cmake -Bbuild -GNinja -DBOARD=nrf52840dongle_nrf52840 .
ninja -Cbuild
```
### Using [west](https://docs.zephyrproject.org/latest/develop/west/index.html)
```sh
west build \
-p always \
-b nrf52840dongle_nrf52840 \
.
```
## Flashing
To flash the image to the nRF52840 Dongle (the dongle used in my bachelor
thesis), make sure you have
[`nrfutil`](https://github.com/NordicSemiconductor/pc-nrfutil) installed.
First, generate the required `zip` file from the compiled `hex` one:
```sh
nrfutil pkg generate \
--hw-version 52 \
--sd-req=0x00 \
--application build/zephyr/zephyr.hex \
--application-version 1 \
hci_usb.zip
```
Then, flash that to the board (assumed to be connected to `/dev/ttyACM0`, please
check before flashing):
```sh
nrfutil dfu usb-serial \
--package hci_usb.zip \
-p /dev/ttyACM0
```
## Resources
Send patches and questions to
[~witcher/public-inbox@lists.sr.ht](https://lists.sr.ht/~witcher/public-inbox).
Instructions for preparing a patch are available at
[git-send-email.io](https://git-send-email.io/).