在上一篇《【ODYSSEY-STM32MP157C】硬件平台及学习资源》中,我们大体了解了 ODYSSEY-STM32MP157C 开发板的情况。除了核心板上的 eMMC,载板上还提供了 SD 卡插槽,通过载板上的滑动开关选择从 eMMC 启动或者从 SD 卡启动。因此开发者可以像树莓派一样,将 Linux 系统镜像烧写到 SD 卡中,即可开启本趟学习之旅。
准备材料
发车之前,请各位旅客对照如下清单并准备号材料。
- ODYSSEY – STM32MP157C 开发板一个
- Wi-Fi 网络
- 4GB 以上的 SD 卡 及 读卡器
- PC 或 Mac 电脑
- USB 转 TTL 串口适配器
- 12V/2A DC 电源适配器 或 Type-C USB 线
注意:USB 转 TTL 串口适配器用于登录 Linux 调试串口,在首次登录时尤为重要。板卡可以通过 12V~24V 电源输入端口或 USB Type-C 接口供电,任选一种方式即可。
启动系统
制作 SD 卡镜像
-
下载镜像 stm32mp1-debian-buster-console-armhf-latest-2gb.img.xz 。
-
下载 Etcher 镜像烧录工具。
-
将 SD 卡通过读卡器连接到 PC 或 Mac 电脑。
-
打开 Etcher 工具,选择
*.img.xz
镜像,选择写入设备,点击“Flash!”按钮,等待烧写完毕。
- 镜像烧录完毕后,将 SD 卡取出来插入 ODYSSEY – STM32MP157C 载板 SD 卡插槽,将滑动开关拨到 SD_CARD 位置,然后上电,如果一切正常将会看到核心板上的 PWR 灯亮,同时 USER LED 闪烁。
登录串口终端
ODYSSEY – STM32MP157C 提供了两种方式登录串口终端:
- 通过 UART 端口(需要 USB 转 TTL 串口适配器)
- 通过 USB 端口(需要 USB type-c 线)
任选一种方式,通过 Putty、Xshell、MobaXterm、Tera Term 甚至 Minicom 等工具打开串口终端,波特率 115200,数据格式 8,N,1(8 位数据位,无校验位,1 位停止位)。
stm32mp1-debian 预设了两个登录账户:
账户 | 密码 | 说明 |
---|---|---|
debian | temppwd | 支持 uart 本地登录和 ssh 远程登录 |
root | root | 只支持 uart 本地登录 |
当然,使用 debian 账户登录后可以通过 sudo su
切换到 root 账户。
从 eMMC 启动(可选)
前面我们说过,ODYSSEY – STM32MP157C 核心板上提供了 4GB 的 eMMC,因此从 SD 卡启动系统后,可以将 SD 卡中的系统克隆到 eMMC 中,这样就可以直接从 eMMC 启动了。
要完成这一步,只需要修改 /boot/uEnv.txt,具体如下:
sudo sh -c "echo cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3-stm32mp1.sh >> /boot/uEnv.txt"
sudo reboot
reboot 之后,系统会执行 init-eMMC-flasher-v3-stm32mp1.sh 脚本完成系统克隆,这一步需要一些时间,请耐心等待。当看到核心板上的 USER LED 开始闪烁,说明已经克隆成功并从 eMMC 启动了。之后就可以断电,取下 SD 卡,将滑动开关拨到 EMMC 侧。
WiFi 设置
使用 connmanctl
网络管理工具完成 WiFi 配置,执行如下命令进入交互命令行,输入 quit 退出交互模式。
debian@npi:~$ sudo connmanctl
connmanctl>
开启 WiFi 功能
connmanctl> enable wifi
扫描 WiFi 服务
connmanctl> scan wifi
列出可用的服务(附近的 WiFi 网络)
connmanctl> services
开启无线网络代理
connmanctl> agent on
连接指定 WiFi 网络,并输入密码
connmanctl> connect wifi_e8de27077de3_41483034303434393134_managed_psk
Agent RequestInput wifi_e8de27077de3_41483034303434393134_managed_psk
Passphrase = [ Type=psk, Requirement=mandatory ]
Passphrase? *************
Connected wifi_e8de27077de3_41483034303434393134_managed_psk
系统更新
替换软件源
软件源列表记录在 /etc/apt/sources.list,保险起见,我们先备份一下。
cd /etc/apt
cp sources.list sources.list.backup
然后将 sources.list 修改为:
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
deb [arch=armhf] https://seeed-studio.github.io/seeed-linux-deb/ buster main
#deb-src [arch=armhf] https://seeed-studio.github.io/seeed-linux-deb/ buster main
#Kernel source (repos.rcn-ee.com) : https://github.com/RobertCNelson/linux-stable-rcn-ee
#
#git clone https://github.com/RobertCNelson/linux-stable-rcn-ee
#cd ./linux-stable-rcn-ee
#git checkout `uname -r` -b tmp
#
deb [arch=armhf] http://repos.rcn-ee.com/debian/ buster main
#deb-src [arch=armhf] http://repos.rcn-ee.com/debian/ buster main
更新系统
sudo apt update
如果出现如下错误
Err:22 https://seeed-studio.github.io/seeed-linux-deb buster InRelease
Temporary failure resolving 'seeed-studio.github.io'
请开启网络代理,或者在 /etc/hosts 文件增加一条记录
185.199.111.153 seeed-studio.github.io
软件安装
安装常用工具
为了方便后续的开发与调试,我们安装常用的一些工具,比如 ssh、git、gcc 等等。
sudo apt install ssh git wget curl gcc make -y
安装 python3
sudo apt install python3 python3-pip -y
安装编译环境
为方便开发,我们在 ODYSSEY – STM32MP157C 上安装对应的内核头文件,这样就可以直接在板上编译应用程序、内核模块、设备树,避免了前期搭建交叉编译环境的麻烦。
sudo apt update
sudo apt install linux-headers-$(uname -r) -y
出现如下错误
E: Unable to locate package linux-headers-4.19.9-stm32-r1
E: Couldn't find any package by glob 'linux-headers-4.19.9-stm32-r1'
E: Couldn't find any package by regex 'linux-headers-4.19.9-stm32-r1'
请开启网络代理,或者修改 /etc/hosts 文件后再次执行。
Get:1 https://seeed-studio.github.io/seeed-linux-deb buster/main armhf linux-headers-4.19.9-stm32-r1 armhf 1stable
好啦!下一节课我们就正式进入开发阶段啦,再见~