forked from tanchou/Verilog
Add UART TX module and testbench, update scripts and constraints
This commit is contained in:
4
Semaine_4/FIFO/.gitignore
vendored
Normal file
4
Semaine_4/FIFO/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
runs
|
||||
.vscode
|
||||
workspace.code-workspace
|
||||
*.pyc
|
19
Semaine_4/FIFO/constraints/top_uart_loopback.cst
Normal file
19
Semaine_4/FIFO/constraints/top_uart_loopback.cst
Normal file
@@ -0,0 +1,19 @@
|
||||
IO_LOC "rx" 70;
|
||||
IO_PORT "rx" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
|
||||
IO_LOC "tx" 69;
|
||||
IO_PORT "tx" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
|
||||
IO_LOC "clk" 4;
|
||||
IO_PORT "clk" PULL_MODE=UP BANK_VCCIO=1.8;
|
||||
|
||||
IO_LOC "leds[0]" 15;
|
||||
IO_PORT "leds[0]" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
|
||||
IO_LOC "leds[1]" 16;
|
||||
IO_PORT "leds[1]" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
|
||||
IO_LOC "leds[2]" 17;
|
||||
IO_PORT "leds[2]" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
|
||||
IO_LOC "leds[3]" 18;
|
||||
IO_PORT "leds[3]" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
|
||||
IO_LOC "leds[4]" 19;
|
||||
IO_PORT "leds[4]" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
|
||||
IO_LOC "leds[5]" 20;
|
||||
IO_PORT "leds[5]" PULL_MODE=UP DRIVE=8 BANK_VCCIO=1.8;
|
6
Semaine_4/FIFO/project.bat
Normal file
6
Semaine_4/FIFO/project.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@call c:\oss-cad-suite\environment.bat
|
||||
@echo off
|
||||
if "%1"=="sim" call scripts\simulate.bat
|
||||
if "%1"=="wave" call scripts\gtkwave.bat
|
||||
if "%1"=="clean" call scripts\clean.bat
|
||||
if "%1"=="build" call scripts\build.bat
|
45
Semaine_4/FIFO/scripts/build.bat
Normal file
45
Semaine_4/FIFO/scripts/build.bat
Normal file
@@ -0,0 +1,45 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
rem === Aller à la racine du projet ===
|
||||
cd /d %~dp0\..
|
||||
|
||||
rem === Config de base ===
|
||||
set DEVICE=GW2AR-LV18QN88C8/I7
|
||||
set BOARD=tangnano20k
|
||||
set TOP=top_uart_loopback
|
||||
set CST_FILE=%TOP%.cst
|
||||
set JSON_FILE=runs/%TOP%.json
|
||||
set PNR_JSON=runs/pnr_%TOP%.json
|
||||
set BITSTREAM=runs/%TOP%.fs
|
||||
|
||||
rem === Créer le dossier runs si nécessaire ===
|
||||
if not exist runs (
|
||||
mkdir runs
|
||||
)
|
||||
|
||||
echo === Étape 1 : Synthèse avec Yosys ===
|
||||
yosys -p "read_verilog -sv src/verilog/%TOP%.v src/verilog/uart_rx.v src/verilog/uart_tx.v; synth_gowin -top %TOP% -json %JSON_FILE%"
|
||||
if errorlevel 1 goto error
|
||||
|
||||
echo === Étape 2 : Placement & Routage avec nextpnr-himbaechel ===
|
||||
nextpnr-himbaechel --json %JSON_FILE% --write %PNR_JSON% --device %DEVICE% --vopt cst=constraints/%CST_FILE% --vopt family=GW2A-18C
|
||||
if errorlevel 1 goto error
|
||||
|
||||
echo === Étape 3 : Packing avec gowin_pack ===
|
||||
gowin_pack -d %DEVICE% -o %BITSTREAM% %PNR_JSON%
|
||||
if errorlevel 1 goto error
|
||||
|
||||
echo === Étape 4 : Flash avec openFPGALoader ===
|
||||
openFPGALoader -b %BOARD% %BITSTREAM%
|
||||
if errorlevel 1 goto error
|
||||
|
||||
echo === Compilation et flash réussis ===
|
||||
goto end
|
||||
|
||||
:error
|
||||
echo === Une erreur est survenue ===
|
||||
|
||||
:end
|
||||
endlocal
|
||||
pause
|
4
Semaine_4/FIFO/scripts/clean.bat
Normal file
4
Semaine_4/FIFO/scripts/clean.bat
Normal file
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
echo === Nettoyage du dossier runs ===
|
||||
rd /s /q runs
|
||||
mkdir runs
|
3
Semaine_4/FIFO/scripts/gtkwave.bat
Normal file
3
Semaine_4/FIFO/scripts/gtkwave.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
echo === Lancement de GTKWave ===
|
||||
gtkwave runs/uart.vcd
|
29
Semaine_4/FIFO/scripts/simulate.bat
Normal file
29
Semaine_4/FIFO/scripts/simulate.bat
Normal file
@@ -0,0 +1,29 @@
|
||||
@echo off
|
||||
echo === Simulation avec Icarus Verilog ===
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Dossier de sortie
|
||||
set OUT=runs/sim.vvp
|
||||
|
||||
:: Top-level testbench module
|
||||
set TOP=tb_uart
|
||||
|
||||
:: Répertoires contenant des fichiers .v
|
||||
set DIRS=src/verilog tests/verilog IP/verilog
|
||||
|
||||
:: Variable pour stocker les fichiers
|
||||
set FILES=
|
||||
|
||||
:: Boucle sur chaque dossier
|
||||
for %%D in (%DIRS%) do (
|
||||
for %%F in (%%D\*.v) do (
|
||||
set FILES=!FILES! %%F
|
||||
)
|
||||
)
|
||||
|
||||
:: Compilation avec Icarus Verilog
|
||||
iverilog -g2012 -o %OUT% -s %TOP% %FILES%
|
||||
|
||||
endlocal
|
||||
|
||||
vvp runs/sim.vvp
|
16
Semaine_4/FIFO/src/verilog/fifo.v
Normal file
16
Semaine_4/FIFO/src/verilog/fifo.v
Normal file
@@ -0,0 +1,16 @@
|
||||
module uart_tx #(
|
||||
parameter DETPH = 16,
|
||||
parameter WIDTH = 8
|
||||
)(
|
||||
input wire clk,
|
||||
input wire wr_en,
|
||||
input wire[WIDTH-1:0] wr_data,
|
||||
input wire rd_en,
|
||||
output wire[WIDTH-1:0] rd_data,
|
||||
|
||||
output wire full,
|
||||
output wire empty,
|
||||
);
|
||||
|
||||
|
||||
endmodule
|
19
Semaine_4/FIFO/tests/verilog/tb_fifo.v
Normal file
19
Semaine_4/FIFO/tests/verilog/tb_fifo.v
Normal file
@@ -0,0 +1,19 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
module tb_fifo;
|
||||
|
||||
reg clk = 0;
|
||||
|
||||
|
||||
always #18.5 clk = ~clk;
|
||||
|
||||
|
||||
|
||||
initial begin
|
||||
$dumpfile("runs/fifo.vcd");
|
||||
$dumpvars(0, tb_fifo);
|
||||
|
||||
|
||||
end
|
||||
|
||||
endmodule
|
Reference in New Issue
Block a user