前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >qt串口通信接收数据不完整_qt串口接收数据

qt串口通信接收数据不完整_qt串口接收数据

作者头像
全栈程序员站长
发布2022-11-07 15:41:47
发布2022-11-07 15:41:47
3.5K00
代码可运行
举报
运行总次数:0
代码可运行

高通QM215 高速串口调试总结

参考文档

1、sp80-pk881-6_a_qm215_linux_android_software_porting_manual.pdf 2、80-pk881-21_a_qm215_linux_peripheral_(uart,_spi,_i2c)_overview.pdf 3、80-ne436-1_j_bam_low-speed_peripherals_for_linux_kernel_configuration_and_debugging_guide.pdf

硬件和复用情况确认

首先确认要使用的UART号,得到其使用的TX,RX,TXS,RXS,并查看是否被复用为其他功能引脚,如SPI、SIM等等 以QM215 UART6为例,其用到的引脚如下,使用到了gpio20,gpio21,gpio22,gpio23,且查看设备树,发现并未被复用为其他功能.

修改如下

1、 msm-4.9/arch/arm64/boot/dts/qcom/msm8917-pinctrl.dtsi

代码语言:javascript
代码运行次数:0
运行
复制
//配置 gpio20 gpio21 gpio22 gpio23 功能为uart
blsp2_uart2 { 
//uart6
blsp2_uart2_active: blsp2_uart2_active { 

mux { 

pins = "gpio20", "gpio21","gpio22", "gpio23";
function = "blsp_uart6";
};
config { 

pins = "gpio20", "gpio21","gpio22", "gpio23";
drive-strength = <2>;
bias-disable;
};
};
blsp2_uart2_sleep: blsp2_uart2_sleep { 

mux { 

pins = "gpio20", "gpio21","gpio22", "gpio23";
function = "blsp_uart6";
};
config { 

pins = "gpio20", "gpio21","gpio22", "gpio23";
drive-strength = <2>;
bias-disable;
};
};
};

2、msm-4.9/arch/arm64/boot/dts/qcom/msm8917.dtsi

代码语言:javascript
代码运行次数:0
运行
复制
//配置uart6为高速串口
blsp2_uart2: uart@7af0000 { 

compatible = "qcom,msm-hsuart-v14";
reg = <0x7af0000 0x200>,
<0x7ac4000  0x1f000>;
reg-names = "core_mem", "bam_mem";
interrupt-names = "core_irq", "bam_irq", "wakeup_irq";
#address-cells = <0>;
interrupt-parent = <&blsp2_uart2>;
interrupts = <0 1 2>;
#interrupt-cells = <1>;
interrupt-map-mask = <0xffffffff>;
interrupt-map = <0 &intc 0 307 0
1 &intc 0 239 0
2 &tlmm 21 0>;
qcom,inject-rx-on-wakeup;
qcom,rx-char-to-inject = <0xfd>;
qcom,bam-tx-ep-pipe-index = <2>;
qcom,bam-rx-ep-pipe-index = <3>;
qcom,master-id = <84>;
clock-names = "core_clk", "iface_clk";
clocks = <&clock_gcc clk_gcc_blsp2_uart2_apps_clk>,
<&clock_gcc clk_gcc_blsp2_ahb_clk>;
pinctrl-names = "sleep", "default";
pinctrl-0 = <&blsp2_uart2_sleep>;
pinctrl-1 = <&blsp2_uart2_active>;
qcom,msm-bus,name = "blsp2_uart2";
qcom,msm-bus,num-cases = <2>;
qcom,msm-bus,num-paths = <1>;
qcom,msm-bus,vectors-KBps =
<84 512 0 0>,
<84 512 500 800>;
};
//配置uart6为低速串口
blsp2_uart2: serial@7af0000 { 
//uart6
compatible = "qcom,msm-uartdm-v1.4",
"qcom,msm-uartdm";
reg = <0x7af0000 0x200>;
interrupts = <0 307 0>;
clocks = <&clock_gcc clk_gcc_blsp2_uart2_apps_clk>,
<&clock_gcc clk_gcc_blsp2_ahb_clk>;
clock-names = "core", "iface";
status = "disabled";
};

3、 msm-4.9/arch/arm64/boot/dts/qcom/qm215-qrd.dtsi

代码语言:javascript
代码运行次数:0
运行
复制
//使能UART6
&blsp2_uart2 { 

status = "ok";
pinctrl-names = "default", "sleep";
pinctrl-0 = <&blsp2_uart2_active>;
pinctrl-1 = <&blsp2_uart2_sleep>;
};

串口调试

编译并烧写成功,在dev目录下查看uart6是否生成. 高速串口:ttyHS* 低速串口:ttyMSM*

测试程序代码:

