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 |
- 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操作系统下的蓝牙设备驱动移植配置过程。