Main Content

Build and Run Executable on ARM Cortex-Mx processor

Configure a Simulink® model, build an executable, and run the executable on ARM® Cortex®-M3/M4/M55/M7 QEMU emulator.

Make sure that you download and install the QEMU Emulator as described in Download and Install QEMU Emulator.

  1. Configure your model as described in Configure a Model for ARM Cortex-Mx Processor.

  2. Go to Hardware tab. From the Build, Deploy & Start drop-down, select the Build button. This action generates code from your model, builds an .elf file and runs the generated .elf in the QEMU emulator.

    The software displays the status of the build process in the MATLAB® Diagnostic Viewer. The QEMU is launched and the generated code starts running in the emulator.

    For example:

    ### 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 opens a window without text in it. This window remains open while QEMU is running the emulation session.

  3. Use the following MATLAB syntax to stop the .elf file on the QEMU emulator:

    codertarget.arm_cortex_m.stopQemu(pid)

    Replace pid in the command with the PID number from the preceding status message. For example, in the MATLAB Command Window, enter:

    codertarget.arm_cortex_m.stopQemu(8500)
    

    The MATLAB Command Window displays the status of the emulator session. For example:

    Terminated QEMU process with PID 8500.
    

Note

You cannot run the generated code for ARM Cortex-M processors on Mac OS X.

Run Generated Code Manually in MATLAB Using QEMU Emulator

Use the following MATLAB syntax to run the .elf file on the QEMU emulator manually.

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

Replace modelname.elf with the name of the .elf file from the preceding status message. For example, in the MATLAB Command Window, enter:

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

The MATLAB Command Window displays the process id (PID) of the emulation session. For example:

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

pid =

        8500
QEMU opens a window without text in it. This window remains open while QEMU is running the emulation session.