ODrive dry # 2 Ubuntu under development environment to build

Ubuntu under ODrive firmware development environment to build

The following applies to developers who want to modify ODrive firmware. Therefore, it assumes that you know such as how to use Git, what is knowledge compiler and the like. If this sounds familiar, the following may not be suitable for you.

Note: The use of Ubuntu version Ubuntu18.04

1 Visual Studio Code

1.1 Installation Visual Studio Code

Double-click to download the Visual Studio Code_1.42.0-1580986622_amd64.deb installation package, follow the prompts to keep the default installation.

1.2 Installing Visual Studio Code Extensions

  • Required extensions:
    • C/C++
    • Cortex-Debug
  • Recommended Extensions installed:
    • Include Autocomplete
    • Path Autocomplete
    • Auto Comment Blocks

Installing method:

  1. Start Visual Studio Code
    1. Click on the red box
      Here Insert Picture Description
    2. Enter vscode in red box Enter
      Here Insert Picture Description
    3. Click Visual Studio Code icon has started
      Here Insert Picture Description
  2. Click the red box to open the plug-in management view
    Here Insert Picture Description
  3. 在红框中输入要安装插件的名称 (如:C/C++) 回车
    Here Insert Picture Description
  4. 点击红框中的 Install 安装
    Here Insert Picture Description
  5. 等待安装完成即可
    Here Insert Picture Description

注意: 安装完所需插件后请关闭 Visual Studio Code 再进行下边的步骤

2 安装 make & make-guile

sudo apt install make      
sudo apt install make-guile

验证安装是否正确

make --version

3 安装 tup

sudo add-apt-repository ppa:jonathonf/tup && sudo apt-get update && sudo apt-get install tup

验证安装是否正确

tup --version				# should be 0.7.5 or later

4 安装 gcc-arm-embedded 工具链

sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa && sudo apt update && sudo apt install gcc-arm-embedded

验证安装是否正确

arm-none-eabi-gcc --version

5 安装 openocd

sudo apt-get install openocd

验证安装是否正确

openocd --version			# should be 0.10.0 or later

6 安装 git

sudo apt install git

验证安装是否正确

git --version

7 设置 python3 为默认 python

由于 Ubuntu18.04 默认已安装 python3,所以只需要设置 python3 为默认的 python 即可

sudo rm -f /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python

验证安装是否正确

python --version

8 尝试编译固件源码

推荐使用 git clone ODrive 固件源码到本地,但是由于政策问题 clone 会非常慢,因此,下面提供了额外的百度网盘下载链接。

注意:以下使用百度网盘下载地址下载的固件进行编译

解压 ODrive-fw-v0.4.11-19-g1c947631.zip

进入 ODrive-fw-v0.4.11-19-g1c947631 文件夹,鼠标右键单击 ODrive_Workspace.code-workspace 文件,点选 Open With Other Application,然后选择 Visual Studio Code 打开
Here Insert Picture Description
单击红框中的 tup.config.default 文件,配置硬件版本,修改为如下代码:

# Copy this file to tup.config and adapt it to your needs
# make sure this fits your board
CONFIG_BOARD_VERSION=v3.5-24V
CONFIG_USB_PROTOCOL=native
CONFIG_UART_PROTOCOL=ascii
CONFIG_DEBUG=false

# Uncomment this to error on compilation warnings
#CONFIG_STRICT=true

然后将 tup.config.default 文件重命名为 tup.config 然后保存。

依次点击菜单中的 Terminal -> Run Build Task… 等待构建、编译完成
Here Insert Picture Description
虽然编译完成了,但是上边的构建过程存在一些问题,这是由于我们使用的源码包而不是通过 git clone 到本地的(如果是通过 git clone 到本地则不存在这个问题),所以执行 version.py 脚本时无法正确获取固件版本信息。可以修改一下 version.py 内部代码,不通过 git 命令获取版本信息而是手动填写版本信息。修改 version.py 内第22行 get_version_from_git() 函数如下:

修改前:

def get_version_from_git():
    script_dir = os.path.dirname(os.path.realpath(__file__))
    try:
        # Determine the current git commit version
        git_tag = subprocess.check_output(["git", "describe", "--always", "--tags", "--dirty=*"],
            cwd=script_dir)
        git_tag = git_tag.decode(sys.stdout.encoding).rstrip('\n')

        (major, minor, revision, is_prerelease) = version_str_to_tuple(git_tag)

        # if is_prerelease:
        #     revision += 1
        return git_tag, major, minor, revision, is_prerelease

    except Exception as ex:
        print(ex)
        return "[unknown version]", 0, 0, 0, 1

修改后:

def get_version_from_git():
    return "fw-v0.4.11-19-g1c947631*", 0, 4, 11, True

9 完成开发环境搭建

9.1 构建工程

  • Terminal -> Run Build Task…

终端窗口将被打开。VSCode配置会在此终端中运行命令 make -j4 ,来编译工程。

9.2 烧录固件

  • Terminal -> Run Task… -> flash

终端窗口将被打开。 VSCode配置会在此终端中运行命令make flash,来烧录固件。

9.3 调试

Cortex-Debug 扩展插件,专门用于调试ARM Cortex项目。 您可以在此处阅读有关Cortex-Debug的更多信息:https://github.com/Marus/cortex-debug

  • 确保将固件源码文件夹作为当前文件夹
  • 用最新固件加载到ODrive (如果使用调试模式可以不需要此操作)
  • 点击Debug -> Start Debugging (或键盘 F5)
  • 处理器将重置并进入暂停
  • 设置断点。注意: 您只能在处理器暂停时设置断点,如果在运行模式下设置断点,则不会应用它们
  • 运行 (F5)
  • Stepping over/in/out, 重新运行, 按下pause (F6) 按钮然后重新设置断点等
  • When debugging, you can press stop(Shift + F5) to stop debugging. At the same time it will automatically shut down openOCD

9.4 Clear build file

If you want to build a new branch of the code, you may need to clean up the files generated when building.

  • Open the terminal command (View -> Terminal) and enter the command in the terminal make cleanEnter

If you have any questions or concerns, you are welcome to join ODrive community or QQ group 851,421,965 exchanges.

Published 16 original articles · won praise 9 · views 20000 +

Guess you like

Origin blog.csdn.net/abf1234444/article/details/104279595