一。 准备编译环境 我的开发环境是Ubuntu24.04 a. 下载编译器 Arm Developer Downloads | GNU Arm Embedded Toolchain Downloads – Arm Developer Download the GNU Embedded Toolchain for ARM, an open-source suite of tools for C, C++, and Assembly programming for 32-bit ARM Cortex-A, ARM Cortex-M and Cortex-R families 如图: b. 添加环境变量 vi /etc/profile 在文件最后添加 export PATH=$PATH:/usr/lib/gcc/gcc-arm-none-eabi-4_9-2014q4/bin 使能环境变量 source /etc/profile 注意:此命令只在当前终端有效,若需要在其它终端中使用,需要重启计算机。 c. 获取FreeRTOS源码并编译 git clone https://github.com/FreeRTOS/FreeRTOS.git --recurse-submodules cd FreeRTOS/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/build/gcc make 生成的镜像文件 output/RTOSDemo.out 二。启动测试 用下面命令启动虚拟机 qemu-system-arm -machine mps2-an385 -cpu cortex-m3 -kernel output/RTOSDemo.out -monitor none -nographic -serial stdio 三。 代码调试 通过vscode打开这个demo的代码 code /FreeRTOS/FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC 在vscode中创建launch.json 和 tasks.json 内容如下图: launch.json的内容如下: { "version": "0.2.0", "configurations": [ { "name": "Launch QEMU RTOSDemo", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/gcc/output/RTOSDemo.out", "cwd": "${workspaceFolder}", "miDebuggerPath": "arm-none-eabi-gdb", "miDebuggerServerAddress": "localhost:1234", "stopAtEntry": false, "preLaunchTask": "Run QEMU" }, ] } tasks.json的内容 如下: { "version": "2.0.0", "tasks": [ { "label": "Build QEMU", "type": "shell", "command": "make --directory=${workspaceFolder}/build/gcc", "problemMatcher": { "base": "$gcc", "fileLocation": ["relative", "${workspaceFolder}/build/gcc"] }, "group": { "kind": "build", "isDefault": true } }, { "label": "Run QEMU", "type": "shell", "command": "echo 'QEMU RTOSdemo started'; qemu-system-arm -machine mps2-an385 -cpu cortex-m3 -kernel ${workspaceFolder}/build/gcc/output/RTOSDemo.out -monitor none -nographic -serial stdio -s -S", "dependsOn": ["Build QEMU"], "isBackground": true, "problemMatcher": [ { "pattern": [ { "regexp": ".", "file": 1, "location": 2, "message": 3 } ], "background": { "activeOnStart": true, "beginsPattern": ".", "endsPattern": "QEMU RTOSdemo started", } } ] } ] } 按F5启动调试 如下图 1 个帖子 - 1 位参与者 阅读完整话题