“Linux内核-蓝牙驱动移植”的版本间的差异
(→实验平台) |
(→实验步骤) |
||
第182行: | 第182行: | ||
==实验步骤== | ==实验步骤== | ||
+ | *开启32.768Hz时钟。<br> | ||
+ | |||
+ | 修改arch/arm/dts/stm32mp15xx-fsmp1x.dts文件中的rtc节点添加如下内容: | ||
+ | |||
+ | <div style="background-color:#F8F8F8;border:1px solid #E5E5E5;font-family: monospace,Courier;"> | ||
+ | :rtc {<br> | ||
+ | <font color="#FF0000"> | ||
+ | :: st,lsco = <RTC_OUT2_RMP>; | ||
+ | :: pinctrl-0 = <&rtc_out2_rmp_pins_a>; | ||
+ | :: pinctrl-names = "default"; | ||
+ | </font> | ||
+ | :: status = "okay"; | ||
+ | :}; | ||
+ | </div> | ||
+ | 其中红色字体部分为要添加的内容。<br> | ||
+ | |||
+ | 添加rtc相关头文件。 | ||
+ | #include <dt-bindings/rtc/rtc-stm32.h> | ||
+ | *添加usart3配置<br> | ||
+ | |||
+ | 修改arch/arm/dts/stm32mp15xx-fsmp1x.dts文件,在文件末尾添加如下内容: | ||
+ | <pre><nowiki> | ||
+ | &usart3 { | ||
+ | pinctrl-names = "default", "sleep", "idle"; | ||
+ | pinctrl-0 = <&usart3_pins_bt>; | ||
+ | pinctrl-1 = <&usart3_idle_pins_bt>; | ||
+ | pinctrl-2 = <&usart3_sleep_pins_bt>; | ||
+ | uart-has-rtscts; | ||
+ | status = "okay"; | ||
+ | |||
+ | bluetooth { | ||
+ | pinctrl-names = "default"; | ||
+ | pinctrl-0 = <&btreg0>; | ||
+ | compatible = "brcm,bcm43438-bt"; | ||
+ | max-speed = <3000000>; | ||
+ | vbat-supply = <&v3v3>; | ||
+ | vddio-supply = <&v3v3>; | ||
+ | }; | ||
+ | }; | ||
+ | </nowiki></pre> | ||
+ | *修改串口名称映射关系<br> | ||
+ | |||
+ | 修改arch/arm/dts/stm32mp157a-fsmp1a.dts文件,在aliases节点中添加如下内容: | ||
+ | <div style="background-color:#F8F8F8;border:1px solid #E5E5E5;font-family: monospace,Courier;"> | ||
+ | :aliases{<br> | ||
+ | :: serial0 = &uart4; | ||
+ | <font color="#FF0000"> | ||
+ | :: serial5 = &usart3; | ||
+ | </font> | ||
+ | :}; | ||
+ | </div> | ||
+ | 其中红色字体部分为要添加的内容。<br> | ||
+ | |||
+ | *配置内核<br> | ||
+ | |||
+ | 由于内核源码默认配置以及支持AP62xx,本节列出主要选项,如下: | ||
+ | <pre><nowiki> | ||
+ | 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 | ||
+ | </nowiki></pre> | ||
+ | *编译内核及设备树 | ||
+ | linux@ubuntu:$ make -j4 uImage dtbs LOADADDR=0xC2000040 | ||
+ | *重启测试<br> | ||
+ | |||
+ | 将编译好的设备树和内核镜像拷贝到/tftpboot目录下,通过tftp引导内核,系统启动后查看/lib/firmware/brcm目录下是否包含BCM.hcd固件,如果没有发现这个文件可从【华清远见-FS_MP1A开发资料\02-程序源码\04-Linux系统移植\04-移植相关文件\02-Linux内核移植\AP6236固件】下拷贝到/lib/firmware/brcm目录下。<br> | ||
+ | |||
+ | 开启蓝牙设备 | ||
+ | root@fsmp1a:# hciconfig hci0 up | ||
+ | 查看设备地址 | ||
+ | root@fsmp1a:# hcitool dev | ||
+ | 扫描蓝牙设备 | ||
+ | root@fsmp1a:# hcitool scan | ||
+ | [[Image:59-1-4-1.png]] <br> |
2020年7月28日 (二) 15:12的版本
实验原理
FS-MP1A开发板蓝牙采用AP6236,WIFI蓝牙二合一芯片。蓝牙部分通过usart3与SoC进行数据交互。
蓝牙部分移需要配置usart3的设备树与AP_CK32KO管脚,可参考stm32mp157c-dk2.dts中的相关配置。
查看原理图得出AP6236数据管脚与STM32MP157A的管脚对应关系如下:
原理图网络编号 | 对应管脚 | 管脚功能 | 管脚功能码 |
---|---|---|---|
BT_UART_TX | PD8 | USART3_TX | AF7 |
BT_UART_RX | PD9 | USART3_RX | AF7 |
BT_UART_CTS | PD11 | USART3_CTS | AF7 |
BT_UART_RTS | PD12 | USART3_RTS | AF7 |
BT_WIFI_RST | PD13 | IO | ANALOG |
AP_CK32KO | PI8 | RTC_OUT2 | ANALOG |
- WiFi设备树节点
参考文档:
Documentation/devicetree/bindings/net/broadcom-bluetooth.txt Documentation/devicetree/bindings/serial/st,stm32-usart.txt
内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见:
arch/arm/boot/dts/stm32mp151.dtsi
stm32mp151中usart3定义如下:
usart3: serial@4000f000 { compatible = "st,stm32h7-uart"; reg = <0x4000f000 0x400>; interrupts-extended = <&exti 28 IRQ_TYPE_LEVEL_HIGH>; clocks = <&rcc USART3_K>; resets = <&rcc USART3_R>; wakeup-source; power-domains = <&pd_core>; dmas = <&dmamux1 45 0x400 0x5>, <&dmamux1 46 0x400 0x1>; dma-names = "rx", "tx"; status = "disabled"; };
上述代码只对usart3做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。
参考文档或stm32mp157f-dk2.dts对于usart2设备节点的描述,增加usart3内容如下:
&usart3 { pinctrl-names = "default", "sleep", "idle"; pinctrl-0 = <&usart3_pins_bt>; pinctrl-1 = <&usart3_idle_pins_bt>; pinctrl-2 = <&usart3_sleep_pins_bt>; uart-has-rtscts; status = "okay"; bluetooth { pinctrl-names = "default"; pinctrl-0 = <&btreg0>; compatible = "brcm,bcm43438-bt"; max-speed = <3000000>; vbat-supply = <&v3v3>; vddio-supply = <&v3v3>; }; };
这里用到了一个btreg0管脚用于控制AP6236蓝牙模块的硬件复位,stm32mp15-pinctrl.dtsi没有对于btreg0管脚的描述,需要增加如下内容描述:
btreg0: bt_reg_on-0 { pins { pinmux = <STM32_PINMUX('D', 13, GPIO)>; drive-push-pull; bias-pull-up; output-high; slew-rate = <0>; }; };
同时stm32mp15-pinctrl.dtsi对于usart3的描述与FS-MP1A所使用管脚不一致,所以无法直接使用,需参考其增加如下内容:
usart3_pins_bt: usart3-bt-0 { pins1 { pinmux = <STM32_PINMUX('D', 8, AF7)>, /* USART3_TX */ <STM32_PINMUX('D', 12, AF7)>; /* USART3_RTS */ bias-disable; drive-push-pull; slew-rate = <0>; }; pins2 { pinmux = <STM32_PINMUX('D', 9, AF7)>, /* USART3_RX */ <STM32_PINMUX('D', 11, AF7)>; /* USART3_CTS_NSS */ bias-disable; }; }; usart3_idle_pins_bt: usart3-idle-bt-0 { pins1 { pinmux = <STM32_PINMUX('D', 8, ANALOG)>, /* USART3_TX */ <STM32_PINMUX('D', 12, ANALOG)>, /* USART3_RTS */ <STM32_PINMUX('D', 11, ANALOG)>; /* USART3_CTS_NSS */ }; pins2 { pinmux = <STM32_PINMUX('D', 9, AF7)>; /* USART3_RX */ bias-disable; }; }; usart3_sleep_pins_bt: usart3-sleep-bt-0 { pins { pinmux = <STM32_PINMUX('D', 8, ANALOG)>, /* USART3_TX */ <STM32_PINMUX('D', 12, ANALOG)>, /* USART3_RTS */ <STM32_PINMUX('D', 11, ANALOG)>, /* USART3_CTS_NSS */ <STM32_PINMUX('D', 9, ANALOG)>; /* USART3_RX */ }; };
- RTC节点
AP6236需要使用一个外部输入的32.768Hz的时钟源,因此我们需要使能RTC的外部32.768Hz功能
参考文档:
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做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。
参考stm32mp157f-dk2.dts对于rtc设备节点的描述,需增加内容如下:
rtc { st,lsco = <RTC_OUT2_RMP>; pinctrl-0 = <&rtc_out2_rmp_pins_a>; pinctrl-names = "default"; status = "okay"; };
实验目的
熟悉基于Linux操作系统下的蓝牙设备驱动移植配置过程。
实验平台
华清远见开发环境,FS-MP1A平台;
实验步骤
- 开启32.768Hz时钟。
修改arch/arm/dts/stm32mp15xx-fsmp1x.dts文件中的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>
- 添加usart3配置
修改arch/arm/dts/stm32mp15xx-fsmp1x.dts文件,在文件末尾添加如下内容:
&usart3 { pinctrl-names = "default", "sleep", "idle"; pinctrl-0 = <&usart3_pins_bt>; pinctrl-1 = <&usart3_idle_pins_bt>; pinctrl-2 = <&usart3_sleep_pins_bt>; uart-has-rtscts; status = "okay"; bluetooth { pinctrl-names = "default"; pinctrl-0 = <&btreg0>; compatible = "brcm,bcm43438-bt"; max-speed = <3000000>; vbat-supply = <&v3v3>; vddio-supply = <&v3v3>; }; };
- 修改串口名称映射关系
修改arch/arm/dts/stm32mp157a-fsmp1a.dts文件,在aliases节点中添加如下内容:
- aliases{
- serial0 = &uart4;
- serial5 = &usart3;
- };
其中红色字体部分为要添加的内容。
- 配置内核
由于内核源码默认配置以及支持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
- 编译内核及设备树
linux@ubuntu:$ make -j4 uImage dtbs LOADADDR=0xC2000040
- 重启测试
将编译好的设备树和内核镜像拷贝到/tftpboot目录下,通过tftp引导内核,系统启动后查看/lib/firmware/brcm目录下是否包含BCM.hcd固件,如果没有发现这个文件可从【华清远见-FS_MP1A开发资料\02-程序源码\04-Linux系统移植\04-移植相关文件\02-Linux内核移植\AP6236固件】下拷贝到/lib/firmware/brcm目录下。
开启蓝牙设备
root@fsmp1a:# hciconfig hci0 up
查看设备地址
root@fsmp1a:# hcitool dev
扫描蓝牙设备
root@fsmp1a:# hcitool scan