2025년 10월 28일 화요일

RTL/pong_pt1: FPGA 에뮬레이션 실습

RTL/pong_pt1: FPGA 에뮬레이션 실습

목차:

CC-BY-NC
by GoodKook, goodkook@gmail.com

----------------------------------------------------------------------------

1. 실습 개요

..........

2. 준비물

2-1. 소프트웨어

    2-1-1. Arduino CLI
    2-1-2. Quartus Standard

2-2. 하드웨어

    2-2-1. Arduino DUE + 어댑터 보드

    2-2-2. Raspberry PI PICO + 어댑터 보드

    2-2-3. CycloneIV EP4CE6 + PSCE-TRANS(Type II) 어댑터 보드

    2-2-4. CycloneIV EP4CE6 + PSCE-TRANS(Type I) 어댑터 보드

2-3. 선행 학습

    2-3-1. 기술노트13: Arduino, VitisHLS, Quartus [링크][pdf]
            * HLS/FIR8: un-timed vs. timed 모델링 인터페이스 실습 [링크]

    2-3-2. 기술노트 15: 내 책상위의 반도체 설계실 꾸미기 [링크][pdf]

    2-3-3. 디자인 킷 예제 pong_pt1 을 자가 실습 [링크]


3. RTL 시뮬레이션

3-1. 환경 설정

$ cd ~/ETRI050_DesignKit/Projects/RTL/pong_pt1

$ source env_settings
    #****************************************************************
    #* Environment setting for RTL, Co-Simulmatio/Emulation & ETRI050
    #****************************************************************
    Setting Environment variables as follows;
    PROJECT_DIR=/home/mychip/ETRI050_DesignKit/Projects/RTL/pong_pt1
    TOP_MODULE=pong_pt1
    HW_STYLE=NONE
    MODE=CA
    MI=DUE_NORMAL

3-2. 베릴로그 RTL

$ ll pong_pt1

    total 24
    drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:37 ./
    drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 ../
    -rw-r--r-- 1 mychip mychip 7525 Oct 27 13:37 pixel_gen.v
    -rw-r--r-- 1 mychip mychip 3551 Oct 27 13:37 pong_pt1.v
    -rw-r--r-- 1 mychip mychip  819 Oct 27 13:37 pong_pt1.ys

3-3. RTL 시뮬레이션

$ cd simulation

$ ll

total 28
drwxr-xr-x 2 mychip mychip 4096 Oct 27 14:33 ./
drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 ../
-rw-r--r-- 1 mychip mychip 3187 Oct 27 13:37 Makefile
-rw-r--r-- 1 mychip mychip  442 Oct 27 13:37 sc_main.cpp
-rw-r--r-- 1 mychip mychip 5465 Oct 27 13:37 sc_pong_pt1_TB.cpp
-rw-r--r-- 1 mychip mychip 3776 Oct 27 13:37 sc_pong_pt1_TB.h

$ make

    Makefile for Co-Simulation, pong_pt1 in MODE=CA

    TOP_MODULE=pong_pt1 make lint
    TOP_MODULE=pong_pt1 VCD_TRACE=[YES]|NO make build
    make run
    make wave
    make clean

