Part Number: CC2564MODN
Hi,
My customer uses STM32 + CC2564MODN (SPP profile)
The application works fine - connection with PC and data transfer goes as expected.
Application logic needs to switch the CC2564MODN off and in somw time restarts it (when next data will be ready).
The problem: BT Stack hangs when application tries to restart the module.
Problem description and what has been done:
First BT Stack launching consists of:
startBtWork(); (it starts InitializeApplication() and OpenStack(HCI_DriverInformation).
In the later function:
BTPS_Init ; (to create mutex kernel)
BSC_Initialize(HCI_DriverInformation, 0); (to create additional 4 mutex, 3 tasks, 4 event objects and 1 binary semaphore)
Switching the Stack off done in the following way:
CloseCurrentServer(); // set ServerPortID = 0
HCITR_COMClose(1);
CloseStack();
// inside CloseStack():
- BSC_Shutdown(); // during execution I see in debugger: deleting of 2 mutex and one event (used inside Stack)
- BTPS_DeInit(); // I tried to clean the tasks in code but it not helps. It is empty function at the moment
turnOff3_1B(); // Power sitching off (switch off 3.1 V; 1.8 V is ON permanently)
I see that my switching Stack off does not delete:
- tasksm which were created during module initialization (excerpt for BT1 task - used in UART)
- mutex semphores
- event objects
I tried to delete above objects manually, but repeated Stack restart fails any way. Hangs occurs in BSC_Initialize, where called my function to power module ON and then I do just pause vTaskDelay(100 / portTICK_PERIOD_MS); Programm cannot returns from vTaskDelay code.
//==============================================================================
/* The following function is responsible for closing the SS1 */
/* Bluetooth Protocol Stack. This function requires that the */
/* Bluetooth Protocol stack previously have been initialized via the */
/* OpenStack() function. This function returns zero on successful */
/* execution and a negative value on all errors. */
int CloseStack(void)
{ // from InitializeApplication() and OpenStack()
int ret_val = 0;
/* First check to see if the Stack has been opened. */
if(BluetoothStackID)
{
/* Simply close the Stack */
BSC_Shutdown(BluetoothStackID);
vTaskDelay(1000 / portTICK_PERIOD_MS); // test
/* Free BTPSKRNL allocated memory. */
BTPS_DeInit();
vTaskDelay(1000 / portTICK_PERIOD_MS); // test
Display(("Stack Shutdown.\r\n")); // because MessageOutputCallback = NULL -- it is not working
/* Flag that the Stack is no longer initialized. */
BluetoothStackID = 0;
/* Flag success to the caller. */
ret_val = 0;
//saveParamDataToFlash(); // 2016 08
}
else
{
/* A valid Stack ID does not exist, inform to user. */
ret_val = UNABLE_TO_INITIALIZE_STACK;
}
return(ret_val);
}
//==============================================================================
/* The following function is responsible for opening the HCI */
/* Transport layer that will be used by Bluetopia to send and receive*/
/* COM (Serial) data. This function must be successfully issued in */
/* order for Bluetopia to function. This function accepts as its */
/* parameter the HCI COM Transport COM Information that is to be used*/
/* to open the port. The final two parameters specify the HCI */
/* Transport Data Callback and Callback Parameter (respectively) that*/
/* is to be called when data is received from the UART. A successful*/
/* call to this function will return a non-zero, positive value which*/
/* specifies the HCITransportID that is used with the remaining */
/* transport functions in this module. This function returns a */
/* negative return value to signify an error. */
int BTPSAPI HCITR_COMOpen(HCI_COMMDriverInformation_t *COMMDriverInformation, HCITR_COMDataCallback_t COMDataCallback, unsigned long CallbackParameter)
{
int ret_val;
/* First, make sure that the port is not already open and make sure */
/* that valid COMM Driver Information was specified. */
if((!HCITransportOpen) && (COMMDriverInformation) && (COMDataCallback))
{
/* Initialize the return value for success. */
ret_val = TRANSPORT_ID;
/* Flag that the HCI Transport is open. */
HCITransportOpen = 1;
/* Initialize the context structure. */
clrUartContext(FALSE); // BTPS_MemInitialize(&UartContext, 0, sizeof(UartContext_t));
UartContext.COMDataCallbackFunction = COMDataCallback;
UartContext.COMDataCallbackParameter = CallbackParameter;
UartContext.TxBytesFree = OUTPUT_BUFFER_SIZE;
UartContext.RxBytesFree = INPUT_BUFFER_SIZE;
UartContext.SuspendState = hssNormal;
/* Create the event that will be used to signal data has arrived. */
vSemaphoreCreateBinary(UartContext.DataReceivedEvent);
if(UartContext.DataReceivedEvent)
{
/* Make sure that the event is in the reset state. */
xSemaphoreTake(UartContext.DataReceivedEvent, 1);
/* Create a thread that will process the received data. */
UartContext.ReceiveThreadHandle = BTPS_CreateThread(RxThread, 1600, NULL);
if(!UartContext.ReceiveThreadHandle)
{
/* Failed to start the thread, delete the semaphore. */
vQueueDelete(UartContext.DataReceivedEvent);
ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT;
HCITransportOpen = 0;
}
}
else
{
ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT;
HCITransportOpen = 0;
}
/* If there was no error, then continue to setup the port. */
if(ret_val != HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT)
{
btIsReset(); // nSHUTD_Pin == 0
turnOn_BT(); // MX_LPUART1_UART_Init(VENDOR_DEFAULT_BAUDRATE)
if(statusWorkCode != SuccessRezult)
{
ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT;
waitStopReceiveTask();
}
}
else
{
waitStopReceiveTask();
}
}
else
{
ret_val = HCITR_ERROR_UNABLE_TO_OPEN_TRANSPORT;
}
return(ret_val);
}
//==============================================================================
/* The following function is responsible for closing the specific HCI*/
/* Transport layer that was opened via a successful call to the */
/* HCITR_COMOpen() function (specified by the first parameter). */
/* Bluetopia makes a call to this function whenever an either */
/* Bluetopia is closed, or an error occurs during initialization and */
/* the driver has been opened (and ONLY in this case). Once this */
/* function completes, the transport layer that was closed will no */
/* longer process received data until the transport layer is */
/* Re-Opened by calling the HCITR_COMOpen() function. */
/* * NOTE * This function *MUST* close the specified COM Port. This */
/* module will then call the registered COM Data Callback */
/* function with zero as the data length and NULL as the */
/* data pointer. This will signify to the HCI Driver that */
/* this module is completely finished with the port and */
/* information and (more importantly) that NO further data */
/* callbacks will be issued. In other words the very last */
/* data callback that is issued from this module *MUST* be a*/
/* data callback specifying zero and NULL for the data */
/* length and data buffer (respectively). */
void BTPSAPI HCITR_COMClose(unsigned int HCITransportID)
{
HCITR_COMDataCallback_t COMDataCallback;
HAL_NVIC_DisableIRQ(HCITR_UART_IRQ); // LPUART1_IRQn
/* Appears to be valid, go ahead and close the port. */
__HAL_UART_DISABLE_IT(&hlpuart1, UART_IT_RXNE);
__HAL_UART_DISABLE_IT(&hlpuart1, UART_IT_TXE);
/* Place the Bluetooth Device in Reset. */
btIsReset();
// maybe add uart is off
/* Check to make sure that the specified Transport ID is valid. */
if((HCITransportID == TRANSPORT_ID) && (HCITransportOpen))
{
/* Flag that the HCI Transport is no longer open. */
HCITransportOpen = 0; // while(HCITransportOpen) UartContext.ReceiveThreadHandle = NULL;
waitStopReceiveTask();
/* Note the Callback information. */
COMDataCallback = UartContext.COMDataCallbackFunction;
UartContext.COMDataCallbackFunction = NULL;
/* All finished, perform the callback to let the upper layer know */
/* that this module will no longer issue data callbacks and is */
/* completely cleaned up. */
if(COMDataCallback)
(*COMDataCallback)(HCITransportID, 0, NULL, UartContext.COMDataCallbackParameter);
UartContext.COMDataCallbackParameter = 0;
}
HAL_UART_DeInit(&hlpuart1);
}