From Hardware to Software: Complete Process of Setting Up STM32MP157 Linux Environment for Industrial Applications
Introduction
The STM32MP157, as a dual-core heterogeneous processor from STMicroelectronics, integrates Cortex-A7 and Cortex-M4 cores, offering unique advantages in industrial control and smart instrumentation. Its support for a hybrid development model of real-time operating systems and Linux provides an ideal development platform for industrial applications. This article will detail the process of setting up the Linux development environment for the STM32MP157.

Hardware and Software Requirements
Hardware Requirements:
- STM32MP157-DK2 Evaluation Board
- 5V/3A Type-C Power Adapter
- ST-LINK/V2 Debugger
- SD Card (8GB or larger, Class 10)
- USB to Serial Module
- Ethernet Cable
Software Requirements:
- Host Operating System: Ubuntu 20.04 LTS
- STM32CubeIDE 1.11.0
- OpenSTLinux SDK 4.1
- STM32CubeProgrammer
- STM32MP1 Development Package
Overview of the Development Environment
The development environment for the STM32MP157 consists of two main parts: the Linux system development environment and the STM32 real-time application development environment. OpenSTLinux provides a complete development toolchain and SDK, enabling collaborative development of Linux applications, kernel drivers, and real-time tasks.
Preparing the Host Development Environment
# Install development dependencies
sudo apt-get update
sudo apt-get install -y build-essential git wget curl \
python3 python3-pip device-tree-compiler bmap-tools \
autoconf libtool libssl-dev expect flex bison \
help2man gawk
# Install OpenSTLinux SDK
wget https://www.st.com/content/downloads/en/sdk/stm32mp1
chmod +x en.SDK-x86_64-stm32mp1-openstlinux-5.4-dunfell-mp1-21-03-31.sh
./en.SDK-x86_64-stm32mp1-openstlinux-5.4-dunfell-mp1-21-03-31.sh
Cross-Compilation Toolchain Configuration
# Set SDK environment variables
source /opt/st/stm32mp1/4.1/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
# Verify toolchain
$CC --version
echo $CROSS_COMPILE
Kernel Source Acquisition and Configuration
# Acquire Linux kernel source
git clone https://github.com/STMicroelectronics/linux.git
cd linux
git checkout v5.10-stm32mp
# Configure and compile the kernel
make stm32mp1_defconfig
make menuconfig
make -j$(nproc) uImage LOADADDR=0xC2000040
make -j$(nproc) dtbs
Building the Root Filesystem
Use the Yocto Project to build a customized root filesystem:
# Initialize Yocto environment
source layers/meta-st/scripts/envsetup.sh
# Configure build target
DISTRO=openstlinux-weston MACHINE=stm32mp1 bitbake st-image-weston
# Build image
bitbake virtual/kernel
bitbake u-boot
System Boot Configuration
# Compile U-Boot
cd u-boot
make stm32mp157d_defconfig
make DEVICE_TREE=stm32mp157d-dk2 all
# Configure boot parameters
cat >> u-boot/uboot.env << EOF
bootargs=root=/dev/mmcblk0p2 rootwait rw console=ttySTM0,115200
EOF
Deploying the System on the Development Board
Use STM32CubeProgrammer for system flashing:
# Prepare SD card partitions
sudo sgdisk --clear \
--new=1:34:545 --change-name=1:fsbl1 --typecode=1:8301 \
--new=2:546:1057 --change-name=2:fsbl2 --typecode=2:8301 \
--new=3:1058:5153 --change-name=3:ssbl --typecode=3:8301 \
--new=4:5154: --change-name=4:rootfs --typecode=4:8305 \
/dev/sdX
# Flash system image
sudo dd if=u-boot-spl.stm32 of=/dev/sdX1 bs=1M conv=fdatasync
sudo dd if=u-boot.img of=/dev/sdX3 bs=1M conv=fdatasync
Environment Testing and Validation
Perform functional validation after booting the system:
# Check processor status
cat /proc/cpuinfo
# Validate CAN bus
ip link set can0 up type can bitrate 500000
candump can0
# Test GPIO
echo 504 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio504/direction
Common Issues and Solutions
-
Dual-core communication issues:
- Check the status of the remoteproc driver
- Verify rpmsg channel configuration
- Ensure M4 firmware is loaded correctly
Real-time performance issues:
- Enable PREEMPT_RT patch
- Adjust CPU isolation settings
- Optimize interrupt handling
Power management issues:
- Check PMIC configuration
- Verify clock tree settings
- Adjust low-power mode parameters
Development Environment Optimization
- Eclipse IDE Integration:
# Install Eclipse plugins
eclipse --install org.eclipse.cdt
eclipse --install org.eclipse.linuxtools
# Configure debugging environment
sudo apt-get install -y openocd gdb-multiarch
- Performance Analysis Tool Configuration:
# Install performance analysis tools
sudo apt-get install -y linux-tools-generic trace-cmd kernelshark
sudo apt-get install -y valgrind oprofile
Conclusion
The setup of the Linux development environment for the STM32MP157 lays the foundation for industrial application development. It is recommended to delve deeper into dual-core heterogeneous development, real-time task scheduling, and industrial bus communication features. Consider exploring advanced topics such as the OpenAMP framework and real-time Linux optimization to fully leverage the advantages of the STM32MP157 in industrial applications.