|
| 1 | +======================================================= |
| 2 | +``zblue`` Zephyr Bluetooth host in userspace |
| 3 | +======================================================= |
| 4 | + |
| 5 | +This application builds the Bluetooth host of the `Zephyr project |
| 6 | +<https://github.com/zephyrproject-rtos/zephyr>`_ as a userspace library. The |
| 7 | +Zephyr source is downloaded from a Zephyr release tag and is used without |
| 8 | +modification; only a small porting layer in ``apps/wireless/bluetooth/zblue`` |
| 9 | +is NuttX code. |
| 10 | + |
| 11 | +It is an optional stack. The NuttX Bluetooth stack |
| 12 | +(``wireless/bluetooth``, ``net/bluetooth``) and NimBLE stay available; only |
| 13 | +one host can be enabled at a time. |
| 14 | + |
| 15 | +Applications use the Zephyr Bluetooth API (``<zephyr/bluetooth/...>``) as |
| 16 | +documented by Zephyr. |
| 17 | + |
| 18 | +Only the simulator is supported for now. On other targets the initialized |
| 19 | +iterable RAM sections of the host (``net_buf`` pools) need support in the |
| 20 | +board linker scripts, which is not there yet. |
| 21 | + |
| 22 | +Configuration |
| 23 | +------------- |
| 24 | + |
| 25 | +``CONFIG_ZBLUE`` |
| 26 | + Enables the stack. It needs ``CONFIG_UART_BTH4``: the host talks to the |
| 27 | + controller through ``/dev/ttyHCIx``, so any driver registered with |
| 28 | + ``bt_driver_register()`` can be used. |
| 29 | + |
| 30 | +``CONFIG_ZBLUE_REF`` |
| 31 | + Zephyr release tag to download, for example ``v4.5.0``. |
| 32 | + |
| 33 | +``CONFIG_ZBLUE_CONF`` |
| 34 | + Zephyr configuration fragment with the ``CONFIG_BT_*`` options, relative |
| 35 | + to the application directory (default ``zblue.conf``). The options are |
| 36 | + the original Zephyr ones. They are resolved with the Zephyr Kconfig |
| 37 | + after download and do not appear in the NuttX menuconfig. |
| 38 | + |
| 39 | +``CONFIG_ZBLUE_HCI_DEVICE`` |
| 40 | + HCI device, default ``/dev/ttyHCI0``. |
| 41 | + |
| 42 | +``CONFIG_ZBLUE_THREAD_PRIORITY`` |
| 43 | + Zephyr cooperative priorities are mapped above this NuttX priority, |
| 44 | + preemptive priorities below it. |
| 45 | + |
| 46 | +Cryptography uses the PSA API of Mbed TLS (``apps/crypto/mbedtls``); the |
| 47 | +options the host needs are selected automatically and |
| 48 | +``CONFIG_MBEDTLS_MINIMAL`` is enabled by default. Mbed TLS needs an entropy |
| 49 | +source, e.g. ``CONFIG_DEV_URANDOM`` on the simulator or the hardware random |
| 50 | +number generator of the board. |
| 51 | + |
| 52 | +Download and build requirements: ``curl``, ``tar`` and ``python3``. |
| 53 | + |
| 54 | +Updating the Zephyr release |
| 55 | +--------------------------- |
| 56 | + |
| 57 | +Change ``CONFIG_ZBLUE_REF`` and remove the ``zephyr`` directory and the |
| 58 | +downloaded archive (``make distclean``). Fixes to the Zephyr host itself are |
| 59 | +made in Zephyr, not here. |
| 60 | + |
| 61 | +Porting layer |
| 62 | +------------- |
| 63 | + |
| 64 | +* Zephyr kernel services used by the host (threads, semaphores, mutexes, |
| 65 | + queues, memory slabs, work queues, timeouts) are implemented on POSIX |
| 66 | + threads, without NuttX internal interfaces. |
| 67 | +* Zephyr cooperative threads are serialized with one lock that is |
| 68 | + released only while a thread blocks; ``k_sched_lock()`` takes the same |
| 69 | + lock. |
| 70 | +* Iterable sections (``BT_CONN_CB_DEFINE()``, ``BT_GATT_SERVICE_DEFINE()``, |
| 71 | + ...) are collected by the linker without changes to the board linker |
| 72 | + script. Entries of a type are in link order. |
| 73 | +* ``SYS_INIT()`` functions run before ``bt_enable()`` starts the host. |
| 74 | + |
| 75 | +Example |
| 76 | +------- |
| 77 | + |
| 78 | +``CONFIG_ZBLUE_PERIPHERAL_EXAMPLE`` builds ``zblue_peripheral``: it |
| 79 | +advertises as ``CONFIG_BT_DEVICE_NAME`` and accepts connections, with the |
| 80 | +GAP and GATT services. See the ``sim:zblue`` configuration of the simulator. |
0 commit comments