当前位置: 首页 > news >正文

STM32MPU开发之旅:从零开始构建嵌入式Linux镜像

前言

在工业4.0与边缘计算深度融合的今天,STM32MP257F作为意法半导体第二代工业级64位微处理器的旗舰产品,凭借异构计算架构、1.35 TOPS边缘AI算力和军工级安全特性,已成为工业自动化、机器视觉和新能源控制等领域的标杆方案。

  1. 性能跃迁的异构架构
    搭载双核Cortex-A35(1.5GHz)与Cortex-M33(400MHz)的异构计算引擎,完美平衡高性能运算与硬实时控制需求:

  2. 边缘AI的落地实践
    内置VeriSilicon GC8000UL NPU的1.35 TOPS算力,配合TensorFlow Lite/ONNX框架支持,可部署机器视觉质检、预测性维护等AI模型:

该处理器已成功应用于国产PLC控制系统(支持EtherCAT总线与32轴同步控制)、储能EMS系统(通过CAN FD实现毫秒级BMS通信)、以及智能充电桩(集成LVDS触控与支付模块)等场景。本文将以Yocto定制开发为主线,开启STM32MP257F开发之旅。

文章目录

  • 前言
  • 材料准备
  • 开发版本选择
  • 实操过程
    • 安装开发环境
    • 获取仓库源码
    • 编译镜像
    • 添加模块
    • 下载到板子
    • 使用UART连接到开发板
    • 开发板联网
    • 开发板时间配置
  • 参考

材料准备

硬件:STM32MP257F-EV1
开发环境:Ubuntu22.04.5

开发版本选择

官方提供三个版本的开发包,选择建议参考:

功能维度Starter Package (入门包)Developer Package (开发者包)Distribution Package (发行包)
定位开箱即用,快速验证功能深度定制化开发企业级产品化开发
核心特点- 预编译镜像
- 无需编译环境
- 功能受限
- 全源码开放
- 支持驱动/内核修改
- 提供交叉编译工具
- 基于Yocto定制系统
- AI/RT扩展包
- 安全启动/OTA
适用场景开发板初体验;原型展示;硬件快速验证二次开发(传感器驱动等);内核优化;多核通信工业产品(HMI/AI网关);团队私有仓库;安全认证项目
技术门槛低(零基础可用)中(需嵌入式开发经验)高(需系统架构经验)
源码/工具支持仅二进制镜像开源代码+SDK开源代码+扩展包+企业级工具链
典型用户学生/方案演示者开发者/小型团队企业研发团队
硬件扩展性仅支持官方配置可适配同系列芯片支持多平台移植

或者参考官方说明。

本文以Distribution Package (发行包)为例

实操过程

安装开发环境

开发环境可以直接安装物理机也可以安装虚拟机,也可以使用虚拟机安装,考虑到性能问题,本文选择直接安装物理机。注意版本一定要选择Ubuntu22.04.5

进入Ubuntu22系统,首先需要配置一些基础环境,参考官方推荐。

关于网络问题可以借鉴这个

安装STM32CubeProgramer,后续要用来烧录镜像,参考官方教程

获取仓库源码

新建一个本地工作目录,推荐使用~/STMicroelectronics/Distribution-Package

mkdir ~/STMicroelectronics/Distribution-Package
cd ~/STMicroelectronics/Distribution-Package

通过repo来拉取远程仓库到本地(注:repo是和git类似的版本管理工具,适合操作较大的仓库)

repo init -u https://github.com/STMicroelectronics/oe-manifest -b refs/tags/openstlinux-6.6-yocto-scarthgap-mpu-v24.12.05
repo sync

编译镜像

首先source一下开发环境

DISTRO=openstlinux-weston MACHINE=stm32mp25-eval source layers/meta-st/scripts/envsetup.sh

执行下面的命令,使用yocto编译st-image-weston镜像

bitbake st-image-weston

如果看到如下界面,说明可以成功开始编译

在这里插入图片描述

添加模块

官方原版的系统为了最小化镜像大小,把很多不常用的模块都去除了,例如git。如果需要用到这些模块,可以按照如下步骤进行添加:

编辑local.conf文件

nano conf/local.conf

