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 <erwan.gouriou@linaro.org>
This commit is contained in:
Erwan Gouriou 2020-10-07 11:04:06 +02:00 committed by Carles Cufí
commit 6c7380183e

View file

@ -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;
}