[FL-1952] BLE bonding fix (#805)
* furi-hal-bt: add mutex guarding core2 state * ble-glue: configure ble keys storage in SRAM2 * bt: add load and save ble keys in internal storage * bt: improve work furi_hal_bt API * bt: rework app_entry -> ble_glue * bt: apply changes for f6 target * desktop: remove furi check * ble-glue: comment NVM in SRAM2 configuration * FuriHal: fix flash controller state corruption, fix incorrect semaphore release, implement C1-C2 flash controller access according to spec. Gui: change logging level. * Libs: better lfs integration with lfs_config. * Ble: switch C2 NVM to RAM. * FuriHalCrypto: ensure that core2 is alive before sending shci commands * Ble: fix incorrect nvm buffer size Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#define BLE_APP_TAG "ble app"
|
||||
|
||||
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t ble_app_cmd_buffer;
|
||||
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint32_t ble_app_nvm[BLE_NVM_SRAM_SIZE];
|
||||
|
||||
typedef struct {
|
||||
osMutexId_t hci_mtx;
|
||||
@@ -26,8 +27,8 @@ static void ble_app_hci_event_handler(void * pPayload);
|
||||
static void ble_app_hci_status_not_handler(HCI_TL_CmdStatus_t status);
|
||||
|
||||
bool ble_app_init() {
|
||||
SHCI_CmdStatus_t status;
|
||||
ble_app = furi_alloc(sizeof(BleApp));
|
||||
|
||||
// Allocate semafore and mutex for ble command buffer access
|
||||
ble_app->hci_mtx = osMutexNew(NULL);
|
||||
ble_app->hci_sem = osSemaphoreNew(1, 0, NULL);
|
||||
@@ -43,6 +44,18 @@ bool ble_app_init() {
|
||||
};
|
||||
hci_init(ble_app_hci_event_handler, (void*)&hci_tl_config);
|
||||
|
||||
// Configure NVM store for pairing data
|
||||
SHCI_C2_CONFIG_Cmd_Param_t config_param = {
|
||||
.PayloadCmdSize = SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE,
|
||||
.Config1 =SHCI_C2_CONFIG_CONFIG1_BIT0_BLE_NVM_DATA_TO_SRAM,
|
||||
.BleNvmRamAddress = (uint32_t)ble_app_nvm,
|
||||
.EvtMask1 = SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE,
|
||||
};
|
||||
status = SHCI_C2_Config(&config_param);
|
||||
if(status) {
|
||||
FURI_LOG_E(BLE_APP_TAG, "Failed to configure 2nd core: %d", status);
|
||||
}
|
||||
|
||||
// Start ble stack on 2nd core
|
||||
SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = {
|
||||
.Header = {{0,0,0}}, // Header unused
|
||||
@@ -67,13 +80,18 @@ bool ble_app_init() {
|
||||
0,
|
||||
}
|
||||
};
|
||||
SHCI_CmdStatus_t status = SHCI_C2_BLE_Init(&ble_init_cmd_packet);
|
||||
status = SHCI_C2_BLE_Init(&ble_init_cmd_packet);
|
||||
if(status) {
|
||||
FURI_LOG_E(BLE_APP_TAG, "Failed to start ble stack: %d", status);
|
||||
}
|
||||
return status == SHCI_Success;
|
||||
}
|
||||
|
||||
void ble_app_get_key_storage_buff(uint8_t** addr, uint16_t* size) {
|
||||
*addr = (uint8_t*)ble_app_nvm;
|
||||
*size = sizeof(ble_app_nvm);
|
||||
}
|
||||
|
||||
static void ble_app_hci_thread(void *arg) {
|
||||
while(1) {
|
||||
osThreadFlagsWait(1, osFlagsWaitAny, osWaitForever);
|
||||
|
Reference in New Issue
Block a user