メインコンテンツ

ARM Cortex-Mx プロセッサ上での実行可能ファイルのビルドと実行

R2026b

Simulink® モデルを構成し、実行可能ファイルをビルドして、ARM® Cortex®-M3/M4/M55/M7 QEMU エミュレーターでその実行可能ファイルを実行します。

Download and Install QEMU Emulatorの説明に従って、QEMU エミュレーターをダウンロードしてインストールしてください。

  1. ARM Cortex-Mx プロセッサ用のモデルの構成の説明に従ってモデルを構成します。

  2. [ハードウェア] タブに移動します。[ビルド、展開、起動] ドロップダウンから [ビルド] ボタンを選択します。この操作により、モデルからコードが生成され、.elf ファイルがビルドされ、生成された .elf が QEMU エミュレーターで実行されます。

    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.
    

メモ

ARM Cortex-M プロセッサ向けに生成されたコードは、Mac OS X では実行できません。

QEMU エミュレーターを使用した MATLAB での生成コードの手動実行

次の 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.