From dd6aecbf6b343e40f75808f5e26a077eb22a2ed2 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 19 Apr 2020 20:44:59 +0200 Subject: Integration of nimble, work in progress. Advertising is working. --- src/main.cpp | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 130 insertions(+), 20 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 106d19eb..f4c5c60a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +//#include #include #include "BLE/BleManager.h" #include "Components/Battery/BatteryController.h" @@ -17,6 +17,18 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #if NRF_LOG_ENABLED #include "Logging/NrfLogger.h" @@ -93,20 +105,20 @@ void OnNewNotification(const char* message, uint8_t size) { systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); } -void OnNewTime(current_time_char_t* currentTime) { - auto dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week; - auto year = currentTime->exact_time_256.day_date_time.date_time.year; - auto month = currentTime->exact_time_256.day_date_time.date_time.month; - auto day = currentTime->exact_time_256.day_date_time.date_time.day; - auto hour = currentTime->exact_time_256.day_date_time.date_time.hours; - auto minute = currentTime->exact_time_256.day_date_time.date_time.minutes; - auto second = currentTime->exact_time_256.day_date_time.date_time.seconds; - - dateTimeController.SetTime(year, month, day, - dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG)); - - systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewTime); -} +//void OnNewTime(current_time_char_t* currentTime) { +// auto dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week; +// auto year = currentTime->exact_time_256.day_date_time.date_time.year; +// auto month = currentTime->exact_time_256.day_date_time.date_time.month; +// auto day = currentTime->exact_time_256.day_date_time.date_time.day; +// auto hour = currentTime->exact_time_256.day_date_time.date_time.hours; +// auto minute = currentTime->exact_time_256.day_date_time.date_time.minutes; +// auto second = currentTime->exact_time_256.day_date_time.date_time.seconds; +// +// dateTimeController.SetTime(year, month, day, +// dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG)); +// +// systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewTime); +//} void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { if(((NRF_SPIM0->INTENSET & (1<<6)) != 0) && NRF_SPIM0->EVENTS_END == 1) { @@ -124,6 +136,100 @@ void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { } } +static void (*radio_isr_addr)(void) ; +static void (*rng_isr_addr)(void) ; +static void (*rtc0_isr_addr)(void) ; + + +/* Some interrupt handlers required for NimBLE radio driver */ +extern "C" { +void RADIO_IRQHandler(void) { + ((void (*)(void)) radio_isr_addr)(); +} + +void RNG_IRQHandler(void) { + ((void (*)(void)) rng_isr_addr)(); +} + +void RTC0_IRQHandler(void) { + ((void (*)(void)) rtc0_isr_addr)(); +} + +void WDT_IRQHandler(void) { + nrf_wdt_event_clear(NRF_WDT_EVENT_TIMEOUT); +} + +void npl_freertos_hw_set_isr(int irqn, void (*addr)(void)) { + switch (irqn) { + case RADIO_IRQn: + radio_isr_addr = addr; + break; + case RNG_IRQn: + rng_isr_addr = addr; + break; + case RTC0_IRQn: + rtc0_isr_addr = addr; + break; + } +} + +uint32_t +npl_freertos_hw_enter_critical(void) { + uint32_t ctx = __get_PRIMASK(); + __disable_irq(); + return (ctx & 0x01); +} + +void npl_freertos_hw_exit_critical(uint32_t ctx) { + if (!ctx) { + __enable_irq(); + } +} + + +static struct ble_npl_eventq g_eventq_dflt; + +struct ble_npl_eventq * +nimble_port_get_dflt_eventq(void) { + return &g_eventq_dflt; +} + +void nimble_port_run(void) { + struct ble_npl_event *ev; + + while (1) { + ev = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER); + ble_npl_event_run(ev); + } +} + +void BleHost(void *) { + nimble_port_run(); +} + +void nimble_port_init(void) { + void os_msys_init(void); + void ble_store_ram_init(void); + ble_npl_eventq_init(&g_eventq_dflt); + os_msys_init(); + ble_hs_init(); + ble_store_ram_init(); + + hal_timer_init(5, NULL); + os_cputime_init(32768); + ble_ll_init(); + ble_hci_ram_init(); + nimble_port_freertos_init(BleHost); + + +} + +void nimble_port_ll_task_func(void *args) { +// extern void ble_ll_task(void *arg); + ble_ll_task(args); +} +} + int main(void) { logger.Init(); @@ -135,11 +241,15 @@ int main(void) { dateTimeController, notificationManager)); systemTask->Start(); - ble_manager_init(); - ble_manager_set_new_time_callback(OnNewTime); - ble_manager_set_ble_connection_callback(OnBleConnection); - ble_manager_set_ble_disconnection_callback(OnBleDisconnection); - ble_manager_set_new_notification_callback(OnNewNotification); + nimble_port_init(); + ble_svc_gap_init(); + ble_svc_gatt_init(); + +// ble_manager_init(); +// ble_manager_set_new_time_callback(OnNewTime); +// ble_manager_set_ble_connection_callback(OnBleConnection); +// ble_manager_set_ble_disconnection_callback(OnBleDisconnection); +// ble_manager_set_new_notification_callback(OnNewNotification); vTaskStartScheduler(); -- cgit v1.2.3-70-g09d2 From 2c9ce1cfc7d4c733b1b35f51a1f6f5da332cf3fa Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 19 Apr 2020 21:26:09 +0200 Subject: Encapsulate nimble code into NimbleController. Handle all GAP events. --- src/CMakeLists.txt | 3 + src/Components/Ble/NimbleController.cpp | 148 ++++++++++++++++++++++++++++++++ src/Components/Ble/NimbleController.h | 19 ++++ src/SystemTask/SystemTask.cpp | 79 +---------------- src/SystemTask/SystemTask.h | 2 + src/main.cpp | 4 +- 6 files changed, 177 insertions(+), 78 deletions(-) create mode 100644 src/Components/Ble/NimbleController.cpp create mode 100644 src/Components/Ble/NimbleController.h (limited to 'src/main.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 59448be8..f16ee0c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,7 @@ set(NIMBLE_SRC libs/mynewt-nimble/nimble/host/src/ble_hs_conn.c libs/mynewt-nimble/nimble/host/src/ble_att_svr.c libs/mynewt-nimble/nimble/host/src/ble_store.c + libs/mynewt-nimble/nimble/host/src/ble_store_util.c libs/mynewt-nimble/nimble/host/src/ble_hs_pvcy.c libs/mynewt-nimble/nimble/host/src/ble_hs_hci.c libs/mynewt-nimble/nimble/host/src/ble_hs_log.c @@ -315,6 +316,7 @@ list(APPEND SOURCE_FILES Components/Ble/NotificationManager.cpp Components/DateTime/DateTimeController.cpp Components/Brightness/BrightnessController.cpp + Components/Ble/NimbleController.cpp drivers/Cst816s.cpp FreeRTOS/port.c FreeRTOS/port_cmsis_systick.c @@ -359,6 +361,7 @@ set(INCLUDE_FILES Components/Ble/NotificationManager.h Components/DateTime/DateTimeController.h Components/Brightness/BrightnessController.h + Components/Ble/NimbleController.h drivers/Cst816s.h FreeRTOS/portmacro.h FreeRTOS/portmacro_cmsis.h diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp new file mode 100644 index 00000000..eaad9077 --- /dev/null +++ b/src/Components/Ble/NimbleController.cpp @@ -0,0 +1,148 @@ +#include "NimbleController.h" +#include +#include +#include +#include +#include +#include + + +using namespace Pinetime::Controllers; + +int GAPEventCallback(struct ble_gap_event *event, void *arg) { + auto nimbleController = static_cast(arg); + return nimbleController->OnGAPEvent(event); +} + +void NimbleController::Init() { + while (!ble_hs_synced()) {} + + ble_svc_gap_init(); + ble_svc_gatt_init(); + + int res; + res = ble_hs_util_ensure_addr(0); + res = ble_hs_id_infer_auto(0, &addrType); + res = ble_svc_gap_device_name_set(deviceName); +} + +void NimbleController::StartAdvertising() { + ble_svc_gap_device_name_set("Pinetime-JF"); + + /* set adv parameters */ + struct ble_gap_adv_params adv_params; + struct ble_hs_adv_fields fields; + /* advertising payload is split into advertising data and advertising + response, because all data cannot fit into single packet; name of device + is sent as response to scan request */ + struct ble_hs_adv_fields rsp_fields; + + /* fill all fields and parameters with zeros */ + memset(&adv_params, 0, sizeof(adv_params)); + memset(&fields, 0, sizeof(fields)); + memset(&rsp_fields, 0, sizeof(rsp_fields)); + + adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; + adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; + + fields.flags = BLE_HS_ADV_F_DISC_GEN | + BLE_HS_ADV_F_BREDR_UNSUP; +// fields.uuids128 = BLE_UUID128(BLE_UUID128_DECLARE( +// 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, +// 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff)); + fields.num_uuids128 = 0; + fields.uuids128_is_complete = 0;; + fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; + + rsp_fields.name = (uint8_t *)"Pinetime-JF"; + rsp_fields.name_len = strlen("Pinetime-JF"); + rsp_fields.name_is_complete = 1; + + int res; + res = ble_gap_adv_set_fields(&fields); + assert(res == 0); + + res = ble_gap_adv_rsp_set_fields(&rsp_fields); + + res = ble_gap_adv_start(addrType, NULL, 10000, + &adv_params, GAPEventCallback, this); + + +} + +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); + StartAdvertising(); + break; + case BLE_GAP_EVENT_CONNECT: { + NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_CONNECT"); + + /* A new connection was established or a connection attempt failed. */ + NRF_LOG_INFO("connection %s; status=%d ", event->connect.status == 0 ? "established" : "failed", + event->connect.status); + + if (event->connect.status != 0) { + /* Connection failed; resume advertising. */ + StartAdvertising(); + } + } + break; + case BLE_GAP_EVENT_DISCONNECT: + NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_DISCONNECT"); + NRF_LOG_INFO("disconnect; reason=%d ", event->disconnect.reason); + + /* Connection terminated; resume advertising. */ + StartAdvertising(); + break; + case BLE_GAP_EVENT_CONN_UPDATE: + NRF_LOG_INFO("Advertising event : BLE_GAP_EVENT_CONN_UPDATE"); + /* The central has updated the connection parameters. */ + NRF_LOG_INFO("connection updated; status=%d ", event->conn_update.status); + break; + case BLE_GAP_EVENT_ENC_CHANGE: + /* Encryption has been enabled or disabled for this connection. */ + NRF_LOG_INFO("encryption change event; status=%d ", event->enc_change.status); + return 0; + case BLE_GAP_EVENT_SUBSCRIBE: + NRF_LOG_INFO("subscribe event; conn_handle=%d attr_handle=%d " + "reason=%d prevn=%d curn=%d previ=%d curi=???\n", + event->subscribe.conn_handle, + event->subscribe.attr_handle, + event->subscribe.reason, + event->subscribe.prev_notify, + event->subscribe.cur_notify, + event->subscribe.prev_indicate); + return 0; + case BLE_GAP_EVENT_MTU: + NRF_LOG_INFO("mtu update event; conn_handle=%d cid=%d mtu=%d\n", + event->mtu.conn_handle, + event->mtu.channel_id, + event->mtu.value); + return 0; + + case BLE_GAP_EVENT_REPEAT_PAIRING: { + /* We already have a bond with the peer, but it is attempting to + * establish a new secure link. This app sacrifices security for + * convenience: just throw away the old bond and accept the new link. + */ + + /* Delete the old bond. */ + struct ble_gap_conn_desc desc; + ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc); + ble_store_util_delete_peer(&desc.peer_id_addr); + + /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should + * continue with the pairing operation. + */ + } + return BLE_GAP_REPEAT_PAIRING_RETRY; + default: + NRF_LOG_INFO("Advertising event : %d", event->type); + break; + } + return 0; +} + diff --git a/src/Components/Ble/NimbleController.h b/src/Components/Ble/NimbleController.h new file mode 100644 index 00000000..1901b14e --- /dev/null +++ b/src/Components/Ble/NimbleController.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +namespace Pinetime { + namespace Controllers { + + class NimbleController { + public: + void Init(); + void StartAdvertising(); + int OnGAPEvent(ble_gap_event *event); + private: + static constexpr char* deviceName = "Pinetime-JF"; + uint8_t addrType; + }; + } +} diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index 59f0a92f..ae031a1e 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include "SystemTask.h" @@ -13,6 +12,7 @@ #include #include #include "../main.h" + using namespace Pinetime::System; SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Drivers::Cst816S &touchPanel, @@ -37,86 +37,15 @@ void SystemTask::Process(void *instance) { app->Work(); } -static int _gap_event_cb(struct ble_gap_event *event, void *arg) -{ - return 0; -} - -static int -adv_event(struct ble_gap_event *event, void *arg) -{ - switch (event->type) { - case BLE_GAP_EVENT_ADV_COMPLETE: - return 0; - case BLE_GAP_EVENT_CONNECT: - return 0; - case BLE_GAP_EVENT_DISCONNECT: - return 0; - default: - return 0; - } -} - void SystemTask::Work() { // watchdog.Setup(7); // watchdog.Start(); NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); APP_GPIOTE_INIT(2); -// bool erase_bonds=true; -// ble_manager_init_peer_manager(); -// nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds); -/* BLE */ - while (!ble_hs_synced()) {} - - int res; - res = ble_hs_util_ensure_addr(0); - assert(res == 0); - uint8_t addrType; - res = ble_hs_id_infer_auto(0, &addrType); - assert(res == 0); - - res = ble_svc_gap_device_name_set("Pinetime-JF"); - assert(res == 0); - - - /* set adv parameters */ - struct ble_gap_adv_params adv_params; - struct ble_hs_adv_fields fields; - /* advertising payload is split into advertising data and advertising - response, because all data cannot fit into single packet; name of device - is sent as response to scan request */ - struct ble_hs_adv_fields rsp_fields; - - /* fill all fields and parameters with zeros */ - memset(&adv_params, 0, sizeof(adv_params)); - memset(&fields, 0, sizeof(fields)); - memset(&rsp_fields, 0, sizeof(rsp_fields)); - - adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; - adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; - - fields.flags = BLE_HS_ADV_F_DISC_GEN | - BLE_HS_ADV_F_BREDR_UNSUP; -// fields.uuids128 = BLE_UUID128(BLE_UUID128_DECLARE( -// 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, -// 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff)); - fields.num_uuids128 = 0; - fields.uuids128_is_complete = 0;; - fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; - - rsp_fields.name = (uint8_t *)"Pinetime-JF"; - rsp_fields.name_len = strlen("Pinetime-JF"); - rsp_fields.name_is_complete = 1; - - res = ble_gap_adv_set_fields(&fields); - assert(res == 0); - - res = ble_gap_adv_rsp_set_fields(&rsp_fields); - - res = ble_gap_adv_start(addrType, NULL, 36000, - &adv_params, adv_event, NULL); - assert(res == 0); +/* BLE */ + nimbleController.Init(); + nimbleController.StartAdvertising(); /* /BLE*/ spi.Init(); diff --git a/src/SystemTask/SystemTask.h b/src/SystemTask/SystemTask.h index a1ba277a..5eba391b 100644 --- a/src/SystemTask/SystemTask.h +++ b/src/SystemTask/SystemTask.h @@ -8,6 +8,7 @@ #include #include #include +#include namespace Pinetime { namespace System { @@ -44,6 +45,7 @@ namespace Pinetime { Pinetime::Drivers::Watchdog watchdog; Pinetime::Drivers::WatchdogView watchdogView; Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::NimbleController nimbleController; static constexpr uint8_t pinSpiSck = 2; diff --git a/src/main.cpp b/src/main.cpp index f4c5c60a..e3226929 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #if NRF_LOG_ENABLED @@ -242,8 +241,7 @@ int main(void) { systemTask->Start(); nimble_port_init(); - ble_svc_gap_init(); - ble_svc_gatt_init(); + // ble_manager_init(); // ble_manager_set_new_time_callback(OnNewTime); -- cgit v1.2.3-70-g09d2 From be67b5297d63dfd0d0c8d732c3e2bce40af4e547 Mon Sep 17 00:00:00 2001 From: Adam Pigg Date: Mon, 27 Apr 2020 14:41:08 +0100 Subject: Remove references to BLE Manager --- src/CMakeLists.txt | 1 - src/SystemTask/SystemTask.cpp | 1 - src/main.cpp | 1 - 3 files changed, 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93878e85..ad83caee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -310,7 +310,6 @@ list(APPEND SOURCE_FILES drivers/SpiMaster.cpp drivers/Watchdog.cpp drivers/DebugPins.cpp - BLE/BleManager.c Components/Battery/BatteryController.cpp Components/Ble/BleController.cpp Components/Ble/NotificationManager.cpp diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index 5dceb89b..a003163c 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/src/main.cpp b/src/main.cpp index e3226929..9748f533 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,6 @@ #include //#include #include -#include "BLE/BleManager.h" #include "Components/Battery/BatteryController.h" #include "Components/Ble/BleController.h" #include -- cgit v1.2.3-70-g09d2 From 746c164c593d2b9aa63a0f9a1c1ad032de9627a0 Mon Sep 17 00:00:00 2001 From: JF Date: Mon, 27 Apr 2020 20:13:27 +0200 Subject: BLE : Display the actual status of the connection on the screen. --- src/CMakeLists.txt | 1 - src/Components/Ble/NimbleController.cpp | 5 +++++ src/Components/Ble/NimbleController.h | 3 ++- src/SystemTask/SystemTask.cpp | 3 ++- src/main.cpp | 39 --------------------------------- 5 files changed, 9 insertions(+), 42 deletions(-) (limited to 'src/main.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ad83caee..bd9f3b42 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -357,7 +357,6 @@ set(INCLUDE_FILES drivers/SpiMaster.h drivers/Watchdog.h drivers/DebugPins.h - BLE/BleManager.h Components/Battery/BatteryController.h Components/Ble/BleController.h Components/Ble/NotificationManager.h diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp index 7894ff43..02f99180 100644 --- a/src/Components/Ble/NimbleController.cpp +++ b/src/Components/Ble/NimbleController.cpp @@ -22,9 +22,11 @@ using namespace Pinetime::Controllers; // Let's try to improve this code (and keep it working!) NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, + Pinetime::Controllers::Ble& bleController, DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager) : systemTask{systemTask}, + bleController{bleController}, dateTimeController{dateTimeController}, notificationManager{notificationManager}, currentTimeClient{dateTimeController}, @@ -149,7 +151,9 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) { if (event->connect.status != 0) { /* Connection failed; resume advertising. */ StartAdvertising(); + bleController.Disconnect(); } else { + bleController.Connect(); connectionHandle = event->connect.conn_handle; ble_gattc_disc_all_svcs(connectionHandle, OnAllSvrDisco, this); } @@ -160,6 +164,7 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) { NRF_LOG_INFO("disconnect; reason=%d ", event->disconnect.reason); /* Connection terminated; resume advertising. */ + bleController.Disconnect(); StartAdvertising(); break; case BLE_GAP_EVENT_CONN_UPDATE: diff --git a/src/Components/Ble/NimbleController.h b/src/Components/Ble/NimbleController.h index 7a7a94c9..99e0c811 100644 --- a/src/Components/Ble/NimbleController.h +++ b/src/Components/Ble/NimbleController.h @@ -12,7 +12,7 @@ namespace Pinetime { class NimbleController { public: - NimbleController(Pinetime::System::SystemTask& systemTask, DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager); + NimbleController(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController, DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager); void Init(); void StartAdvertising(); int OnGAPEvent(ble_gap_event *event); @@ -28,6 +28,7 @@ namespace Pinetime { private: static constexpr char* deviceName = "Pinetime-JF"; Pinetime::System::SystemTask& systemTask; + Pinetime::Controllers::Ble& bleController; DateTime& dateTimeController; Pinetime::Controllers::NotificationManager& notificationManager; diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp index a003163c..6516f68b 100644 --- a/src/SystemTask/SystemTask.cpp +++ b/src/SystemTask/SystemTask.cpp @@ -21,7 +21,8 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Drivers::C Pinetime::Controllers::NotificationManager& notificationManager) : spi{spi}, lcd{lcd}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, bleController{bleController}, dateTimeController{dateTimeController}, - watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, nimbleController(*this, dateTimeController, notificationManager) { + watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, + nimbleController(*this, bleController,dateTimeController, notificationManager) { systemTaksMsgQueue = xQueueCreate(10, 1); } diff --git a/src/main.cpp b/src/main.cpp index 9748f533..7c5eaf7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ #include #include #include -//#include #include #include "Components/Battery/BatteryController.h" #include "Components/Ble/BleController.h" @@ -90,34 +89,6 @@ void DebounceTimerCallback(TimerHandle_t xTimer) { systemTask->OnButtonPushed(); } -void OnBleConnection() { - bleController.Connect(); -} - -void OnBleDisconnection() { - bleController.Disconnect(); -} - -void OnNewNotification(const char* message, uint8_t size) { - notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, message, size); - systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); -} - -//void OnNewTime(current_time_char_t* currentTime) { -// auto dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week; -// auto year = currentTime->exact_time_256.day_date_time.date_time.year; -// auto month = currentTime->exact_time_256.day_date_time.date_time.month; -// auto day = currentTime->exact_time_256.day_date_time.date_time.day; -// auto hour = currentTime->exact_time_256.day_date_time.date_time.hours; -// auto minute = currentTime->exact_time_256.day_date_time.date_time.minutes; -// auto second = currentTime->exact_time_256.day_date_time.date_time.seconds; -// -// dateTimeController.SetTime(year, month, day, -// dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG)); -// -// systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewTime); -//} - void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { if(((NRF_SPIM0->INTENSET & (1<<6)) != 0) && NRF_SPIM0->EVENTS_END == 1) { NRF_SPIM0->EVENTS_END = 0; @@ -218,8 +189,6 @@ void nimble_port_init(void) { ble_ll_init(); ble_hci_ram_init(); nimble_port_freertos_init(BleHost); - - } void nimble_port_ll_task_func(void *args) { @@ -238,16 +207,8 @@ int main(void) { systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, touchPanel, lvgl, batteryController, bleController, dateTimeController, notificationManager)); systemTask->Start(); - nimble_port_init(); - -// ble_manager_init(); -// ble_manager_set_new_time_callback(OnNewTime); -// ble_manager_set_ble_connection_callback(OnBleConnection); -// ble_manager_set_ble_disconnection_callback(OnBleDisconnection); -// ble_manager_set_new_notification_callback(OnNewNotification); - vTaskStartScheduler(); for (;;) { -- cgit v1.2.3-70-g09d2 From ed168716b5055d3efec9b30b1b1a3c7ef6c5b17d Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 2 May 2020 17:42:26 +0200 Subject: Add Asssert & debug messages. --- src/Components/Ble/NimbleController.cpp | 21 +++++++++++++-------- src/main.cpp | 7 +++++-- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src/main.cpp') 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); -- cgit v1.2.3-70-g09d2 From d6c6ac4cf5801e17caf7bfc0878423703ed0413b Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 16 May 2020 16:13:22 +0200 Subject: Remove reference to NRF Softdevice in CMake and documentation. Update documentation. Remove Asserts when starting advertising to prevent crash (known bug). Set version 0.5.0. --- CMakeLists.txt | 2 +- README.md | 26 ++----- cmake-nRF5x/CMake_nRF5x.cmake | 124 +------------------------------- src/Components/Ble/NimbleController.cpp | 13 +++- src/main.cpp | 1 - 5 files changed, 19 insertions(+), 147 deletions(-) (limited to 'src/main.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 5af971f0..f803cecc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(pinetime VERSION 0.4.0 LANGUAGES C CXX ASM) +project(pinetime VERSION 0.5.0 LANGUAGES C CXX ASM) set(NRF_TARGET "nrf52") diff --git a/README.md b/README.md index 790e3de1..4c970f8e 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,16 @@ I've tested this project on the actual PineTime hardware. * Project builds and runs on the Pinetime; * Logs available via JLink RTT; * SPI (DMA & IRQ based) LCD driver; - * BLE advertising, connection and bonding; + * Open source BLE stack : [NimBLE](https://github.com/apache/mynewt-nimble); + * BLE advertising and connection connection; * BLE CTS client (retrieves the time from the connected device if it implements a CTS server); * Push button to go to disable screen (and go to low power mode) / enable screen (and wake-up) and UI navigation * Touch panel support; * Rich user interface (using [LittleVGL](https://littlevgl.com/)) via display, touchpanel and push button. * Digital watch face and 4 demo applications (spinning meter, analog gauche, push button and message box); * Watchdog (automatic reset in case of firmware crash) and reset support (push and hold the button for 7 - 10s); - * BLE Notification support (still Work-In-Progress, [companion app](https://github.com/JF002/gobbledegook) needed). + * BLE Notification support (still Work-In-Progress, [companion app](https://github.com/JF002/gobbledegook) needed); + * Supported by companion app [Amazfish](https://openrepos.net/content/piggz/amazfish) (time synchronization and notifications are integrated). ## Documentation @@ -77,10 +79,6 @@ See [this page](./doc/PinetimeStubWithNrf52DK.md) - -DOPENOCD_BIN_PATH=[path to openocd] - * Optionally, you can define MERGEHEX with the path to the ```mergehex``` tool from [NRF5X Command Line Tools](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_nrf5x_cltools%2FUG%2Fcltools%2Fnrf5x_command_line_tools_lpage.html&cp=6_1) to be able to merge the application and softdevice into one HEX file. In this case the merged file is generated in src/pinetime-app-full.hex - - - -DMERGEHEX=[Path to the mergehex executable] - JLINK ``` $ mkdir build @@ -116,18 +114,6 @@ $ make -j pinetime-app $ make FLASH_ERASE ``` -* Flash softdevice & application - -``` -$ make FLASH_SOFTDEVICE -$ make FLASH_pinetime-app -``` - -Or, with ```mergehex``` - -``` -$ make FLASH_MERGED_pinetime-app -``` * For your information : list make targets : @@ -208,7 +194,7 @@ $ JLinkRTTClient - https://github.com/eliotstock/memory : display the memory usage (FLASH/RAM) using the .map file from GCC. -## BLE connection, bonding and time synchronization +## BLE connection and time synchronization At runtime, BLE advertising is started. You can then use a smartphone or computer to connect and bond to your Pinetime. As soon as a device is bonded, Pinetime will look for a **CTS** server (**C**urrent **T**ime **S**ervice) on the connected device. @@ -223,7 +209,7 @@ Here is how to do it with an Android smartphone running NRFConnect: - Select server configuration "Current Time Service" and tap OK * Go back to the main screen and scan for BLE devices. A device called "PineTime" should appear * Tap the button "Connect" next to the PineTime device. It should connect to the PineTime and switch to a new tab. -* On this tab, on the top right, there is a 3 dots button. Tap on it and select Bond. The bonding process begins, and if it is sucessful, the PineTime should update its time and display it on the screen. +* If a CTS server is found, the Pinetime should update its time with the time provided by the server. ### Using Linux and bluetoothctl * Ensure that your bluetooth controller is enabled and working fine. I've tested this on a x86 Debian computer and on a RaspberryPi 3. diff --git a/cmake-nRF5x/CMake_nRF5x.cmake b/cmake-nRF5x/CMake_nRF5x.cmake index ec4b47db..c1785d36 100755 --- a/cmake-nRF5x/CMake_nRF5x.cmake +++ b/cmake-nRF5x/CMake_nRF5x.cmake @@ -5,10 +5,6 @@ if (NOT NRF5_SDK_PATH) message(FATAL_ERROR "The path to the nRF5 SDK (NRF5_SDK_PATH) must be set.") endif () -#if (NOT NRFJPROG) -# message(FATAL_ERROR "The path to the nrfjprog utility (NRFJPROG) must be set.") -#endif () - # convert toolchain path to bin path if(DEFINED ARM_NONE_EABI_TOOLCHAIN_PATH) set(ARM_NONE_EABI_TOOLCHAIN_BIN_PATH ${ARM_NONE_EABI_TOOLCHAIN_PATH}/bin) @@ -70,23 +66,15 @@ macro(nRF5x_setup) endif() set(CPU_FLAGS "-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16") add_definitions(-DNRF52 -DNRF52832 -DNRF52832_XXAA -DNRF52_PAN_74 -DNRF52_PAN_64 -DNRF52_PAN_12 -DNRF52_PAN_58 -DNRF52_PAN_54 -DNRF52_PAN_31 -DNRF52_PAN_51 -DNRF52_PAN_36 -DNRF52_PAN_15 -DNRF52_PAN_20 -DNRF52_PAN_55 -DBOARD_PCA10040) -# add_definitions(-DSOFTDEVICE_PRESENT -DS132 -DSWI_DISABLE0 -DBLE_STACK_SUPPORT_REQD -DNRF_SD_BLE_API_VERSION=6) add_definitions(-DFREERTOS) add_definitions(-DDEBUG_NRF_USER) -# add_definitions(-D__STARTUP_CLEAR_BSS) -# add_definitions(-D__HEAP_SIZE=8192) -# add_definitions(-D__STACK_SIZE=2048) - include_directories( -# "${NRF5_SDK_PATH}/components/softdevice/s132/headers" -# "${NRF5_SDK_PATH}/components/softdevice/s132/headers/nrf52" "${NRF5_SDK_PATH}/components/drivers_nrf/nrf_soc_nosd" ) list(APPEND SDK_SOURCE_FILES "${NRF5_SDK_PATH}/modules/nrfx/mdk/system_nrf52.c" "${NRF5_SDK_PATH}/modules/nrfx/mdk/gcc_startup_nrf52.S" ) -# set(SOFTDEVICE_PATH "${NRF5_SDK_PATH}/components/softdevice/s132/hex/s132_nrf52_6.1.1_softdevice.hex") endif () set(COMMON_FLAGS "-MP -MD -mthumb -mabi=aapcs -Wall -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums ${CPU_FLAGS} -Wreturn-type -Werror=return-type") @@ -243,7 +231,6 @@ macro(nRF5x_setup) # Other external include_directories( "${NRF5_SDK_PATH}/external/fprintf/" -# "${NRF5_SDK_PATH}/external/utf_converter/" ) list(APPEND SDK_SOURCE_FILES @@ -255,103 +242,25 @@ macro(nRF5x_setup) # LCD/GFX include_directories( "${NRF5_SDK_PATH}/external/thedotfactory_fonts" -# "${NRF5_SDK_PATH}/components/ble/ble_db_discovery" ) - list(APPEND SDK_SOURCE_FILES -# "${NRF5_SDK_PATH}/components/ble/ble_db_discovery/ble_db_discovery.c" -# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_cts_c/ble_cts_c.c" -# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_ans_c/ble_ans_c.c" -# "${NRF5_SDK_PATH}/external/thedotfactory_fonts/orkney24pts.c" - ) - - #BLE S132 -# include_directories( -# "${NRF5_SDK_PATH}/components/ble/common" -# "${NRF5_SDK_PATH}/components/ble/ble_advertising" -# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_bas" -# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_hrs" -# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_dis" -# "${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt" -# "${NRF5_SDK_PATH}/components/libraries/sensorsim" -# "${NRF5_SDK_PATH}/components/ble/peer_manager" -# "${NRF5_SDK_PATH}/components/ble/nrf_ble_qwr" -# ) - - LIST(APPEND SDK_SOURCE_FILES -# "${NRF5_SDK_PATH}//components/ble/common/ble_srv_common.c" -# "${NRF5_SDK_PATH}/components/ble/ble_advertising/ble_advertising.c" -# "${NRF5_SDK_PATH}/components/ble/common/ble_advdata.c" -# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_bas/ble_bas.c" -# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_hrs/ble_hrs.c" -# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_dis/ble_dis.c" -# "${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt/nrf_ble_gatt.c" -# "${NRF5_SDK_PATH}/components/libraries/sensorsim/sensorsim.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c" -# "${NRF5_SDK_PATH}/components/ble/nrf_ble_qwr/nrf_ble_qwr.c" -# "${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/auth_status_tracker.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/gatt_cache_manager.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/gatts_cache_manager.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/id_manager.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_data_storage.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_database.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_id.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager_handler.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/pm_buffer.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/security_dispatcher.c" -# "${NRF5_SDK_PATH}/components/ble/peer_manager/security_manager.c" -# "${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c" -# "${NRF5_SDK_PATH}/components/ble/common/ble_conn_params.c" -# "${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c" -# "${NRF5_SDK_PATH}/components/libraries/atomic_flags/nrf_atflags.c" -# "${NRF5_SDK_PATH}/components/libraries/fds/fds.c" -# "${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage.c" -# "${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage_sd.c" -# "${NRF5_SDK_PATH}/components/libraries/atomic_fifo/nrf_atfifo.c" -# "${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh.c" -# "${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_ble.c" -# "${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_freertos.c" -# "${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_soc.c" -# "${NRF5_SDK_PATH}/components/libraries/experimental_section_vars/nrf_section_iter.c" -# "${NRF5_SDK_PATH}/components/libraries/bsp/bsp_btn_ble.c" -# "${NRF5_SDK_PATH}/components/libraries/hardfault/hardfault_implementation.c" -# "${NRF5_SDK_PATH}/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c" - ) - LIST(APPEND SDK_SOURCE_FILES "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_twi.c" ) - # adds target for erasing and flashing the board with a softdevice + # adds target for erasing if(USE_JLINK) - add_custom_target(FLASH_SOFTDEVICE - COMMAND ${NRFJPROG} --program ${SOFTDEVICE_PATH} -f ${NRF_TARGET} --sectorerase - COMMAND sleep 0.5s - COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET} - COMMENT "flashing SoftDevice" - ) - add_custom_target(FLASH_ERASE COMMAND ${NRFJPROG} --eraseall -f ${NRF_TARGET} COMMENT "erasing flashing" ) elseif(USE_GDB_CLIENT) - add_custom_target(FLASH_SOFTDEVICE - COMMAND ${GDB_CLIENT_BIN_PATH} -nx --batch -ex 'target extended-remote ${GDB_CLIENT_TARGET_REMOTE}' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'kill' ${SOFTDEVICE_PATH} - COMMENT "flashing SoftDevice" - ) add_custom_target(FLASH_ERASE COMMAND ${GDB_CLIENT_BIN_PATH} -nx --batch -ex 'target extended-remote ${GDB_CLIENT_TARGET_REMOTE}' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'mon erase_mass' COMMENT "erasing flashing" ) elseif(USE_OPENOCD) - add_custom_target(FLASH_SOFTDEVICE - COMMAND ${OPENOCD_BIN_PATH} -c "tcl_port disabled" -c "gdb_port 3333" -c "telnet_port 4444" -f interface/stlink.cfg -c 'transport select hla_swd' -f target/nrf52.cfg -c "program \"${SOFTDEVICE_PATH}\"" -c reset -c shutdown - COMMENT "flashing SoftDevice" - ) - add_custom_target(FLASH_ERASE + add_custom_target(FLASH_ERASE COMMAND ${OPENOCD_BIN_PATH} -f interface/stlink.cfg -c 'transport select hla_swd' -f target/nrf52.cfg -c init -c halt -c 'nrf5 mass_erase' -c reset -c shutdown COMMENT "erasing flashing" ) @@ -392,35 +301,6 @@ macro(nRF5x_addExecutable EXECUTABLE_NAME SOURCE_FILES) COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_NAME}.out "${EXECUTABLE_NAME}.hex" COMMENT "post build steps for ${EXECUTABLE_NAME}") - if(MERGEHEX) - add_custom_command(TARGET ${EXECUTABLE_NAME} - POST_BUILD - COMMAND ${MERGEHEX} --merge ${EXECUTABLE_NAME}.hex ${NRF5_SDK_PATH}/components/softdevice/s132/hex/s132_nrf52_6.1.1_softdevice.hex --output ${EXECUTABLE_NAME}-full.hex - COMMENT "merging HEX files") - - if(USE_JLINK) - add_custom_target("FLASH_MERGED_${EXECUTABLE_NAME}" - DEPENDS ${EXECUTABLE_NAME} - COMMAND ${NRFJPROG} --program ${EXECUTABLE_NAME}-full.hex -f ${NRF_TARGET} --sectorerase - COMMAND sleep 0.5s - COMMAND ${NRFJPROG} --reset -f ${NRF_TARGET} - COMMENT "flashing ${EXECUTABLE_NAME}-full.hex" - ) - elseif(USE_GDB_CLIENT) - add_custom_target("FLASH_MERGED_${EXECUTABLE_NAME}" - DEPENDS ${EXECUTABLE_NAME} - COMMAND ${GDB_CLIENT_BIN_PATH} -nx --batch -ex 'target extended-remote ${GDB_CLIENT_TARGET_REMOTE}' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'kill' ${EXECUTABLE_NAME}-full.hex - COMMENT "flashing ${EXECUTABLE_NAME}-full.hex" - ) - elseif(USE_OPENOCD) - add_custom_target("FLASH_MERGED_${EXECUTABLE_NAME}" - DEPENDS ${EXECUTABLE_NAME} - COMMAND ${OPENOCD_BIN_PATH} -c "tcl_port disabled" -c "gdb_port 3333" -c "telnet_port 4444" -f interface/stlink.cfg -c 'transport select hla_swd' -f target/nrf52.cfg -c "program \"${EXECUTABLE_NAME}-full.hex\"" -c reset -c shutdown - COMMENT "flashing ${EXECUTABLE_NAME}-full.hex" - ) - endif() - endif() - # custom target for flashing the board if(USE_JLINK) add_custom_target("FLASH_${EXECUTABLE_NAME}" diff --git a/src/Components/Ble/NimbleController.cpp b/src/Components/Ble/NimbleController.cpp index 172bcb9f..2fe03571 100644 --- a/src/Components/Ble/NimbleController.cpp +++ b/src/Components/Ble/NimbleController.cpp @@ -126,14 +126,21 @@ void NimbleController::StartAdvertising() { int res; res = ble_gap_adv_set_fields(&fields); - ASSERT(res == 0); + //ASSERT(res == 0); res = ble_gap_adv_rsp_set_fields(&rsp_fields); - ASSERT(res == 0); + //ASSERT(res == 0); res = ble_gap_adv_start(addrType, NULL, 10000, &adv_params, GAPEventCallback, this); - ASSERT(res == 0); + //ASSERT(res == 0); + + // TODO I've disabled these ASSERT as they sometime asserts and reset the mcu. + // For now, the advertising is restarted as soon as it ends. There may be a race condition + // that prevent the advertising from restarting reliably. + // I remove the assert to prevent this uncesseray crash, but in the long term, the management of + // the advertising should be improve (better error handling, and advertise for 3 minutes after + // the application has been woken up, for example. } int OnAllSvrDisco(uint16_t conn_handle, diff --git a/src/main.cpp b/src/main.cpp index e0e9b65e..797495bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -195,7 +195,6 @@ void nimble_port_init(void) { } void nimble_port_ll_task_func(void *args) { -// extern void ble_ll_task(void *arg); ble_ll_task(args); } } -- cgit v1.2.3-70-g09d2