Skip to content

Commit 1780864

Browse files
committed
Make stacks bigger to match usage
This fix a crash in the GUI thread as it's stack was to low. This will also start printing the stack usage in the 5min-update. Signed-off-by: Zingo Andersen <zingo@zingo.org>
1 parent f6a8ba6 commit 1780864

5 files changed

Lines changed: 49 additions & 24 deletions

File tree

include/common.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ extern ESP32Time rtc;
2121
extern uint32_t raceStartIn;
2222
extern bool raceOngoing;
2323

24+
#define TASK_BT_PRIO 20
25+
#define TASK_RACEDB_PRIO 10
26+
#define TASK_GUI_PRIO 5
27+
28+
// Stack size in words, not bytes.
29+
#define TASK_BT_STACK (4*1024)
30+
#define TASK_RACEDB_STACK (8*1024)
31+
#define TASK_GUI_STACK (32*1024)
32+
33+
34+
extern TaskHandle_t xHandleBT;
35+
extern TaskHandle_t xHandleRaceDB;
36+
extern TaskHandle_t xHandleGUI;
37+
2438
// Broadcast...() - Don't touch data, just send messages, can be used from any context
2539
void BroadcastRaceClear();
2640
void BroadcastRaceStart(time_t raceStartTime);

src/bluetooth.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void vTaskBTConnect( void *pvParameters )
206206
/* The parameter value is expected to be 1 as 1 is passed in the
207207
pvParameters value in the call to xTaskCreate() below.
208208
*/
209-
configASSERT( ( ( uint32_t ) pvParameters ) == 1 );
209+
//configASSERT( ( ( uint32_t ) pvParameters ) == 1 );
210210

211211
BLEScan* pBLEScan;
212212
ESP_LOGI(TAG,"BLEDevice init");
@@ -284,15 +284,14 @@ void initBluetooth()
284284
{
285285
// Start BT Task (scan and inital connect&config)
286286
BaseType_t xReturned;
287-
TaskHandle_t xHandle = NULL;
288287
/* Create the task, storing the handle. */
289288
xReturned = xTaskCreate(
290289
vTaskBTConnect, /* Function that implements the task. */
291290
"BTConnect", /* Text name for the task. */
292-
4096, /* Stack size in words, not bytes. */
293-
( void * ) 1, /* Parameter passed into the task. */
294-
20, /* Priority 0-(configMAX_PRIORITIES-1) idle = 0 = tskIDLE_PRIORITY*/
295-
&xHandle ); /* Used to pass out the created task's handle. */
291+
TASK_BT_STACK, /* Stack size in words, not bytes. */
292+
NULL, /* Parameter passed into the task. */
293+
TASK_BT_PRIO, /* Priority 0-(configMAX_PRIORITIES-1) idle = 0 = tskIDLE_PRIORITY*/
294+
&xHandleBT ); /* Used to pass out the created task's handle. */
296295

