Linux内核-Wi-Fi驱动移植

来自华清远见研发中心
FarSight讨论 | 贡献2021年3月22日 (一) 09:20的版本 实验步骤

跳转至: 导航搜索

实验原理

FS-MP1A开发板蓝牙采用AP6236,WIFI蓝牙二合一芯片。WiFi部分通过SDIO接口与SoC进行数据交互。

59-1-1-1.png

在FS-MP1A开发板上sdmmc1用于连接sdcard,sdmmc2用于连接eMMC,sdmmc3则用于连接我们这里所用到的AP6236的WiFi接口。

sdmmc3的设备树配置可参考stm32mp157c-dk2.dts中的相关配置,需要重新调整sdmmc3所使用的管脚,AP_CK32KO管脚配置和BT_WIFI_RST管脚配置。

60-1-1-2.png 60-1-1-3.png

60-1-1-4.png 59-1-1-3.png

查看原理图得出AP6236数据管脚与STM32MP157A的管脚对应关系如下:

原理图网络编号 对应管脚 管脚功能 管脚功能码
SD3_DATA0 PF0 SDMMC3_D0 AF9
SD3_DATA1 PF4 SDMMC3_D1 AF9
SD3_DATA2 PD5 SDMMC3_D2 AF10
SD3_DATA3 PD7 SDMMC3_D3 AF10
SD3_CMD PD0 SDMMC3_CMD AF10
SD3_CLK PG15 SDMMC3_CK AF10
WL_REG_ON PD4 IO ANALOG
AP_CK32KO PI8 RTC_OUT2 ANALOG
  1. WiFi设备树节点
  2. 参考文档:

    Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
    Documentation/devicetree/bindings/mmc/mmc.txt
    

    内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见:

    arch/arm/boot/dts/stm32mp151.dtsi
    

    stm32mp151中sdmmc3定义如下:

    sdmmc3: sdmmc@48004000 {
        compatible = "arm,pl18x", "arm,primecell";
        arm,primecell-periphid = <0x00253180>;
        reg = <0x48004000 0x400>, <0x48005000 0x400>;
        interrupts = <GIC_SPI 137 IRQ_TYPE_LEVEL_HIGH>;
        interrupt-names = "cmd_irq";
        clocks = <&rcc SDMMC3_K>;
        clock-names = "apb_pclk";
        resets = <&rcc SDMMC3_R>;
        cap-sd-highspeed;
        cap-mmc-highspeed;
        max-frequency = <120000000>;
        status = "disabled";
    };
    
    

    上述代码只对sdmmc3做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。

    参考文档或stm32mp157c-dk2.dts对于sdmmc2设备节点的描述,增加sdmmc3内容如下:

    &sdmmc3 {
        arm,primecell-periphid = <0x10153180>;
        pinctrl-names = "default", "opendrain", "sleep";
        pinctrl-0 = <&sdmmc3_b4_wifi_pins_a>;
        pinctrl-1 = <&sdmmc3_b4_od_wifi_pins_a>;
        pinctrl-2 = <&sdmmc3_b4_sleep_wifi_pins_a>;
        non-removable;
        st,neg-edge;
        bus-width = <4>;
        vmmc-supply = <&v3v3>;
        mmc-pwrseq = <&wifi_pwrseq>;
        #address-cells = <1>;
        #size-cells = <0>;
        keep-power-in-suspend;
        status = "okay";
    
        brcmf: bcrmf@1 {
            reg = <1>;
            compatible = "brcm,bcm4329-fmac";
        };
    };
    
    

    这里用到了一个mmc-pwrseq管脚用于控制AP6236的电源,可以stm32mp157c-dk2.dts对于wifi_pwrseq设备节点的描述,增加wifi_pwrseq内容如下:

    wifi_pwrseq: wifi-pwrseq {
        compatible = "mmc-pwrseq-simple";
        reset-gpios = <&gpiod 4 GPIO_ACTIVE_LOW>;
    };
    
    

    stm32mp15-pinctrl.dtsi对于sdmmc3的描述与FS-MP1A所使用管脚不一致,所以无法直接使用,需参考其增加如下内容:

    sdmmc3_b4_wifi_pins_a: sdmmc3-b4-wifi-0 {
        pins1 {
            pinmux = <STM32_PINMUX('F', 0, AF9)>, /* SDMMC3_D0 */
                 <STM32_PINMUX('F', 4, AF9)>, /* SDMMC3_D1 */
                 <STM32_PINMUX('D', 5, AF10)>, /* SDMMC3_D2 */
                 <STM32_PINMUX('D', 7, AF10)>, /* SDMMC3_D3 */
                 <STM32_PINMUX('D', 0, AF10)>; /* SDMMC3_CMD */
            slew-rate = <1>;
            drive-push-pull;
            bias-pull-up;
        };
        pins2 {
            pinmux = <STM32_PINMUX('G', 15, AF10)>; /* SDMMC3_CK */
            slew-rate = <2>;
            drive-push-pull;
            bias-pull-up;
        };
    };
    
    sdmmc3_b4_od_wifi_pins_a: sdmmc3-b4-od-wifi-0 {
        pins1 {
            pinmux = <STM32_PINMUX('F', 0, AF9)>, /* SDMMC3_D0 */
                 <STM32_PINMUX('F', 4, AF9)>, /* SDMMC3_D1 */
                 <STM32_PINMUX('D', 5, AF10)>, /* SDMMC3_D2 */
                 <STM32_PINMUX('D', 7, AF10)>; /* SDMMC3_D3 */
            slew-rate = <1>;
            drive-push-pull;
            bias-pull-up;
        };
        pins2 {
            pinmux = <STM32_PINMUX('G', 15, AF10)>; /* SDMMC3_CK */
            slew-rate = <2>;
            drive-push-pull;
            bias-pull-up;
        };
        pins3 {
            pinmux = <STM32_PINMUX('D', 0, AF10)>; /* SDMMC2_CMD */
            slew-rate = <1>;
            drive-open-drain;
            bias-pull-up;
        };
    };
    
    sdmmc3_b4_sleep_wifi_pins_a: sdmmc3-b4-sleep-wifi-0 {
        pins {
            pinmux = <STM32_PINMUX('F', 0, ANALOG)>, /* SDMMC3_D0 */
                 <STM32_PINMUX('F', 4, ANALOG)>, /* SDMMC3_D1 */
                 <STM32_PINMUX('D', 5, ANALOG)>, /* SDMMC3_D2 */
                 <STM32_PINMUX('D', 7, ANALOG)>, /* SDMMC3_D3 */
                 <STM32_PINMUX('G', 15, ANALOG)>, /* SDMMC3_CK */
                 <STM32_PINMUX('D', 0, ANALOG)>; /* SDMMC3_CMD */
        };
    };
    
    
  3. RTC节点
  4. AP6236需要使用一个外部输入的32.768KHz的时钟源,因此我们需要使能RTC的外部32.768KHz功能

    参考文档:

    Documentation/devicetree/bindings/rtc/st,stm32-rtc.txt
    

    内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见:

    arch/arm/boot/dts/stm32mp151.dtsi
    

    stm32mp151中rtc定义如下:

    rtc: rtc@5c004000 {
        compatible = "st,stm32mp1-rtc";
        reg = <0x5c004000 0x400>;
        clocks = <&scmi0_clk CK_SCMI0_RTCAPB>,
             <&scmi0_clk CK_SCMI0_RTC>;
        clock-names = "pclk", "rtc_ck";
        interrupts-extended = <&exti 19 IRQ_TYPE_LEVEL_HIGH>;
        status = "disabled";
    };
    
    

    上述代码只对rtc做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。

    参考stm32mp157c-dk2.dts对于rtc设备节点的描述,需增加内容如下:

    rtc {
     	  st,lsco = <RTC_OUT2_RMP>;
     	  pinctrl-0 = <&rtc_out2_rmp_pins_a>;
     	  pinctrl-names = "default";
       status = "okay";
    };
    

