MiniZedでLチカ(3) Vitis

Avent社のFPGAボード MiniZedでLチカする手順です。前の記事でBitstreamを出力するところまで済ませました。この記事ではLチカまでを書きます。

開発環境

Vitisの起動

f:id:otto5:20210623162630p:plain

Tools -> Laungh Vitis IDE をクリック

f:id:otto5:20210623163729p:plain

プロジェクトルートを指定してLaunghをクリック

Platform Projectの作成

f:id:otto5:20210623163900p:plain

Create Platform Projectをクリック

f:id:otto5:20210623164008p:plain

Platform project nameを入力してNextをクリック

f:id:otto5:20210623164129p:plain

プロジェクトルートにVivadoから出力したxsaファイルがあるのでこれを指定してFinishをクリック

Application Projectの作成

f:id:otto5:20210623164304p:plain

File -> New -> Application Project をクリック

f:id:otto5:20210623165522p:plain

Nextをクリック

f:id:otto5:20210623165543p:plain

Nextをクリック

f:id:otto5:20210623165856p:plain

Application project name入力してNextをクリック

f:id:otto5:20210623165655p:plain

Nextをクリック

f:id:otto5:20210623170436p:plain

Finishをクリック

プログラム記述

f:id:otto5:20210623182301p:plain

helloworld.c内にLチカするプログラムを追加します。 Hardware User GuideのTable 13 – Allocation of MIO pinsを見ると、LEDは52番ピンと53番ピンにつながっていることが分かります。

#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "sleep.h" // sleep()に必要
#include "xgpiops.h" // gpio操作に必要


int main()
{
    XGpioPs_Config *cfg;
    XGpioPs ins;

    init_platform();
    cfg = XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID);
    XGpioPs_CfgInitialize(&ins, cfg, cfg->BaseAddr); // gpioのconfigを初期化

    // ピンの入出力を指定 第3引数が0で入力, 1で出力
    XGpioPs_SetDirectionPin(&ins, 52, 1); 
    XGpioPs_SetDirectionPin(&ins, 53, 1);
    // ピンの出力を有効化
    XGpioPs_SetOutputEnablePin(&ins, 52, 1); 
    XGpioPs_SetOutputEnablePin(&ins, 53, 1);

    print("Hello World\n\r");
    print("Successfully ran Hello World application");

    while(1) {
        XGpioPs_WritePin(&ins, 53, 0);
        sleep(1);
        XGpioPs_WritePin(&ins, 52, 1);
        sleep(1);
        XGpioPs_WritePin(&ins, 53, 1);
        sleep(1);
        XGpioPs_WritePin(&ins, 52, 0);
        sleep(1);
    }

    cleanup_platform();
    return 0;
}

プログラムの書き込み

まず、ボードのディップスイッチを書き込みモードになっていることを確認します。 HW Users Guideの5章 Boot Modes をみると、JTAG Boot Modeを選択するにはMIO[5], MIO[4], MIO[3]をすべて0にすれば良いことが分かります。さらに、Table 15 – Boot Mode Switch Selectionsを見るとBoot Mode SwitchをJにすれば良いことが分かります。

f:id:otto5:20210624223550p:plain

続いて、USB JTAG UART のMicro USBポートとPCを接続して、プログラムをZynqに書き込みます。

f:id:otto5:20210624223651p:plain

Xilinx -> Program Device をクリック

f:id:otto5:20210624223801p:plain

Program をクリック ボードのDONE LED(青色)が点灯すれば完了です。

プログラムのビルド

f:id:otto5:20210624221834p:plain

LedBlink_system[System]を右クリック -> Buildをクリック

f:id:otto5:20210624222018p:plain

Console にエラーがなくビルドが終了していれば成功です。

プログラムの実行

f:id:otto5:20210624224954p:plain

Debugを右クリック -> Run -> Debugger_LedBlink-Default (Single Application Debug) をクリック

PS LEDが赤 -> 黄 -> 緑 -> 滅 と点滅します。

参考にさせていただいたサイト

ハードもソフトもZynqで開発3 | 株式会社コンピューテックス