I am developing a ble application based on the wireless uart freertos demo of the sdk_2.x_frdm kw 36 sdk. version 2.2.5.
I am trying to create a new task and a queue as described in the following document.
After the task creation, the method call to Init the ble host stack returns gBleOsError_c.
if (Ble_Initialize(App_GenericCallback) != gBleSuccess_c)
{
panic(0,0,0,0);
return;
}
Disabling the newly created task makes the code initialize the host stack.
Further debugging shows that task creation mHost_TaskId = OSA_TaskCreate(OSA_TASK(Host_Task), NULL); fails in ble_host_tasks.c as mHost_TaskId is returned null.
Any help will be appreciated.
Thanks in advance
Solved! Go to Solution.
The problem was the serial baudrate.Changing the baudrate to 230400 in
wireless_uart.c BleApp_Init() as follows solved the problem.
(void)Serial_SetBaudRate(gAppSerMgrIf, (uint32_t)gUARTBaudRate230400_c);
The problem was the serial baudrate.Changing the baudrate to 230400 in
wireless_uart.c BleApp_Init() as follows solved the problem.
(void)Serial_SetBaudRate(gAppSerMgrIf, (uint32_t)gUARTBaudRate230400_c);
Hi again,
I previously marked your answer as solution but as I proceeded I figured out that reducing the stack size for the newly created task did not solve my problem.
So I cancelled creating a new task.To explain briefly ,I get messages form android phone and try to send back particular responses through ble.
I receive data without any problem. I process the data form a response stream and send it as follows.
void SendMessage(uint8_t * pMsg,uint16_t msgLen){
uint8_t *pBuffer = NULL;
/* Allocate buffer for asynchronous write */
pBuffer = MEM_BufferAlloc(msgLen);
if (pBuffer != NULL)
{
FLib_MemCpy(pBuffer , pMsg, (uint32_t)msgLen);
(void)Serial_AsyncWrite(gAppSerMgrIf, pBuffer, msgLen, Uart_RxCallBack, pBuffer);
}
}
Here are my callback functions
void Uart_RxCallBack(void *pData)
{
uint16_t byteCount = 0;
(void)Serial_RxBufferByteCount(gAppSerMgrIf, &byteCount);
if (byteCount < mAppUartBufferSize)
{
/* Restart flush timer */
(void)TMR_StartLowPowerTimer(mUartStreamFlushTimerId,
gTmrLowPowerSingleShotMillisTimer_c,
mAppUartFlushIntervalInMs_c,
UartStreamFlushTimerCallback, NULL);
}
else
{
/* Post App Msg only one at a time */
if (!mAppDapaPending)
{
mAppDapaPending = TRUE;
(void)App_PostCallbackMessage(BleApp_FlushUartStream, NULL);
}
}
}
static void UartStreamFlushTimerCallback(void *pData)
{
if (!mAppDapaPending)
{
mAppDapaPending = TRUE;
(void)App_PostCallbackMessage(BleApp_FlushUartStream, NULL);
}
}
static void BleApp_FlushUartStream(void *pParam)
{
uint8_t *pMsg = NULL;
uint16_t bytesRead = 0;
uint8_t mPeerId = 0;
bool_t mValidDevices = FALSE;
/* Valid devices are in Running state */
for (mPeerId = 0; mPeerId < (uint8_t)gAppMaxConnections_c; mPeerId++)
{
if ((gInvalidDeviceId_c != maPeerInformation[mPeerId].deviceId) &&
(mAppRunning_c == maPeerInformation[mPeerId].appState))
{
mValidDevices = TRUE;
break;
}
}
if (mValidDevices)
{
/* Allocate buffer for GATT Write */
pMsg = MEM_BufferAlloc(mAppUartBufferSize);
if (pMsg != NULL)
{
/* Collect the data from the serial manager buffer */
if (Serial_Read(gAppSerMgrIf, pMsg, mAppUartBufferSize, &bytesRead) == gSerial_Success_c)
{
if (bytesRead != 0U)
{
/* Send data over the air */
BleApp_SendUartStream(pMsg, (uint8_t)bytesRead);
}
}
/* Free Buffer */
(void)MEM_BufferFree(pMsg);
}
}
mAppDapaPending = FALSE;
}
I simply send "pong" as an indicator of established ble link. I see first two letters of the pong message as "po" on serial terminal and immediately get
a hard fault.
These are my stack szie definitons
#define gHost_TaskStackSize_c 1200
#define gControllerTaskStackSize_c 1200
/* Defines Size for Serial Manager Task*/
#define gSerialTaskStackSize_c 500
/* Defines Size for TMR Task*/
#define gTmrTaskStackSize_c 600
I have been messing with nearly all available stack size combinations with no success.
Nay help will be appreciated.
Thanks
default host task stack size ( gHost_TaskStackSize_c in ble_host_task.h file) was 1500.reducing it solved the problem.
Thank you very much.
Thanks for the fast reponse.I will check and inform about the result.
Hi,
I guess the stack you allocate for the task is too large. Reduce it. If not, please debug into the function OSA_TaskCreate to make sense of why it returns NULL.
Have a great day,
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------