From 6c7380183e88effa1a9efccbbb40575a80b98d51 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Wed, 7 Oct 2020 11:04:06 +0200 Subject: [PATCH] drivers/bluetooth: ipm_stm32: Wake up C2 at init When C2 is powered on, flash erase/write operation requires C1 to share a flash mutex with C2. This can only be done if IPM communication is set up (SHCI). Instead of configuring C2 (BLE controller) at on ble open, do it at driver start up. This allows flash operations before ble_open. Signed-off-by: Erwan Gouriou --- drivers/bluetooth/hci/ipm_stm32wb.c | 45 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/bluetooth/hci/ipm_stm32wb.c b/drivers/bluetooth/hci/ipm_stm32wb.c index bae45b4d743..75d7a56a2a9 100644 --- a/drivers/bluetooth/hci/ipm_stm32wb.c +++ b/drivers/bluetooth/hci/ipm_stm32wb.c @@ -44,6 +44,8 @@ static void sysevt_received(void *pdata); #define HCI_SCO 0x03 #define HCI_EVT 0x04 +#define STM32WB_C2_LOCK_TIMEOUT K_MSEC(500) + static K_SEM_DEFINE(c2_started, 0, 1); static K_SEM_DEFINE(ble_sys_wait_cmd_rsp, 0, 1); static K_SEM_DEFINE(acl_data_ack, 1, 1); @@ -490,31 +492,13 @@ static int bt_ipm_open(void) { int err; - /* Start RX thread */ - k_thread_create(&ipm_rx_thread_data, ipm_rx_stack, - K_KERNEL_STACK_SIZEOF(ipm_rx_stack), - (k_thread_entry_t)bt_ipm_rx_thread, NULL, NULL, NULL, - K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), - 0, K_NO_WAIT); - - /* Take BLE out of reset */ - ipcc_reset(); - - transport_init(); - - /* Device will let us know when it's ready */ - k_sem_take(&c2_started, K_FOREVER); - BT_DBG("C2 unlocked"); - - stm32wb_start_ble(); - - BT_DBG("IPM Channel Open Completed"); - err = bt_ipm_ble_init(); if (err) { return err; } + BT_DBG("IPM Channel Open Completed"); + return 0; } @@ -533,6 +517,27 @@ static int _bt_ipm_init(const struct device *unused) bt_hci_driver_register(&drv); start_ble_rf(); + + /* Start RX thread */ + k_thread_create(&ipm_rx_thread_data, ipm_rx_stack, + K_KERNEL_STACK_SIZEOF(ipm_rx_stack), + (k_thread_entry_t)bt_ipm_rx_thread, NULL, NULL, NULL, + K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), + 0, K_NO_WAIT); + + /* Take BLE out of reset */ + ipcc_reset(); + + transport_init(); + + /* Device will let us know when it's ready */ + if (k_sem_take(&c2_started, STM32WB_C2_LOCK_TIMEOUT)) { + return -ETIMEDOUT; + } + BT_DBG("C2 unlocked"); + + stm32wb_start_ble(); + return 0; }