Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver: bluetooth: HCI: add Ambiq Apollo3 BLE support #72609

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

aaronyegx
Copy link
Contributor

This PR implements the SPI based HCI driver for Ambiq Apollo3 Blue/Apollo3 Plus Blue. Apollo3 Blue/Apollo3 Plus Blue BLE integrates one core for running BLE controller only. The MCU can work as BLE host and talk to the integrated BLE controller via SPI based BLEIF module. The SPI BLEIF pins are not exposed from MCU and the new implemented SPI BLEIF driver is added for HCI.

Test passed on the following samples:
-samples/bluetooth/peripheral
-samples/bluetooth/peripheral_hr
-samples/bluetooth/peripheral_ht
-samples/bluetooth/peripheral_esp
-samples/bluetooth/peripheral_dis
-samples/bluetooth/peripheral_gatt_write
-samples/bluetooth/peripheral_sc_only
-samples/bluetooth/central
-samples/bluetooth/central_hr
-samples/bluetooth/central_ht
-samples/bluetooth/central_gatt_write
-samples/bluetooth/broadcaster
-samples/bluetooth/broadcaster_multiple
-samples/bluetooth/beacon
-samples/bluetooth/observer
-samples/bluetooth/scan_adv
-samples/bluetooth/mtu_update
-samples/bluetooth/eddystone
-samples/bluetooth/ibeacon
-samples/bluetooth/hci_uart
-tests/bluetooth/init

@zephyrbot
Copy link
Collaborator

zephyrbot commented May 11, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_ambiq zephyrproject-rtos/hal_ambiq@94dd874 zephyrproject-rtos/hal_ambiq@fcbbd99 (main) zephyrproject-rtos/hal_ambiq@94dd874c..fcbbd99e

Note: This message is automatically posted and updated by the Manifest GitHub Action.

Copy link
Contributor

@RichardSWheatley RichardSWheatley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as the Ambiq stuff goes, this looks good.
I will let the other BLE people discuss that section.

boards/ambiq/apollo3p_evb/Kconfig.defconfig Outdated Show resolved Hide resolved
@decsny decsny removed their request for review May 13, 2024 14:55
@aaronyegx
Copy link
Contributor Author

@jhedberg it seems you have another PR for HCI driver API change #72323 and HCI Ambiq driver will also be modified (not update yet). So should this PR for Apollo3 support go first or after that PR getting done?

@jhedberg
Copy link
Member

@jhedberg it seems you have another PR for HCI driver API change #72323 and HCI Ambiq driver will also be modified (not update yet). So should this PR for Apollo3 support go first or after that PR getting done?

It's likely that the HCI API rewrite will only get merged after the next release, so in that sense any new drivers (using the old API) should be able to be merged before that. For now, I also have #if DT_HAS_CHOSEN(zephyr_bt_hci) blocks in my PR in order to support drivers using the old API, but those might go away before my PR is merged.

Some Ambiq Apollox Blue SOC (e.g. Apollo3 Blue) uses internal designed
BLEIF module which is different from the general IOM module for SPI
transceiver. The called HAL API will also be independent. This driver is
implemented for the BLEIF module usage scenarios.

Signed-off-by: Aaron Ye <aye@ambiq.com>
This commits add the BLEIF instance which is compatible with
"ambiq,spi-bleif" on Ambiq apollo3p_evb and apollo3_evb.
Also creates the default pinctrl for the defined instance.

Signed-off-by: Aaron Ye <aye@ambiq.com>
This commit add the SPI-based HCI support for the Ambiq Apollo3 Blue
SOC (e.g. Apollo3 Blue Plus, Apollo3 Blue) support.
Also correct the dependency of necessary peripheral.

Signed-off-by: Aaron Ye <aye@ambiq.com>
The BLE controller of some Ambiq Apollox Blue SOC may have issue to
report the expected supported features bitmask successfully, thought the
features are actually supportive. Need to correct them before going to
the host stack.

Signed-off-by: Aaron Ye <aye@ambiq.com>
…ario

The controller may be unavailable to receive packets because it is busy
on processing something or have packets to send to host. Need to free the
SPI bus and wait some moment to try again.

Signed-off-by: Aaron Ye <aye@ambiq.com>
This commit defines the bt-hci subnode under the bleif node on
Ambiq Apollo3 Blue and Apollo3 Blue Plus SOC.
Also add the default configurations for Bluetooth feature on Ambiq
apollo3_evb and apollo3p_evb.

Signed-off-by: Aaron Ye <aye@ambiq.com>
@aaronyegx
Copy link
Contributor Author

@jhedberg Would you mind taking a look at this PR when you are available? Thank you.

@jhedberg
Copy link
Member

@aaronyegx approved from my side, but I'll likely need some guidance on how to best convert this to the new HCI API (especially the DTS parts of it).

@aaronyegx
Copy link
Contributor Author

aaronyegx commented May 22, 2024

@aaronyegx approved from my side, but I'll likely need some guidance on how to best convert this to the new HCI API (especially the DTS parts of it).

It is likely we need to have a new "zephyr,bt-hci-spi" binding. And the bt-hci dts node may need to adapt for Apollo4 Blue from:

bt-hci@0 {
	compatible = "ambiq,bt-hci-spi";
	reg = <0>;
	irq-gpios = <&gpio32_63 21 GPIO_ACTIVE_HIGH>;
	reset-gpios = <&gpio32_63 23 GPIO_ACTIVE_LOW>;
	clkreq-gpios = <&gpio32_63 20 GPIO_ACTIVE_HIGH>;
};

to:

bt_hci_spi: bt_hci_spi {
	compatible = "zephyr,bt-hci-spi";
	status = "okay";

	bt-hci@0 {
		compatible = "ambiq,bt-hci-spi";
		reg = <0>;
		irq-gpios = <&gpio32_63 21 GPIO_ACTIVE_HIGH>;
		reset-gpios = <&gpio32_63 23 GPIO_ACTIVE_LOW>;
		clkreq-gpios = <&gpio32_63 20 GPIO_ACTIVE_HIGH>;
	};
};
chosen {
	zephyr,bt-hci = &bt_hci_spi;
};

In the driver, I think we also need a hci_spi_config struct like:

struct hci_spi_config {
	struct bt_hci_info info;
	const struct device *hci_spi;
	k_thread_stack_t *rx_thread_stack;
	size_t rx_thread_stack_size;
	struct k_thread *rx_thread;
};

but not sure if we must include all global variables to one new hci_spi_data structure.
For the API adaption I think you already have a good implementation for drivers/bluetooth/hci/h4.c in #72323. The hci_ambiq.c should be similar.

Anyway, I will test the changes once you finish the upgrading on the supported Apollo3/4 EVB.

@aaronyegx
Copy link
Contributor Author

@RichardSWheatley Please help take another look, thanks.

@jori-nordic jori-nordic removed their request for review May 24, 2024 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants