This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2340R5: UART callback implementation affecting pairing

Part Number: CC2340R5

Tool/software:

Hi,

In basic_ble OAD Peripheral project we are observing different behavior in pairing depending on the UART callback implementation.

Below are the two different implementations:

Observations:

With Implementation 1 : We are not getting passkey enter popup on remote device(mobile phone), Eventually pairing is failing every time and also we are not getting BLEAPPUTIL_PAIRING_STATE_COMPLETE event.

With Implementation 2 : Pairing is successful. 

We want to go with implementation 1 to handle UART exchange properly but failing at pairing, Kindly suggest solution.

SDK Version : simplelink_lowpower_f3_sdk_8_10_01_02 

CCS version: CCS 12.7.1

//Global variables
uint8_t uartReadBuffer[100] = {0};
uint8_t uartPacketSize = 0;



//Implemention 1:

void HandlingFunction(char *pData)
{
	uint8_t *pDataBase = NULL;
    pDataBase = pData;
    uint8_t len = *pData;
    pData++;
    UART2_write(uart, pDataBase,len+1, 0);
	UART2_read(uart, &uartReadBuffer, UART_MAX_READ_SIZE,0);
}

void UARTCallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
   
	uint8_t *idx = NULL;
	uint8_t *data = BLEAppUtil_malloc(count);
	idx = data;
	*idx = count;
	idx++;
	memcpy(idx, buffer, count);
	BLEAppUtil_invokeFunction(HandlingFunction, data);
	memset(uartReadBuffer,0,sizeof(uartReadBuffer));
}

//Implemention 2:

void HandlingFunction(char *pData)
{
	UART2_write(uart, uartReadBuffer,uartPacketSize, 0);
	memset(uartReadBuffer,0,sizeof(uartReadBuffer));
	UART2_read(uart, &uartReadBuffer, UART_MAX_READ_SIZE,0);
}

void UARTCallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
    uartPacketSize = count;
    BLEAppUtil_invokeFunction(HandlingFunction, NULL);
}

Thanks,

Vignesh.

  • Hi Vignesh, 

    Thanks for reaching out. 

    Looking into your code for implementation 1, for line 23 can you try to add +1 after count as below:

    uint8_t *data = BLEAppUtil_malloc(count+1);

    Let me know if this works. 

    Option 2: Can you also try to use the following for line 28 without any changes above: 

    BLEAppUtil_invokeFunctionNoData(HandlingFunction);

    This function receives a callback and data and switches the context in order to call the call back from the BLE App Util module context. Let me know if you still get errors?

    In addition, we also have an example for a complete UART over BLE example that you could look into: data stream UART over BLE example

    Regards

    Ivan