Linux内核-蓝牙驱动移植
实验原理
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 |
- 蓝牙设备树节点
- RTC节点
参考文档:
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做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。
参考文档或stm32mp157c-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 { shutdown-gpios = <&gpiod 13 GPIO_ACTIVE_HIGH>; compatible = "brcm,bcm43438-bt"; max-speed = <3000000>; vbat-supply = <&v3v3>; vddio-supply = <&v3v3>; }; };
同时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 */ }; };
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做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。
参考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.768KHz时钟
- rtc {
- st,lsco = <RTC_OUT2_RMP>;
- pinctrl-0 = <&rtc_out2_rmp_pins_a>;
- pinctrl-names = "default";
- status = "okay";
- };
- 添加usart3配置
- 添加功能管脚配置
- &pinctrl {
- ... ...
- 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 */
- };
- };
- ... ...
- };
- 修改串口名称映射关系
- aliases{
- serial0 = &uart4;
- serial5 = &usart3;
- };
- 配置内核
- 编译内核及设备树
- 重启测试
linux@ubuntu:$ source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件中的rtc节点添加如下内容:
其中红色字体部分为要添加的内容。
添加rtc相关头文件。
#include <dt-bindings/rtc/rtc-stm32.h>
修改arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件,在文件末尾添加如下内容:
&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 { shutdown-gpios = <&gpiod 13 GPIO_ACTIVE_HIGH>; compatible = "brcm,bcm43438-bt"; max-speed = <3000000>; vbat-supply = <&v3v3>; vddio-supply = <&v3v3>; }; };
要添加管脚配置需要有pinctrl节点,如果之前已经做了MIPI LCD移植或者RGB LCD则在arch/arm/boot/dts/stm32mp15xx-fsmp1x.dtsi文件下找到pinctrl节点添加如下配置,如果之前没有做MIPI LCD移植或者RGB LCD那么需要新建一个pinctrl节点,然后添加如下配置。
修改arch/arm/dts/stm32mp157a-fsmp1a.dts文件,在aliases节点中添加如下内容:
其中红色字体部分为要添加的内容。
由于内核源码默认配置以及支持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