主要内容

在 ARM Cortex-Mx 处理器上编译和运行可执行文件

R2026b

配置 Simulink® 模型,编译可执行文件,并在 ARM® Cortex®-M3/M4/M55/M7 QEMU 模拟器上运行该可执行文件。

确保您按照Download and Install QEMU Emulator中所述下载并安装 QEMU 模拟器。

  1. 按照为 ARM Cortex-Mx 处理器配置模型中所述配置您的模型。

  2. 转至硬件选项卡。从编译、部署和启动下拉菜单中,选择编译按钮。此操作将从您的模型生成代码,编译 .elf 文件,并在 QEMU 模拟器中运行生成的 .elf。

    Simulink Hardware tab showing the Build, Deploy, and Start menu with the Build option selected to generate and run code.

    该软件在 MATLAB® 诊断查看器中显示编译过程的状态。QEMU 启动,所生成代码开始在模拟器中运行。

    例如:

    ### Created: ../untitled1.elf
    ### Invoking postbuild tool Binary Converter ...
    arm-none-eabi-objcopy -O binary ../untitled1.elf ../untitled1.bin
    ### Done invoking postbuild tool.
    ### Invoking postbuild tool Hex Converter ...
    arm-none-eabi-objcopy -O ihex ../untitled1.elf ../untitled1.hex
    ### Done invoking postbuild tool.
    ### Invoking postbuild tool Executable Size ...
    arm-none-eabi-size ../untitled1.elf
       text	   data	    bss	    dec	    hex	filename
       2328	     20	   2136	   4484	   1184	../untitled1.elf
    ### Done invoking postbuild tool.
    ### Successfully generated all binary outputs.
    QEMU 会打开一个不包含文本的窗口。当 QEMU 运行模拟会话时,此窗口保持打开状态。

    QEMU emulator window launched while the generated executable runs on the emulated ARM Cortex‑M processor.

  3. 使用以下 MATLAB 语法来停止 QEMU 模拟器上的 .elf 文件:

    codertarget.arm_cortex_m.stopQemu(pid)

    将命令中的 pid 替换为前一条状态消息中的 PID 编号。例如,在 MATLAB 命令行窗口中,输入:

    codertarget.arm_cortex_m.stopQemu(8500)
    

    MATLAB 命令行窗口显示模拟器会话的状态。例如:

    Terminated QEMU process with PID 8500.
    

注意

您无法在 Mac OS X 上为 ARM Cortex-M 处理器运行生成代码。

在 MATLAB 中使用 QEMU 模拟器手动运行生成代码

使用以下 MATLAB 语法手动在 QEMU 模拟器上运行 .elf 文件。

pid = codertarget.arm_cortex_m.runQemu('modelname.elf')

将 modelname.elf 替换为前一条状态消息中的 .elf 文件的名称。例如,在 MATLAB 命令行窗口中,输入:

pid = codertarget.arm_cortex_m.runQemu('untitled1.elf')

MATLAB 命令行窗口显示模拟会话的进程 ID (PID)。例如:

### Downloading application...untitled1.elf
Started new QEMU process with PID 8500.

pid =

        8500
QEMU 会打开一个不包含文本的窗口。当 QEMU 运行模拟会话时,此窗口保持打开状态。

QEMU emulator window launched while the generated executable runs on the emulated ARM Cortex‑M processor.