I am having problems with the uart flow control (using RTS/CTS) in my application that is based on the Ti ble5_simple_serial_socket_server_cc2640r2lp example.
I have a separate processor that sends data through the BLE to an Android device, but my application is not transmitting all of the data - particularly the last few bytes of the message gets missed. I can see the data being send on a scope and can see the RTS pin being raised periodically and the processor responding to this and stops sending data until RTS is lowered again.
The only changes I have made to the example are - extra pin definitions, UUIDs, advertData and scanRspData to match my Android app. and obviously assigning the .ctsPin and .rtsPin in UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[]. I am also controlling two other IO pins to signal that a connection has been made and the stream is open (in the GAP_LINK_ESTABLISHED_EVENT and GAP_LINK_TERMINATED_EVENT and also in SimpleStreamServer_cccUpdateCB() )
To help debugging, I set a hardware pin in SimpleSerialSocketServer_processAppMsg for the OUTGOING_DATA event and cleared it again after the uart data has been passed to SimpleStreamServer_sendData(). This signals that the uart data has been read correctly. Code snippet follows for this part (basically the same as the example with just the test pin added)
static void SimpleSerialSocketServer_processAppMsg(ssssEvt_t *pMsg)
{
switch (pMsg->hdr.event)
{
// Outgoing data event
case SSSS_OUTGOING_DATA:
{
// You could do processing of data here ...
PIN_setOutputValue(ledPinHandle, Board_TEST_IO_11, 1); // This is the UART_RD test pin
// For now, just Send the data read from UART over the air
bStatus_t status = SimpleStreamServer_sendData(connHandle, &uartReadBuffer, pMsg->arg0);
// If status is not successful, register for connection events for further processing
if (status != SUCCESS) {
SimpleSerialSocketServer_RegisterToAllConnectionEvent(FOR_STREAM);
}
PIN_setOutputValue(ledPinHandle, Board_TEST_IO_11, 0);
// Start another read
UART_read(uartHandle, uartReadBuffer, UART_MAX_READ_SIZE);
break;
}
..
..
..
This all works as expected but although the data is being read by the uart, it seems that the very last few bytes are not passed into the output queue.
I am thinking that SimpleStreamServer_sendData() fails on SimpleStreamServer_allocateWithHeadroom(), and as there are no further uart messages, the uart read is never retried so so the data is not passed to SimpleStreamServer_sendData() again. Is this likely?
I am also curious how the uart hardware flow control works in these circumstances. I would have thought that if there is no space in the queue, the uart flow control would prevent the external processor sending more data.
I have attached a couple of scope traces. The first trace is the complete message (requested by the Android) and the second is a zoom of just the last part. You can see the RTS line does it job and also the uart is being read after the last few bytes. (TX1, RTS, CONN_UP, STRM and UART_RD are outputs from the cc2640r2. RX1 and CTS which are outputs from the external processor)