代码语言:javascript
代码运行次数:0
运行
复制
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<termios.h>
#include<strings.h>
int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)
{ 

struct termios newtio,oldtio;
if( tcgetattr( fd,&oldtio)  !=  0) { 

perror("tcgetattr error");
return -1;
}
bzero( &newtio, sizeof( newtio ) );
newtio.c_cflag  |=  CLOCAL | CREAD; 
newtio.c_cflag &= ~CSIZE; 
switch( nBits )
{ 

case 7:
newtio.c_cflag |= CS7;
break;
case 8:
newtio.c_cflag |= CS8;
break;
}
switch( nEvent )
{ 

case 'O':
newtio.c_cflag |= PARENB; 
newtio.c_cflag |= PARODD;  
newtio.c_iflag |= (INPCK | ISTRIP); 
break;
case 'E':
newtio.c_iflag |= (INPCK | ISTRIP);
newtio.c_cflag |= PARENB;
newtio.c_cflag &= ~PARODD;
break;
case 'N': 
newtio.c_cflag &= ~PARENB;
break;
}
switch( nSpeed )
{ 

case 2400:
cfsetispeed(&newtio, B2400);
cfsetospeed(&newtio, B2400);
break;
case 4800:
cfsetispeed(&newtio, B4800);
cfsetospeed(&newtio, B4800);
break;
case 9600:
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
break;
case 115200:
cfsetispeed(&newtio, B115200);
cfsetospeed(&newtio, B115200);
break;
case 460800:
cfsetispeed(&newtio, B460800);
cfsetospeed(&newtio, B460800);
break;
case 500000:
cfsetispeed(&newtio, B500000);
cfsetospeed(&newtio, B500000);
break; 
case 576000:
cfsetispeed(&newtio, B576000);
cfsetospeed(&newtio, B576000);
break; 
case 921600:
cfsetispeed(&newtio, B921600);
cfsetospeed(&newtio, B921600);
break;   
case 1000000:
cfsetispeed(&newtio, B1000000);
cfsetospeed(&newtio, B1000000);
break; 
case 1152000:
cfsetispeed(&newtio, B1152000);
cfsetospeed(&newtio, B1152000);
break;
default:
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
break;
}
if( nStop == 1){ 

newtio.c_cflag &=  ~CSTOPB; 
}else if ( nStop == 2 ){ 

newtio.c_cflag |=  CSTOPB;
} 
newtio.c_cc[VTIME]  = 0;
newtio.c_cc[VMIN] = 0;
tcflush(fd,TCIFLUSH); 
if((tcsetattr(fd,TCSANOW,&newtio))!=0)
{ 

perror("set error");
return -1;
}
return 0;
}
int main(int argc,char *argv[])
{ 

int fd,ret_set,ret_read,ret;
char buf_read[1024];
char buf_write[1024];
char tty[20]="/dev/";
if(3 < argc)
{ 

strcat(tty,argv[1]);
fd = open(tty, O_RDWR);
if(fd == -1)
{ 

printf("Open %s failed! Exit!\n",tty);
exit(1);
}
printf("open %s successfully!\n",tty);
ret_set = set_opt(fd, atoi(argv[2]), 8, 'N', 1);
if (ret_set == -1)
{ 

printf("Set %s failed! Exit!\n",tty);
exit(1);
}
printf("Set %s successfully!\n",tty);
printf("Baud rate: %s\n",argv[2]);
memset(buf_write, 0, sizeof(buf_write));	
memcpy(buf_write,argv[3],sizeof(buf_write));
buf_write[99] = '\n';
printf("Data: %s, size: %lu\n",buf_write,strlen(buf_write));		
while (1)
{ 
 
memset(buf_read, 0, sizeof(buf_read));
ret = write(fd, buf_write, strlen(buf_write)+1);
if( ret > 0){ 

printf("Write data: %s\n",buf_write);
}else{ 

printf("Write data failed! Exit!\n");
exit(1);
}
ret_read = read(fd, buf_read, 100);
if(ret_read > 0){ 

printf("Read data: %s\n\n", buf_read);
}
sleep(3);
}
close(fd);
}else{ 

printf("Usage: uart [tty node] [baud rate] [data] [data size < 1024]\n");
printf("Sample: uart ttyHSL1 115200 test\n");
}
return 0;
}

短接TX和RX,运行测试程序,得到以下结果,uart调试成功

将串口设置为高速串口,AP端收到的数据一直为0XFD

将串口设置为高速串口,与电脑通信,则AP端收到的数据一直为0XFD(原因不明),修改msm-4.9/drivers/tty/serial/msm_serial_hs.c如下,接收发送皆正常.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/183632.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年10月10日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 高通QM215 高速串口调试总结
  • 参考文档
    • 硬件和复用情况确认
    • 修改如下
    • 串口调试
    • 测试程序代码:
    • 将串口设置为高速串口,AP端收到的数据一直为0XFD
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档