Skip to content

Commit 2a41855

Browse files
committed
reduce task stack size
- ble task from 512*3 -> 256*5 - loop task from 512*3 -> 256*4 - callback task from 512*2 -> 256*3 - usbd task from 150 -> 200
1 parent 8395b5e commit 2a41855

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_TinyUSB_Core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3535
//--------------------------------------------------------------------+
3636

37-
#define USBD_STACK_SZ (150)
37+
#define USBD_STACK_SZ (200)
3838

3939
// tinyusb function that handles power event (detected, ready, removed)
4040
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.

cores/nRF5/linker/nrf52832_s132_v6.ld

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ MEMORY
1414
* - Concurrent connection peripheral + central + secure links
1515
* - Event Len, HVN queue, Write CMD queue
1616
*/
17-
/* RAM (rwx) : ORIGIN = 0x20003200, LENGTH = 0x20010000 - 0x20003200 */
1817
RAM (rwx) : ORIGIN = 0x20003400, LENGTH = 0x20010000 - 0x20003400
1918
}
2019

cores/nRF5/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ static TaskHandle_t _loopHandle;
3737
void initVariant() __attribute__((weak));
3838
void initVariant() { }
3939

40-
#define LOOP_STACK_SZ (512*3)
40+
#define LOOP_STACK_SZ (256*4)
41+
#define CALLBACK_STACK_SZ (256*3)
4142

4243
static void loop_task(void* arg)
4344
{
@@ -81,7 +82,7 @@ int main( void )
8182
xTaskCreate( loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);
8283

8384
// Initialize callback task
84-
ada_callback_init();
85+
ada_callback_init(CALLBACK_STACK_SZ);
8586

8687
// Start FreeRTOS scheduler.
8788
vTaskStartScheduler();

cores/nRF5/rtos.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void yield(void)
9494
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
9595
{
9696
LOG_LV1("RTOS", "%s Stack Overflow !!!", pcTaskName);
97+
while(1) yield();
9798
}
9899

99100
void vApplicationMallocFailedHook(void)

cores/nRF5/utility/AdaCallback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ void ada_callback_invoke(const void* malloc_data, uint32_t malloc_len, const voi
134134
ada_callback_queue(cb_data);
135135
}
136136

137-
void ada_callback_init(void)
137+
void ada_callback_init(uint32_t stack_sz)
138138
{
139139
// queue to hold "Pointer to callback data"
140140
_cb_qdepth = INITIAL_QUEUE_DEPTH;
141141
_cb_queue = xQueueCreate(_cb_qdepth, sizeof(void*));
142142

143143
TaskHandle_t callback_task_hdl;
144-
xTaskCreate( adafruit_callback_task, "Callback", CFG_CALLBACK_TASK_STACKSIZE, NULL, TASK_PRIO_NORMAL, &callback_task_hdl);
144+
xTaskCreate( adafruit_callback_task, "Callback", stack_sz, NULL, TASK_PRIO_NORMAL, &callback_task_hdl);
145145
}
146146

147147
bool ada_callback_queue_resize(uint32_t new_depth)

cores/nRF5/utility/AdaCallback.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838

3939
#include "common_inc.h"
4040

41-
#ifndef CFG_CALLBACK_TASK_STACKSIZE
42-
#define CFG_CALLBACK_TASK_STACKSIZE (512*2)
43-
#endif
44-
4541
#ifndef CFG_CALLBACK_TIMEOUT
4642
#define CFG_CALLBACK_TIMEOUT 100
4743
#endif
@@ -107,7 +103,7 @@ typedef void (*adacb_5arg_t) (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
107103
#define ada_callback(...) _cb_setup(__VA_ARGS__)
108104

109105

110-
void ada_callback_init(void);
106+
void ada_callback_init(uint32_t stack_sz);
111107
void ada_callback_invoke(const void* mdata, uint32_t mlen, const void* func, uint32_t arguments[], uint8_t argcount);
112108
void ada_callback_queue(ada_callback_t* cb_item);
113109
bool ada_callback_queue_resize(uint32_t new_depth);

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@
3838
#include "utility/bonding.h"
3939

4040
#ifndef CFG_BLE_TX_POWER_LEVEL
41-
#define CFG_BLE_TX_POWER_LEVEL 0
41+
#define CFG_BLE_TX_POWER_LEVEL 0
4242
#endif
4343

4444
#ifndef CFG_DEFAULT_NAME
45-
#define CFG_DEFAULT_NAME "Bluefruit52"
45+
#define CFG_DEFAULT_NAME "Bluefruit52"
4646
#endif
4747

48-
4948
#ifndef CFG_BLE_TASK_STACKSIZE
50-
#define CFG_BLE_TASK_STACKSIZE (512*3)
49+
#define CFG_BLE_TASK_STACKSIZE (256*5)
5150
#endif
5251

5352
#ifndef CFG_SOC_TASK_STACKSIZE
54-
#define CFG_SOC_TASK_STACKSIZE (200)
53+
#define CFG_SOC_TASK_STACKSIZE (200)
5554
#endif
5655

5756
#ifdef USE_TINYUSB
@@ -103,7 +102,6 @@ static void bluefruit_blinky_cb( TimerHandle_t xTimer )
103102
digitalToggle(LED_BLUE);
104103
}
105104

106-
107105
static void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info)
108106
{
109107
#if CFG_DEBUG
@@ -743,13 +741,14 @@ void adafruit_ble_task(void* arg)
743741
{
744742
(void) arg;
745743

744+
// malloc buffered is algined by 4
746745
uint8_t * ev_buf = (uint8_t*) rtos_malloc(BLE_EVT_LEN_MAX(BLE_GATT_ATT_MTU_MAX));
747746

748747
while (1)
749748
{
750749
if ( xSemaphoreTake(Bluefruit._ble_event_sem, portMAX_DELAY) )
751750
{
752-
uint32_t err = ERROR_NONE;
751+
uint32_t err = NRF_SUCCESS;
753752

754753
// Until no pending events
755754
while( NRF_ERROR_NOT_FOUND != err )
@@ -759,10 +758,13 @@ void adafruit_ble_task(void* arg)
759758
// Get BLE Event
760759
err = sd_ble_evt_get(ev_buf, &ev_len);
761760

762-
// Handle valid event, ignore error
763-
if( ERROR_NONE == err)
761+
// Handle valid event
762+
if( NRF_SUCCESS == err)
764763
{
765764
Bluefruit._ble_handler( (ble_evt_t*) ev_buf );
765+
}else if ( NRF_ERROR_NOT_FOUND != err )
766+
{
767+
LOG_LV1("BLE", "SD event error %s", dbg_err_str(err));
766768
}
767769
}
768770
}

0 commit comments

Comments
 (0)