本帖最后由 xinmeng_wit 于 2024-1-3 18:06 编辑
【安装SDK】
1、安装需要的工具
xinmeng@7420-vm:~$ sudo apt-get install build-essential libncurses-dev libyaml-dev libssl-dev
xinmeng@7420-vm:~$ sudo apt-get install coreutils bsdmainutils sed curl bc lrzsz corkscrew cvs subversion mercurial nfs-common nfs-kernel-server libarchive-zip-perl dos2unix texi2html libxml2-utils
2、配置MMC分区
必须安装额外的配置,以支持每个MMC最多16个分区。默认情况下,在Linux®系统上,MMC上最多允许8个分区。所有软件包(Starter软件包,…)的存储设备都需要10个以上的分区。为了将每个设备的分区数扩展到16个,必须向modprobe添加以下选项:
xinmeng@7420-vm:~$ echo 'options mmc_block perdev_minors=16' > /tmp/mmc_block.conf
xinmeng@7420-vm:~$ sudo mv /tmp/mmc_block.conf /etc/modprobe.d/mmc_block.conf
3、下载SDK
下载en.SDK-x86_64-stm32mp1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21.tar.gz放入目录$HOME/STM32MPU_workspace/tmp中。
下载地址:https://www.st.com/en/embedded-s ... v.html#get-software
4、解压SDK
xinmeng@7420-vm:~/STM32MPU_workspace/tmp$ tar xvf en.SDK-x86_64-stm32mp1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21.tar.gz
5、创建STM32MP1 Developer Package SDK目录
xinmeng@7420-vm:~/STM32MPU_workspace/tmp$ mkdir -p $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/SDK
6、增加SDK安装脚本的执行权限
xinmeng@7420-vm:~/STM32MPU_workspace/tmp/en.SDK-x86_64-stm32mp1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21$ chmod +x stm32mp1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21/sdk/st-image-weston-openstlinux-weston-stm32mp1-x86_64-toolchain-4.2.1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21.sh
7、执行SDK安装脚本
xinmeng@7420-vm:~/STM32MPU_workspace/tmp/en.SDK-x86_64-stm32mp1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21$ ./stm32mp1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21/sdk/st-image-weston-openstlinux-weston-stm32mp1-x86_64-toolchain-4.2.1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21.sh -d $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/SDK
完成安装结果如下
ST OpenSTLinux - Weston - (A Yocto Project Based Distro) SDK installer version 4.2.1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21
===================================================================================================================================
You are about to install the SDK to "/home/xinmeng/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/SDK". Proceed [Y/n]? y
Extracting SDK........................................................................................................................................................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
$ . /home/xinmeng/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
注意:每次重开终端都必须重新source一下环境
xinmeng@7420-vm:~/STM32MPU_workspace/tmp/en.SDK-x86_64-stm32mp1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21[ DISCUZ_CODE_124 ]nbsp; cd $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package[ DISCUZ_CODE_124 ]nbsp; source SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
8、安装完成后检查环境是否正常
1)检查目标芯片架构
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package$ echo $ARCH
返回结果:
arm
2)检查交叉编译工具
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package$ echo $CROSS_COMPILE
返回结果:
arm-ostl-linux-gnueabi-
3)检查C编译器版本
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package$ $CC --version
返回结果:
arm-ostl-linux-gnueabi-gcc (GCC) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4)检查SDK版本
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package$ echo $OECORE_SDK_VERSION
返回结果:
4.2.1-openstlinux-6.1-yocto-mickledore-mp1-v23.06.21
【运行第一个APP程序】
1、创建目录用于存放app源代码
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package$ mkdir $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/stm32mp1-openstlinux-23.06.21
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package$ mkdir $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/stm32mp1-openstlinux-23.06.21/sources
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package$ mkdir $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/stm32mp1-openstlinux-23.06.21/sources/gtk_hello_world_example
2、进入gtk_hello_world_example目录
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package$ cd $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/stm32mp1-openstlinux-23.06.21/sources/gtk_hello_world_example
3、创建源文件gtk_hello_world.c并键入如下代码
#include <gtk/gtk.h>
static void
print_hello (GtkWidget *widget,
gpointer data)
{
g_print ("Hello World\n");
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *button_box;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (window), button_box);
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
gtk_container_add (GTK_CONTAINER (button_box), button);
gtk_widget_show_all (window);
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
4、创建Makefile文件并键入如下内容
PROG = gtk_hello_world
SRCS = gtk_hello_world.c
CLEANFILES = $(PROG)
# Add / change option in CFLAGS and LDFLAGS
CFLAGS += -Wall $(shell pkg-config --cflags gtk+-3.0)
LDFLAGS += $(shell pkg-config --libs gtk+-3.0)
all: $(PROG)
$(PROG): $(SRCS)
$(CC) -o $[url=home.php?mod=space&uid=72445]@[/url] $^ $(CFLAGS) $(LDFLAGS)
clean:
rm -f $(CLEANFILES) $(patsubst %.c,%.o, $(SRCS))
5、编译
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/stm32mp1-openstlinux-23.06.21/sources/gtk_hello_world_example$ make
编译后生成gtk_hello_world可执行文件
6、通过SSH上传到开发板
xinmeng@7420-vm:~/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/stm32mp1-openstlinux-23.06.21/sources/gtk_hello_world_example$ scp gtk_hello_world root@192.168.7.1:/usr/local
7、运行程序
第一个APP程序运行成功
|