HLS/FIR8: un-timed vs. timed 모델링 인터페이스 실습
목차:
1. 실습 개요
2. 준비물
2-1. 소프트웨어
2-2. 하드웨어
2-3. 선행 학습
2-3-1. 기술노트13: Arduino, VitisHLS, Quartus [링크][pdf]
2-3-2. 기술노트 15: 내 책상위의 반도체 설계실 꾸미기 [링크][pdf]
3. FIR 디지털 필터 알고리즘의 언-타임드 C++ 모델
3-1. 환경변수 설정
3-2. 언-타임드 C++ 모델 빌드
3-3. 언-타임드 모델 실행
3-3-1. 알고리즘 시뮬레이션 출력 저장
3-3-2. 시뮬레이션 데이터 시각화(파이썬)
4. 모델링 인터페이스
4-1. 언타임드 C++ 알고리즘의 타임드 입출력 모델링
4-1-1. 인터페이스 모델 테스트벤치
4-1-2. 에뮬레이터 프록시
4-2. Arduino DUE 에서 언-타임드 C++ 모델 실행
4-2-1. 언-타임드 C++ 모델이 포함된 모델링 인터페이스 빌드
4-2-2. 아듀이노 CLI 환경: 코어(보드) 개발 툴(GCC) 설치
4-2-3. 아듀이노 CLI 환경: 라이브러리 설치
4-2-4. 언-타임드 C++ 모델이 포함된 모델링 인터페이스 펌웨어 업로드
4-2-5. 언-타임드 C++ 모델의 재사용
4-2-6. 에뮬레이터 실행
4-2-7. 모델링 인터페이스의 출력 타이밍 변경
4-3. Raspberry PI PICO 에서 언-타임드 C++ 모델 실행
4-3-1. 아듀이노 CLI 환경: RP2040 코어(보드) 개발 툴(GCC) 설치
4-3-2. 언-타임드 C++ 모델이 포함된 모델링 인터페이스 빌드
4-3-3. 언-타임드 C++ 모델이 포함된 모델링 인터페이스 업로드
4-3-4. 언-타임드 C++ 모델의 인터페이스 타이밍 에뮬레이션
CC-BY-NC
by GoodKook, goodkook@gmail.com
-------------------------------------------------------------------
설계 과정 에서 해당 부분 그림
2. 준비물
2-1. 소프트웨어
Arduino CLI
2-2. 하드웨어
2-2-1. Raspberry PI Pico + 어댑터 보드
2-2-2. Arduino DUE + 어댑터 보드
2-3. 선행 학습
2-3-1. 기술노트13: Arduino, VitisHLS, Quartus [링크][pdf]
2-3-2. 기술노트 15: 내 책상위의 반도체 설계실 꾸미기 [링크][pdf]
3. FIR 디지털 필터 알고리즘의 언-타임드 C++ 모델
3-1. 환경변수 설정
$ cd ~/ETRI050_DesignKit/Projects/HLS/FIR8
$ source env_settings
#****************************************************************
#* Environment setting for HLS, Co-Simulmatio/Emulation & ETRI050
#****************************************************************
Setting Environment variables as follows;
PROJECT_DIR=~/ETRI050_DesignKit/Projects/HLS/FIR8
TOP_MODULE=FIR8
HW_STYLE=FIR_MAC_VERSION
MODE=CA
MI=DUE_NORMAL
3-2. 언-타임드 C++ 모델 빌드
$ cd c_untimed
$ ll
total 44
drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:42 ./
drwxr-xr-x 8 mychip mychip 4096 Oct 27 13:37 ../
-rw-r--r-- 1 mychip mychip 2848 Oct 27 13:37 FIR8.cpp
-rw-r--r-- 1 mychip mychip 1276 Oct 27 13:37 FIR8.h
-rw-r--r-- 1 mychip mychip 2061 Oct 27 13:37 FIR8_TB.cpp
-rw-r--r-- 1 mychip mychip 1803 Oct 27 13:37 Makefile
-rw-r--r-- 1 mychip mychip 477 Oct 27 13:37 calcDFT.cpp
-rw-r--r-- 1 mychip mychip 7330 Oct 27 13:37 cnoise.cpp
-rw-r--r-- 1 mychip mychip 2768 Oct 27 13:37 cnoise.h
-rw-r--r-- 1 mychip mychip 1713 Oct 27 13:37 plotDFT.py
$ make
Makefile for un-timed C simulation of FIR8
TOP_MODULE=FIR8 HW_STYLE=FIR_MAC_VERSION make build
TOP_MODULE=FIR8 make run
TOP_MODULE=FIR8 make clean
$ make build
clang++ -I/opt/systemc/include -L/opt/systemc/lib \
-o FIR8_TB \
-DFIR_MAC_VERSION_SC \
./calcDFT.cpp ./cnoise.cpp \
./FIR8.cpp ./FIR8.h ./FIR8_TB.cpp \
-lsystemc -lgsl
3-3. 언-타임드 모델 실행
3-3-1. 알고리즘 시뮬레이션 출력 저장
$ make run | tee result.txt
./FIR8_TB
SystemC 3.0.2-Accellera --- Aug 19 2025 16:50:37
Copyright (c) 1996-2025 by all Contributors,
ALL RIGHTS RESERVED
0 124 26.243 496 36.263
1 90 13.222 1848 23.956
2 124 11.542 4676 22.473
......
4795 185 14.501 15444 24.305
4796 59 13.516 15475 23.078
4797 121 13.911 16278 23.623
4798 109 11.542 16676 22.473
4799 73 13.222 16634 23.956
3-3-2. 시뮬레이션 데이터 시각화(파이썬)
plotDFT.py <TXT> <option>
Plot graph from text file. <option> is one of followings,
input, inputDFT, output, outputDFT
$ python3 plotDFT.py result.txt outputDFT
Traceback (most recent call last):
File ".../FIR8/c_untimed/plotDFT.py", line 32, in <module>
y1.append(int(lines[1]))
~~~~~^^^
IndexError: list index out of range
-----------------------------------
* result.txt 파일에서 첫줄 삭제
-----------------------------------
$ python3 plotDFT.py result.txt input
$ python3 plotDFT.py result.txt inputDFT
$ python3 plotDFT.py result.txt output
$ python3 plotDFT.py result.txt outputDFT
4. 모델링 인터페이스
4-1. 언타임드 C++ 알고리즘의 타임드 입출력 모델링
4-1-1. 인터페이스 모델 테스트벤치
sc_FIR8_TB.h [링크]
sc_FIR8_TB.cpp [링크]
4-1-2. 에뮬레이터 프록시
EFIR8.h [링크]
...
4-2. Arduino DUE 에서 언-타임드 C++ 모델 실행
$ cd ~/ETRI050_DesignKit/Projects/HLS/FIR8/emulation/PSCE-MI
$ ll
total 28
drwxr-xr-x 6 mychip mychip 4096 Oct 27 13:37 ./
drwxr-xr-x 4 mychip mychip 4096 Oct 27 14:30 ../
drwxr-xr-x 3 mychip mychip 4096 Oct 27 13:53 EFIR8_AL/
drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:37 EFIR8_CA/
drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:37 EFIR8_SA/
-rw-r--r-- 1 mychip mychip 3630 Oct 27 13:37 Makefile
drwxr-xr-x 2 mychip mychip 4096 Oct 27 13:37 PSCE_API/
4-2-1. 언-타임드 C++ 모델이 포함된 모델링 인터페이스 빌드
$ MODE=AL MI=DUE_NORMAL make build
Linking Un-Timed model...
arduino-cli compile --clean --fqbn arduino:sam:arduino_due_x_dbg \
EFIR8_AL \
--build-path ./EFIR8_AL/build \
--build-property compiler.cpp.extra_flags=\
"-DOLED_DISPLAY -DDUE_NORMAL -DUART_BPS=115200 -DCYCLONE_IV"\
" -DFIR_MAC_VERSION"
Error during build: Platform 'arduino:sam' not found:
platform not installed
Try running `arduino-cli core install arduino:sam`
make: *** [Makefile:66: build] Error 1
4-2-2. 아듀이노 CLI 환경: 코어(보드) 개발 툴(GCC 컴파일러) 설치
설치된 코어(보드) 목록 보기,
$ arduino-cli board listall
Board Name FQBN
Adafruit Circuit Playground arduino:avr:circuitplay32u4cat
Arduino BT arduino:avr:bt
Arduino Duemilanove or Diecimila arduino:avr:diecimila
.....
Atmel ARM 코어 개발 툴 설치,
$ arduino-cli core update-index
Downloading index: package_index.tar.bz2 downloaded
$ arduino-cli core install arduino:sam
Downloading packages...
arduino:arm-none-eabi-gcc@4.8.3-2014q1 downloaded
arduino:bossac@1.6.1-arduino downloaded
arduino:sam@1.6.12 downloaded
Installing arduino:arm-none-eabi-gcc@4.8.3-2014q1...
Configuring tool....
arduino:arm-none-eabi-gcc@4.8.3-2014q1 installed
Installing arduino:bossac@1.6.1-arduino...
Configuring platform....
Platform arduino:sam@1.6.12 installed
$ MODE=AL MI=DUE_NORMAL make build
arduino-cli compile --clean --fqbn arduino:sam:arduino_due_x_dbg \
EFIR8_AL \
--build-path ./EFIR8_AL/build \
--build-property compiler.cpp.extra_flags=\
"-DOLED_DISPLAY -DDUE_NORMAL -DUART_BPS=115200 -DCYCLONE_IV"\
" -DFIR_MAC_VERSION"
In file included from
.../HLS/FIR8/emulation/PSCE-MI/EFIR8_AL/PSCE_Config.h:33:0,
from
.../HLS/FIR8/emulation/PSCE-MI/EFIR8_AL/EFIR8_AL.ino:6:
.../HLS/FIR8/emulation/PSCE-MI/EFIR8_AL/PSCE_APIs.h:21:54:
fatal error: U8g2lib.h: No such file or directory
#include <U8g2lib.h> // OLED Display Libraries
^
compilation terminated.
Used library Version Path
Wire 1.0
~/.arduino15/packages/arduino/hardware/sam/1.6.12/libraries/Wire
Used platform Version Path
arduino:sam 1.6.12
~/.arduino15/packages/arduino/hardware/sam/1.6.12
Error during build: exit status 1
make: *** [Makefile:66: build] Error 1
4-2-3. 아듀이노 CLI 환경: 라이브러리 설치
u8g2 라이브러리 설치
$ arduino-cli lib install u8g2
Downloading U8g2@2.35.30...
U8g2@2.35.30 downloaded
Installing U8g2@2.35.30...
Installed U8g2@2.35.30
4-2-4. 언-타임드 C++ 모델이 포함된 모델링 인터페이스 펌웨어 업로드
모델링 인터페이스 빌드
$ MODE=AL MI=DUE_NORMAL make build
arduino-cli compile --clean --fqbn arduino:sam:arduino_due_x_dbg \
EFIR8_AL \
--build-path ./EFIR8_AL/build \
--build-property compiler.cpp.extra_flags=\
"-DOLED_DISPLAY -DDUE_NORMAL -DUART_BPS=115200 -DCYCLONE_IV"\
" -DFIR_MAC_VERSION"
Sketch uses 35048 bytes (6%) of program storage space.
Maximum is 524288 bytes.
USB 장치 확인
$ lsusb
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 001 Device 003: ID 2341:003d Arduino SA Due Programming Port
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
모델링 인터페이스 펌웨어 업로드
$ MODE=AL MI=DUE_NORMAL make upload
arduino-cli upload -p /dev/ttyACM0 --fqbn \
arduino:sam:arduino_due_x_dbg EFIR8_AL \
--input-file ./EFIR8_AL/build/EFIR8_AL.ino.bin
Cannot perform port reset: 1200-bps touch: opening port at
1200bps: Permission denied
No device found on ttyACM0
Failed uploading: uploading error: exit status 1
make: *** [Makefile:91: upload] Error 1
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 Oct 27 17:22 /dev/ttyACM0
$ sudo chmod 666 /dev/ttyACM0
[sudo] password for mychip:
$ ls -l /dev/ttyACM0
crw-rw-rw- 1 root dialout 166, 0 Oct 27 17:22 /dev/ttyACM0
$ MODE=AL MI=DUE_NORMAL make upload
arduino-cli upload -p /dev/ttyACM0 --fqbn \
arduino:sam:arduino_due_x_dbg EFIR8_AL \
--input-file ./EFIR8_AL/build/EFIR8_AL.ino.bin
Atmel SMART device 0x285e0a60 found
Erase flash
Write 37140 bytes to flash (146 pages)
[==============================] 100% (146/146 pages)
done in 8.820 seconds
Set boot flash true
CPU reset.
New upload port: /dev/ttyACM0 (serial)
4-2-5. 언-타임드 C++ 모델의 재사용
$ ls -l EFIR8_AL
total 8
-rw-rw-r-- 1 mychip ... EFIR8_AL.ino
lrwxrwxrwx 1 mychip ... FIR8.cpp -> ../../../c_untimed/FIR8.cpp
lrwxrwxrwx 1 mychip ... FIR8.h -> ../../../c_untimed/FIR8.h
......
4-2-6. 에뮬레이터 실행
$ make run
./sc_FIR8_TB
SystemC 3.0.2-Accellera --- Aug 19 2025 16:50:37
Copyright (c) 1996-2025 by all Contributors,
ALL RIGHTS RESERVED
Info: (I703) tracing timescale unit set: 100 ps (EFIR8.vcd)
Request emulator connection......
make: *** [Makefile:73: run] Interrupt
모델링 인터페이스 보드 리셋 후,
$ make run
./sc_FIR8_TB
SystemC 3.0.2-Accellera --- Aug 19 2025 16:50:37
Copyright (c) 1996-2025 by all Contributors,
ALL RIGHTS RESERVED
Info: (I703) tracing timescale unit set: 100 ps (EFIR8.vcd)
Request emulator connection......
Connection established...
Info: (I703) tracing timescale unit set: 100 ps (sc_FIR8_TB.vcd)
[ 0] y= 0 Y= 0 OK
[ 1] y= 0 Y= 628 ERROR
[ 2] y= 628 Y= 2056 ERROR
[ 3] y= 2056 Y= 4941 ERROR
[ 4] y= 4941 Y= 8345 ERROR
[ 5] y= 8345 Y=11513 ERROR
[ 6] y=11513 Y=13553 ERROR
[ 7] y=13553 Y=14122 ERROR
[ 8] y=14122 Y=14180 ERROR
[ 9] y=14180 Y=14007 ERROR
[ 10] y=14007 Y=14480 ERROR
......
[4793] y=15039 Y=15367 ERROR
[4794] y=15367 Y=15031 ERROR
[4795] y=15031 Y=14326 ERROR
[4796] y=14326 Y=14271 ERROR
[4797] y=14271 Y=14512 ERROR
[4798] y=14512 Y=15436 ERROR
[4799] y=15436 Y=15868 ERROR
Info: /OSCI/SystemC: Simulation stopped by user.
4-2-7. 모델링 인터페이스의 출력 타이밍 변경
// Filename: EFIR8_AL.ino
void loop()
{
psce.EMU_Blinker(0x40); // Blinker speed
psce.RxData(N_RX);
y_ap_vld = ap_ready = ap_idle = ap_done = false;
if (psce.rxByte[0] & C_AP_RST)
cState = S_RESET;
else
{
switch(cState)
{
case S_RESET:
ap_idle = true;
cState = S_IDLE;
break;
case S_IDLE:
if (psce.rxByte[0] & C_AP_START)
cState = S_READY;
else
ap_idle = true;
break;
case S_READY:
ap_ready = true;
cState = S_GET_INPUT;
break;
case S_GET_INPUT:
x = psce.rxByte[1];
cState = S_DONE;
break;
case S_DONE:
y_ap_vld = ap_done = true;
//FIR8(&y, x);
cState = S_SET_OUTPUT;
break;
case S_SET_OUTPUT:
cState = S_IDLE;
FIR8(&y, x);
break;
}
}
psce.txByte[0] = 0x00;
if (y_ap_vld) psce.txByte[0] |= C_Y_AP_VLD;
if (ap_ready) psce.txByte[0] |= C_AP_READY;
if (ap_idle) psce.txByte[0] |= C_AP_IDLE;
if (ap_done) psce.txByte[0] |= C_AP_DONE;
psce.txByte[1] = y;
psce.txByte[2] = (y>>8);
psce.TxData(N_TX);
}
모델링 인터페이스 빌드, 업로드 및 에뮬레이터 실행
......
4-3. Raspberry PI PICO 에서 언-타임드 C++ 모델 실행
4-3-1. 아듀이노 CLI 환경: RP2040 코어(보드) 개발 툴(GCC) 설치
$ arduino-cli config add board_manager.additional_urls \
https://github.com/earlephilhower/\
arduino-pico/releases/download/global/\
package_rp2040_index.json
$ arduino-cli core update-index
$ arduino-cli core install rp2040:rp2040
4-3-2. 언-타임드 C++ 모델이 포함된 모델링 인터페이스 빌드
$ cd ~/ETRI050_DesignKit/Projects/HLS/FIR8/emulation/PSCE-MI
$ MODE=AL MI=PI_PICO make build
Linking Un-Timed model...
ln: failed to create symbolic link 'EFIR8_AL/FIR8.cpp': File exists
ln: failed to create symbolic link 'EFIR8_AL/FIR8.h': File exists
make: *** [Makefile:65: build] Error 1
$ rm EFIR8_AL/FIR8.cpp
$ rm EFIR8_AL/FIR8.h
$ MODE=AL MI=PI_PICO make build
Linking Un-Timed model...
arduino-cli compile --clean --fqbn rp2040:rp2040:rpipico \
EFIR8_AL \
--build-path ./EFIR8_AL/build \
--build-property compiler.cpp.extra_flags=\
"-DPI_PICO -DUART_BPS=115200 -DCYCLONE_IV"\
" -DFIR_MAC_VERSION"
Sketch uses 57180 bytes (2%) of program storage space.
Maximum is 2093056 bytes.
Global variables use 9600 bytes (3%) of dynamic memory,
leaving 252544 bytes for local variables.
Maximum is 262144 bytes.
4-3-3. 언-타임드 C++ 모델이 포함된 모델링 인터페이스 업로드
$ sudo mount -t drvfs F: /mnt/f
[sudo] password for mychip:
$ MODE=AL MI=PI_PICO make upload
arduino-cli upload -p /dev/ttyACM0 --fqbn rp2040:rp2040:rpipico \
EFIR8_AL \
--input-file ./EFIR8_AL/build/EFIR8_AL.ino.bin
Resetting /dev/ttyACM0
Converting to uf2, output size: 147968, start address: 0x2000
Scanning for RP2040 devices
Flashing /mnt/f (RPI-RP2)
Wrote 147968 bytes to /mnt/f/NEW.UF2
New upload port: /dev/ttyACM0 (serial)
4-3-4. 언-타임드 C++ 모델의 인터페이스 타이밍 에뮬레이션
$ cd ..
$ pwd
~/ETRI050_DesignKit/Projects/HLS/FIR8/emulation
clang++ -I/opt/systemc/include -L/opt/systemc/lib \
-I../emulation \
-I../simulation \
-I../c_untimed \
-DFIR_MAC_VERSION_SC \
-DEMULATED_CO_SIM \
-DVCD_TRACE_TEST_TB \
-lsystemc -lgsl \
-osc_FIR8_TB \
../c_untimed/cnoise.cpp ../c_untimed/FIR8.cpp \
../simulation/sc_FIR8_TB.cpp ../simulation/sc_main.cpp
$ make run
./sc_FIR8_TB
SystemC 3.0.2-Accellera --- Aug 9 2025 08:00:31
Copyright (c) 1996-2025 by all Contributors,
ALL RIGHTS RESERVED
Info: (I703) tracing timescale unit set: 100 ps (EFIR8.vcd)
Error opening serial port: No such file or directory
Info: (I703) tracing timescale unit set: 100 ps (sc_FIR8_TB.vcd)
^Cmake: *** [Makefile:73: run] Interrupt
$ ll /dev/ttyACM0
ls: cannot access '/dev/ttyACM0': No such file or directory
-------------------------------------------------
PS C:\> usbipd list
Connected:
BUSID VID:PID DEVICE STATE
1-5 0461:4e87 USB 입력 장치 Not shared
..........
7-1 2e8a:000a USB Serial Device(COM14) Not shared
PS C:\> usbipd bind --busid 7-1
PS C:\> usbipd attach --wsl --busid 7-1
usbipd: info: Using WSL distribution 'Ubuntu-24.04' to attach;
the device will be available in all WSL 2 distributions.
usbipd: info: Loading vhci_hcd module.
usbipd: info: Detected networking mode 'nat'.
usbipd: info: Using IP address 172.23.96.1 to reach the host.
-------------------------------------------------
$ make run
./sc_FIR8_TB
SystemC 3.0.2-Accellera --- Aug 9 2025 08:00:31
Copyright (c) 1996-2025 by all Contributors,
ALL RIGHTS RESERVED
Info: (I703) tracing timescale unit set: 100 ps (EFIR8.vcd)
Request emulator connection......
Connection established...
Info: (I703) tracing timescale unit set: 100 ps (sc_FIR8_TB.vcd)
[ 0] y= 0 Y= 0 OK
[ 1] y= 0 Y= 0 OK
[ 2] y= 564 Y= 564 OK
[ 3] y= 2004 Y= 2004 OK
[ 4] y= 5033 Y= 5033 OK
[ 5] y= 8844 Y= 8844 OK
[ 6] y=12573 Y=12573 OK
[ 7] y=15015 Y=15015 OK
[ 8] y=15676 Y=15676 OK
[ 9] y=15333 Y=15333 OK
[ 10] y=14374 Y=14374 OK
..........
[4795] y=15994 Y=15994 OK
[4796] y=14985 Y=14985 OK
[4797] y=14470 Y=14470 OK
[4798] y=13981 Y=13981 OK
[4799] y=14196 Y=14196 OK
Info: /OSCI/SystemC: Simulation stopped by user.
댓글 없음:
댓글 쓰기