在文件最后添加需要的模块,例如需要添加gitnanotmux等模块

IMAGE_INSTALL:append = " \git \tmux \nano \"

编译过程如果提示ERROR: st-image-weston-1.0-r0 do_image_tar: The rootfs size 1277996(K) exceeds IMAGE_ROOTFS_MAXSIZE: 1000000(K),说明添加模块之后导致整个镜像大小超过了限制,可以在conf/local.conf最后添加下面的命令,增加大小限制到1000000 kB

IMAGE_ROOTFS_MAXSIZE = "1000000"

继续使用yocto重新编译st-image-weston镜像

bitbake st-image-weston -c cleanall

编译完成后的文件结构如下:

acc@acc-server:~/STMicroelectronics/Distribution-Package/build-openstlinuxweston-stm32mp25-eval/tmp-glibc/deploy/images/stm32mp25-eval$ pwd
/home/acc/STMicroelectronics/Distribution-Package/build-openstlinuxweston-stm32mp25-eval/tmp-glibc/deploy/images/stm32mp25-evalacc@acc-server:~/STMicroelectronics/Distribution-Package/build-openstlinuxweston-stm32mp25-eval/tmp-glibc/deploy/images/stm32mp25-eval$ tree -L 1
.
├── arm-trusted-firmware
├── arm-trusted-firmware-m
├── fip
├── flashlayout_st-image-weston
├── kernel
├── optee
├── scripts
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.ext4
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.manifest
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.spdx.tar.zst
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.tar.xz
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.testdata.json
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs.ext4 -> st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.ext4
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs.manifest -> st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.manifest
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs.spdx.tar.zst -> st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.spdx.tar.zst
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs.tar.xz -> st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.tar.xz
├── st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs.testdata.json -> st-image-bootfs-openstlinux-weston-stm32mp25-eval.bootfs-20250425080741.testdata.json
├── st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs-20250425080741.cpio.gz
├── st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs-20250425080741.manifest
├── st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs-20250425080741.spdx.tar.zst
├── st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs-20250425080741.testdata.json
├── st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs.cpio.gz -> st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs-20250425080741.cpio.gz
├── st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs.manifest -> st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs-20250425080741.manifest
├── st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs.spdx.tar.zst -> st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs-20250425080741.spdx.tar.zst
├── st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs.testdata.json -> st-image-resize-initrd-openstlinux-weston-stm32mp25-eval.rootfs-20250425080741.testdata.json
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.ext4
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.manifest
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.spdx.tar.zst
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.tar.xz
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.testdata.json
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs.ext4 -> st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.ext4
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs.manifest -> st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.manifest
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs.spdx.tar.zst -> st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.spdx.tar.zst
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs.tar.xz -> st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.tar.xz
├── st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs.testdata.json -> st-image-userfs-openstlinux-weston-stm32mp25-eval.userfs-20250425080741.testdata.json
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.ext4
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.manifest
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.spdx.tar.zst
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.tar.xz
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.testdata.json
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs.ext4 -> st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.ext4
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs.manifest -> st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.manifest
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs.spdx.tar.zst -> st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.spdx.tar.zst
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs.tar.xz -> st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.tar.xz
├── st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs.testdata.json -> st-image-vendorfs-openstlinux-weston-stm32mp25-eval.vendorfs-20250425080741.testdata.json
├── st-initrd-openstlinux-weston-stm32mp25-eval
└── u-boot8 directories, 39 files

下载到板子

通过开发板的OTG口连接到PC,同时通过USB_PWR口进行供电。注意:供电口尽量使用type-C转type-C的线,否则可能出现供电不足导致无法启动

使用如下命令将镜像下载到板子

