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
drivers: bluetooth: Add Ambiq HCI driver for Apollo4 Blue Plus #66227
drivers: bluetooth: Add Ambiq HCI driver for Apollo4 Blue Plus #66227
Conversation
The following west manifest projects have been modified in this Pull Request:
Note: This message is automatically posted and updated by the Manifest GitHub Action. |
8872afa
to
f83c9a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the submission! A few initial comments inline.
drivers/bluetooth/hci/hci_ambiq.c
Outdated
static K_SEM_DEFINE(sem_irq, 0, 1); | ||
static K_SEM_DEFINE(sem_spi_available, 1, 1); | ||
|
||
#if defined(CONFIG_SOC_APOLLO4P_BLUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like this driver does anything useful for any other SoC than SOC_APOLLO4P_BLUE
so these conditions seem rather useless. I'd suggest to just remove them. If at any point you need to support multiple platforms or SoCs you can then start introducing feature-based conditions, but right now it seems premature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jhedberg , thanks for your comments. Yes, we are integrating Apollo3 Blue Plus which uses SPI for the HCI as well, so I just try to reserve the condition then I can add Apollo3 Blue Plus support soon. I'm happy to remove these soc conditions at this moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jhedberg , thanks for your comments. Yes, we are integrating Apollo3 Blue Plus which uses SPI for the HCI as well, so I just try to reserve the condition then I can add Apollo3 Blue Plus support soon. I'm happy to remove these soc conditions at this moment.
The code that remains if APOLLO4P is not set doesn't seem to result any kind of functional driver. The sections behind APOLLO4P are so large, that if you will have equally large sections for Apollo3 then it sounds like you might want to make these two separate drivers (potentially refactoring shared parts into a common c-file).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jhedberg , I removed the #if defined(CONFIG_SOC_APOLLO4P_BLUE)
to avoid confusing at this moment. And will add the adaptable condition when I add Apollo3 Blue support further.
I refactored the HCI driver to two files: hci_ambiq.c to include the shared parts (spi, bt related codes) and apollox_blue.c to include the Ambiq Apollox specific codes. When it's time to add Apollo3 support, it is most likely that I only need to add something in apollox_blue.c file. Could you help check if it is acceptable?
Btw, now that we're starting to have multiple SPI HCI drivers, it makes the existence of @HoZHel @msmttchr @arbrauns I'd appreciate your thoughts on this. |
@jhedberg, I fully agree with you:
I am more and more convinced that splitting the files is eventually the best approach.
Finally, whether there is a common part, it is a bit hard to evaluate (at least for me). |
a9a4fe1
to
607157a
Compare
drivers/bluetooth/hci/hci_ambiq.c
Outdated
extern int bt_apollo_dev_init(void); | ||
extern int bt_apollo_spi_send(uint8_t *data, uint16_t len, bt_spi_transceive_fun transceive); | ||
extern int bt_apollo_spi_rcv(uint8_t *data, uint16_t *len, bt_spi_transceive_fun transceive); | ||
extern int bt_apollo_controller_init(spi_transmit_fun transmit); | ||
extern int bt_apollo_vnd_setup(void); | ||
extern bool bt_apollo_vnd_rcv_ongoing(uint8_t *data, uint16_t len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be cleaner to have a proper header file for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a header file in hal_ambiq to declare these functions to make the HCI driver cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a header file in hal_ambiq to declare these functions to make the HCI driver cleaner.
Aren't all of these APIs implemented by apollox_blue.c
? The right place for the header file would therefore be here in the same directory, not in the HAL tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't all of these APIs implemented by
apollox_blue.c
? The right place for the header file would therefore be here in the same directory, not in the HAL tree.
I put the header file apollox_blue.h
in the same directory with apollox_blue.c
, thank you.
90212d9
to
11a8770
Compare
This commits create the dts binding for Ambiq BT HCI instance. And create the SPI based common HCI driver for Ambiq Apollox Blue SoC and the extended soc driver for HCI. Signed-off-by: Aaron Ye <aye@ambiq.com>
The BT HCI uses internal IOM4 (SPI4) for communication bus. Set the default configuration for BT based on the controller supported capability and HCI driver dependency. Signed-off-by: Aaron Ye <aye@ambiq.com>
11a8770
to
9875be9
Compare
Imported the original Cooper (Apollo4x BLE controller) device files from AmbiqSuite SDK 4.4.0 and adapts them to support the new implemented HCI driver for Apollo4 Blue Plus. Signed-off-by: Aaron Ye <aye@ambiq.com>
9875be9
to
b9ffe32
Compare
Hi @jhedberg , we merged the hal_ambiq PR and updated the revision in west.yml accordingly. Could you reapprove this? Thank you. |
Hi @fkokosinski @tgorochowik , this PR enables the Bluetooth/HCI feature for Ambiq Apollo4 Blue Plus and incoming other Bluetooth series soc of Ambiq platform. If possible, could you also take a look at this? Thanks very much. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I think now also hci_uart is working
Hi @fkokosinski @tgorochowik , we passed most of the adaptable Zephyr Bluetooth samples (refer to the test list in the PR description) with the implemented Ambiq HCI driver of this PR on apollo4p_blue_kxr_evb board. We are trying to release this important feature required by the waiting wide customers for evaluation as soon as possible and getting feedback from them for code quality improvement or bug fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Board and dts bindings changes LGTM. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I merge this, may I ask the following 2 questions:
Why wasn't the existingI realize now by reading the comments.hci_spi.c
reused by extending it?- Why the need to the
apollox_blue.*
files if we havehci_ambiq.c
? Couldn't we just have a single file with all the code?
Hi @carlescufi , based on our previous discussion in this PR (see #66227 (comment)), we will integrate Apollo3 Blue Plus which also uses SPI for HCI but there are many differences between Apollo4 and Apollo3 in SPI protocol. Using a single file was the initial submission in this PR, but we thought using a single file to include all the contents would make the file too large and less readable/maintainable. So, we decide to create |
Hi @carlescufi , could you help revisit this, please? Thank you. |
Hi @carlescufi , could you look at the answer for your merging question? Sorry I marked some comments resolved to make you miss some information in your first review. I think the comments #66227 (comment), #66227 (comment), #66227 (comment) should clear your confusion. We started to announce Zephyr supports Apollo family SoCs, the Bluetooth is the basic supported feature, which is waiting for merging here. Thank you so much. |
Thanks for your explanation. Approving now. |
&iom4 { | ||
compatible = "ambiq,spi"; | ||
pinctrl-0 = <&spi4_default>; | ||
pinctrl-names = "default"; | ||
cs-gpios = <&gpio32_63 22 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; | ||
clock-frequency = <DT_FREQ_M(24)>; | ||
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>; | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these wired internally in the chip? If that's the case I think it would make sense to have the nodes declared in ambiq_apollo4p_blue.dtsi
so that you don't have to redefine the same things on every board using the chip, it's not like you can change it anyway. See stm32wl.dtsi
with the stm32wl-subghz-radio
node in the internal spi for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabiobaltieri thanks for your following. Will have an independent PR to optimize this.
This PR implements the SPI based HCI driver for Ambiq Apollo4 Blue Plus. We will use HCI-SPI to communicate between the Zephyr Bluetooth host stack and Ambiq Apollo4 Blue Plus internal Bluetooth controller.
The Bluetooth low energy controller inside of Apollo4 Blue Plus is another die running Cortex-M0 core. It works as SPI slave, while Apollo4 Blue Plus host (Cortex-M4) works as SPI master. There are only SPI, interrupt GPIO, clock request GPIO, reset GPIO, XO32MHz and XO32kHz connecting internally between controller and host. The host provides the clock source to controller. No pin of controller die is exposed on the Apollo4 Blue Plus soc.
This PR should be merged after the hal_ambiq PR zephyrproject-rtos/hal_ambiq#9 merged.
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_accept_list
-samples/bluetooth/peripheral_sc_only
-samples/bluetooth/central
-samples/bluetooth/central_hr
-samples/bluetooth/central_ht
-samples/bluetooth/central_gatt_write
-samples/bluetooth/central_past
-samples/bluetooth/broadcaster
-samples/bluetooth/broadcaster_multiple
-samples/bluetooth/beacon
-samples/bluetooth/observer
-samples/bluetooth/direct_adv
-samples/bluetooth/scan_adv
-samples/bluetooth/mtu_update
-samples/bluetooth/direction_finding_central
-samples/bluetooth/direction_finding_peripheral
-samples/bluetooth/periodic_adv
-samples/bluetooth/periodic_sync
-samples/bluetooth/eddystone
-samples/bluetooth/ibeacon
-samples/bluetooth/hci_uart
-tests/bluetooth/init