Basys 3 ASCII terminal: VGA 80x30 text, USB keyboard, UART

- VGA 640x480@60 text display, 8x16 CP437 font ROM from Linux console fonts
- USB HID keyboard (PS/2 via onboard PIC24), scan code set 2 to ASCII
  with xterm sequences for cursor/editing keys
- UART RX/TX with switch-selectable baud, local echo option
- Terminal engine: control codes, deferred wrap, hardware scroll,
  VT100/ANSI subset (cursor moves, erase, reverse video, cursor hide)
- Vivado build/program/flash scripts and xsim whole-design testbench

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
barantandClaude Opus 5.5 committed 2026-11-17 10:26:13 -08:00
commit 0e95a14cfe
18 files changed
+5596

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
#!/bin/bash
# Build the bitstream; add "program" or "flash" to load it onto a connected board.
set -e
cd "$(dirname "$0")/.."
source scripts/vivado_env.sh
mkdir -p build
cd build
vivado -mode batch -nojournal -log build.log -source ../scripts/build.tcl
case "$1" in
program) vivado -mode batch -nojournal -log program.log -source ../scripts/program.tcl ;;
flash) vivado -mode batch -nojournal -log program.log -source ../scripts/program.tcl -tclargs flash ;;
esac
+23
View File
@@ -0,0 +1,23 @@
# Non-project Vivado build: vivado -mode batch -source scripts/build.tcl
set root [file normalize [file dirname [info script]]/..]
set out $root/build
file mkdir $out
read_verilog [glob $root/rtl/*.v]
read_mem $root/font/font.mem
read_xdc $root/constraints/basys3.xdc
synth_design -top basys3_terminal -part xc7a35tcpg236-1
opt_design
place_design
route_design
report_utilization -file $out/utilization.rpt
report_timing_summary -file $out/timing.rpt
write_bitstream -force $out/basys3_terminal.bit
write_cfgmem -force -format mcs -interface SPIx4 -size 4 \
-loadbit "up 0x0 $out/basys3_terminal.bit" $out/basys3_terminal.mcs
set wns [get_property SLACK [get_timing_paths -max_paths 1 -setup]]
puts "Worst setup slack: $wns ns"
if {$wns < 0} { error "timing not met" }
+31
View File
@@ -0,0 +1,31 @@
# Program the Basys 3 over its USB-JTAG port.
# vivado -mode batch -source scripts/program.tcl (SRAM, lost at power-off)
# vivado -mode batch -source scripts/program.tcl -tclargs flash (QSPI flash, survives power-off)
set root [file normalize [file dirname [info script]]/..]
set mode [expr {[llength $argv] > 0 ? [lindex $argv 0] : "sram"}]
open_hw_manager
connect_hw_server
open_hw_target
set dev [lindex [get_hw_devices xc7a35t*] 0]
current_hw_device $dev
refresh_hw_device -update_hw_probes false $dev
if {$mode eq "flash"} {
create_hw_cfgmem -hw_device $dev [lindex [get_cfgmem_parts {s25fl032p-spi-x1_x2_x4}] 0]
set mem [get_property PROGRAM.HW_CFGMEM $dev]
set_property PROGRAM.FILES [list $root/build/basys3_terminal.mcs] $mem
set_property PROGRAM.ADDRESS_RANGE use_file $mem
set_property PROGRAM.ERASE 1 $mem
set_property PROGRAM.CFG_PROGRAM 1 $mem
set_property PROGRAM.VERIFY 1 $mem
create_hw_bitstream -hw_device $dev [get_property PROGRAM.HW_CFGMEM_BITFILE $dev]
program_hw_devices $dev
program_hw_cfgmem -hw_cfgmem $mem
puts "Flash programmed; set JP1 to QSPI and power-cycle (or press PROG)."
} else {
set_property PROGRAM.FILE $root/build/basys3_terminal.bit $dev
program_hw_devices $dev
puts "FPGA configured."
}
close_hw_manager
Executable
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
# Run the testbench in Vivado's simulator; output lands in sim/work.
set -e
cd "$(dirname "$0")/.."
ROOT=$(pwd)
source scripts/vivado_env.sh
mkdir -p sim/work
cd sim/work
xvlog -d FONT_FILE="\"$ROOT/font/font.mem\"" "$ROOT"/rtl/*.v "$ROOT"/sim/tb_terminal.v
xelab -debug off tb_terminal -s tb_terminal
xsim tb_terminal -R
if command -v python3 >/dev/null; then
python3 -c "from PIL import Image; Image.open('frame.ppm').save('frame.png')" && echo "wrote sim/work/frame.png"
fi
+14
View File
@@ -0,0 +1,14 @@
# Sourced by build.sh and sim.sh: sets up Vivado's environment.
# VIVADO picks the install; default is the newest in ~/vivado/<version>/Vivado.
VIVADO=${VIVADO:-$(ls -d "$HOME"/vivado/*/Vivado 2>/dev/null | sort -V | tail -1)}
source "$VIVADO/settings64.sh"
# Vivado still links against ncurses 5; newer distros only ship 6, which works.
COMPAT_LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/build/compat-lib"
mkdir -p "$COMPAT_LIB"
for l in ncurses tinfo; do
if ! ldconfig -p | grep -q "lib$l.so.5" && [ -e /usr/lib/x86_64-linux-gnu/lib$l.so.6 ]; then
ln -sf /usr/lib/x86_64-linux-gnu/lib$l.so.6 "$COMPAT_LIB/lib$l.so.5"
fi
done
export LD_LIBRARY_PATH="$COMPAT_LIB${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"