前言
在工業4.0與邊緣計算深度融合的今天,STM32MP257F作為意法半導體第二代工業級64位微處理器的旗艦產品,憑借異構計算架構、1.35 TOPS邊緣AI算力和軍工級安全特性,已成為工業自動化、機器視覺和新能源控制等領域的標桿方案。
-
性能躍遷的異構架構
搭載雙核Cortex-A35(1.5GHz)與Cortex-M33(400MHz)的異構計算引擎,完美平衡高性能運算與硬實時控制需求: -
邊緣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
在文件最后添加需要的模塊,例如需要添加git
、nano
、tmux
等模塊
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