基于Ubuntu Server编译YTM32 SDK工程

基于Ubuntu Server编译YTM32 SDK工程

需求

在Linux系统环境下搭建SDK的编译环境:

  • 方便加入到持续集成工具链
  • Linux系统中运行armgcc的速度更快,适合较为频繁的CI验证过程
  • 服务器上多使用Linux系统,比较容易找到装Linux系统的服务器,用旧电脑、虚拟机或者云服务均可
  • 一些客户需要,要么规避工具链的商业付费授权,要么习惯使用Linux系统(欧美开发者)

下载软件包

  • VirtualBox - Virtual Machine: https://download.virtualbox.org/virtualbox/7.0.12/VirtualBox-7.0.12-159484-Win.exe
  • Ubuntu 18.04 Server ISO Image: https://releases.ubuntu.com/18.04/ubuntu-18.04.6-live-server-amd64.iso
  • Tera Term - Remote Access Terminal:
  • WinSCP - FTP/SFTP Client on Windows: https://winscp.net/eng/download.php
  • gcc-arm-none-eabi for Linux: https://developer.arm.com/downloads/-/gnu-rm

安装与配置

配置虚拟机联网模式

VirtualBox网络模式,默认是NAT,可改为桥接模式。

在桥接模式下,虚拟主机同物理主机相互独立,通过物理主机连接的路由器组网(在Wifi网络中不需要再输入无线路由密码),在同一个局域网网段。桥接模式下的虚拟主机,同在局域网中加入一个物理主机服务器最接近。

为了验证虚拟主机系统已经联网成功,可通过ifconfig命令查看Linux主机的ip地址:

在这里插入图片描述

图x 查看远程服务器ip地址

前期的一些关于网络的配置工作,仍需要在虚拟机界面下完成。例如,先要安装并启用SSH服务,使得本地主机可以通过SSH连接到远程主机。

启用ssh连接

sudo apt install openssh-server # 安装ssh server
sudo service ssh start  # 启动ssh服务
sudo ufw allow 22 # 更新防火墙规则,开放22号端口

为了方便在本地主机(物理主机)系统中操作服务器,接下来将在本地主机使用SSH终端访问远程主机(虚拟主机)系统。
在这里插入图片描述

图x 使用Tera Term建立同远程主机的SSH连接

登录后,接下来的配置工作就都可以在Tera Term终端中进行了。如图x所示。

在这里插入图片描述

图x 使用Tera Term建立同远程主机的SSH连接2

启用ftp连接

通过FTP连接,本机主机可以向远程主机传送文件和下载文件。如此,可以在本地主机下载好必要的软件包,例如armgcc的工具链软件包。

在远程主机安装并启用FTP服务:

sudo apt-get install vsftpd # 安装vsftpd
sudo systemctl start vsftpd # 启用vsftpd服务
sudo systemctl enable vsftpd

配置vsfptd,启用读写访问权限:

sudo nano /etc/vsftpd.conf # 修改配置文件

默认仅需要开启写使能即可:

write_enable=YES

保存修改配置后,重启服务:

sudo systemctl restart vsftpd

在本地主机的Windows系统上,可以使用WinSCP作为FTP客户端。如图x所示。

在这里插入图片描述

图x 使用FTP向远程主机传文件

安装armgcc编译工具链

Ubuntu 18.04的软件源中,gcc-arm-none-eabi工具集的版本比较老,通常要使用较新版的编译器,可以通过直接解压压缩包的方式安装到远程主机的Linux系统中。

