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: Added Infineon AIROC CYW43xxx BT driver #55014

Merged

Conversation

npal-cy
Copy link
Contributor

@npal-cy npal-cy commented Feb 20, 2023

@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding area: Bluetooth labels Feb 20, 2023
@npal-cy npal-cy changed the title driver: bluetooth: Added Infineon cyw43xxx BT driver driver: bluetooth: Added Infineon AIROC CYW43xxx BT driver Feb 20, 2023
drivers/bluetooth/hci/vendor/infineon/CMakeLists.txt Outdated Show resolved Hide resolved
drivers/bluetooth/hci/vendor/infineon/Kconfig Outdated Show resolved Hide resolved
drivers/bluetooth/hci/vendor/infineon/Kconfig Outdated Show resolved Hide resolved
drivers/bluetooth/hci/Kconfig Outdated Show resolved Hide resolved
@npal-cy npal-cy force-pushed the topic/add_bt_cyw43xxx_driver branch from 8996183 to b43af6a Compare February 22, 2023 09:08
jori-nordic
jori-nordic previously approved these changes Feb 22, 2023
Copy link
Member

@jhedberg jhedberg left a comment

Choose a reason for hiding this comment

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

Generally looks pretty good! Just a few mainly style-related comments.

bool "MURATA_1YN"
endchoice

config CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB
Copy link
Member

Choose a reason for hiding this comment

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

Where and how is this option used? I don't see any references to it in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will push one more commit with zephyr\modules\hal_infineon\btstack-integration\CMakeLists.txt after #44211.

Zephyr\modules\hal_infineon\btstack-integration\CMakeLists.txt will use this.
So user in prj.conf should provide path to HCD blob file:

it can be relative path from Application folder:

 CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB="BCM4343A1_001.002.009.0153.0000_Generic.hcd"

or absolute path:

CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB="c:/cyw43xxx_fw/BCM4343A1_001.002.009.0153.0000_Generic.hcd"

zephyr\modules\hal_infineon\btstack-integration\CMakeLists.txt will check CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB and generate c-array. See fragment of cmake below, full version i attached in post #55014 (comment):

....
....
# use user provided FIRMWARE HCD file (path must be defined in CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB)
if(CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB)
  # Allowed to pass absolute path to HCD blob file, or relative path from Application folder. 
  if(IS_ABSOLUTE ${CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB}) 
    set(blob_hcd_file  ${CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB})
  else()
    set(blob_hcd_file  ${APPLICATION_SOURCE_DIR}/${CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB})
  endif()
endif()

# generate Bluetooth include blob from HCD binary
if(EXISTS ${blob_hcd_file})
  message(INFO " generate include of blob Bluetooth file: ${blob_hcd_file}")

  generate_inc_file_for_target(app ${blob_hcd_file} ${blob_gen_inc_file})
  zephyr_library_sources(${CMAKE_CURRENT_SOURCE_DIR}/w_bt_firmware_controller.c)
endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added commits 2424db1 with Cmake where this option is used.

Comment on lines 234 to 238
printk("Error %d: failed to configure bt_reg_on %s pin %d\n",
err, bt_reg_on.port->name, bt_reg_on.pin);
Copy link
Member

Choose a reason for hiding this comment

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

LOG_ERR()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment on lines 226 to 230
printk("Error: failed to configure bt_reg_on %s pin %d\n",
bt_reg_on.port->name, bt_reg_on.pin);
Copy link
Member

Choose a reason for hiding this comment

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

LOG_ERR()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

