Commit graph

593 commits

Author SHA1 Message Date
Pawel Osypiuk 7bc93a62b8 drivers: bluetooth: rpmsg: implement .close()
Add .close() implementation for the HCI RPMsg driver.

When running on the nRF5340 application core, it will power-cycle the
network core.

Signed-off-by: Pawel Osypiuk <pawelosyp@gmail.com>
Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-09-29 13:53:13 +02:00
Jordan Yates c667b43697 bluetooth: hci: enable backends by default
Enable backends by default, instead of requiring some other module to
turn them on. This aligns with the behaviour of sensor drivers and
`BT_RPMSG`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-25 16:43:42 +02:00
Jordan Yates ca5931065c testsuite: boards: unit_testing: default HCI bus
Be explicit about the HCI backend that Bluetooth unit tests require.
Some unit tests depend on `BT_HAS_HCI_VS`, so also enable that.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-25 16:43:42 +02:00
Gerard Marull-Paretas 691facc20f include: always use <> for Zephyr includes
Double quotes "" should only be used for local headers.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-09-14 13:49:58 +02:00
Markus Fuchs ba57c1880c drivers: bluetooth: slz_hci: Set Number of Completed Packets threshold
Configure the Number of Completed Packets event threshold to 1, so the
SiLabs Bluetooth controller will always send the Number of Completed
Packets HCI event to the host, even for small numbers of transmitted
packets.

Fixes #62279

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-09-12 11:23:14 +02:00
Markus Fuchs c33492655f drivers: bluetooth: slz_hci: Adapt to library BLOBs version 4.2.4
Make HCI driver compatible to the updated versions of the
EFR32 Bluetooth library BLOBs consisting of:
* libbluetooth_controller
* libbgcommon
* librail

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-09-12 11:23:14 +02:00
Jordan Yates 72c94d982c bluetooth: hci: spi: warn about l2cap MTU values
`CONFIG_BT_L2CAP_TX_MTU` drives the maximum supported MTU on a Bluetooth
connection, but the SPI backend also imposes its own hidden limits.

Display a warning if a value is chosen that can result in failures to
send. This is done here instead of as a range on `BT_L2CAP_TX_MTU` as
ranges on that symbol are already defined in terms of software features,
which would conflict with this check.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-05 11:41:33 +02:00
Ali Hozhabri be5cf2ddb9 driver: bluetooth: hci: fix potential "block forever" issue
Interrupt is enabled before reset is released to make sure that the
first IRQ edge is captured, and rx thread can process it.

Remove delay in spi_open as it was redundant due to the "sem_initialised"
semaphore.

