From 833c53424a211f34774fa210be3eb96ad4f35210 Mon Sep 17 00:00:00 2001 From: JF Date: Mon, 27 Apr 2020 20:46:25 +0200 Subject: [PATCH 1/3] Re-enable watchdog --- src/SystemTask/SystemTask.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index 6516f68b..fc37ecb2 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -38,8 +38,8 @@ void SystemTask::Process(void *instance) { } void SystemTask::Work() { -// watchdog.Setup(7); -// watchdog.Start(); + watchdog.Setup(7); + watchdog.Start(); NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); APP_GPIOTE_INIT(2); From 332b51464a75e40f2e306c50092735891acfe406 Mon Sep 17 00:00:00 2001 From: JF Date: Thu, 30 Apr 2020 20:47:28 +0200 Subject: [PATCH 2/3] Fix random crash caused by bad implementation of ble_npl_hw_enter_critical(). --- .../porting/npl/freertos/include/nimble/nimble_npl_os.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h index f04145d3..d8810f35 100644 --- a/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h +++ b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h @@ -282,8 +282,8 @@ static inline uint32_t ble_npl_hw_enter_critical(void) { //vPortEnterCritical(); - npl_freertos_hw_enter_critical(); - return 0; + + return npl_freertos_hw_enter_critical(); } static inline void From ed168716b5055d3efec9b30b1b1a3c7ef6c5b17d Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 2 May 2020 17:42:26 +0200 Subject: [PATCH 3/3] Add Asssert & debug messages. --- src/Components/Ble/NimbleController.cpp | 21 +++++++++++++-------- src/main.cpp | 7 +++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp index 02f99180..64ec379d 100644 --- a/src/Components/Ble/NimbleController.cpp +++ b/src/Components/Ble/NimbleController.cpp @@ -76,9 +76,14 @@ void NimbleController::Init() { currentTimeClient.Init(); int res; res = ble_hs_util_ensure_addr(0); + ASSERT(res == 0); res = ble_hs_id_infer_auto(0, &addrType); + ASSERT(res == 0); res = ble_svc_gap_device_name_set(deviceName); - ble_gatts_start(); + + ASSERT(res == 0); + res = ble_gatts_start(); + ASSERT(res == 0); } void NimbleController::StartAdvertising() { @@ -115,14 +120,14 @@ void NimbleController::StartAdvertising() { int res; res = ble_gap_adv_set_fields(&fields); - assert(res == 0); + ASSERT(res == 0); - ble_gap_adv_rsp_set_fields(&rsp_fields); + res = ble_gap_adv_rsp_set_fields(&rsp_fields); + ASSERT(res == 0); - ble_gap_adv_start(addrType, NULL, 10000, + res = ble_gap_adv_start(addrType, NULL, 10000, &adv_params, GAPEventCallback, this); - - + ASSERT(res == 0); } int OnAllSvrDisco(uint16_t conn_handle, @@ -138,7 +143,7 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) { switch (event->type) { case BLE_GAP_EVENT_ADV_COMPLETE: NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_ADV_COMPLETE"); - NRF_LOG_INFO("advertise complete; reason=%d", event->adv_complete.reason); + NRF_LOG_INFO("advertise complete; reason=%dn status=%d", event->adv_complete.reason, event->connect.status); StartAdvertising(); break; case BLE_GAP_EVENT_CONNECT: { @@ -161,7 +166,7 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) { break; case BLE_GAP_EVENT_DISCONNECT: NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_DISCONNECT"); - NRF_LOG_INFO("disconnect; reason=%d ", event->disconnect.reason); + NRF_LOG_INFO("disconnect; reason=%d", event->disconnect.reason); /* Connection terminated; resume advertising. */ bleController.Disconnect(); diff --git a/src/main.cpp b/src/main.cpp index 7c5eaf7c..e0e9b65e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -184,8 +184,11 @@ void nimble_port_init(void) { ble_hs_init(); ble_store_ram_init(); - hal_timer_init(5, NULL); - os_cputime_init(32768); + int res; + res = hal_timer_init(5, NULL); + ASSERT(res == 0); + res = os_cputime_init(32768); + ASSERT(res == 0); ble_ll_init(); ble_hci_ram_init(); nimble_port_freertos_init(BleHost);