嵌入式跨平台工具链终极方案

发布于:2024-12-18 ⋅ 阅读:(50) ⋅ 点赞:(0)


我们从8051开始学习嵌入式,用过了不少IDE,比如经典的keil和IAR,但是这些IDE都不便宜,如果不用点科学手段,我们是无法使用的。秉承做个正值合法,诚实守信的良好公民,我们还是需要找到更完美的开发方案,不仅能节约个人或者公司的开发成本,还能大大提高开发技术和效率。今天给大家推荐一套开源免费的跨平台开发方案工具链:“ vs code + GCC(或者其他编译器)+CMAKE+xmak/ninjia + vscode-commandbar +git+JLINK(芯片公司提供的IDE)"
这个方案不仅不要钱,还可以多平台使用,不再让开发限制在windows平台下,我们在linux和mac也能愉快的开发我们的产品,大大提高效率。

1. 解决烦人的编译,从编译器开始

为什么我们要用收费的IDE,最大的原因是他给我们提供了编译脚本,用过比较简单的图形化界面,就可以把我们的代码编译成可执行文件。这样看似简化了大家的门槛,但是大大提高了项目的成本,也提高了大家对其他方法的学习成本。
编译最重要的是将代码转换为可执行文件,在十年前,大家使用makefile来构建编译工程确实很难,晦涩难懂的语法,阻挡了90%的程序员,但是随着cmake/xmake/ninjia等简单的编译脚本兴起,makefile不再是我们使用make来构建编译工程的”拦路虎“
给大家推荐一个demo,大家都能学会,里面还有github的demo工程供大家参考。

  1. cmake 构建库:如何使用CMAKE gcc生成一个库文件?-CSDN博客
  2. cmake 构建可执行文件:如何使用CMAKE gcc生成一个可执行文件?_怎么使用cmake 生成可执行文件-CSDN博客
  3. cmake 构建各种刷写的二进制文件:如何使用CMAKE 将elf 转成二进制文件_cmake -oihex obinary-CSDN博客

2. T0级别的代码编辑器IDE

VS code是一个优秀的代码编辑工具,只要安装简单的插件,都能让开发效率大大提高,相比99%的开发者都知道,我就不再多说了。
今天给大家推荐一个图形化插件,让编译等脚本通过GUI实现,不再烦人的敲命令。
”vscode-commandbar“,自定义GUI神器,让脚本编程GUI的桥梁,步骤如下

  1. vscode-commandbar 添加GUI图标并,启动task脚本
{

  "skipTerminateQuickPick": true,
  "skipSwitchToOutput": false,
  "skipErrorMessage": true,
  "commands": [
    {
      "text": "$(gear) build",
      "tooltip": "build UI",
      "color": "yellow",
      "commandType": "palette",
      "command": "workbench.action.tasks.runTask|make build",
      "alignment": "left",
      "skipTerminateQuickPick": true,
      "skipSwitchToOutput":false,
      "priority": 3
    },
    {
      "text": "$(bug) debug",
      "tooltip": "debug UI",
      "color": "green",
      "commandType": "palette",
      "command": "workbench.action.tasks.runTask|make debug",
      "alignment": "left",
      "skipTerminateQuickPick": true,
      "skipSwitchToOutput":false,
      "priority": 2
    }
  ]
}

vscode 按钮效果|100 这样实现了自定义的UI编译与下载。

  1. task 启动shell脚本,实现编译或者下载调试
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "make build",
      "type": "shell",
      "command": " ./build.sh",
      "group": "build",
      "presentation": {
          "reveal": "always",
          "panel": "new"
      },
      "options": {
          "cwd": "${workspaceFolder}/"
      }
    },
    {
      "label": "make debug",
      "type": "shell",
      "command": " ./debug.sh",
      "group": "build",
      "presentation": {
          "reveal": "always",
          "panel": "new"
      },
      "options": {
          "cwd": "${workspaceFolder}/tools/lauterbach/"
      }
    }
  ]
}
  1. cmake 编译脚本实现编译命令启动
rm -rf build
mkdir build
cd build
LOG_FILE="cmake.log"
echo "Configuring project..."
cmake -G "Unix Makefiles" .. > >(tee "$LOG_FILE") 2>&1
#cmake --build . --target all -- -k -j $(nproc) >> "$LOG_FILE" 2>&1
make -j$(nproc) 2>&1 | tee build.log
make install
cd ..
  1. lauterbach 启动脚本(当然大家也可以启动其他的调试IDE,lauterbach是比较常用的)
#!/bin/bash
set -e
export SYS=${T32_PATH:-"/home/$USER/t32"}
echo "To customize the T32 installation path, please set environment variable 'T32_PATH'; currently using '${SYS}'."
echo "To configure custom user behaviour this script will load config from ~/.user_cmm . Please add your custom setup there."
echo "To load ELF files please assign given variables: &myELF in your custom cmm file!"
"${SYS}/bin/pc_linux64/t32marm" -c usb_configs/config_usb_mcu.t32 ${SYS} -s cmm/debug.cmm
exit

3. git linus之父开发神奇的分布式代码管理工具

git 在开发界比较有名,直接引用网友的教程:Git使用教程(超详细!)-CSDN博客
如果侵权,通知必删。


网站公告

今日签到

点亮在社区的每一天
去签到