Skip to content

Commit 852d7eb

Browse files
committed
fix 'ap_rst' port polarity for active high case
1 parent c9c10a2 commit 852d7eb

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

hls4ml/templates/vivado/ip_stitcher.tcl

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,35 @@ proc stitch_procedure {base_dir stitch_project_name original_project_name bd_nam
152152
# Get the CONFIG.POLARITY property from one of the IP's 'ap_rst' pins
153153
set sample_rst_pin [lindex $ap_rst_ports 0]
154154
set rst_polarity [get_property CONFIG.POLARITY $sample_rst_pin]
155-
# Create the 'ap_rst' port
156-
set rst_port_name "ap_rst"
157-
create_bd_port -dir I -type rst $rst_port_name
158-
set ap_rst_port [get_bd_ports ap_rst]
159155

160-
# Set the CONFIG.POLARITY property of the 'ap_rst' port based on the retrieved polarity
156+
# Only proceed if the polarity is defined
161157
if {$rst_polarity ne ""} {
158+
# Create the 'ap_rst' port
159+
set rst_port_name "ap_rst"
160+
create_bd_port -dir I -type rst $rst_port_name
161+
set ap_rst_port [get_bd_ports ap_rst]
162+
163+
# Set the CONFIG.POLARITY property of the 'ap_rst' port based on the retrieved polarity
162164
set_property CONFIG.POLARITY $rst_polarity $ap_rst_port
163-
# naming convention for active-low signals
164-
set rst_port_name "ap_rst_n"
165-
set_property NAME $rst_port_name $ap_rst_port
165+
166+
# Rename the port based on polarity
167+
if {$rst_polarity eq "ACTIVE_LOW"} {
168+
set rst_port_name "ap_rst_n"
169+
set_property NAME $rst_port_name $ap_rst_port
170+
puts "Setting reset port ap_rst_n (ACTIVE_LOW)."
171+
} else {
172+
puts "Setting reset port ap_rst (ACTIVE_HIGH)."
173+
}
174+
# Connect all 'ap_rst' pins to the 'ap_rst' port
175+
foreach rst_pin $ap_rst_ports {
176+
connect_bd_net $ap_rst_port $rst_pin
177+
}
166178
} else {
167-
# Fallback to ACTIVE_HIGH if the retrieved polarity is not defined
168-
set_property CONFIG.POLARITY ACTIVE_HIGH $ap_rst_port
169-
}
170-
# Connect all 'ap_rst' pins to the 'ap_rst' port
171-
foreach rst_pin $ap_rst_ports {
172-
connect_bd_net $ap_rst_port $rst_pin
179+
# Fallback: Undefined polarity, no port created
180+
puts "Warning: CONFIG.POLARITY of ap_rst is undefined. No reset port created."
173181
}
182+
} else {
183+
puts "Error: No reset ports found."
174184
}
175185

176186
# Determine interface type
@@ -185,7 +195,7 @@ proc stitch_procedure {base_dir stitch_project_name original_project_name bd_nam
185195
set interface_type "axi_stream"
186196
break
187197
} elseif {[regexp {^layer(?:\d+_)?out_(\d+)$} $port_name]} {
188-
set interface_type "unpacked"
198+
set interface_type "partition"
189199
break
190200
}
191201
}
@@ -220,8 +230,8 @@ proc stitch_procedure {base_dir stitch_project_name original_project_name bd_nam
220230
set ip_i_cell [get_bd_cells $ip_i]
221231
set ip_i_plus1_cell [get_bd_cells $ip_i_plus1]
222232

223-
if {$interface_type == "unpacked"} {
224-
# Existing unpacked interface connection logic
233+
if {$interface_type == "partition"} {
234+
# Existing partitioned interface connection logic
225235
# Get all output pins from ip_i
226236
set output_ports [get_bd_pins -of $ip_i_cell]
227237

@@ -434,7 +444,7 @@ proc stitch_procedure {base_dir stitch_project_name original_project_name bd_nam
434444
puts "Warning: Could not find 'ap_done' pin for last IP"
435445
}
436446

437-
} elseif {$interface_type == "unpacked"} {
447+
} elseif {$interface_type == "partition"} {
438448
# Make 'ap_start' of the first IP external
439449
set first_ip_cell [get_bd_cells [lindex $ip_instances 0]]
440450
if {[string length $first_ip_cell] == 0} {

0 commit comments

Comments
 (0)