> For the complete documentation index, see [llms.txt](https://dev.solid-run.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.solid-run.com/nxp/imx8/sbc-platform/imx8m-other-articles/building-newt-nimble-blehci-firmware-for-the-imx8mq-nina-b1-module.md).

# Building Newt Nimble BLEHCI firmware for the iMX8MQ NINA-B1 Module

### Overview

This is a mynewt project skeleton for quickly and easily building the blehci firmware that can be flashed to the SolidRun iMX8MQ SOM's NINA-B1 chip. This firmware allows the NINA-B1 to act like a normal HCI device and is compatible with newer Bluez stacks.

### Building

Apache blehci contains an example Apache Mynewt Nimble application called blehci. When loaded on compatible hardware this application allows the NINA-B1 to be used under Linux as a normal HCI device, using the traditional Bluez stack.

1. Download and install the requirements for SolidRun's Newt BSP.

You will need to download and install:

* the Apache Newt tool, as documented in the [mynewt documentation](https://mynewt.apache.org/latest/get_started/index.html)
* an embedded toolchain, e.g. `apt install gcc-arm-embedded`
* this fork of [openOCD for i.MX SoCs](https://github.com/SolidRun/openocd/blob/master/doc/BUILD-IMX.md).

As a shortcut and to avoid installing all development files to the target systems, a [fork of the mynewt docker image](https://github.com/Josua-SR/newt-docker) built for arm64 is available at <http://quay.io/josua-sr/newt:latest> . For the steps below, installing an alias for the *newt* command to docker is sufficient:

```
sudo apt install docker.io
sudo usermod -a -G docker <username>
# log out and back in
alias newt='docker run -e NEWT_HOST=$(uname) $ti --rm --device=/dev/bus/usb --privileged -v $(pwd):/workspace -w /workspace quay.io/josua-sr/newt:latest /newt'
```

1. Download the SolidRun BSP, Apache Mynewt Core package, and Nimble (executed from the mynewt-sr-blehci directory).

```
newt upgrade
```

1. Build the Newt bootloader for the NINA-B1 using the "nina-b1\_boot" target (executed from the mynewt-sr-blehci directory).

```
newt build nina-b1_boot
```

1. Build the blehci application for the NINA-B1 using the "blehci" target (executed from the mynewt-sr-blehci directory).

```
newt build blehci
newt create-image blehci 0.0.1
```

1. load the bootloader and application to the NINA-B1. *this is stored in the onboard flash and only needs to be done just once* (executed from the mynewt-sr-blehci directory).

```
newt load nina-b1_boot
newt load blehci
```

### Initializing under Linux

The device should now be ready to be initialized under Linux.

```
sudo btattach -B /dev/ttymxc3 -S 1000000 -N
# Note: btattach is available with bluez on debian
```

The hci interface should now be available.

```
hciconfig
hci0:   Type: Primary  Bus: UART
    BD Address: BB:EC:E6:0D:DC:04  ACL MTU: 255:12  SCO MTU: 0:0
    UP RUNNING 
    RX bytes:231 acl:0 sco:0 events:16 errors:0
    TX bytes:112 acl:0 sco:0 commands:16 errors:0
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.solid-run.com/nxp/imx8/sbc-platform/imx8m-other-articles/building-newt-nimble-blehci-firmware-for-the-imx8mq-nina-b1-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
