From a83f067af9af82f034596f6f6154f4dccf598ace Mon Sep 17 00:00:00 2001 From: JF Date: Thu, 2 Jul 2020 21:38:52 +0200 Subject: Reduce RAM memory usage by tuning the stack of the stasks and the heap allocated for FreeRTOS. Add Monitor to log the stack usage of each task. --- .../mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libs') diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c b/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c index 8ee3475a..64196b36 100644 --- a/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c +++ b/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c @@ -37,7 +37,7 @@ nimble_port_freertos_init(TaskFunction_t host_task_fn) * provided by NimBLE and in case of FreeRTOS it does not need to be wrapped * since it has compatible prototype. */ - xTaskCreate(nimble_port_ll_task_func, "ll", configMINIMAL_STACK_SIZE + 400, + xTaskCreate(nimble_port_ll_task_func, "ll", configMINIMAL_STACK_SIZE + 100, NULL, configMAX_PRIORITIES - 1, &ll_task_h); #endif @@ -46,6 +46,6 @@ nimble_port_freertos_init(TaskFunction_t host_task_fn) * have separate task for NimBLE host, but since something needs to handle * default queue it is just easier to make separate task which does this. */ - xTaskCreate(host_task_fn, "ble", configMINIMAL_STACK_SIZE + 400, + xTaskCreate(host_task_fn, "ble", configMINIMAL_STACK_SIZE + 200, NULL, tskIDLE_PRIORITY + 1, &host_task_h); } -- cgit v1.2.3 From 71842667a0bce3543c2a649c0e753c59353bd975 Mon Sep 17 00:00:00 2001 From: JF Date: Wed, 8 Jul 2020 21:14:52 +0200 Subject: Remove debug (and bad) #includes. --- src/libs/mynewt-nimble/nimble/controller/src/ble_ll.c | 1 - src/libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_phy.c | 1 - src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c | 1 - 3 files changed, 3 deletions(-) (limited to 'src/libs') diff --git a/src/libs/mynewt-nimble/nimble/controller/src/ble_ll.c b/src/libs/mynewt-nimble/nimble/controller/src/ble_ll.c index da5d2972..996ad9c3 100644 --- a/src/libs/mynewt-nimble/nimble/controller/src/ble_ll.c +++ b/src/libs/mynewt-nimble/nimble/controller/src/ble_ll.c @@ -21,7 +21,6 @@ #include #include #include -#include #include "sysinit/sysinit.h" #include "syscfg/syscfg.h" #include "os/os.h" diff --git a/src/libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_phy.c b/src/libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_phy.c index 83730a44..2f6ce08e 100644 --- a/src/libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_phy.c +++ b/src/libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_phy.c @@ -20,7 +20,6 @@ #include #include #include -#include #include "syscfg/syscfg.h" #include "os/os.h" #include "ble/xcvr.h" diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c index 2bbcc598..87936bd8 100644 --- a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c +++ b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c @@ -20,7 +20,6 @@ #include #include #include -#include #include "nimble/nimble_npl.h" static inline bool -- cgit v1.2.3 From 09adb78b551ef7659fd7e8e71c337e7de81023d2 Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 11 Jul 2020 20:50:40 +0200 Subject: Fix/Workaround a memory leak each time a device connects to BLE. --- src/CMakeLists.txt | 2 +- src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/libs') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be73dbfb..ff2e1812 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,7 @@ set(SDK_SOURCE_FILES # FreeRTOS ${NRF5_SDK_PATH}/external/freertos/source/croutine.c ${NRF5_SDK_PATH}/external/freertos/source/event_groups.c - ${NRF5_SDK_PATH}/external/freertos/source/portable/MemMang/heap_1.c + ${NRF5_SDK_PATH}/external/freertos/source/portable/MemMang/heap_4.c ${NRF5_SDK_PATH}/external/freertos/source/list.c ${NRF5_SDK_PATH}/external/freertos/source/queue.c ${NRF5_SDK_PATH}/external/freertos/source/stream_buffer.c diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c index 87936bd8..eb3b4c99 100644 --- a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c +++ b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c @@ -268,10 +268,16 @@ void npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg) { + // I added this 'if' because nimble seems to never delete the timers. I assume it wants to recycle them. + // This condition ensure that a new timer is created only if 'co' points to an uninitialized structure. + // If the struct contains an existing timer, no new timer is created, which prevent a significant memory leak. + // TODO Ensure that this workaround is valid and does not generate bad side-effect. + if(co->handle == NULL) { memset(co, 0, sizeof(*co)); co->handle = xTimerCreate("co", 1, pdFALSE, co, os_callout_timer_cb); co->evq = evq; ble_npl_event_init(&co->ev, ev_cb, ev_arg); + } } ble_npl_error_t -- cgit v1.2.3