STM32MP157C-DK2->Develop on Arm® Cortex®-A7之 开启UART7串口功能

开启并测试STM32MP157C-DK2开发板上的uart7的收发功能。

根据en.MB1272-DK2-C01_Schematic可以得知STM32MP157C-DK2开发板的CN14的D0和D1为UART7的TX(gpio-pin:PE8)和RX(gpio-pin:PE7),连接也比较方便,CN14连接器信号定义:

STM32MP157C-DK2->Develop on Arm® Cortex®-A7之 开启UART7串口功能_第1张图片

开发板上实际的位置:

STM32MP157C-DK2->Develop on Arm® Cortex®-A7之 开启UART7串口功能_第2张图片

查看SDK的源码,drivers/tty/serial/Stm32-usart.h得知Serial在dev下的名称位ttySTM*,如ttySTM0,ttySTM1,代码如下所示:

STM32MP157C-DK2->Develop on Arm® Cortex®-A7之 开启UART7串口功能_第3张图片

通过终端命令查看开发板启动的串口,只有ttySTM0启动了:

root@stm32mp1:/# cd dev/
root@stm32mp1:/dev# dmesg | grep ttySTM*
[    0.000000] Kernel command line: root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200
[    0.517065] 40010000.serial: ttySTM0 at MMIO 0x40010000 (irq = 25, base_baud = 4000000) is a stm32-usart
[    1.453140] console [ttySTM0] enabled
[    4.290053] systemd[1]: Unnecessary job for dev-ttySTM0.device was removed.

可查看开发板的dts文件确定ttySTM0是对应的uart编号,查看../STM32MP15-Ecosystem-v1.1.0/Developer-Package/stm32mp1-openstlinux-4.19-thud-mp1-19-10-09/sources/arm-openstlinux_weston-linux-gnueabi/linux-stm32mp-4.19-r0/linux-4.19.49/arch/arm/boot/stm32mp157c-dk2.dts

// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
 * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
 * Author: Alexandre Torgue .
 */

/dts-v1/;

#include "stm32mp157a-dk1.dts"
#include 

/ {
	model = "STMicroelectronics STM32MP157C-DK2 Discovery Board";
	compatible = "st,stm32mp157c-dk2", "st,stm32mp157";

	aliases {
		serial3 = &usart2;
	};

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

代码里面只有关于Serial3的定义,将usart2定义为Serial3,用于蓝牙的串口通信。但是stm32mp157c-dk2.dts包含了"stm32mp157a-dk1.dts",查看../STM32MP15-Ecosystem-v1.1.0/Developer-Package/stm32mp1-openstlinux-4.19-thud-mp1-19-10-09/sources/arm-openstlinux_weston-linux-gnueabi/linux-stm32mp-4.19-r0/linux-4.19.49/arch/arm/boot/stm32mp157c-dk1.dts

// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
 * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
 * Author: Alexandre Torgue .
 */

/dts-v1/;

#include "stm32mp157c.dtsi"
#include "stm32mp157c-m4-srm.dtsi"
#include "stm32mp157cac-pinctrl.dtsi"
#include 
#include 

/ {
	model = "STMicroelectronics STM32MP157A-DK1 Discovery Board";
	compatible = "st,stm32mp157a-dk1", "st,stm32mp157";

	aliases {
		ethernet0 = ðernet0;
		serial0 = &uart4;
		serial1 = &usart3;
		serial2 = &uart7;
	};

代码里定义了uart4为serial0,也就是ttySTM0,usart3为serial1,uart7为serial2。

关于uart4的配置,引脚为uart4_pins_a(在stm32mp157-pinctrl.dtsi有关于uart4_pins_a的定义),状态为开启:

&uart4 {
	pinctrl-names = "default", "sleep", "idle", "no_console_suspend";
	pinctrl-0 = <&uart4_pins_a>;
	pinctrl-1 = <&uart4_sleep_pins_a>;
	pinctrl-2 = <&uart4_idle_pins_a>;
	pinctrl-3 = <&uart4_pins_a>;
	status = "okay";
};

关于usart3的配置,引脚为usart3_pins_b(在stm32mp157-pinctrl.dtsi有关于usart3_pins_b的定义),状态为关闭:

&usart3 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&usart3_pins_b>;
	pinctrl-1 = <&usart3_sleep_pins_b>;
	pinctrl-2 = <&usart3_idle_pins_b>;
	status = "disabled";
};

关于uart7的配置,引脚为uart7_pins_a(在stm32mp157-pinctrl.dtsi有关于uart7_pins_a的定义),状态为关闭: 

&uart7 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&uart7_pins_a>;
	pinctrl-1 = <&uart7_sleep_pins_a>;
	pinctrl-2 = <&uart7_idle_pins_a>;
	status = "disabled";
};

查看../STM32MP15-Ecosystem-v1.1.0/Developer-Package/stm32mp1-openstlinux-4.19-thud-mp1-19-10-09/sources/arm-openstlinux_weston-linux-gnueabi/linux-stm32mp-4.19-r0/linux-4.19.49/arch/arm/boot/stm32mp157-pinctrl.dtsi.dts

关于uart4_pins_a的定义,UART4_TX-PG11,UART4_RX-PB2:

    			uart4_pins_a: uart4-0 {
				pins1 {
					pinmux = ; /* UART4_TX */
					bias-disable;
					drive-push-pull;
					slew-rate = <0>;
				};
				pins2 {
					pinmux = ; /* UART4_RX */
					bias-disable;
				};
			};

