瑞萨RZ/G2L串口SCI的使用(上)

描述

RZ/G2L串口简介

瑞萨RZ/G2L的串口简称SCI,全称Serial Communication Interface。

RZ/G2L有两种串口,一种带FIFO叫SCIFA,另一种不带FIFO叫SCIg。

串口

所以,RZ/G2L有5路SCIFA和2路SCIg总共7路的串口。

RZ/G2L串口驱动

包含驱动代码和设备树两部分:

内核中的驱动文件sh-sci.c

该源码文件路径:drivers/tty/serial/sh-sci.c,该驱动代码包含SCIFA和SCIg两种型号的完整驱动代码。

编译内核的时候需进行以下配置

左右滑动查看完整内容

 

egrep -rin "CONFIG_SERIAL_SH_SCI" .out/.config
2180:CONFIG_SERIAL_SH_SCI=y
2181:CONFIG_SERIAL_SH_SCI_NR_UARTS=18
2182:CONFIG_SERIAL_SH_SCI_CONSOLE=y
2183:CONFIG_SERIAL_SH_SCI_EARLYCON=y
2184:CONFIG_SERIAL_SH_SCI_DMA=y

 

该配置能够确保sh-sci.c的驱动代码能够被编译包含到Image中。

github上提供的内核源码的defconfig中默认已包含SCI驱动代码的编译。

SCI串口的设备树节点在r9a07g044.dtsi中定义,分别定义了scif0~4, sci0~1共7路。

左右滑动查看完整内容

 

    scif0: serial@1004b800 {
      compatible = "renesas,scif-r9a07g044";
      reg = <0 0x1004b800 0 0x400>;
      interrupts = ,
             ,
             ,
             ,
             ,
             ;
      interrupt-names = "eri", "rxi", "txi",
            "bri", "dri", "tei";
      clocks = <&cpg CPG_MOD R9A07G044_SCIF0_CLK_PCK>;
      clock-names = "fck";
      dmas = <&dmac 0x4e79>, <&dmac 0x4e7a>;
      dma-names = "tx", "rx";
      power-domains = <&cpg>;
      resets = <&cpg R9A07G044_SCIF0_RST_SYSTEM_N>;
      status = "disabled";
    };


    scif1: serial@1004bc00 {
      compatible = "renesas,scif-r9a07g044";
      reg = <0 0x1004bc00 0 0x400>;
      interrupts = ,
             ,
             ,
             ,
             ,
             ;
      interrupt-names = "eri", "rxi", "txi",
            "bri", "dri", "tei";
      clocks = <&cpg CPG_MOD R9A07G044_SCIF1_CLK_PCK>;
      clock-names = "fck";
      dmas = <&dmac 0x4e7d>, <&dmac 0x4e7e>;
      dma-names = "tx", "rx";
      power-domains = <&cpg>;
      resets = <&cpg R9A07G044_SCIF1_RST_SYSTEM_N>;
      status = "disabled";
    };


    scif2: serial@1004c000 {
      compatible = "renesas,scif-r9a07g044";
      reg = <0 0x1004c000 0 0x400>;
      interrupts = ,
             ,
             ,
             ,
             ,
             ;
      interrupt-names = "eri", "rxi", "txi",
            "bri", "dri", "tei";
      clocks = <&cpg CPG_MOD R9A07G044_SCIF2_CLK_PCK>;
      clock-names = "fck";
      dmas = <&dmac 0x4e81>, <&dmac 0x4e82>;
      dma-names = "tx", "rx";
      power-domains = <&cpg>;
      resets = <&cpg R9A07G044_SCIF2_RST_SYSTEM_N>;
      status = "disabled";
    };


    scif3: serial@1004c400 {
      compatible = "renesas,scif-r9a07g044";
      reg = <0 0x1004c400 0 0x400>;
      interrupts = ,
             ,
             ,
             ,
             ,
             ;
      interrupt-names = "eri", "rxi", "txi",
            "bri", "dri", "tei";
      clocks = <&cpg CPG_MOD R9A07G044_SCIF3_CLK_PCK>;
      clock-names = "fck";
      dmas = <&dmac 0x4e85>, <&dmac 0x4e86>;
      dma-names = "tx", "rx";
      power-domains = <&cpg>;
      resets = <&cpg R9A07G044_SCIF3_RST_SYSTEM_N>;
      status = "disabled";
    };


    scif4: serial@1004c800 {
      compatible = "renesas,scif-r9a07g044";
      reg = <0 0x1004c800 0 0x400>;
      interrupts = ,
             ,
             ,
             ,
             ,
             ;
      interrupt-names = "eri", "rxi", "txi",
            "bri", "dri", "tei";
      clocks = <&cpg CPG_MOD R9A07G044_SCIF4_CLK_PCK>;
      clock-names = "fck";
      dmas = <&dmac 0x4e89>, <&dmac 0x4e8a>;
      dma-names = "tx", "rx";
      power-domains = <&cpg>;
      resets = <&cpg R9A07G044_SCIF4_RST_SYSTEM_N>;
      status = "disabled";
    };


    sci0: serial@1004d000 {
      compatible = "renesas,r9a07g044-sci", "renesas,rz-sci";
      reg = <0 0x1004d000 0 0x400>;
      interrupts = ,
             ,
             ,
             ;
      interrupt-names = "eri", "rxi", "txi", "tei";
      clocks = <&cpg CPG_MOD R9A07G044_SCI0_CLKP>;
      clock-names = "fck";
      power-domains = <&cpg>;
      resets = <&cpg R9A07G044_SCI0_RST>;
      status = "disabled";
    };


    sci1: serial@1004d400 {
      compatible = "renesas,r9a07g044-sci", "renesas,rz-sci";
      reg = <0 0x1004d400 0 0x400>;
      interrupts = ,
             ,
             ,
             ;
      interrupt-names = "eri", "rxi", "txi", "tei";
      clocks = <&cpg CPG_MOD R9A07G044_SCI1_CLKP>;
      clock-names = "fck";
      power-domains = <&cpg>;
      resets = <&cpg R9A07G044_SCI1_RST>;
      status = "disabled";
    };

 