在Arm的官网(https://developer.arm.com/downloads/-/gnu-rm)下载Linux版本的gcc-arm-none-eabi工具集,如图x所示。

在这里插入图片描述

图x 下载Linux版本的gcc-arm-none-eabi工具集

使用WinSCP将下载好的gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2文件,上传至远程主机的目录/home/andrew/ytm32-mcu/tools中,再解压:

tar -jxvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2

最后,将编译器程序所在的目录添加到Linux的环境变量中。

sudo nano /etc/profile

在文件结尾处添加:

export PATH="$PATH:/home/andrew/ytm32-mcu/tools/gcc-arm-none-eabi-10.3-2021.10/bin"

保存.bashrc文件后,重新激活:

source /etc/profile

此时,在bash中试用arm-none-eabi-gcc命令,可以看到,bash已经可以检索到armgcc的编译器:

andrew@andrew-pc:~/ytm32-mcu$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release)
Copyright (C) 2020 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.

andrew@andrew-pc:~/ytm32-mcu$

确认make工具

YTM32的SDK使用Makefile组织源码工程。

PS:Ninja对Windows的支持似乎要好于Linux,因此YTM32的SDK在Windows系统中搭建免费的开发环境,就选用了Ninja。Make在Windows系统上没有专门的软件包,不能在Windows原生的命令行环境中直接调用,只得通过mingw环境套用一个兼容性的make工具。但是,Make在Linux系统环境下是天然被支持的,因此在Linux系统环境下,YTM32的SDK优先使用Make工具。

在bash中,试着运行make命令,确认是否已经安装。

andrew@andrew-pc:~/ytm32-mcu$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
andrew@andrew-pc:~/ytm32-mcu$

确认过眼神,是对的人。

验证

通过WinSCP将SDK的软件包传送至远程主机,解压软件包:

andrew@andrew-pc:~/ytm32-mcu$ unzip YTM32Bx_SDK_RTM_1.1.0.zip

然后以hello_world工程为例,切换至hello_world工程的Makefile文件所在目录,试着编译一下:

andrew@andrew-pc:~/ytm32-mcu/YTM32Bx_SDK_RTM_1.1.0/sdk/demos/YTM32B1MD1/hello_world/GCC$ make
======================================================================
Checked for uname, found: Linux
Assuming Unix like environment
======================================================================
Creating directory for object files
======================================================================
Compiling FLASH/flash/YTM32B1MD1_startup_gcc.o
======================================================================
Compiling FLASH/flash/dma_driver.o
======================================================================
Compiling FLASH/flash/dma_hw_access.o
======================================================================
Compiling FLASH/flash/dma_irq.o
======================================================================
Compiling FLASH/flash/interrupt_manager.o
======================================================================
Compiling FLASH/flash/pins_driver.o
======================================================================
Compiling FLASH/flash/pins_port_hw_access.o
======================================================================
Compiling FLASH/flash/linflexd_uart_driver.o
======================================================================
Compiling FLASH/flash/linflexd_uart_irq.o
======================================================================
Compiling FLASH/flash/clock_YTM32B1Mx.o
======================================================================
Compiling FLASH/flash/osif_baremetal.o
======================================================================
Compiling FLASH/flash/printf.o
======================================================================
Compiling FLASH/flash/startup.o
======================================================================
Compiling FLASH/flash/system_YTM32B1MD1.o
======================================================================
Compiling FLASH/flash/clock_config.o
======================================================================
Compiling FLASH/flash/peripherals_config.o
======================================================================
Compiling FLASH/flash/pin_mux.o
======================================================================
Compiling FLASH/flash/main.o
======================================================================
Linking to FLASH/flash.elf
   text    data     bss     dec     hex filename
   6604      84    9324   16012    3e8c FLASH/flash.elf
======================================================================
Build complete!

Bingo。

鉴于大多数在服务器上做CI(持续集成,Continuous Integration)只是编译,不做下载和调试,本文暂不继续介绍下载可执行文件的操作。实际上,编译之后的可执行文件,例如flash.elf,可以通过WinSCP取回到本地主机,在Windows系统下通过各种下载器(例如JLink或者DAPLink)下载到芯片上,或者通过Bootloader的方式更新固件,用户可以根据需要选用合适的操作方式。

  • END
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值