Skip to content

Instantly share code, notes, and snippets.

@hansemro
Created November 2, 2025 14:33
Show Gist options
  • Select an option

  • Save hansemro/7f7d3532e8e9dc82fb0a36108175699b to your computer and use it in GitHub Desktop.

Select an option

Save hansemro/7f7d3532e8e9dc82fb0a36108175699b to your computer and use it in GitHub Desktop.
[OpenOCD][DLC10] Boundary Scan Utilities + DLC10 LED Blinking via EXTEST
# Copyright (C) 2025 Hansem Ro <[email protected]>
# SPDX-License-Identifier: 0BSD
# Version: 1.0
# Required TAP-specific parameters
#set g_tap xc3s.tap
#set g_boundary_length 637
#set g_extest_instr 0b001111
#set g_sample_instr 0b000001
#=====Boundary Scan Cell Utilities=====
# Cached Boundary Scan Cells
set g_cells ""
## Helper Operations on Long Hex-Strings
# Get n-th bit from a string of hexadecimal values
# Args:
# - hexstr: string of hexadecimal values in msb->lsb string order and without 0x prefix
# - n: bit index
# Returns n-th bit of hexstr
proc get_bit_from_hexstr {hexstr n} {
set rev [string reverse $hexstr]
set i [expr {($n / 4)}]
set hex_digit [string cat 0x [string index $rev $i]]
return [expr {$hex_digit >> ($n % 4) & 1}]
}
# Set n-th bit of the string of hexadecimal values and return it
# Args:
# - hexstr: string of hexadecimal values in msb->lsb string order and without 0x prefix
# - n: bit index
# - value: 0 | 1
# Returns hexstr with n-th bit set/cleared
proc set_bit_in_hexstr {hexstr n value} {
set mask [expr {~(1 << ($n % 4)) & 0xf}]
set value [expr {($value & 1) << ($n % 4)}]
set rev [string reverse $hexstr]
set i [expr {($n / 4)}]
set hex_digit [string cat 0x [string index $rev $i]]
set hex_digit [format %x [expr {$hex_digit & $mask | ($value)}]]
set rev [string replace $rev $i $i $hex_digit]
return [string reverse $rev]
}
## Boundary Scan Cell Operations
# Sample/Preload Boundary Scan Cells
# Args:
# - value: value to load into Boundary Register
# Returns Boundary Register as a string of hexadecimal values in msb->lsb string order and without 0x prefix
proc sample_bscs {value} {
global g_tap
global g_boundary_length
global g_sample_instr
irscan $g_tap $g_sample_instr -endstate RUN/IDLE
set ret [drscan $g_tap $g_boundary_length $value -endstate RUN/IDLE]
return $ret
}
# Sample Boundary Scan Cells and return value of n-th cell
# Args:
# - n: Boundary Scan Cell index
# Returns value of n-th Boundary Scan Cell
proc get_signal {n} {
global g_boundary_length
global g_cells
if {$g_cells == ""} {
set g_cells [sample_bscs 0]
}
return [get_bit_from_hexstr $g_cells $n]
}
# Overwrite n-th cell then drive external pins with EXTEST
# Args:
# - n: Boundary Scan Cell index
# - value: 0 | 1
proc set_signal {n value} {
global g_tap
global g_boundary_length
global g_cells
global g_extest_instr
if {$g_cells == ""} {
set g_cells [sample_bscs $value]
}
set g_cells [set_bit_in_hexstr $g_cells $n $value]
set ignore [sample_bscs [string cat 0x $g_cells]]
irscan $g_tap $g_extest_instr -endstate RUN/IDLE
}
# Copyright (C) 2025 Hansem Ro <[email protected]>
# SPDX-License-Identifier: 0BSD
# Glasgow jtag-openocd remote_bitbang:
# adapter driver remote_bitbang
# remote_bitbang port 2222
# reset_config none
# IXO-USB-JTAG:
# adapter driver usb_blaster
# usb_blaster vid_pid 0x16C0 0x06AD 0xdead 0xcafe
# usb_blaster lowlevel_driver ftdi
# source [find cpld/xilinx-xc3s.cfg]
# init
# Spartan-3A XC3S200A-FT256 TAP
set bypass_instr 0b111111
set idcode_instr 0b001001
set extest_instr 0b001111
set sample_instr 0b000001
set user1_instr 0b000010
set user2_instr 0b000011
set xc3s200a_ft256_blength 637
# Xilinx DLC10 FPGA Pin-BSC Map
set bsc_led_red 138
set bsc_led_green 144
source "bsc_utils.cfg"
set g_tap xc3s.tap
set g_boundary_length $xc3s200a_ft256_blength
set g_extest_instr $extest_instr
set g_sample_instr $sample_instr
proc blink_leds {} {
global extest_instr
global xc3s200a_ft256_blength
global bsc_led_red
global bsc_led_green
echo "turning on all leds"
set_signal $bsc_led_red 1
set_signal $bsc_led_green 1
sleep 1000
echo "turning on red led"
set_signal $bsc_led_red 1
set_signal $bsc_led_green 0
sleep 1000
echo "turning on green led"
set_signal $bsc_led_red 0
set_signal $bsc_led_green 1
sleep 1000
echo "turning on all leds"
set_signal $bsc_led_red 1
set_signal $bsc_led_green 1
sleep 1000
echo "turning off all leds"
set_signal $bsc_led_red 0
set_signal $bsc_led_green 0
sleep 1000
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment