[STM32MP135F-DK]测评 ④安装SDK及HelloWorld
<div class='showpostmsg'> 本帖最后由 不爱胡萝卜的仓鼠 于 2023-12-11 17:01 编辑<p> </p>
<p>今天来整一个HelloWorld,这下就必须要使用Ubuntu了,我用的一个虚拟机,Ubuntu 20.04</p>
<p> </p>
<p><span style="font-size:22px;">一、安装SDK</span></p>
<p> 安装SDK在Ubuntu虚拟机中进行,首先安装额外的包</p>
<pre>
<code>sudo apt-get update
sudo apt-get install gawk wget git diffstat unzip texinfo gcc-multilibchrpath socat cpio python3 python3-pip python3-pexpect </code></pre>
<div style="text-align: center;"></div>
<pre>
<code>sudo apt-get install libssl-dev libgmp-dev libmpc-dev lz4 zstd</code></pre>
<div style="text-align: center;">
<div style="text-align: center;"></div>
<div style="text-align: left;">
<pre>
<code>sudo apt-get install build-essential libncurses-dev libyaml-dev libssl-dev</code></pre>
<p> </p>
</div>
<div style="text-align: center;"></div>
<div style="text-align: left;">
<pre>
<code>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</code></pre>
<div style="text-align: center;"></div>
<p>额外的配置</p>
<pre>
<code>echo 'options mmc_block perdev_minors=16' > /tmp/mmc_block.conf
sudo mv /tmp/mmc_block.conf /etc/modprobe.d/mmc_block.conf</code></pre>
<p>下载SDK(<a href="https://www.st.com/en/embedded-software/stm32mp1dev.html" target="_blank">SDK下载地址</a>)</p>
<div style="text-align: center;"></div>
<p>放到虚拟机中(在home路径下创建一个叫“STM32MPU_workspace”的文件夹,在这个文件夹下再创建一个名叫“tmp”的文件夹),解压</p>
<div style="text-align: center;"></div>
<div>
<div>
<p>运行SDK安装脚本</p>
</div>
<p>创建一个文件夹</p>
</div>
<div>
<pre>
<code>mkdir -p $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/SDK</code></pre>
<p>修改SDK安装脚本的权限,使其可执行 </p>
<pre>
<code>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</code></pre>
<p> </p>
</div>
</div>
<div style="text-align: center;"></div>
<div style="text-align: left;">执行SDK安装脚本</div>
<div style="text-align: left;">
<pre>
<code>./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/ubuntuadmin/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/SDK</code></pre>
<p> </p>
</div>
<div style="text-align: center;">
<div style="text-align: center;"></div>
<div style="text-align: left;">检查一下安装结果,在每次使用前都要source一下环境变量,如下</div>
<div style="text-align: left;">
<pre>
<code>cd $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package
source SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi</code></pre>
<p>检查目标体系结构 </p>
<pre>
<code>echo $ARCH</code></pre>
<p> 检查toolchain</p>
<pre>
<code>echo $CROSS_COMPILE</code></pre>
<p>检查C编译器的版本</p>
<pre>
<code>$CC --version</code></pre>
<p>检查SDK版本 </p>
<pre>
<code>echo $OECORE_SDK_VERSION</code></pre>
<p> </p>
</div>
</div>
<div style="text-align: center;"></div>
</div>
<p><span style="font-size:22px;">二、HelloWorld</span></p>
<p>创建一个存放源代码的目录</p>
<div style="text-align: center;"></div>
<div>创建一个存放helloworld代码的文件夹</div>
<div>
<pre>
<code>mkdir $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/stm32mp1-openstlinux-23.06.21/sources/gtk_hello_world_example
cd $HOME/STM32MPU_workspace/STM32MP1-Ecosystem-v5.0.0/Developer-Package/stm32mp1-openstlinux-23.06.21/sources/gtk_hello_world_example</code></pre>
<div style="text-align: center;"></div>
<p> </p>
</div>
<p>然后创建两个文件,一个.c、一个Makeflie</p>
<div style="text-align: center;">
<div style="text-align: center;"></div>
<p> </p>
</div>
<p>然后在终端中直接输入make,完了有error,提示找不到gtk.h(图中路径请忽略,这是之前的截图)</p>
<div style="text-align: center;"></div>
<p>那我得装一下gtk,这里特别注意,要装GTK3,不要装2.0(图中路径请忽略,这是之前的截图)</p>
<div style="text-align: center;">
<div style="text-align: center;"></div>
<p style="text-align: left;">再次make,这次不报这个错误了,换别的了(图中路径请忽略,这是之前的截图)</p>
<div style="text-align: center;"></div>
<p style="text-align: left;">不管了,听报错的,我改,改了2次,就可以编译通过了(图中路径请忽略,这是之前的截图)</p>
<div style="text-align: center;"></div>
<p style="text-align: left;">得到的编译结果(图中路径请忽略,这是之前的截图)</p>
<div style="text-align: center;"></div>
<div style="text-align: left;">把这个文件从虚拟机中拷贝到win,再通过SSH放到135的/usr/local/ 路径下</div>
<div style="text-align: center;"></div>
<p> </p>
</div>
<p>然后在终端中,输入命令运行helloworld</p>
<pre>
<code>su -l weston -c "/usr/local/gtk_hello_world"</code></pre>
<div style="text-align: center;"></div>
<p>报错没有权限,看一下我对这个文件的权限</p>
<pre>
<code>ls -l</code></pre>
<div style="text-align: center;"></div>
<p>修改一下权限</p>
<div style="text-align: center;">
<div style="text-align: center;"></div>
<p style="text-align: left;">再次运行</p>
<div style="text-align: center;"></div>
<p style="text-align: left;">完蛋,一堆乱码</p>
<p style="text-align: left;"> </p>
<p style="text-align: left;">经过一段时间的摸索,我找到了原因,还记得在SDK安装时有一句话吗?“在每次使用前都要source一下环境变量”,在打开一个终端后,要编译代码,就要先在终端source一下环境变量,然后在cd到代码路径,再make</p>
<div style="text-align: center;"></div>
<p style="text-align: left;">终于,可以成功运行了</p>
<div style="text-align: center;"></div>
</div>
<p> </p>
<p>1cc36750f3f51d50330bafd10cff8016</p>
<p> </p>
<p>最后贴一下.c和Makefile中的内容</p>
<pre>
<code>#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_REPLACE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}</code></pre>
<p> </p>
<pre>
<code>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 $@ $^ $(CFLAGS) $(LDFLAGS)
clean:
rm -f $(CLEANFILES) $(patsubst %.c,%.o, $(SRCS))</code></pre>
<p><br />
</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>老哥我也是卡在最后乱码的问题,你文章中提到的source具体是怎样操作的,我在虚拟机里make的结果是这样</p>
<div style="text-align: center;"></div>
<div style="text-align: center;"></div>
<p> </p>
2609 发表于 2024-3-24 00:36
老哥我也是卡在最后乱码的问题,你文章中提到的source具体是怎样操作的,我在虚拟机里make的结果是这样
...
<p>就是这句</p>
<pre>
<code>source SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi</code></pre>
<div style="text-align: center;"></div>
<p> </p>
不爱胡萝卜的仓鼠 发表于 2024-4-10 23:13
就是这句
source SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
  ...
<p>多谢老哥 问题已解决</p>
页:
[1]