实验目的

熟悉基于Linux操作系统下的WiFi设备驱动移植配置过程。

实验平台

华清远见开发环境,FS-MP1A平台;

实验步骤

  1. 导入交叉编译工具链
  2. linux@ubuntu:$ source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    

    由于WiFi部分与蓝牙部分共用1路RTC时钟,有些操作与蓝牙要修改的内容相同,因此如果之前已经做过了蓝牙的移植,则这些部分不需要再重复修改。

  3. 增加设备树文件
  4. 修改arch/arm/dts/stm32mp15xx-fsmp1x.dtsi文件,在文件末尾添加如下内容:

    &sdmmc3 {
        arm,primecell-periphid = <0x10153180>;
        pinctrl-names = "default", "opendrain", "sleep";
        pinctrl-0 = <&sdmmc3_b4_wifi_pins_a>;
        pinctrl-1 = <&sdmmc3_b4_od_wifi_pins_a>;
        pinctrl-2 = <&sdmmc3_b4_sleep_wifi_pins_a>;
        non-removable;
        st,neg-edge;
        bus-width = <4>;
        vmmc-supply = <&v3v3>;
        mmc-pwrseq = <&wifi_pwrseq>;
        #address-cells = <1>;
        #size-cells = <0>;
        keep-power-in-suspend;
        status = "okay";
    
        brcmf: bcrmf@1 {
            reg = <1>;
            compatible = "brcm,bcm4329-fmac";
        };
    };
    
    
  5. 添加pwrseq管脚配置
  6. 修改arch/arm/dts/stm32mp15xx-fsmp1x.dtsi文件,在根节点末尾下添加如下内容:

    wifi_pwrseq: wifi-pwrseq {
        compatible = "mmc-pwrseq-simple";
        reset-gpios = <&gpiod 4 GPIO_ACTIVE_LOW>;
    };
    
    
  7. 添加功能管脚配置
  8. 要添加管脚配置需要有pinctrl节点,如果之前已经做了MIPI LCD移植或者RGB LCD则在arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件下找到pinctrl节点添加如下配置,如果之前没有做MIPI LCD移植或者RGB LCD那么需要新建一个pinctrl节点,然后添加如下配置。

    &pinctrl {
    	... ...
    	sdmmc3_b4_wifi_pins_a: sdmmc3-b4-wifi-0 {
    		pins1 {
    			pinmux = <STM32_PINMUX('F', 0, AF9)>, /* SDMMC3_D0 */
    				 <STM32_PINMUX('F', 4, AF9)>, /* SDMMC3_D1 */
    				 <STM32_PINMUX('D', 5, AF10)>, /* SDMMC3_D2 */
    				 <STM32_PINMUX('D', 7, AF10)>, /* SDMMC3_D3 */
    				 <STM32_PINMUX('D', 0, AF10)>; /* SDMMC3_CMD */
    			slew-rate = <1>;
    			drive-push-pull;
    			bias-pull-up;
    		};
    		pins2 {
    			pinmux = <STM32_PINMUX('G', 15, AF10)>; /* SDMMC3_CK */
    			slew-rate = <2>;
    			drive-push-pull;
    			bias-pull-up;
    		};
    	};
    
    	sdmmc3_b4_od_wifi_pins_a: sdmmc3-b4-od-wifi-0 {
    		pins1 {
    			pinmux = <STM32_PINMUX('F', 0, AF9)>, /* SDMMC3_D0 */
    				 <STM32_PINMUX('F', 4, AF9)>, /* SDMMC3_D1 */
    				 <STM32_PINMUX('D', 5, AF10)>, /* SDMMC3_D2 */
    				 <STM32_PINMUX('D', 7, AF10)>; /* SDMMC3_D3 */
    			slew-rate = <1>;
    			drive-push-pull;
    			bias-pull-up;
    		};
    		pins2 {
    			pinmux = <STM32_PINMUX('G', 15, AF10)>; /* SDMMC3_CK */
    			slew-rate = <2>;
    			drive-push-pull;
    			bias-pull-up;
    		};
    		pins3 {
    			pinmux = <STM32_PINMUX('D', 0, AF10)>; /* SDMMC2_CMD */
    			slew-rate = <1>;
    			drive-open-drain;
    			bias-pull-up;
    		};
    	};
    
    	sdmmc3_b4_sleep_wifi_pins_a: sdmmc3-b4-sleep-wifi-0 {
    		pins {
    			pinmux = <STM32_PINMUX('F', 0, ANALOG)>, /* SDMMC3_D0 */
    				 <STM32_PINMUX('F', 4, ANALOG)>, /* SDMMC3_D1 */
    				 <STM32_PINMUX('D', 5, ANALOG)>, /* SDMMC3_D2 */
    				 <STM32_PINMUX('D', 7, ANALOG)>, /* SDMMC3_D3 */
    				 <STM32_PINMUX('G', 15, ANALOG)>, /* SDMMC3_CK */
    				 <STM32_PINMUX('D', 0, ANALOG)>; /* SDMMC3_CMD */
    		};
    	};
    	... ...
    };
    
    
  9. 开启32.768Hz时钟
  10. 如果之前已经做过了蓝牙的移植,则这部分不需要再重复修改。

    修改arch/arm/dts/stm32mp15xx-fsmp1x.dtsi文件中的rtc节点添加如下内容:

    rtc {

    st,lsco = <RTC_OUT2_RMP>;
    pinctrl-0 = <&rtc_out2_rmp_pins_a>;
    pinctrl-names = "default";

    status = "okay";
    };

    其中红色字体部分为要添加的内容。

    添加rtc相关头文件。如果之前已经做过了蓝牙的移植,则这部分不需要再重复修改。

    #include <dt-bindings/rtc/rtc-stm32.h>
    
  11. 修改启动选项
  12. 在系统中加入了sdmmc3的配置选项,导致系统中eMMC的设备号发生了改变,系统在启动过程中找不到原来的eMMC设备会导致启动失败。我们可以通过修改ubuntu主机中的/tftpboot/pxelinux.cfg/01-00-80-e1-42-60-17文件配置来解决这个问题。

    # Generic Distro Configuration file generated by OpenEmbedded menu title Select the boot mode MENU BACKGROUND /splash.bmp TIMEOUT 20 DEFAULT stm32mp157a-fsmp1a-emmc LABEL stm32mp157a-fsmp1a-emmc

    KERNEL /uImage
    FDT /stm32mp157a-fsmp1a.dtb
    APPEND root=/dev/mmcblk2p4 rootwait rw console=ttySTM0,115200

    LABEL stm32mp157a-fsmp1a-mipi050-emmc

    KERNEL /uImage
    FDT /stm32mp157a-fsmp1a-mipi050.dtb
    APPEND root=/dev/mmcblk2p4 rootwait rw ::console=ttySTM0,115200

    LABEL stm32mp157a-fsmp1a-rgb070-emmc

    KERNEL /uImage
    FDT /stm32mp157a-fsmp1a-rgb070.dtb
    APPEND root=/dev/mmcblk2p4 rootwait rw console=ttySTM0,115200
  13. 配置内核
  14. 由于内核源码默认配置以及支持AP62xx,本节列出主要选项,如下:

    linux@ubuntu:$ make menuconfig
    Device Drivers  --->
    	<*> Broadcom specific AMBA  --->
    		[*]   Support for BCMA in a SoC
    		[*]   ChipCommon-attached serial flash support
    		[*]   BCMA Broadcom GBIT MAC COMMON core driver
    		[*]   BCMA GPIO driver
    
  15. 编译内核及设备树
  16. linux@ubuntu:$ make -j4 uImage dtbs LOADADDR=0xC2000040
    
  17. 重启测试
  18. 将编译好的设备树和内核镜像拷贝到/tftpboot目录下,通过tftp引导内核,系统启动后查看/lib/firmware/brcm目录下是否包含brcmfmac43430-sdio.bin和brcmfmac43430-sdio.st,stm32mp157a-dk1.txt两个固件,如果没有发现这两个文件可从【华清远见-FS-MP1A开发资料\02-程序源码\04-Linux系统移植\04-移植相关文件\02-Linux内核移植\AP6236固件】下拷贝到/lib/firmware/brcm目录下。

    使用wpa_passphrase工具生成WiFi的配置文件。运行该命令之后需要输入wifi的连接密码。

    root@fsmp1a:# wpa_passphrase "你的WiFi SSID" > wifi.conf
    

    连接WiFi

    root@fsmp1a:# wpa_supplicant -B -c wifi.conf -i wlan0
    

    配置WiFi网络

    root@fsmp1a:# udhcpc -i wlan0
    root@fsmp1a:# echo "nameserver 114.114.114.114" > /etc/resolv.conf
    root@fsmp1a:# echo "nameserver 8.8.8.8" >> /etc/resolv.conf
    root@fsmp1a:# ping -c 4 www.baidu.com
    

    60-1-4-1.png