297296
if( xReturned != pdPASS )
298297
{

src/gui.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static void taEdit_event_cb(lv_event_t * e)
273273

274274
// Name updated -> send update signal to RaceDB, and update signal will be send back
275275
// that will resync name in all tabs.
276-
if(code == LV_EVENT_READY || code == LV_EVENT_DEFOCUSED)
276+
if(code == LV_EVENT_READY || code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL)
277277
{
278278
uint32_t color0 = lv_color_to32(lv_obj_get_style_bg_color(guiParticipants[handleGFX].ledColor0, LV_PART_MAIN));
279279
uint32_t color1 = lv_color_to32(lv_obj_get_style_bg_color(guiParticipants[handleGFX].ledColor1, LV_PART_MAIN));
@@ -1513,7 +1513,7 @@ void vTaskLVGL( void *pvParameters )
15131513
/* The parameter value is expected to be 2 as 2 is passed in the
15141514
pvParameters value in the call to xTaskCreate() below.
15151515
*/
1516-
configASSERT( ( ( uint32_t ) pvParameters ) == 2 );
1516+
//configASSERT( ( ( uint32_t ) pvParameters ) == 2 );
15171517

15181518
ESP_LOGI(TAG, "Setup GFX");
15191519
gfx->begin();
@@ -1594,15 +1594,15 @@ void initLVGL()
15941594
{
15951595
// Start LVGL Task
15961596
BaseType_t xReturned;
1597-
TaskHandle_t xHandle = NULL;
1597+
15981598
/* Create the task, storing the handle. */
15991599
xReturned = xTaskCreate(
16001600
vTaskLVGL, /* Function that implements the task. */
16011601
"GUI", /* Text name for the task. */
1602-
4096, /* Stack size in words, not bytes. */
1603-
( void * ) 2, /* Parameter passed into the task. */
1604-
5, /* Priority 0-(configMAX_PRIORITIES-1) idle = 0 = tskIDLE_PRIORITY*/
1605-
&xHandle ); /* Used to pass out the created task's handle. */
1602+
TASK_GUI_STACK, /* Stack size in words, not bytes. */
1603+
NULL, /* Parameter passed into the task. */
1604+
TASK_GUI_PRIO, /* Priority 0-(configMAX_PRIORITIES-1) idle = 0 = tskIDLE_PRIORITY*/
1605+
&xHandleGUI ); /* Used to pass out the created task's handle. */
16061606

16071607
if( xReturned != pdPASS )
16081608
{

src/iTag.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ void vTaskRaceDB( void *pvParameters )
869869
/* The parameter value is expected to be 2 as 2 is passed in the
870870
pvParameters value in the call to xTaskCreate() below.
871871
*/
872-
configASSERT( ( ( uint32_t ) pvParameters ) == 2 );
872+
//configASSERT( ( ( uint32_t ) pvParameters ) == 2 );
873873

874874
// Add all Participants in race to race page
875875
for(int handleDB=0; handleDB<ITAG_COUNT; handleDB++)
@@ -1006,8 +1006,8 @@ void vTaskRaceDB( void *pvParameters )
10061006
}
10071007
case MSG_ITAG_UPDATE_USER:
10081008
{
1009-
//ESP_LOGI(TAG,"Received: MSG_ITAG_UPDATE_USER MSG:0x%x handleDB:0x%08x handleGFX:0x%08x inRace:%d ? myinRace:%d",
1010-
// msg.UpdateParticipantRaceStatus.header.msgType, msg.UpdateParticipantRaceStatus.handleDB, msg.UpdateParticipantRaceStatus.handleGFX, msg.UpdateParticipantRaceStatus.inRace,iTags[handleDB].participant.getInRace());
1009+
ESP_LOGI(TAG,"Received: MSG_ITAG_UPDATE_USER MSG:0x%x handleDB:0x%08x handleGFX:0x%08x inRace:%d",
1010+
msg.UpdateParticipantRaceStatus.header.msgType, msg.UpdateParticipantRaceStatus.handleDB, msg.UpdateParticipantRaceStatus.handleGFX, msg.UpdateParticipantRaceStatus.inRace);
10111011

10121012
uint32_t handleDB = msg.UpdateParticipant.handleDB;
10131013
iTags[handleDB].participant.setHandleGFX(msg.UpdateParticipant.handleGFX, true);
@@ -1156,15 +1156,14 @@ void initRaceDB()
11561156
{
11571157
// Start iTag Task
11581158
BaseType_t xReturned;
1159-
TaskHandle_t xHandle = NULL;
11601159
/* Create the task, storing the handle. */
11611160
xReturned = xTaskCreate(
11621161
vTaskRaceDB, /* Function that implements the task. */
11631162
"RaceDB", /* Text name for the task. */
1164-
4096, /* Stack size in words, not bytes. */
1165-
( void * ) 2, /* Parameter passed into the task. */
1166-
5, /* Priority 0-(configMAX_PRIORITIES-1) idle = 0 = tskIDLE_PRIORITY*/
1167-
&xHandle ); /* Used to pass out the created task's handle. */
1163+
TASK_RACEDB_STACK, /* Stack size in words, not bytes. */
1164+
NULL, /* Parameter passed into the task. */
1165+
TASK_RACEDB_PRIO, /* Priority 0-(configMAX_PRIORITIES-1) idle = 0 = tskIDLE_PRIORITY*/
1166+
&xHandleRaceDB ); /* Used to pass out the created task's handle. */
11681167

11691168
if( xReturned != pdPASS )
11701169
{

src/main.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ uint32_t raceStartIn = 0;
3737
bool raceOngoing = false;
3838

3939

40-
QueueHandle_t queueRaceDB;
41-
QueueHandle_t queueBTConnect;
42-
QueueHandle_t queueGFX;
40+
QueueHandle_t queueBTConnect = NULL;
41+
QueueHandle_t queueRaceDB = NULL;
42+
QueueHandle_t queueGFX = NULL;
43+
44+
TaskHandle_t xHandleBT = NULL;
45+
TaskHandle_t xHandleRaceDB = NULL;
46+
TaskHandle_t xHandleGUI = NULL;
47+
4348

4449
void initMessageQueues()
4550
{
@@ -192,5 +197,13 @@ void loop()
192197
if ((lastTimeUpdate+5*60) <= now) { //one per 5 min
193198
lastTimeUpdate = now;
194199
showHeapInfo(); //Monitor heap to see if memory leaks
200+
ESP_LOGI(TAG,"Main used stack: %d",uxTaskGetStackHighWaterMark(nullptr));
201+
ESP_LOGI(TAG,"BT used stack: %d / %d",uxTaskGetStackHighWaterMark(xHandleBT),TASK_BT_STACK);
202+
//#if NIMBLE_CFG_CONTROLLER
203+
// ESP_LOGI(TAG,"BT ll used stack: %d",nimble_port_freertos_get_ll_hwm());
204+
//#endif
205+
// ESP_LOGI(TAG,"BT hs used stack: %d",nimble_port_freertos_get_hs_hwm());
206+
ESP_LOGI(TAG,"RaceDB used stack: %d / %d",uxTaskGetStackHighWaterMark(xHandleRaceDB),TASK_RACEDB_STACK);
207+
ESP_LOGI(TAG,"GUI used stack: %d / %d",uxTaskGetStackHighWaterMark(xHandleGUI),TASK_GUI_STACK);
195208
}
196209
}

0 commit comments

Comments
 (0)