Signed-off-by: Ali Hozhabri <ali.hozhabri@st.com>
2023-09-01 13:22:08 +02:00
Ali Hozhabri 6d9f2a9143 drivers: bluetooth: hci: spi: Revert to edge sensitive interrupt. (#59459)
Solved also a mutex issue with SPI access.

Signed-off-by: Ali Hozhabri <ali.hozhabri@st.com>
2023-09-01 13:22:08 +02:00
Victor Chavez 80d4c76a1f Bluetooth: Userchan: Parse multiple hci packets
After conducting tests with a a virtual Bluetooth controller
over TCP it was noticed that some HCI packets may arrive on the
same buffer if sent over a short period of time.
This update ensures the hci packets are parsed correctly in the case
multiple packets are in the same recieving buffer according to
the Bluetooth Spec v5.4 Part E.

Signed-off-by: Victor Chavez <chavez-bermudez@fh-aachen.de>
2023-08-30 10:18:41 +02:00
Nick Ward 2d65acca3a drivers: gpio: use gpio_is_ready_dt helper function
Update `struct gpio_dt_spec` use with gpio_is_ready_dt()

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-08-28 08:48:35 -05:00
Victor Chavez 33c922a771 Bluetooth: Userchan: Add support for TCP Connection
Added support to connect to an HCI TCP Server. This
allows to do integration tests with other frameworks
that support a virtual hci interface.

Signed-off-by: Victor Chavez <chavez-bermudez@fh-aachen.de>
2023-08-22 15:50:56 +02:00
Daniel Leung e3ecca5784 bluetooth: fixes shadow variables
Massaging code to fix shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-17 13:00:09 +02:00
Carles Cufi 6f8a1669cc drivers: bluetooth: hci: spi: Check and propagate return values
Check and propagate return values from GPIO calls.

Fixes https://github.com/zephyrproject-rtos/zephyr/issues/59529.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-08-04 11:56:48 +03:00
Antoine Bout dbea999347 soc/arm/silabs: Kconfig: add SOC_GECKO_USE_RAIL kconfig option
Currently on zephyr, RAIL is used only for bluetooth. RAIL library is
needed to use efr32 radio regardless of the protocol used. We add
SOC_GECKO_USE_RAIL kconfig option to indicate if we use radio.
FPU is needed when using RAIL, we configure it if SOC_GECKO_USE_RAIL
is set.

Signed-off-by: Antoine Bout <antoine.bout@silabs.com>
2023-07-31 09:05:17 +00:00
Marek Matej 6b57b3b786 soc: xtensa,riscv: esp32xx: refactor folder structure
Refactor the ESP32 target SOCs together with
all related boards. Most braking changes includes:

- changing the CONFIG_SOC_ESP32* to refer to
  the actual soc line (esp32,esp32s2,esp32s3,esp32c3)
- replacing CONFIG_SOC with the CONFIG_SOC_SERIES
- creating CONFIG_SOC_FAMILY_ESP32 to embrace all
  the ESP32 across all used architectures
- introducing CONFIG_SOC_PART_NUMBER_* to
  provide a SOC model config
- introducing the 'common' folder to hide all
  commonly used configs and files.
- updating west.yml to reflect previous changes in hal

Signed-off-by: Marek Matej <marek.matej@espressif.com>
2023-07-25 18:12:33 +02:00
Markus Fuchs fbe6ac852f drivers: bluetooth: slz_hci: Fix incoming HCI packet handling
Currently, HCI packet handling does not consider the BT_RECV_CONTEXT
choice selection. It calls bt_recv() and bt_recv_prio() only depending
on the HCI packet type and event flags.
However, for selections other than BT_RECV_BLOCKING, the "HCI driver
shall not call bt_recv_prio()". Fix that by only calling bt_recv_prio()
when CONFIG_BT_RECV_BLOCKING is enabled.

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-07-25 14:41:13 +02:00
Jordan Yates b3f12b430f drivers: bluetooth: hci: spi: add small read delay
Add a small delay between reading the transport header and reading the
HCI data. Failing to do so on a nRF9160<->nRF52832 link was reliably
resulting in the nRF9160 trying to read data before the nRF52832 had
set up the SPI transaction, resulting in the host reading a buffer full
of 0x00 and having to run the entire read result again.

Transceiving a 10 byte packet takes at least 31uS, while 100 byte
packets are around 150uS (duration of `spi_transceive` call). Waiting
1 tick to eliminate the need for most retransmissions is a valid
tradeoff.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-07-05 14:15:18 +02:00
Armin Brauns 2fc212c2a0 bluetooth: hci: spi: initialize IRQ callback before registering it
GPIO callbacks need to be initialized before being registered with a GPIO
driver, otherwise the NULL `handler` hits an assert.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-06-22 10:48:07 +02:00
Jordan Yates 607efa8edd Bluetooth: hci: spi: don't block on IRQ line
Don't wait for the IRQ line to be de-asserted in `bt_spi_send`. As this
function can be called by the RX processing thread, the previous
behaviour could cause deadlocks under heavy load:
 * SPI RX thread starts blocking on `bt_buf_get_evt` due to load
 * BT controller generates another event, asserting the IRQ line
 * RX processing thread calls `bt_spi_send` in reponse to event
 * RX processing thread blocks forever on the removed condition

There is no need to attempt to rate-limit how often `bt_spi_send` is
called to allow the RX thread to run. If the bus is so congested that
there is no remaining capacity, prioritising RX over TX is not going to
improve the situation.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-06-17 07:37:59 -04:00
Filip Kokosinski abd1817366 drivers/bluetooth/hci: enable BT_SILABS_HCI on EFR32BG27
This commit enabled the Silicon Labs Bluetooth interface driver on the
EFR32BG27 SoC series in the Kconfig.

Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2023-05-26 05:54:40 -04:00
Filip Kokosinski 93b7e492bf drivers/bluetooth/hci/slz_hci: bump blobs to version 4.1
This commits adapts the driver to the newer version of the EFR32 BT
blobs:
* libbluetooth_controller
* libbgcommon
* librail

Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2023-05-26 05:54:40 -04:00
Roman Dobrodii defb159ab1 soc/arm/silabs: support BLE with PM in Series 2 SoCs
Using EM2 or deeper sleep states (where HF clocks are off) requires
special care if BLE radio is used, since BLE radio relies on that clock,
and its power/clock requirements need to be taken into account
On SiLabs, radio PM is implemented as part of RAIL blob, which relies
on sl_power_manager HAL service. I've implemented SoC PM
state changes using sl_power_manager instead of emlib, and added
call to RAIL PM initialization in Gecko HCI driver.

Signed-off-by: Roman Dobrodii <rdobrodii@antmicro.com>
2023-05-24 13:31:44 -04:00
Sreeram Tatapudi ea591e2899 drivers: bluetooth: Add Infineon Bluetooth driver
Add initial version of the Bluetooth driver for
the cy8cproto_063_ble board

Signed-off-by: Sreeram Tatapudi <sreeram.praveen@infineon.com>
2023-05-17 09:59:36 +03:00
Filip Kokosinski a4902b1c35 boards/arm/efr32xg24_dk2601b: add BLE support
This commit adds BLE support to the `efr32xg24_dk2601b` board. It also
modifies the SiLabs BT HCI driver to accomodate the EFR32xG24 SoC
series.

Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2023-05-15 13:09:34 +02:00
Aleksander Wasaznik bb1ede6a9b Bluetooth: Use bt_addr_eq
Refactor. Using `bt_addr_eq` instead of `bt_addr_cmp`.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-05-09 09:23:52 +02:00
Jordan Yates ca6c08f960 Bluetooth: hci: spi: use level triggered interrupts
Use level triggered interrupts instead of edge triggered interrupts to
make it impossible for the interrupt line to be active without the RX
thread attempting to read pending data.

This fixes a race condition for re-enabling the interrupt in edge
triggered mode, where `gpio_pin_interrupt_configure_dt` is not called
before the controller re-asserts the interrupt line.

As a result the controller can be reset before booting the RX thread.

Fixes #53980.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-05-02 12:36:09 +02:00
Gerard Marull-Paretas 3f2c2d4130 drivers: spi: make SPI dt-spec macros compatible with C++
As of today it is not possible to use SPI dt-spec macros in C++,
something known and documented. The main reason is because `cs` property
is initialized using a compound literal, something not supported in C++.
This PR takes another approach, that is to not make `cs` a pointer but a
struct member. This way, we can perform a regular initialization, at the
cost of using extra memory for unused delay/pin/flags if `cs` is not
used.

Fixes #56572

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-24 21:29:55 +02:00
Filip Kokosinski 0355e085c4 drivers/bluetooth/hci/slz_hci: remove unused const struct device
This commit removes the unused argument form the `slz_bt_init` function,
and makes it consistent with what `SYS_INIT` expects - `int (*)(void)`.

Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2023-04-21 12:55:56 +02:00
Filip Kokosinski 4a614de289 drivers/bluetooth/hci: add SiLabs BLE HCI driver
This commit adds the SiLabs Bluetooth HCI driver. It also enables this
BLE HCI driver on the efr32bg_sltb010a board.

Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2023-04-20 16:13:14 +02:00
Guillaume Gautier ceebbf8bcf drivers: bluetooth: hci: update macro name after stm32 hal update
Update macro name that changed in latest STM32 HAL update.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2023-04-18 18:55:26 +02:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Henrik Brix Andersen c41dd36de2 drivers: kconfig: unify menuconfig title strings
Unify the drivers/*/Kconfig menuconfig title strings to the format
"<class> [(acronym)] [bus] drivers".

Including both the full name of the driver class and an acronym makes
menuconfig more user friendly as some of the acronyms are less well-known
than others. It also improves Kconfig search, both via menuconfig and via
the generated Kconfig documentation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2023-03-28 15:06:06 +02:00
Nazar Palamar f91e35d447 driver: bluetooth: Added Infineon cyw43xxx BT driver
Added initial version of Infineon cyw43xxx BT (
H4 HCI extension drivers/bluetooth/hci/CMakeLists.txt)

Add initial version of binding file for Infineon CYW43xx BT
HCI extension driver.

Signed-off-by: Nazar Palamar <nazar.palamar@infineon.com>
2023-03-22 16:40:55 +01:00
Armin Brauns 821fddc2e1 drivers: bluetooth: hci_spi: fix condition causing infinite loop
With a size of 0, the inner loop will never terminate, so don't try to
enter it.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-03-08 08:58:33 +01:00
Jonathan Rico 894275c098 Bluetooth: HCI: Make driver stack sizes configurable
This is necessary to prevent stack overflows when building with
non-standard configurations (e.g. CONFIG_DEBUG).

Adding them as hidden kconfig options to avoid the stuck kconfig syndrome.
Users are free to redefine them in their app to force a value.

The userchan.c driver is only built for posix, and the help text for
ARCH_POSIX_RECOMMENDED_STACK_SIZE states that the real stack comes from
somewhere else (the pthread stack), hence why it doesn't use the new
kconfig options.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-02-22 11:58:15 +01:00
Erwan Gouriou c5ab922f50 drivers: hci: stm32wb: Use clock_control driver for clock configuration
Instead of relying on STM32Cube API, use clock_control framework
for clock configuration inside this driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-08 19:48:27 +01:00
Erwan Gouriou f3e788e84e drivers: hci: stm32wb: Refactor c2_reset()
In preparation of the introduction of dt configured clock in this
driver, refactor clock related clocks.
- remove start_ble_rf()
- Move  IPCC clock activation in c2_reset()

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-08 19:48:27 +01:00
Erwan Gouriou 079a43d9f8 drivers: hci: stm32wb: LSE clock configuration not required
As long as LSE clock is set in device tree, configuration will be
done in clock control driver, no need to do it here.
Besides, remove back up domain related code as this is also already
handled in clock_control driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-08 19:48:27 +01:00
Erwan Gouriou 52b9724a88 drivers: hci: stm32wb: LSI is not an allowed clock for BLE RF.
Remove code related to LSI used as clock source for RF wakeup,
it isn't a valid clock source.
Also don't disable LSI when LSE is selected.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-08 19:48:27 +01:00
Erwan Gouriou f1dfeff282 drivers: hci: stm32wb: Don't mess with RTC Clock source
No reason to update RTC clock source in this driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-08 19:48:27 +01:00
Bartosz Bilas e077fb73ec drivers: tests: replace usage of spi_is_ready with spi_is_ready_dt
`spi_is_ready` function is being deprecated in favor of
`spi_is_ready_dt` so let's replace the old usage in the tree.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-12-07 09:40:23 -06:00
Francois Ramu 2ed292e1be drivers: stm32: do not enable the HSI48 locally
The HSI48 is enabled by clock control driver.
It is no more done by each driver that requires this clock
However when using rng or sdmmc or bluetooth/ipm or usb,
the HSI48 clock must be present in the DTS.
Add a warning for this particular check but keep the deprecated
HSI48 clock enable : keeping for legacy but to remove later.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-12-07 10:03:11 +00:00
Théo Battrel e458f5aae6 Bluetooth: Use Zephyr standard log system instead of bluetooth/common/log
The `bluetooth/common/log.h` and `bluetooth/common/log.c` files have been
removed. Files that were using them have been updated to use
`zephyr/logging/log.h` instead.

Those replacement have been done consequently:
- `/BT_DBG/LOG_DBG/`
- `/BT_ERR/LOG_ERR/`
- `/BT_WARN/LOG_WRN/`
- `/BT_INFO/LOG_INF/`
- `/BT_HEXDUMP_DBG/LOG_HEXDUMP_DBG/`
- `/BT_DBG_OBJ_ID/LOG_DBG_OBJ_ID/`

Also, some files were relying on the `common/log.h` include to include
`zephyr/bluetooth/hci.h`, in those cases the include of `hci.h` has
been added.

For files that were including `common/log.h` but not using any logs,
the include has been removed and not replaced.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-25 17:08:36 +01:00
Théo Battrel f16738b62b Bluetooth: Move crypto toolbox functions from smp.c to their own files
Move functions defined in the Cryptographic toolbox of the Bluetooth
specification inside their own files in the following folder:
`zephyr/subsys/bluetooth/bt_crypto`. The functions were previously
implemented in `zephyr/subsys/bluetooth/host/smp.c`.

The cryptographic toolbox functions can now be accessed from outside of the
host.

In addition to that, tests for each cryptographic toolbox functions have
been added.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-10 09:28:28 +01:00
Théo Battrel c9d68a5a4f Bluetooth: Move out string related function of common/log.h
Functions related to string manipulation that were defined in
`common/log.h` has been moved to the `common/bt_str.h` file and their
implementation in `common/bt_str.c`.

Files that were using those functions has been updated consequently.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-02 13:28:57 +01:00
Martin Tverdal 0cf6cac77e Bluetooth: extended adv reports with legacy content discardable
To avoid legacy extended adv repots blocking important
events or work, mark them as discaradble.

Signed-off-by: Martin Tverdal <martin.tverdal@nordicsemi.no>
2022-10-28 07:55:44 +00:00
Théo Battrel fdd0a26348 Bluetooth: Remove BT_HEXDUMP_DBG
Replace unnecessary `BT_HEXDUMP_DBG` with `LOG_HEXDUMP_DBG`.

`BT_HEXDUMP_DBG` did an extra cast to `const uint8_t *` on its first
argument. This was probably the reason it was introduced. But the
current definition of `LOG_HEXDUMP_DBG` does this cast for us.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-10-25 10:48:17 +02:00
Gerard Marull-Paretas 178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Jordan Yates 23fbdf35b1 bluetooth: hci: spi: propagate vendor specific events
Propagate vendor specific events that are not handled by the SPI driver
up the host stack, so that `bt_hci_register_vnd_evt_cb` can work
correctly.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-10-12 18:47:48 +09:00