Jelajahi Sumber

[FL-3264] Various stop mode fixes (#2584)

* BleGlue: log hci_cmd_resp invocation
* BleGlue: increase BleHciDriver stack size
* ble hid app: increase stack
* ble: comment unnecessary hci reset
* BleGlue: stricter checks in communication with core2, cleanup code
* Furi: enter insomnia when executing from RAM
---------
Co-authored-by: gornekich <n.gorbadey@gmail.com>
あく 2 tahun lalu
induk
melakukan
f68c3b2a65

+ 1 - 1
firmware/targets/f7/ble_glue/app_debug.c

@@ -68,7 +68,7 @@ static const APPD_GpioConfig_t aGpioConfigList[GPIO_CFG_NBR_OF_FEATURES] = {
     {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* END_OF_CONNECTION_EVENT - Set on Entry / Reset on Exit */
     {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* TIMER_SERVER_CALLBACK - Toggle on Entry */
     {GPIOA, LL_GPIO_PIN_4, 1, 0}, /* PES_ACTIVITY - Set on Entry / Reset on Exit */
-    {GPIOB, LL_GPIO_PIN_2, 1, 0}, /* MB_BLE_SEND_EVT - Set on Entry / Reset on Exit */
+    {GPIOC, LL_GPIO_PIN_0, 1, 0}, /* MB_BLE_SEND_EVT - Set on Entry / Reset on Exit */
     /* From v1.3.0 */
     {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_NO_DELAY - Set on Entry / Reset on Exit */
     {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_STACK_STORE_NVM_CB - Set on Entry / Reset on Exit */

+ 14 - 19
firmware/targets/f7/ble_glue/ble_app.c

@@ -137,38 +137,33 @@ static int32_t ble_app_hci_thread(void* arg) {
 // Called by WPAN lib
 void hci_notify_asynch_evt(void* pdata) {
     UNUSED(pdata);
-    if(ble_app) {
-        FuriThreadId thread_id = furi_thread_get_id(ble_app->thread);
-        furi_assert(thread_id);
-        furi_thread_flags_set(thread_id, BLE_APP_FLAG_HCI_EVENT);
-    }
+    furi_check(ble_app);
+    FuriThreadId thread_id = furi_thread_get_id(ble_app->thread);
+    furi_assert(thread_id);
+    furi_thread_flags_set(thread_id, BLE_APP_FLAG_HCI_EVENT);
 }
 
 void hci_cmd_resp_release(uint32_t flag) {
     UNUSED(flag);
-    if(ble_app) {
-        furi_semaphore_release(ble_app->hci_sem);
-    }
+    furi_check(ble_app);
+    furi_check(furi_semaphore_release(ble_app->hci_sem) == FuriStatusOk);
 }
 
 void hci_cmd_resp_wait(uint32_t timeout) {
-    UNUSED(timeout);
-    if(ble_app) {
-        furi_semaphore_acquire(ble_app->hci_sem, FuriWaitForever);
-    }
+    furi_check(ble_app);
+    furi_check(furi_semaphore_acquire(ble_app->hci_sem, timeout) == FuriStatusOk);
 }
 
 static void ble_app_hci_event_handler(void* pPayload) {
     SVCCTL_UserEvtFlowStatus_t svctl_return_status;
     tHCI_UserEvtRxParam* pParam = (tHCI_UserEvtRxParam*)pPayload;
 
-    if(ble_app) {
-        svctl_return_status = SVCCTL_UserEvtRx((void*)&(pParam->pckt->evtserial));
-        if(svctl_return_status != SVCCTL_UserEvtFlowDisable) {
-            pParam->status = HCI_TL_UserEventFlow_Enable;
-        } else {
-            pParam->status = HCI_TL_UserEventFlow_Disable;
-        }
+    furi_check(ble_app);
+    svctl_return_status = SVCCTL_UserEvtRx((void*)&(pParam->pckt->evtserial));
+    if(svctl_return_status != SVCCTL_UserEvtFlowDisable) {
+        pParam->status = HCI_TL_UserEventFlow_Enable;
+    } else {
+        pParam->status = HCI_TL_UserEventFlow_Disable;
     }
 }
 

+ 0 - 2
firmware/targets/f7/ble_glue/gap.c

@@ -289,8 +289,6 @@ static void gap_init_svc(Gap* gap) {
     tBleStatus status;
     uint32_t srd_bd_addr[2];
 
-    // HCI Reset to synchronise BLE Stack
-    hci_reset();
     // Configure mac address
     aci_hal_write_config_data(
         CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, gap->config->mac_address);

+ 3 - 0
firmware/targets/f7/src/main.c

@@ -29,6 +29,8 @@ int main() {
     FuriThread* main_thread = furi_thread_alloc_ex("Init", 4096, init_task, NULL);
 
 #ifdef FURI_RAM_EXEC
+    // Prevent entering sleep mode when executed from RAM
+    furi_hal_power_insomnia_enter();
     furi_thread_start(main_thread);
 #else
     furi_hal_light_sequence("RGB");
@@ -44,6 +46,7 @@ int main() {
         furi_hal_power_reset();
     } else if(boot_mode == FuriHalRtcBootModeUpdate) {
         furi_hal_light_sequence("rgb BR");
+        // Do update
         flipper_boot_update_exec();
         // if things go nice, we shouldn't reach this point.
         // But if we do, abandon to avoid bootloops