当前位置: 首页 > 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

http://www.xdnf.cn/news/143515.html

相关文章:

  • 高职人工智能技术应用专业(计算机视觉方向)实训室解决方案
  • WordPress AI 原创文章自动生成插件 24小时全自动生成SEO原创文章 | 多语言支持 | 智能配图与排版
  • 本土网盟推广孟加拉slot游戏出海营销优势
  • CSS常遇到自适应高度动画、带三角气泡阴影一行样式解决
  • 鸿蒙NEXT开发剪贴板工具类(ArkTs)
  • 智慧医院建设的三大关键领域
  • [AI技术(二)]JSONRPC协议MCPRAGAgent
  • 【Linux篇】理解信号:如何通过信号让程序听从操作系统的指令
  • 二项式分布html实验
  • 在Android中如何使用Protobuf上传协议
  • 隧道调频广播覆盖的实现路径:隧道无线广播技术赋能行车安全升级,隧道汽车广播收音系统助力隧道安全管理升级
  • http://noi.openjudge.cn/——2.5基本算法之搜索——200:Solitaire
  • NVIDIA 高级辅助驾驶汽车安全系统 系列读后感(1)
  • 【C++】继承----下篇
  • 使用命令行加密混淆C#程序
  • MySQL表达式之公用表表达式(CTE)的使用示例
  • 海量信息处理分析有效决策
  • 反序列化漏洞1
  • RK3562/3588 系列之0—NPU基础概念
  • 链表系列一>两两交换链表中的结点
  • 大厂面试-框架篇
  • Bytebase 取得 SOC 2 Type 2 认证
  • 驱动支持的最高CUDA版本与实际安装的Runtime版本
  • 在 Spring Boot 项目中如何使用索引来优化 SQL 查询?
  • BGE-Reranker-v2-M3介绍
  • 【Pandas】pandas DataFrame radd
  • 【防火墙 pfsense】3 portal
  • Serverless 在云原生后端的实践与演化:从函数到平台的革新
  • 开发体育直播系统内容与用户管理机制技术实现方案
  • 数据结构手撕--【二叉树】