Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页

    设置T113串口波特率为1M

    MR Series
    2
    3
    2575
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      linsen LV 7 last edited by

      用UART5非标准波率通信,波特率设置为1M,应用程序中串口配置如下:

      	//open uart
      	fd = open("/dev/ttyS5", O_RDWR);
      	if (fd < 0)
      	{
      		printf("open failed\n");
      		return -1;
      	}
      
      	/*set baudrate*/
      	tcgetattr(fd, &options);
      	cfsetispeed(&options, B1000000);
      	cfsetospeed(&options, B1000000);
      	options.c_cflag |= (CLOCAL | CREAD);
      
      	/*set databits*/
      	options.c_cflag &= ~CSIZE;
      	options.c_cflag |= CS8;
      
      	/*set crc*/
      	options.c_cflag &= ~PARENB;
      	options.c_cflag &= ~CSTOPB;
      
      	/*set stopbits*/
      	options.c_cflag &= ~CSTOPB; 
      
      	/*set parity*/
      	options.c_cflag &= ~PARENB;
      
      	options.c_lflag  &= ~(ICANON | ECHO | ECHOE | ISIG);  
      	options.c_oflag  &= ~OPOST;  
      
      	options.c_cc[VTIME] = 0;
      	options.c_cc[VMIN] = 0;
      

      系统启动后,启动应用程序,发现报如下错误:

      [  241.774864] sw_uart_check_baudset()837 - uart5, select set 5, baud 1000000, uartclk 24000000 beyond rance[31000000, 120000000]
      

      发现串口的时钟源为24MHZ,不支持该波特率设置,于是查看Linux_UART_开发指南.pdf,查找波特率的修改方法,具体可以查看该开发指南,这里贴出修改方法。

      修改设备树,修改串口的时钟源
      /lichee/linux-5.4/arch/arm/boot/dts/sun8iw20p1.dtsi

      uart5: uart@2501400 {
      	compatible = "allwinner,sun8i-uart";
      	device_type = "uart5";
      	reg = <0x0 0x02501400 0x0 0x400>;
      	interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
      	sunxi,uart-fifosize = <256>;
      	clocks = <&ccu CLK_BUS_UART5>;
      	clock-names = "uart5";
      	resets = <&ccu RST_BUS_UART5>;
      	uart5_port = <5>;
      	uart5_type = <2>;
      	status = "disabled";
      };
      

      编译,烧录,启动发现终端乱码,这里把终端串口的时钟源也进行修改

      uart0: uart@2500000 {
      	compatible = "allwinner,sun8i-uart";
      	device_type = "uart0";
      	reg = <0x0 0x02500000 0x0 0x400>;
      	interrupts = <GIC_SPI 2 IRQ_TYPE_LEVEL_HIGH>;
      	sunxi,uart-fifosize = <64>;
      	clocks = <&ccu CLK_BUS_UART0>,<&ccu CLK_APB1>,<&ccu CLK_PSI_AHB>;
      	clock-frequency = <50000000>;
      	clock-names = "uart0";
      	resets = <&ccu RST_BUS_UART0>;
      	uart0_port = <0>;
      	uart0_type = <2>;
      	status = "disabled";
      };
      
      

      再次,烧录,启动,运行程序,进行数据收发测试
      708e2491-bae3-49f1-8bb7-1619e7a7c8ba-image.png

      L 1 Reply Last reply Reply Quote Share 1
      • L
        linsen LV 7 @lansecd last edited by

        @lansecd 在 设置T113串口波特率为1M 中说:

        uart5: uart@2501400 {
        compatible = "allwinner,sun8i-uart";
        device_type = "uart5";
        reg = <0x0 0x02501400 0x0 0x400>;
        interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
        sunxi,uart-fifosize = <256>;
        clocks = <&ccu CLK_BUS_UART5>;
        clock-names = "uart5";
        resets = <&ccu RST_BUS_UART5>;
        uart5_port = <5>;
        uart5_type = <2>;
        status = "disabled";
        };

        uart5: uart@2501400 {
        	compatible = "allwinner,sun8i-uart";
        	device_type = "uart5";
        	reg = <0x0 0x02501400 0x0 0x400>;
        	interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
        	sunxi,uart-fifosize = <256>;
        	clocks = <&ccu CLK_BUS_UART5>,<&ccu CLK_APB1>,<&ccu CLK_PSI_AHB>;
                clock-frequency = <50000000>;
        	clock-names = "uart5";
        	resets = <&ccu RST_BUS_UART5>;
        	uart5_port = <5>;
        	uart5_type = <2>;
        	status = "disabled";
        };
        
        1 Reply Last reply Reply Quote Share 0
        • E
          Eason LV 3 last edited by

          你好,我修改时钟为50m后,发现twi工作不正常了,我应该怎么去修改。

          1 Reply Last reply Reply Quote Share 0
          • 1 / 1
          • First post
            Last post

          Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

          行为准则 | 用户协议 | 隐私权政策