- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi BCM,
We find some info in the Community, which inform developper to to check thread and stack size in APP layer.
The lib DIR: /WICED-Smart-SDK/Wiced-Smart/tier2/brcm/libraries/inc/thread_and_mem_mgmt.h
My question is:
1. blecm_SetApplicationThreadStackSizeInWords() to get the stack size,
The callback functions in our APP layer, such as timer callback, connection up/down callback, gatt etc., all of these use this one Application thread ?
Eg. /// Default is 256 = 1024 byte stack and this is the minimum recommended.
if we define a temp buffer in gatt or callback function in APP layer, whose size is 1025B, Would it cause this thread stack overflow ?
Many thank...maxsong
Solved! Go to Solution.
- Labels:
-
MasterSlave
-
SDK 2.X
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don’t call blecm_StackCheckInit() in APPLICATION_INIT();
Call it in application create function, such as:
void hello_sensor_create(void)
{
BLEPROFILE_DB_PDU db_pdu;
extern UINT32 blecm_configFlag ;
blecm_configFlag |= BLECM_DBGUART_LOG | BLECM_DBGUART_LOG_L2CAP | BLECM_DBGUART_LOG_SMP;
blecm_StackCheckInit();
…
}
As said by declaration of the function:
Prepares the stack to allow the app to check for stack overflow.
For blecm_DidStackOverflow() to be used by the app, this (blecm_StackCheckInit)
must be called once in application_create function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
blecm_SetApplicationThreadStackSizeInWords() is to set the stack size,
The callback functions in our APP layer, such as timer callback, connection up/down callback, gatt etc., all of these use this one Application thread ?
Yes.
Eg. /// Default is 256 = 1024 byte stack and this is the minimum recommended.
if we define a temp buffer in gatt or callback function in APP layer, whose size is 1025B, Would it cause this thread stack overflow ?
Yes.
And don''t define a large buffer in callback functions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Max,
We test the thread stack size functions. and below is the result
1. Call blecm_StackCheckInit() in APPLICATION_INIT
2. call blecm_DidStackOverflow() in app_creat(void), and it returns 1, which means overflow
3. call blecm_DidStackOverflow() in gatt write callback function, and it still returns 1, which means overflow
4. we try to call blecm_SetApplicationThreadStackSizeInWords(4096/sizeof(unsigned)) in APPLICATION_INIT after blecm_StackCheckInit(), and retest the test2, test3. the result is the same, all are overflow.
But our APP runs well with this issue...
Do you have any suggestion about that ?
We would try to do this test in Hello sensor or other APPs for double confirm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Create a test program, reproduce this issue and update the test program here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Max,
We test this thread_and_mem_mgmt in WICED APP: hello_sensor
1. Includes:
#include "bleprofile.h"
#include "bleapp.h"
#include "gpiodriver.h"
#include "string.h"
#include "stdio.h"
#include "platform.h"
#include "hello_sensor.h"
#include "spar_utils.h"
#include "thread_and_mem_mgmt.h"
2. add blecm_StackCheckInit() in APPLICATION_INIT()
// Application initialization
APPLICATION_INIT()
{
bleapp_set_cfg((UINT8 *)hello_sensor_gatt_database,
sizeof(hello_sensor_gatt_database),
(void *)&hello_sensor_cfg,
(void *)&hello_sensor_puart_cfg,
(void *)&hello_sensor_gpio_cfg,
hello_sensor_create);
// By Leman
// It's only for test the thread_and_mem_mgmt.h
blecm_StackCheckInit();
// BLE_APP_DISABLE_TRACING(); ////// Uncomment to disable all tracing
}
3. trace out the stack size in hello_sensor_timeout() function
void hello_sensor_timeout(UINT32 arg)
{
ble_trace1("hello_sensor_timeout:%d\n", hello_sensor_timer_count);
// By Leman
// It's only for test the thread_and_mem_mgmt.h
ble_trace1("stack overflow ? : %d",(UINT32)blecm_DidStackOverflow());
switch(arg)
{
case BLEPROFILE_GENERIC_APP_TIMER:
{
hello_sensor_timer_count++;
}
break;
}
}
Here stack overflow function blecm_DidStackOverflow() return 1
tks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don’t call blecm_StackCheckInit() in APPLICATION_INIT();
Call it in application create function, such as:
void hello_sensor_create(void)
{
BLEPROFILE_DB_PDU db_pdu;
extern UINT32 blecm_configFlag ;
blecm_configFlag |= BLECM_DBGUART_LOG | BLECM_DBGUART_LOG_L2CAP | BLECM_DBGUART_LOG_SMP;
blecm_StackCheckInit();
…
}
As said by declaration of the function:
Prepares the stack to allow the app to check for stack overflow.
For blecm_DidStackOverflow() to be used by the app, this (blecm_StackCheckInit)
must be called once in application_create function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Max,
thanks for your info. we would test it.
Many tks...