stm32mp15x环境搭建基于linux环境(上)
一.安装工具包
1)Install the tools
TM32CubeProgrammer requires 1.8 version of the Java platform,需要1.8版本的java平台
a.sudo apt-get install openjdk-8-jre
sudo update-alternatives --config java
b.在主机上面创建STM32MPU工具目录
mkdir $HOME/STM32MPU_workspace/STM32MPU-Tools
mkdir $HOME/STM32MPU_workspace/STM32MPU-Tools/STM32CubeProgrammer-2.2.0
c.在STM32MPU_workspace创建一个临时工作目录
mkdir $HOME/STM32MPU_workspace/tmp
d.下载STM32CubeProgrammer v2.2.0在 $HOME/STM32MPU_workspace/tmp此目录
eg:Download STM32CubeProgrammer v2.2.0 in the following directory
$HOME/STM32MPU_workspace/tmp
进入此目录,并解压zip文件
cd $HOME/STM32MPU_workspace/tmp
unzip SetupSTM32CubeProgrammer.zip
解压过后会看到三个文件
SetupSTM32CubeProgrammer-2.2.0.app
SetupSTM32CubeProgrammer-2.2.0.exe
SetupSTM32CubeProgrammer-2.2.0.linux
执行linux文件安装,并选择"$HOME/STM32MPU-Tools/STM32CubeProgrammer-2.2.0"安装目录,如下:
./SetupSTM32CubeProgrammer-2.2.0.linux
e.添加STM32CubeProgrammer到PATH环境变量
export PATH=$HOME/STM32MPU_workspace/STM32MPU-Tools/STM32CubeProgrammer-2.2.0/bin:$PATH
f.检查STM32CubeProgrammer工具是否正确安装
STM32_Programmer_CLI --h,如果正确安装会显示以下信息
------------------------------------------------------------------- STM32CubeProgrammer v2.2.0 -------------------------------------------------------------------
二.Install the libusb on your host computer(安装libusb在主机电脑上面)
1)sudo apt-get install libusb-1.0-0
2)To allow STM32CubeProgrammer to access the USB port through low-level commands, proceed as follows(STM32CubeProgrammer允许通过基本命令连接到usb端口),如下:
cd $HOME/STM32MPU_workspace/STM32MPU-Tools/STM32CubeProgrammer-2.2.0/Drivers/rules
sudo cp *.* /etc/udev/rules.d/
三.在主机上创建一个STM32MP15 启动目录
1)PC $>mkdir $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0
PC $> mkdir $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Starter-Package
PC $> cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Starter-Package
2)下载 STM32MP15-Ecosystem-v1.1.0 启动包 到下面这个目录:
$HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Starter-Package
包文件这个格式en.FLASH-stm32mp1-openstlinux-4.19-thud-mp1-19-10-09.tar.xz
3)解压文件
通过xz -d en.FLASH-stm32mp1-openstlinux-4.19-thud-mp1-19-10-09.tar.xz
解压成en.FLASH-stm32mp1-openstlinux-4.19-thud-mp1-19-02-20.tar
然后tar -xvf en.FLASH-stm32mp1-openstlinux-4.19-thud-mp1-19-02-20.tar
解压成stm32mp1-openstlinux-4.19-thud-mp1-19-02-20文件夹
四.制作sdcard启动镜像
1)进入这个目录cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Starter-Package/stm32mp1-openstlinux-4.19-thud-mp1-19-02-20/images/stm32mp1
2)获得usb设备端口连接情况如下:
STM32_Programmer_CLI -l usb ------------------------------------------------------------------- STM32CubeProgrammer v2.2.0 ------------------------------------------------------------------- ===== DFU Interface ===== Total number of available STM32 device in DFU mode: 1 Device Index : USB1 USB Bus Number : 003 USB Address Number : 002 Product ID : DFU in HS Mode @Device ID /0x500, @Revision ID /0x0000 Serial number : 004800233338511634383330 Firmware version : 0x0110 Device ID : 0x0500
3)用microSD card制作可靠的引导程序
STM32_Programmer_CLI -c port=usb1 -w flashlayout_st-image-weston/FlashLayout_sdcard_stm32mp157c-dk2-trusted.tsv
注意:如果板子供电电流没有达到3A,红灯指示的问题分为下面几种情况:
blink | console message | boot process |
---|---|---|
2 times | WARNING 500mA power supply detected
Current too low, use a 3A power supply! |
Continue and red LED stays ON |
3 times | WARNING 1500mA power supply detected
Current too low, use a 3A power supply! |
Continue and red LED stays ON |
forever | ERROR USB TYPE-C connection in unattached mode
Check that USB TYPE-C cable is correctly plugged |
stop |
forever | USB TYPE-C charger not compliant with USB specification | stop |
镜像成功之后,会答应下面信息Flashing service completed successfully!
然后是上电复位启动板子。
六.接下来解释板子linux终端通过ST-LINK/V2-1连接主机
通过uart接口与板子进行串行通信
1)安装minicom串口
sudo apt-get install minicom
2)获取需要用于访问ST-LINK/V2-1的ttyACM设备实例,需要插上ST-LINK
ls /dev/ttyACM*
/dev/ttyACM0
3)连接minicom到/dev//ttyACM0设备
minicom -D /dev/ttyACM0
Welcome to minicom 2.7 OPTIONS: I18n Compiled on Nov 15 2018, 20:18:47. Port /dev/ttyACM0, 15:56:03 Press CTRL-A Z for help on special keys
4)按复位按钮重启板子,在minicom窗口可以看到启动的信息如下:
NOTICE: CPU: STM32MP157CAC Rev.B
NOTICE: Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
NOTICE: Board: MB1272 Var2 Rev.C-01
INFO: Reset reason (0x14): INFO: Pad Reset from NRST
INFO: Using SDMMC INFO: Instance 1
INFO: Boot used partition fsbl1
NOTICE: BL2: v2.0-r1.5(debug):
NOTICE: BL2: Built : 13:13:37, Oct 2 2018
INFO: BL2: Doing platform setup INFO: PMIC version = 0x10
INFO: RAM: DDR3-1066/888 bin G 1x4Gb 533MHz v1.45
INFO: Memory size = 0x20000000 (512 MB)
INFO: BL2 runs SP_MIN setup
INFO: BL2: Loading image id 4
INFO: Loading image id=4 at address 0x2fff0000
INFO: Image id=4 loaded: 0x2fff0000 - 0x30000000
INFO: BL2: Loading image id 5
INFO: Loading image id=5 at address 0xc0100000
INFO: STM32 Image size : 805258 WARNING: Skip signature check (header option)
INFO: Image id=5 loaded: 0xc0100000 - 0xc01c498a
INFO: read version 0 current version 0
NOTICE: BL2: Booting BL32
INFO: Entry point address = 0x2fff0000
INFO: SPSR = 0x1d3
INFO: PMIC version = 0x10
NOTICE: SP_MIN: v2.0-r1.5(debug): NOTICE: SP_MIN: Built : 13:13:37, Oct 2 2018
INFO: ARM GICv2 driver initialized
INFO: stm32mp HSI (18): Secure only
INFO: stm32mp HSE (20): Secure only INFO: stm32mp PLL2 (27): Secure only INFO: stm32mp PLL2_R (30): Secure only INFO: SP_MIN: Initializing runtime services INFO: SP_MIN: Preparing exit to normal world U-Boot 2018.11-stm32mp-r3 (Nov 14 2018 - 16:10:06 +0000) CPU: STM32MP157CAC Rev.B Model: STMicroelectronics STM32MP157C-DK2 Discovery Board Board: stm32mp1 in trusted mode (st,stm32mp157c-dk2) Board: MB1272 Var2 Rev.C-01 DRAM: 512 MiB Clocks: - MPU : 650 MHz - MCU : 208.878 MHz - AXI : 266.500 MHz - PER : 24 MHz - DDR : 533 MHz NAND: 0 MiB MMC: STM32 SDMMC2: 0, STM32 SDMMC2: 1 Loading Environment from EXT4... OK In: serial Out: serial Err: serial Net: eth0: [email protected] Hit any key to stop autoboot: 0 Boot over mmc0! switch to partitions #0, OK mmc0 is current device Scanning mmc 0:4... Found U-Boot script /boot.scr.uimg 1553 bytes read in 1 ms (1.5 MiB/s) ## Executing script at c4100000 Scanning mmc 0:4... Found /mmc0_stm32mp157c-dk2_extlinux/extlinux.conf Retrieving file: /mmc0_stm32mp157c-dk2_extlinux/extlinux.conf 614 bytes read in 1 ms (599.6 KiB/s) Retrieving file: /splash.bmp 46180 bytes read in 3 ms (14.7 MiB/s) Select the boot mode 1: stm32mp157c-dk2-sdcard 2: stm32mp157c-dk2-a7-examples-sdcard 3: stm32mp157c-dk2-m4-examples-sdcard Enter choice: 1: stm32mp157c-dk2-sdcard Retrieving file: /uImage 6652480 bytes read in 295 ms (21.5 MiB/s) append: root=/dev/mmcblk0p6 rootwait rw console=ttySTM0,115200 Retrieving file: /stm32mp157c-dk2.dtb 68852 bytes read in 4 ms (16.4 MiB/s) ## Booting kernel from Legacy Image at c2000000 ... Image Name: Linux-4.19.49 Created: 2019-06-09 7:17:25 UTC Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 6652416 Bytes = 6.3 MiB Load Address: c2000040 Entry Point: c2000040 Verifying Checksum ... OK ## Flattened Device Tree blob at c4000000 Booting using the fdt blob at 0xc4000000 XIP Kernel Image ... OK Using Device Tree in place at c4000000, end c4013cf3 Starting kernel ... [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.19.49 ([email protected]) (gcc version 8.2.0 (GCC)) #1 SMP PREEMPT Sun Jun 9 07:17:25 UTC 2019 [ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d [ 0.000000] CPU: div instructions available: patching division code [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache [ 0.000000] OF: fdt: Machine model: STMicroelectronics STM32MP157C-DK2 Discovery Board [ 0.000000] Memory policy: Data cache writealloc [ 0.000000] efi: Getting EFI parameters from FDT: [ 0.000000] efi: UEFI not found. ... [ 3.110076] Run /sbin/init as init process [ 3.115137] hub 2-1:1.0: USB hub found [ 3.117776] hub 2-1:1.0: 4 ports detected [ 3.358998] systemd[1]: System time before build time, advancing clock. [ 3.455504] NET: Registered protocol family 10 [ 3.495900] Segment Routing with IPv6 [ 3.521434] systemd[1]: systemd 239 running in system mode. (+PAM -AUDIT -SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP -LIBCRYPTSETUP -GCRYPT -GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID -ELFUTILS +KMOD -ID) [ 3.542498] systemd[1]: Detected architecture arm. Welcome to ST OpenSTLinux - Weston - (A Yocto Project Based Distro) 2.6-openstlinux-4.19-thud-mp1-19-10-09 (thud)! [ 3.601262] systemd[1]: Set hostname to <stm32mp1>. [ 3.613928] systemd[1]: Hardware watchdog 'STM32 Independent Watchdog', version 0 [ 3.621153] systemd[1]: Set hardware watchdog to 30s. [ 4.269410] systemd[1]: Unnecessary job for dev-ttySTM0.device was removed. [ 4.277529] systemd[1]: Listening on initctl Compatibility Named Pipe. ... [ OK ] Started Getty on tty1. [ OK ] Reached target Login Prompts. [ OK ] Reached target Sound Card. [ OK ] Started Load/Save RF Kill Switch Status. [ OK ] Started Login Service. [ OK ] Reached target Multi-User System. Starting Update UTMP about System Runlevel Changes... [ OK ] Started Update UTMP about System Runlevel Changes. [ OK ] Started Hostname Service. ST OpenSTLinux - Weston - (A Yocto Project Based Distro) 2.6-openstlinux-4.19-thud-mp1-19-10-09 stm32mp1 ttySTM0 stm32mp1 login: root (automatic login)
5)打印板子详细分配信息
lsb_release -a LSB
Version: core-5.0-noarch:core-5.0-arm Distributor ID: openstlinux-weston Description: ST OpenSTLinux - Weston - (A Yocto Project Based Distro) 2.6-openstlinux-4.19-thud-mp1-19-10-09 Release: 2.6-openstlinux-4.19-thud-mp1-19-10-09 Codename: thud
6)打印板子系统信息
Board $> uname -a Linux stm32mp1 4.19.49 #1 SMP PREEMPT Sun Jun 9 07:17:25 UTC 2019 armv7l armv7l armv7l GNU/Linux
7)打印板子内核和编译器版本
Board $> cat /proc/version Linux version 4.19.49 ([email protected]) (gcc version 8.2.0 (GCC)) #1 SMP PREEMPT Sun Jun 9 07:17:25 UTC 2019
8)打印挂载到系统文件下的磁盘空间
df -h
9)打印板子的IP地址
ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff inet xx.xx.xx.xx/22 brd xx.xx.xx.xx scope global dynamic eth0 valid_lft 159045sec preferred_lft 159045sec inet6 xx::xx:xx:xx:xx/64 scope link valid_lft forever preferred_lft forever
10)On the host computer connect the terminal to the board using ssh(主机通过ssh连接板子终端)
PC $> ssh [email protected]
七.安装stm32mp157开发包,包括编译应用程序和内核的软件开发包工具
运行环境:Ubuntu 16.04
1.安装Install the SDK
1.1:配置主机电脑,安装额外的工具包
PC $> sudo apt-get update
PC $> sudo apt-get install sed wget curl cvs subversion git-core coreutils unzip texi2html texinfo docbook-utils gawk python-pysqlite2 diffstat help2man make gcc build-essential g++ desktop-file-utils chrpath libxml2-utils xmlto docbook bsdmainutils iputils-ping cpio python-wand python-pycryptopp python-crypto
PC $> sudo apt-get install libsdl1.2-dev xterm corkscrew nfs-common nfs-kernel-server device-tree-compiler mercurial u-boot-tools libarchive-zip-perl
PC $> sudo apt-get install ncurses-dev bc linux-headers-generic gcc-multilib libncurses5-dev libncursesw5-dev lrzsz dos2unix lib32ncurses5 repo libssl-dev
PC $> sudo apt-get install default-jre
1.2:附加的配置
运行每个MMC之多16个分区
注意:在linux系统上,默认分配给MMC最大8个分区,然而所有的程序包需要存储设备有超过10个分区,为了把每个设备的分区扩展到16个,必须添加自动处理可以载入模块,如下命令:
PC $> echo 'options mmc_block perdev_minors=16' > /tmp/mmc_block.conf
PC $> sudo mv /tmp/mmc_block.conf /etc/modprobe.d/mmc_block.conf
1.3:下载 STM32MP15-Ecosystem-v1.1.0 开发包 SDK 到下面的目录:
$HOME/STM32MPU_workspace/tmp
进入该目录
PC $> cd $HOME/STM32MPU_workspace/tmp
解压文件
通过xz -d en.SDK-x86_64-stm32mp1-openstlinux-4.19-thud-mp1-19-10-09.tar.xz解压成tar格式
en.SDK-x86_64-stm32mp1-openstlinux-4.19-thud-mp1-19-02-20.tar
然后tar xvf en.SDK-x86_64-stm32mp1-openstlinux-4.19-thud-mp1-19-10-09.tar成
stm32mp1-openstlinux-4.19-thud-mp1-19-02-20文件夹
1.4:在主机上创建 STM32MP15 开发包SDK 目录
PC $> mkdir $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package
PC $> mkdir $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package/SDK
1.5:便于安装,改变SDK安装脚本执行权限
PC $> chmod +x $HOME/STM32MPU_workspace/tmp/stm32mp1-openstlinux-4.19-thud-mp1-19-02-20/sdk/st-image-weston-openstlinux-weston-stm32mp1-x86_64-toolchain-2.6-openstlinux-4.19-thud-mp1-19-02-20.sh
1.6:执行安装脚本
PC $> $HOME/STM32MPU_workspace/tmp/stm32mp1-openstlinux-4.19-thud-mp1-19-02-20/sdk/st-image-weston-openstlinux-weston-stm32mp1-x86_64-toolchain-2.6-openstlinux-4.19-thud-mp1-19-02-20.sh -d $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package/SDK
1.7:如果成功安装,会显示下面的信息:
ST OpenSTLinux - Weston - (A Yocto Project Based Distro) SDK installer version 2.6-openstlinux-4.19-thud-mp1-19-10-09 ===================================================================================================================== You are about to install the SDK to "/local/home/frq08927/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package/SDK". Proceed[Y/n]? Y Extracting SDK..................................................................................................................................................................done Setting it up...done SDK has been successfully set up and is ready to be used. Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g. $ . /<working directory absolute path>/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-openstlinux_weston-linux-gnueabi
1.8:使得SDK生效,
注意:
The SDK environment setup script must be run once in each new working terminal in which you cross-compile,也就是说每一个新工作的终端都必须运行一次脚本
PC $> cd $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v1.1.0/Developer-Package
PC $> source SDK/environment-setup-cortexa7t2hf-neon-vfpv4-openstlinux_weston-linux-gnueabi
1.9:检查编译环境是否正确安装
a.Check the target architecture
PC $> echo $ARCH
arm
b.检查目标编译工具
PC $> echo $CROSS_COMPILE
arm-openstlinux_weston-linux-gnueabi-
c.检查编译版本
PC $> $CC --version
arm-openstlinux_weston-linux-gnueabi-gcc (GCC) 8.2.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
d.检查是否为预期的编译版本
PC $> echo $OECORE_SDK_VERSION
2.6-openstlinux-4.19-thud-mp1-19-10-09 /* For ecosystem release v1.1.0 */
If any of these commands fails or does not return the expected result, please try to reinstall the SDK. 如果以上检查都没有类似的打印结果,重新安装SDK