打印
[STM32MP1]

【STM32MP135F-DK测评】SDK安装&运行第一个app程序

[复制链接]
1171|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 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程序运行成功



使用特权

评论回复
沙发
jobszheng| | 2024-1-16 18:51 | 只看该作者
有意思!
今天晚上复刻你的方案 ~~

使用特权

评论回复
板凳
ming899| | 2024-1-18 14:18 | 只看该作者
赞!

使用特权

评论回复
地板
zhgongzuoshi| | 2024-6-25 15:52 | 只看该作者
1、安装需要的工具
是在板子上还是pc上的linux?

使用特权

评论回复
5
LOVEEVER| | 2024-6-25 19:04 | 只看该作者
在Linux下进行的开发嘛?

使用特权

评论回复
6
zhgongzuoshi| | 2024-7-4 16:45 | 只看该作者
请教一下博主,参考你的步骤尝试运行一个app,但是在编译make的时候遇到问题了,请指点一下:

使用特权

评论回复
7
hehhehee| | 2024-7-26 15:02 | 只看该作者
基本的初始化过程
#include "stm32h5xx_hal.h"

TIM_HandleTypeDef htim2;
TIM_OC_InitTypeDef sConfigOC;

// 定时器初始化函数
void MX_TIM2_Init(void)
{
    __HAL_RCC_TIM2_CLK_ENABLE();

    htim2.Instance = TIM2;
    htim2.Init.Prescaler = 0;
    htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim2.Init.Period = 4095;
    htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
    if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
    {
        Error_Handler();
    }

    sConfigOC.OCMode = TIM_OCMODE_PWM1;
    sConfigOC.Pulse = 2048;
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
    if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
    {
        Error_Handler();
    }

    HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
}

// GPIO初始化函数
void MX_GPIO_Init(void)
{
    __HAL_RCC_GPIOA_CLK_ENABLE();

    GPIO_InitTypeDef GPIO_InitStruct = {0};
    GPIO_InitStruct.Pin = GPIO_PIN_0;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}


使用特权

评论回复
8
xinmeng_wit|  楼主 | 2024-7-29 12:15 | 只看该作者
zhgongzuoshi 发表于 2024-7-4 16:45
请教一下博主,参考你的步骤尝试运行一个app,但是在编译make的时候遇到问题了,请指点一下:

...

没有找到hello_world.c
这个文件是要自己写的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

69

主题

247

帖子

1

粉丝