/* Allocate buffer for hci_write_ram/hci_launch_ram command. */
buf = bt_hci_cmd_create(op_code, data_length);
if (buf == NULL) {
printk("Unable to allocate command buffer\n");
Copy link
Member

Choose a reason for hiding this comment

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

LOG_ERR()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

buf = bt_hci_cmd_create(BT_HCI_VND_OP_UPDATE_BAUDRATE,
HCI_VSC_UPDATE_BAUD_RATE_LENGTH);
if (buf == NULL) {
return -1;
Copy link
Member

Choose a reason for hiding this comment

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

It's a bad idea to mix -1 with other negative error values that actually mean something specific (POSIX error numbers), like you do when passing the error back up e.g. from bt_hci_cmd_send_sync(). Probably something like return -ENOMEM; would make sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Member

Choose a reason for hiding this comment

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

updated

It doesn't look like you did. Did you forget to commit the change?

static int bt_hci_uart_set_baudrate(const struct device *bt_uart_dev, uint32_t baudrate)
{
struct uart_config uart_cfg;
int err = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary initialisation upon declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

dts/bindings/bluetooth/infineon,cyw43xxx-bt-hci.yaml Outdated Show resolved Hide resolved
drivers/bluetooth/hci/Kconfig Outdated Show resolved Hide resolved
drivers/bluetooth/hci/Kconfig Outdated Show resolved Hide resolved
drivers/bluetooth/hci/Kconfig.infineon Outdated Show resolved Hide resolved
drivers/bluetooth/hci/Kconfig.infineon Outdated Show resolved Hide resolved
drivers/bluetooth/hci/cyw43xxx.c Outdated Show resolved Hide resolved
drivers/bluetooth/hci/cyw43xxx.c Outdated Show resolved Hide resolved
* ensure the integrity of the firmware image sent to the bluetooth chip.
*/
while (remaining_length) {
size_t data_length = data[2]; /* data length from firmware image block */
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest adding a debug log line in the cycle, this hangs after the first command if the firmware is incorrect, may come in handy. Up to you.

drivers/bluetooth/hci/cyw43xxx.c Outdated Show resolved Hide resolved
drivers/bluetooth/hci/cyw43xxx.c Outdated Show resolved Hide resolved
ifyall
ifyall previously approved these changes Mar 1, 2023
buf = bt_hci_cmd_create(BT_HCI_VND_OP_UPDATE_BAUDRATE,
HCI_VSC_UPDATE_BAUD_RATE_LENGTH);
if (buf == NULL) {
return -1;
Copy link
Member

Choose a reason for hiding this comment

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

updated

It doesn't look like you did. Did you forget to commit the change?

buf = bt_hci_cmd_create(BT_HCI_VND_OP_UPDATE_BAUDRATE,
HCI_VSC_UPDATE_BAUD_RATE_LENGTH);
if (buf == NULL) {
printk("Unable to allocate command buffer\n");
Copy link
Member

Choose a reason for hiding this comment

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

LOG_ERR()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

/* Allocate buffer for hci_write_ram/hci_launch_ram command. */
buf = bt_hci_cmd_create(op_code, data_length);
if (buf == NULL) {
LOG_ERR("Unable to allocate command buffer\n");
Copy link
Member

Choose a reason for hiding this comment

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

The LOG_*() macros automatically take care of line terminators, so you should remove the \n here

return -ENOMEM;
}
net_buf_unref(rsp);
net_buf_unref(buf);
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a bug. The bt_hci_cmd_send*() functions take ownership of the buffer passed to it. If you enabled net_buf asserts you'd probably trigger them when testing this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

/* Configure bt_reg_on as output */
err = gpio_pin_configure_dt(&bt_reg_on, GPIO_OUTPUT | GPIO_PULL_UP);
if (err) {
LOG_ERR("Error %d: failed to configure bt_reg_on %s pin %d\n",
Copy link
Member

Choose a reason for hiding this comment

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

Remove the \n

fabiobaltieri
fabiobaltieri previously approved these changes Mar 10, 2023
west.yml Outdated
@@ -73,7 +73,7 @@ manifest:
groups:
- hal
- name: hal_infineon
revision: 8485083ad91d3e2cc5d706da3464716718a6a42e
revision: pull/7/head
Copy link
Member

Choose a reason for hiding this comment

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

zephyrproject-rtos/hal_infineon#7 has been merged, can you update this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done with minor documentation updates in:

  • dts/bindings/bluetooth/infineon,cyw43xxx-bt-hci.yaml (added note that CYW43xxx requires fetch binary files of BT controller)
  • drivers/bluetooth/hci/Kconfig.infineon (update/simplified description for modules)

- Added Cmakefiles for modules\hal_infineon\btstack-integration\,
  where handle generation of Bluetooth include blob from HCD binary.

- Supported following device/modules:
 -- CYW43012/MURATA-1LV module
 -- CYW4343W/MURATA-1DX module
 -- CYW43439/MURATA-1YN module
 -- CYW4373/STERLING-LWB5plus module

- Added possibility to use user provided BT Firmware HCD file via
  kconfig (path must be defined in
  CONFIG_CYW43XX_CUSTOM_FIRMWARE_HCD_BLOB)

- Updated top makefile

Signed-off-by: Nazar Palamar <nazar.palamar@infineon.com>
@npal-cy npal-cy dismissed stale reviews from fabiobaltieri, jori-nordic, and mniestroj via 5a2826f March 22, 2023 11:11
@npal-cy npal-cy force-pushed the topic/add_bt_cyw43xxx_driver branch from 0fd68f2 to 5a2826f Compare March 22, 2023 11:11
@zephyrbot zephyrbot added platform: Infineon Infineon Technologies AG and removed DNM This PR should not be merged (Do Not Merge) labels Mar 22, 2023
@npal-cy npal-cy force-pushed the topic/add_bt_cyw43xxx_driver branch from 5a2826f to 13a2767 Compare March 22, 2023 11:31
@carlescufi carlescufi requested a review from jhedberg March 22, 2023 12:54
Comment on lines 181 to 183
void *data_buf = net_buf_add(buf, data_length);

(void)memcpy(data_buf, (void *)&data[3], data_length);
Copy link
Member

Choose a reason for hiding this comment

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

net_buf_add_mem(buf, &data[3], data_length);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

npal-cy added 2 commits March 22, 2023 15:38
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>
Enable BLE features for CY8CPROTO-062-4343W board.

Signed-off-by: Nazar Palamar <nazar.palamar@infineon.com>
@npal-cy npal-cy force-pushed the topic/add_bt_cyw43xxx_driver branch from 13a2767 to 6828284 Compare March 22, 2023 13:39
@npal-cy npal-cy requested review from jhedberg and removed request for nashif, Vudentz, Thalley, sjanc, galak, hermabe, asbjornsabo, alwa-nordic and theob-pro March 22, 2023 14:01
@ifyall ifyall self-requested a review March 22, 2023 14:38
@carlescufi carlescufi merged commit 8fb4a18 into zephyrproject-rtos:main Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants