1、说明
基于SDK3.4,将BLE MTU由默认的23byte 更改为245 byte
2、操作
A.修改FIFO大小,在app.c中修改以下代码(#if 1部分为修改或者新增部分)
#if 0
#define RX_FIFO_SIZE 64
#define RX_FIFO_NUM 8
#define TX_FIFO_SIZE 40
#define TX_FIFO_NUM 16
#endif
#if 1
#define RX_FIFO_SIZE 272
#define RX_FIFO_NUM 8
#define TX_FIFO_SIZE 260
#define TX_FIFO_NUM 8
#endif
#if 1
MYFIFO_INIT(blt_rxfifo, RX_FIFO_SIZE, RX_FIFO_NUM);
#else
_attribute_data_retention_ u8 blt_rxfifo_b[RX_FIFO_SIZE * RX_FIFO_NUM] = {0};
_attribute_data_retention_ my_fifo_t blt_rxfifo = {
RX_FIFO_SIZE,
RX_FIFO_NUM,
0,
0,
blt_rxfifo_b,};
#endif
#if 1
MYFIFO_INIT(blt_txfifo, TX_FIFO_SIZE, TX_FIFO_NUM);
#else
_attribute_data_retention_ u8 blt_txfifo_b[TX_FIFO_SIZE * TX_FIFO_NUM] = {0};
_attribute_data_retention_ my_fifo_t blt_txfifo = {
TX_FIFO_SIZE,
TX_FIFO_NUM,
0,
0,
blt_txfifo_b,};
#endif
#if 1
void MG_task_DLE(u8 e, u8 *p, int n)
{
//ll_data_extension_t data;
#if 1
u16 Rx_len,Tx_len,my_Rx_len,my_Tx_len,remote_Rx_len,remote_Tx_len;
u8 my_buf[245];
u8 i=0;
for(i=0; i<245; i++)
{
my_buf[i] = i;
}
Rx_len = p[0]|p[1];
Tx_len = p[2]|p[3];
my_Rx_len = p[4]|p[5];
my_Tx_len = p[6]|p[7];
remote_Rx_len = p[8]|p[9];
remote_Tx_len = p[10]|p[11];
printf("DLE->Rx_len is : %d\r\n",Rx_len);
printf("DLE->Tx_len is : %d\r\n",Tx_len);
printf("DLE->my_Rx_len is : %d\r\n",my_Rx_len);
printf("DLE->my_Tx_len is : %d\r\n",my_Tx_len);
printf("DLE->remote_Rx_len is : %d\r\n",remote_Rx_len);
printf("DLE->remote_Tx_len is : %d\r\n",remote_Tx_len);
bls_att_pushNotifyData(MG_TMHR_OUTPUT_DP_H,my_buf,245);
#endif
}
#endif
B.在app.c的user_init_normal中添加以下测试代码
//MG add
//Data Length Extension
#if 1
ble_sts_t MTU_Result;
MTU_Result = blc_att_setRxMtuSize(248);
printf("The MTU_Result is :%d\r\n",MTU_Result);
bls_app_registerEventCallback (BLT_EV_FLAG_DATA_LENGTH_EXCHANGE, &MG_task_DLE);
#endif
3、现象
打开手机APP(TTC),右上角选择 Large MTU,连接成功后右下角MTU填入248,点击更新,此时手机APP会收到245 byte的数据(0~244),且可以看到串口打印的消息