acc@acc-server:~/STMicroelectronics/Distribution-Package/build-openstlinuxweston-stm32mp25-eval/tmp-glibc/deploy/images/stm32mp25-eval$ STM32_Programmer_CLI -c port=usb1 -w flashlayout_st-image-weston/optee/FlashLayout_sdcard_stm32mp257f-ev1-optee.tsv -------------------------------------------------------------------STM32CubeProgrammer v2.18.0                  -------------------------------------------------------------------USB speed   : High Speed (480MBit/s)
Manuf. ID   : STMicroelectronics
Product ID  : DFU in HS Mode @Device ID /0x505, @Revision ID /0x2000
SN          : 002D001D4136500B00373653
DFU protocol: 1.1
Board       : --
Device ID   : 0x0505
Device name : STM32MP23xx/25xx
Device type : MPU
Revision ID : --  
Device CPU  : Cortex-A35Start Embedded Flashing serviceOpening and parsing file: tf-a-stm32mp257f-ev1-optee-programmer-usb.stm32Memory Programming ...File          : tf-a-stm32mp257f-ev1-optee-programmer-usb.stm32Size          : 198.95 KB Partition ID  : 0x01 Download in Progress:
^C=================================                ]  68% 

使用UART连接到开发板

将供电口同时也是ST-LINK口连接到带有串口助手的PC,这里的串口命令行软件使用的是Putty,打开对应串口,同时板子已经上电,就能在软件上看到系统启动信息,等待启动完成

开发板联网

为了让开发板连接到网络,这里连接上以太网,同时将PC的互联网连接共享到以太网口。

具体参考

开发板时间配置

如果直接使用apt update,会提示如下错误

root@stm32mp25-eval-e3-e0-f5:~# apt updateThe software package is provided AS IS, and by downloading it, you agree to be bound to the terms of the software license agreement (SLA).
The detailed content licenses can be found at https://wiki.st.com/stm32mpu/wiki/OpenSTLinux_licenses.Get:1 http://packages.openstlinux.st.com/6.0 scarthgap InRelease [5724 B]
Reading package lists... Done                                
E: Release file for http://packages.openstlinux.st.com/6.0/dists/scarthgap/InRelease is not valid yet (invalid for another 301d 18h 9min 33s). Updates for this repository will not be applied.

具体原因是本机系统时间和互联网时间没有对应,需要手动设置本机时间

date -s "2025-04-25 16:04:00"

重新尝试apt update即可

本文完!

参考

https://wiki.st.com/stm32mpu/index.php/STM32MPU_Distribution_Package
https://www.st.com/en/embedded-software/stm32mp2distrib.html#documentation
https://wiki.st.com/stm32mpu/index.php?title=Category:Yocto-based_OpenSTLinux_embedded_software&sfr=stm32mpu
https://wiki.st.com/stm32mpu/wiki/STM32CubeProgrammer

相关文章:

  • 《深入理解 AOP》
  • 【金仓数据库征文】-金仓数据库性能调优 “快准稳” 攻略:实战优化,让数据处理飞起来
  • 新闻速递丨Altair 与 Databricks 达成合作,加速数据驱动型创新
  • 银发科技:AI健康小屋如何破解老龄化困局
  • Qt知识点1『16进制数值与文本互相转换』
  • 【金仓数据库征文】- 国产化迁移实战:从Oracle到KingbaseES的平滑过渡
  • day32 学习笔记
  • C++学习之网络攻防以及信息搜索
  • MDF标准
  • 用 Python 打造打篮球字符动画!控制台彩色炫酷输出,抖音搞怪视频灵感还原
  • Dubbo负载均衡策略深度解析
  • 借助内核逻辑锁pagecache到内存
  • 大模型微调 - 自注意力机制
  • Doris表设计与分区策略:让海量数据管理更高效
  • contenthash 持久化缓存
  • 使用Go语言实现轻量级消息队列
  • 施工配电箱巡检二维码应用
  • verilog中实现单周期cpu的RVM指令(乘除取模)
  • 线程池总结
  • 匠心打造超级 ping,多运营商多协议全方位测试,sir.net 正式上线!
  • 韩国首尔江南区一大型商场起火,消防部门正在灭火中
  • 审议民营经济促进法草案等,十四届全国人大常委会第十五次会议将举行
  • 北京市平谷区政协原主席王春辉接受纪律审查和监察调查
  • 冒充县领导亲戚十年骗取38箱香菇木耳,河南一男子被判拘役
  • 宁夏回族自治区人大环境与资源保护委员会主任委员张柏森被查
  • 瞭望:高校大门要向公众打开,不能让“一关了之”成为常态