central_uart example UART Rx can not receive all data sometimes

Hi,

NCS v2.4.3

nRF52DK (nRF52832)

Based on central_uart example, I extend MTU to 247 and UART_BUF_SIZE to 500,

and I send UART hex data from PC to DK with 61 bytes to test,

0001020304050607080910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758590a

I output log in uart_cb(), case UART_RX_RDY:

	case UART_RX_RDY:
		LOG_DBG("UART_RX_RDY");
		buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
		buf->len += evt->data.rx.len;

		if (disable_req) {
			return;
		}

		if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
		    (evt->data.rx.buf[buf->len - 1] == '\r')) {

			disable_req = true;
			uart_rx_disable(uart);
		}

		else
		{
			LOG_INF("*** len = %d\n", buf->len);

			//Hexdump some data
    		LOG_HEXDUMP_INF(buf->data, buf->len, "UART Rx data"); 
		}
		break;

Sometime RX receive less than 61 bytes, like the following log:

00> [00:00:17.269,805] <inf> central_uart: *** len = 60
00> 
00> [00:00:17.269,836] <inf> central_uart: UART Rx data
00>                                        00 01 02 03 04 05 06 07  08 09 10 11 12 13 14 15 |........ ........
00>                                        16 17 18 19 20 21 22 23  24 25 26 27 28 29 30 31 |.... !"# $%&'()01
00>                                        32 33 34 35 36 37 38 39  40 41 42 43 44 45 46 47 |23456789 @ABCDEFG
00>                                        48 49 50 51 52 53 54 55  56 57 58 59             |HIPQRSTU VWXY    
00> [00:00:18.274,780] <inf> central_uart: *** len = 121
00> 
00> [00:00:18.274,810] <inf> central_uart: UART Rx data
00>                                        00 01 02 03 04 05 06 07  08 09 10 11 12 13 14 15 |........ ........
00>                                        16 17 18 19 20 21 22 23  24 25 26 27 28 29 30 31 |.... !"# $%&'()01
00>                                        32 33 34 35 36 37 38 39  40 41 42 43 44 45 46 47 |23456789 @ABCDEFG
00>                                        48 49 50 51 52 53 54 55  56 57 58 59 0a 00 01 02 |HIPQRSTU VWXY....
00>                                        03 04 05 06 07 08 09 10  11 12 13 14 15 16 17 18 |........ ........
00>                                        19 20 21 22 23 24 25 26  27 28 29 30 31 32 33 34 |. !"#$%& '()01234
00>                                        35 36 37 38 39 40 41 42  43 44 45 46 47 48 49 50 |56789@AB CDEFGHIP
00>                                        51 52 53 54 55 56 57 58  59                      |QRSTUVWX Y       
00> [00:00:19.272,094] <inf> central_uart: *** len = 181
00> 
00> [00:00:19.272,125] <inf> central_uart: UART Rx data
00>                                        00 01 02 03 04 05 06 07  08 09 10 11 12 13 14 15 |........ ........
00>                                        16 17 18 19 20 21 22 23  24 25 26 27 28 29 30 31 |.... !"# $%&'()01
00>                                        32 33 34 35 36 37 38 39  40 41 42 43 44 45 46 47 |23456789 @ABCDEFG
00>                                        48 49 50 51 52 53 54 55  56 57 58 59 0a 00 01 02 |HIPQRSTU VWXY....
00>                                        03 04 05 06 07 08 09 10  11 12 13 14 15 16 17 18 |........ ........
00>                                        19 20 21 22 23 24 25 26  27 28 29 30 31 32 33 34 |. !"#$%& '()01234
00>                                        35 36 37 38 39 40 41 42  43 44 45 46 47 48 49 50 |56789@AB CDEFGHIP
00>                                        51 52 53 54 55 56 57 58  59 0a 00 01 02 03 04 05 |QRSTUVWX Y.......
00>                                        06 07 08 09 10 11 12 13  14 15 16 17 18 19 20 21 |........ ...... !
00>                                        22 23 24 25 26 27 28 29  30 31 32 33 34 35 36 37 |"#$%&'() 01234567
00>                                        38 39 40 41 42 43 44 45  46 47 48 49 50 51 52 53 |89@ABCDE FGHIPQRS
00>                                        54 55 56 57 58                                   |TUVWX            

It receive just 60 bytes and not receive the last byte 0x0a.

How to improve UART Rx unstable condition?

Related