设备树文件路径

arch/arm64/boot/dts/renesas/r9a07g044.dtsi

根据项目需要,使能需要使用的设备节点,如欲使用SCIFA2:

左右滑动查看完整内容

 

&scif2 {
  pinctrl-0 = <&scif2_pins>;
  pinctrl-names = "default";
  uart-has-rtscts;
  status = "okay";
};

 

注意需通过scif2_pins正确处理IO口复用问题。如果不使用DMA需要将设备节点中的dmas和dma-names删除。

编译内核:

左右滑动查看完整内容

 

export ARCH=arm64
export CROSS_COMPILE=aarch64-none-elf-
export PATH=$PATH:/opt/arm/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf/bin
make defconfig O=.out && make -j8 O=.out

 

使用当前编译生成的内核Image和dtb

左右滑动查看完整内容

 

.out/arch/arm64/boot/Image 
.out/arch/arm64/boot/dts/renesas/r9a07g044l2-smarc.dtb

 

启动板子后就能在系统路径下生成/dev/ttySC2节点。

Linux应用层使用RZ/G2L的串口SCI

RZ/G2L的串口设备节点在Linux应用层遵循POSIX标准,使用方法和PC端的Ubuntu系统并无差别。

RZ/G2L除了支持市面上常用的串口波特率如9600/115200/921600等,实际上除POSIX系统定义的波特率都支持外,RZ/G2L能够支持的最大串口波特率是12.5Mbps,下一篇我们将介绍如何在内核驱动代码中实现RZ/G2L的最大波特率12.5Mbps

 

  审核编辑:汤梓红

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分