6 Steps to Complete Linux System Porting and Development Environment Configuration for STM32MP157

6 Steps to Complete Linux System Porting and Development Environment Configuration for STM32MP157

Introduction

The STM32MP157, as a dual-core heterogeneous processor launched by ST, integrates Cortex-A7 and Cortex-M4 cores, and has a wide range of applications in industrial control and smart devices. This article will detail how to set up a professional embedded Linux development environment on the STM32MP157 platform, helping developers quickly start project development.

6 Steps to Complete Linux System Porting and Development Environment Configuration for STM32MP157

Hardware and Software Requirements

Hardware Requirements:

  • STM32MP157-DK2 Development Board
  • ST-LINK/V2 Debugger
  • High-speed SD card (16GB or more)
  • 5V/3A Type-C Power Adapter

Software Requirements:

  • Host System: Ubuntu 22.04 LTS
  • STM32CubeIDE 1.13.0
  • OpenSTLinux SDK (version 4.1.0)
  • STM32CubeProgrammer
  • OpenSTLinux Toolchain

Overview of the Development Environment

The development environment is built on the official ST OpenSTLinux SDK, adopting a partition layout that includes: a boot partition (for TF-A and U-Boot) and a rootfs partition. It supports dual-core heterogeneous development, allowing simultaneous Linux application development and real-time task development.

Preparing the Host Development Environment

# Install development dependencies
sudo apt-get update && sudo apt-get install -y \
    build-essential git python3 python3-pip \
    chrpath cpio diffstat gawk libncurses5-dev \
    texinfo wget gdisk bison flex fakeroot cmake \
    libssl-dev device-tree-compiler

# Create working directory
mkdir -p ~/stm32mp1
cd ~/stm32mp1

# Download SDK
wget https://www.st.com/resource/en/utilities/\
st-openstlinux-sdk-4.1.0.tar.gz
tar xf st-openstlinux-sdk-4.1.0.tar.gz

SDK Installation and Environment Configuration

# Install SDK
./stm32mp1-openstlinux-4.1.0/sdk/st-image-weston-openstlinux-weston-stm32mp1\
-x86_64-toolchain-4.1.0.sh

# Configure environment variables
source ~/stm32mp1-sdk/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi

# Verify toolchain
$CC --version

Building TF-A and U-Boot

# Get TF-A source code
git clone https://github.com/STMicroelectronics/arm-trusted-firmware.git -b v2.6-stm32mp
cd arm-trusted-firmware

# Compile TF-A
make CROSS_COMPILE=arm-ostl-linux-gnueabi- \
    PLAT=stm32mp1 ARCH=aarch32 ARM_ARCH_MAJOR=7 \
    DTB_FILE_NAME=stm32mp157c-dk2.dtb \
    BL33_CFG=/path/to/u-boot.dtb \
    all

# Compile U-Boot
cd ../u-boot
make stm32mp15_defconfig
make DEVICE_TREE=stm32mp157c-dk2 all

Kernel Configuration and Compilation

# Get kernel source code
git clone https://github.com/STMicroelectronics/linux.git -b v5.15-stm32mp
cd linux

# Configure kernel
make multi_v7_defconfig fragment/*.config

# Compile kernel
make ARCH=arm CROSS_COMPILE=arm-ostl-linux-gnueabi- \
    LOADADDR=0xC2000040 uImage dtbs modules -j4

Building the Root File System

# Use Yocto to build the root file system
cd ~/stm32mp1
source layers/meta-st/scripts/envsetup.sh

# Configure build target
DISTRO=openstlinux-weston MACHINE=stm32mp1 bitbake \
    st-image-weston

# Generate SD card image
DISTRO=openstlinux-weston MACHINE=stm32mp1 bitbake \
    st-image-weston -c populate_sdk

System Deployment and Verification

# Use STM32CubeProgrammer to flash the image
sudo STM32_Programmer_CLI -c port=usb1 \
    -w flashlayout_st-image-weston/trusted/FlashLayout_sdcard_stm32mp157c-dk2-trusted.tsv

# Verify system startup
minicom -D /dev/ttyACM0 -b 115200

Common Issues and Solutions

  1. Compilation Errors:

    # Clean the compilation environment
    make clean
    source environment-setup-xxx  # Reload environment variables
    
  2. Startup Failure:

  • Check partition table configuration
  • Verify the correctness of the device tree file
  • Network Issues:

    # Configure Ethernet
    ifconfig eth0 up
    udhcpc -i eth0
    
  • Development Environment Optimization

    • Configure Eclipse remote debugging environment
    • Set up NFS shared directory to accelerate development
    • Use STM32CubeIDE to integrate and develop M4 firmware

    Conclusion

    After completing the above configurations, you will have a complete STM32MP157 development environment that supports Linux application development on the A7 core and real-time task development on the M4 core. It is recommended to delve into advanced topics such as device tree configuration and dual-core communication mechanisms.

    Leave a Comment