关于uart7_pins_a的定义,UART7_TX-PE8,UART7_RX-PE7: 

			uart7_pins_a: uart7-0 {
				pins1 {
					pinmux = ; /* USART7_TX */
					bias-disable;
					drive-push-pull;
					slew-rate = <0>;
				};
				pins2 {
					pinmux = ; /* USART7_RX */
					bias-disable;
				};
			};

关于usart3_pins_b的定义, USART3_TX-PB10,USART3_RX-PB12: 

			usart3_pins_b: usart3-1 {
				pins1 {
					pinmux = , /* USART3_TX */
						 ; /* USART3_RTS */
					bias-disable;
					drive-push-pull;
					slew-rate = <0>;
				};
				pins2 {
					pinmux = , /* USART3_RX */
						 ; /* USART3_CTS_NSS */
					bias-disable;
				};
			};

通过以上文件关于uart7的配置得知,uart7对应的串口名称为serial2,为关闭状态,如果需要使用还需开启,uart7默认的TX为PE8,RX为PE7,和CN14的D0和D1连接的GPIO引脚是一致的。

启动uart7

修改stm32mp157c-dk1.dts文件,启动uart7:

将
&uart7 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&uart7_pins_a>;
	pinctrl-1 = <&uart7_sleep_pins_a>;
	pinctrl-2 = <&uart7_idle_pins_a>;
	status = "disabled";
};
改为
&uart7 {
	pinctrl-names = "default", "sleep", "idle";
	pinctrl-0 = <&uart7_pins_a>;
	pinctrl-1 = <&uart7_sleep_pins_a>;
	pinctrl-2 = <&uart7_idle_pins_a>;
	status = "okay";
};

修改好后,重新编译dtb并且更新到开发板上:

caiyong@caiyong-virtual-machine:~/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package$ source SDK/environment-setup-cortexa7t2hf-neon-vfpv4-openstlinux_weston-linux-gnueabi

caiyong@caiyong-virtual-machine:~/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package/stm32mp1-openstlinux-4.19-thud-mp1-19-10-09/sources/arm-openstlinux_weston-linux-gnueabi/linux-stm32mp-4.19-r0/linux-4.19.49$ make dtbs
  CALL    scripts/checksyscalls.sh
  DTC     arch/arm/boot/dts/stm32mp157a-dk1.dtb
  DTC     arch/arm/boot/dts/stm32mp157c-dk2.dtb
  DTC     arch/arm/boot/dts/stm32mp157c-dk2-a7-examples.dtb
  DTC     arch/arm/boot/dts/stm32mp157c-dk2-m4-examples.dtb

caiyong@caiyong-virtual-machine:~/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package/stm32mp1-openstlinux-4.19-thud-mp1-19-10-09/sources/arm-openstlinux_weston-linux-gnueabi/linux-stm32mp-4.19-r0/linux-4.19.49$ scp arch/arm/boo
t/dts/stm32mp157*.dtb [email protected]:/boot
stm32mp157a-dk1.dtb                           100%   66KB 924.6KB/s   00:00    
stm32mp157c-dk2-a7-examples.dtb               100%   67KB 814.2KB/s   00:00    
stm32mp157c-dk2.dtb                           100%   67KB 780.1KB/s   00:00    
stm32mp157c-dk2-m4-examples.dtb               100%   68KB   1.0MB/s   00:00    
stm32mp157c-ed1.dtb                           100%   62KB 633.6KB/s   00:00    
stm32mp157c-ev1-a7-examples.dtb               100%   72KB   1.4MB/s   00:00    
stm32mp157c-ev1.dtb                           100%   72KB 730.1KB/s   00:00    
stm32mp157c-ev1-m4-examples.dtb               100%   72KB 835.6KB/s   00:00    

重新开发板:

在开发板的命令终端是执行以下命令,会看到ttySTM2:

root@stm32mp1:~# cd /dev/
root@stm32mp1:/dev# ls
root@stm32mp1:/dev# ls ttySTM*
ttySTM0  ttySTM2

测试UART7

使用一根USB转LVTTL的串口线连接开发板和电脑,然后在电脑上找到相应的串口号,启动串口调试助手,设置波特率为115200,检验位:无,数据位:8位,停止位:1位,然后打开该串口:

在开发板的命令终端上配置ttySTM2,115200波特率 8数据位 1停止位 无校验位,命令如下:

root@stm32mp1:/# stty -F /dev/ttySTM2 speed 115200  cs8 -parenb -cstopb

通过ttySTM2发送"hello world"到电脑的串口调试助手,命令如下:

root@stm32mp1:/# echo "hello world" > /dev/ttySTM2

串口调试助手显示收到的内容:

STM32MP157C-DK2->Develop on Arm® Cortex®-A7之 开启UART7串口功能_第4张图片

启动开发板的ttySTM2的接收功能,命令如下:

root@stm32mp1:/# cat /dev/ttySTM2

通过串口调试助手的发送窗口发送内容给开发板,开发板回显到串口调试助手上,如下图所示:

STM32MP157C-DK2->Develop on Arm® Cortex®-A7之 开启UART7串口功能_第5张图片

火柴棍科技工作室:www.huochaigun.top

技术交流群

STM32MP1:861926625

ESP8266:476685983

你可能感兴趣的:(STM32MP1,STM32,MPU)