$ make build

    verilator --sc -Wno-WIDTHTRUNC -Wno-WIDTHEXPAND --trace \
        --timing --pins-sc-uint \
        --top-module pong_pt1  --exe --build \
        -CFLAGS -g \
        -CFLAGS -I/opt/systemc/include \
        -CFLAGS -DVCD_TRACE_TEST_TB \
        -CFLAGS -DVCD_TRACE_DUT_VERILOG \
        -CFLAGS -DCA -LDFLAGS \
        -LDFLAGS -lSDL2 \
        ../pong_pt1/*.v \
        ./sc_main.cpp ./sc_pong_pt1_TB.cpp

    make[1]: Entering directory '.../pong_pt1/simulation/obj_dir'

        ..........

    make[1]: Leaving directory '.../pong_pt1/simulation/obj_dir'

    - V e r i l a t i o n   R e p o r t: Verilator 5.039
    - Verilator: Built from 0.050 MB sources in 3 modules
    - Verilator: Walltime 4.906 s (elab=0.017, cvt=0.053, bld=4.714);

$ make run

    ./obj_dir/Vpong_pt1
        SystemC 3.0.2-Accellera --- Aug  9 2025 08:00:31
        Copyright (c) 1996-2025 by all Contributors,
        ALL RIGHTS RESERVED

    Warning: (W509) module construction not properly completed:
                    ... module 'u_sc_pong_pt1_TB'

    In file: .../Tools/systemc/src/sysc/kernel/sc_module.cpp:376

    nVSync[436] nHSync[15]

4. FPGA 에뮬레이션

$ cd ../emulation

$ pwd

    ~/ETRI050_DesignKit/Projects/RTL/pong_pt1/emulation

$ ll

    total 44
    drwxr-xr-x 5 mychip mychip 4096 Oct 27 14:57 ./
    drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 ../
    -rw-r--r-- 1 mychip mychip 5726 Oct 27 13:37 Epong_pt1.h
    -rw-r--r-- 1 mychip mychip 1897 Oct 27 13:37 Makefile
    drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 PSCE-MI/
    drwxr-xr-x 3 mychip mychip 4096 Oct 27 13:37 PSCE-TRANS/
    -rw-r--r-- 1 mychip mychip 5067 Oct 27 13:37 pong_pt1_tester.v
    -rw-r--r-- 1 mychip mychip 2297 Oct 27 13:37 pong_pt1_wrapper.v

4-1. 에뮬레이션 트랜잭터

$ cd PSCE-TRANS/Altera_Cmd/

$ ll

    total 416
    drwxr-xr-x 5 mychip mychip   4096 Oct 27 14:43 ./
    drwxr-xr-x 3 mychip mychip   4096 Oct 27 13:37 ../
    -rw-r--r-- 1 mychip mychip   1360 Oct 27 13:37 Makefile
    -rw-r--r-- 1 mychip mychip  10115 Oct 27 13:37 pong_pt1_tester.tcl
    -rw-r--r-- 1 mychip mychip   6994 Oct 27 14:41 pong_pt1_wrapper.tcl

$ make

    Quartus Command Line for pong_pt1_wrapper

    MODE=CA make build
    * Set MODE=TESTER for Chip-Test wrapper
    make gen_rbf
    make config

-----------------------------------------------------------------------

* Type-I & II FPGA 보드의 핀배치 변경(pong_pt1_wrapper.tcl)

- Type-I 회로도 [pdf]

set_location_assignment PIN_24 -to clk_dut
set_location_assignment PIN_23 -to clk_emu
set_location_assignment PIN_114 -to Addr_emu[1]

- Type-II 회로도 [pdf]

set_location_assignment PIN_143 -to clk_dut
set_location_assignment PIN_144 -to clk_emu
set_location_assignment PIN_110 -to Addr_emu[1]

------------------------------------------------------------------------

4-1-1. 트랜잭터 빌드

$ make build

    quartus_sh -t pong_pt1_wrapper.tcl

    Info: *********************************************************
    Info: Running Quartus Prime Shell
    ............
    Info (293000): Quartus Prime Full Compilation was successful.
                         0 errors, 35 warnings
    Info (23030): Evaluation of Tcl script pong_pt1_wrapper.tcl was successful
    Info: Quartus Prime Shell was successful. 0 errors, 35 warnings
    Info: Peak virtual memory: 456 megabytes

4-1-2. FPGA 트랜잭터 컨피규레이션

--------------------------------------------------------------

openFPGALoader 설치

* sudo apt update & upgrade 할 것
* Tools 디렉토리에 openFPGALoader 디렉토리에서 설치 스크립트 실행

--------------------------------------------------------------

$ lsusb

    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 004: ID 2341:003d Arduino SA Due Programming Port
    Bus 001 Device 005: ID 0403:6014 FT232H Single HS USB-UART/FIFO IC
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

$ make gen_rbf

    quartus_cpf -c ./output_files/pong_pt1_wrapper.sof output_file.rbf

$ make config

    sudo openFPGALoader -c digilent_hs2 output_file.rbf

    [sudo] password for mychip:

    empty
    Jtag frequency : requested 6.00MHz    -> real 6.00MHz
    Load SRAM: [==================================================]
    Done

4-2. CA 모드 에뮬레이션 모델링 인터페이스(MI)

$ cd ../../PSCE-MI

$ ll

    total 28
    drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 ./
    drwxr-xr-x 5 mychip mychip 4096 Oct 27 14:57 ../
    drwxr-xr-x 3 mychip mychip 4096 Oct 27 14:48 Epong_pt1_CA/
    drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:37 Epong_pt1_Disp/
    drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:37 Epong_pt1_SA/
    -rw-r--r-- 1 mychip mychip 2622 Oct 27 13:37 Makefile

$ make

    Arduino-CLI for Building Modeling-Interface of Epong_pt1_CA

    TOP_MODULE=pong_pt1 MODE=CA MI=DUE_NORMAL make build
    TOP_MODULE=pong_pt1 MODE=CA MI=DUE_NORMAL make upload
    TOP_MODULE=pong_pt1 MODE=CA MI=DUE_NORMAL make clean

    * MODE must be one of followings;
    CA           : Cycle Accurate
    SA           : System Accurate/Clock controlled by MI

    * MI must be one of followings;
    DUE_NORMAL   : Arduino DUE
    PI_PICO      : Raspberry Pi Pico

    * Firmware of Display Controller/SH1106
    MODE=Disp MI=PI_PICO make build
    MODE=Disp MI=PI_PICO make upload

4-2-1. CA 모드 MI 빌드

$ make build

    arduino-cli compile --clean --fqbn \
                arduino:sam:arduino_due_x_dbg Epong_pt1_CA \
                --build-path ./Epong_pt1_CA/build \
                --build-property compiler.cpp.extra_flags=\
                    "-DDUE_NORMAL -DUART_BPS=115200 -DCYCLONE_IV"

    Sketch uses 12072 bytes (2%) of program storage space.
    Maximum is 524288 bytes.

또는,

$ MI=PI_PICO make build

    arduino-cli compile --clean --fqbn \
        rp2040:rp2040:rpipico Epong_pt1_CA \
        --build-path ./Epong_pt1_CA/build \
        --build-property compiler.cpp.extra_flags=\
        "-DPI_PICO -DUART_BPS=115200 -DCYCLONE_IV"

    Sketch uses 60116 bytes (2%) of program storage space.
     Maximum is 2093056 bytes.

    Global variables use 9716 bytes (3%) of dynamic memory,
     leaving 252428 bytes for local variables.
     Maximum is 262144 bytes.

4-2-2. CA 모드 MI 업로드

* Windows의 USB 장치 WSL2와 공유: usbipd list, bind, attach

$ make upload

    arduino-cli upload -p /dev/ttyACM0 --fqbn  \
                arduino:sam:arduino_due_x_dbg Epong_pt1_CA \
               --input-file ./Epong_pt1_CA/build/Epong_pt1_CA.ino.bin

    Atmel SMART device 0x285e0a60 found
    Erase flash
    done in 0.040 seconds

    Write 13252 bytes to flash (52 pages)
    [==============================] 100% (52/52 pages)
    done in 2.767 seconds
    Set boot flash true
    CPU reset.
    New upload port: /dev/ttyACM0 (serial)

4-3. 싸이클 상세(CA) 에뮬레이션

$ cd ..

$ pwd

    ~/ETRI050_DesignKit/Projects/RTL/pong_pt1/emulation

$ ll

total 44
drwxr-xr-x 5 mychip mychip 4096 Oct 27 14:57 ./
drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 ../
-rw-r--r-- 1 mychip mychip 5726 Oct 27 13:37 Epong_pt1.h
-rw-r--r-- 1 mychip mychip 1897 Oct 27 13:37 Makefile
drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 PSCE-MI/
drwxr-xr-x 3 mychip mychip 4096 Oct 27 13:37 PSCE-TRANS/
-rw-r--r-- 1 mychip mychip 5067 Oct 27 13:37 pong_pt1_tester.v
-rw-r--r-- 1 mychip mychip 2297 Oct 27 13:37 pong_pt1_wrapper.v

4-3-1. CA 에뮬레이터 빌드

$ make

    Makefile for CA-Mode emulation of "pong_pt1"

    TOP_MODULE=pong_pt1 MODE=CA make build
    TOP_MODULE=pong_pt1 make run
    TOP_MODULE=pong_pt1 make clean

$ make build

    clang++ -I/opt/systemc/include -L/opt/systemc/lib \
        -I../emulation \
        -I../simulation \
        -DCA \
        -DEMULATED_CO_SIM \
        -DVCD_TRACE_TEST_TB \
        -lsystemc -lSDL2 \
        -osc_pong_pt1_TB \
        ../simulation/sc_pong_pt1_TB.cpp ../simulation/sc_main.cpp

4-3-2. CA 에뮬레이션

$ ls -l /dev/ttyACM0

    crw-rw---- 1 root dialout 166, 0 Oct 28 15:21 /dev/ttyACM0

$ sudo chmod 666 /dev/ttyACM0

    [sudo] password for mychip:

$ ls -l /dev/ttyACM0

    crw-rw-rw- 1 root dialout 166, 0 Oct 28 15:21 /dev/ttyACM0

$ make run

4-4. SA 모드 에뮬레이션 모델링 인터페이스(MI)

$ cd PSCE-MI

$ ll

    total 28
    drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 ./
    drwxr-xr-x 5 mychip mychip 4096 Oct 27 14:57 ../
    drwxr-xr-x 3 mychip mychip 4096 Oct 27 14:48 Epong_pt1_CA/
    drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:37 Epong_pt1_Disp/
    drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:37 Epong_pt1_SA/
    -rw-r--r-- 1 mychip mychip 2622 Oct 27 13:37 Makefile

$ make

    Arduino-CLI for Building Modeling-Interface of Epong_pt1_CA

    TOP_MODULE=pong_pt1 MODE=CA MI=DUE_NORMAL make build
    TOP_MODULE=pong_pt1 MODE=CA MI=DUE_NORMAL make upload
    TOP_MODULE=pong_pt1 MODE=CA MI=DUE_NORMAL make clean

    * MODE must be one of followings;
    CA           : Cycle Accurate
    SA           : System Accurate/Clock controlled by MI

    * MI must be one of followings;
    DUE_NORMAL   : Arduino DUE
    PI_PICO      : Raspberry Pi Pico

    * Firmware of Display Controller/SH1106
    MODE=Disp MI=PI_PICO make build
    MODE=Disp MI=PI_PICO make upload

4-4-1. 모델링 인터페이스 빌드

$ MODE=SA make build

    arduino-cli compile --clean --fqbn \
                arduino:sam:arduino_due_x_dbg Epong_pt1_SA \
                --build-path ./Epong_pt1_SA/build \
                --build-property compiler.cpp.extra_flags=\
                    "-DDUE_NORMAL -DUART_BPS=115200 -DCYCLONE_IV"

    Sketch uses 12072 bytes (2%) of program storage space.
    Maximum is 524288 bytes.

또는,

$ MODE=SA MI=PI_PICO make build

    arduino-cli compile --clean --fqbn \
        rp2040:rp2040:rpipico Epong_pt1_SA \
        --build-path ./Epong_pt1_SA/build \
        --build-property compiler.cpp.extra_flags=\
        "-DPI_PICO -DUART_BPS=115200 -DCYCLONE_IV"

    Sketch uses 60116 bytes (2%) of program storage space.
     Maximum is 2093056 bytes.

    Global variables use 9716 bytes (3%) of dynamic memory,
     leaving 252428 bytes for local variables.
     Maximum is 262144 bytes.

4-4-2. 모델링 인터페이스 업로드

* Windows의 USB 장치 WSL2와 공유: usbipd list, bind, attach

$ MODE=SA make upload

    arduino-cli upload -p /dev/ttyACM0 --fqbn  \
                arduino:sam:arduino_due_x_dbg Epong_pt1_SA \
               --input-file ./Epong_pt1_SA/build/Epong_pt1_SA.ino.bin

    Atmel SMART device 0x285e0a60 found
    Erase flash
    done in 0.040 seconds

    Write 13252 bytes to flash (52 pages)
    [==============================] 100% (52/52 pages)
    done in 2.767 seconds
    Set boot flash true
    CPU reset.

    New upload port: /dev/ttyACM0 (serial).....


.
























댓글 없음:

댓글 쓰기