tinyfpga/TinyFPGA-Bootloader

Latch inferred by yosys

smunaut opened this issue · 3 comments

Some of the 'always' block don't always set every 'reg' and this gets inferred as latch. For instance, for state machine, adding a default assignment of the 'next' state to the 'current' state at the beginning or things like that.

See the attached diff (as .txt because of stupid github ...)

They're all fairly straightforward except out_ep_acked for this one it's a bit of a guess and should be checked by someone who knows the code :p

tinyfpga.txt

esden commented

for convenience here is the patch quoted for easier viewing:

diff --git a/common/usb_fs_in_arb.v b/common/usb_fs_in_arb.v
index a331406..186a272 100644
--- a/common/usb_fs_in_arb.v
+++ b/common/usb_fs_in_arb.v
@@ -20,6 +20,8 @@ module usb_fs_in_arb #(
   always @* begin
     grant = 0;
 
+    arb_in_ep_data <= 0;
+
     for (i = 0; i < NUM_IN_EPS; i = i + 1) begin
       in_ep_grant[i] <= 0;
 
@@ -29,9 +31,5 @@ module usb_fs_in_arb #(
         grant = 1;
       end
     end
-
-    if (!grant) begin
-      arb_in_ep_data <= 0;
-    end
   end
 endmodule
diff --git a/common/usb_fs_in_pe.v b/common/usb_fs_in_pe.v
index d999de4..fbc38a5 100644
--- a/common/usb_fs_in_pe.v
+++ b/common/usb_fs_in_pe.v
@@ -166,6 +166,8 @@ module usb_fs_in_pe #(
       always @* begin
         in_ep_acked[ep_num] <= 0;
 
+        ep_state_next[ep_num] <= ep_state[ep_num];
+
         if (in_ep_stall[ep_num]) begin
           ep_state_next[ep_num] <= STALL;
 
@@ -277,9 +279,11 @@ module usb_fs_in_pe #(
   reg rollback_in_xfr;
 
   always @* begin
+    in_xfr_state_next <= in_xfr_state;
     in_xfr_start <= 0;
     in_xfr_end <= 0;
     tx_pkt_start <= 0;
+    tx_pid <= 4'b0000;
     rollback_in_xfr <= 0;
 
     case (in_xfr_state)
diff --git a/common/usb_fs_out_pe.v b/common/usb_fs_out_pe.v
index 2e43be5..b1fa005 100644
--- a/common/usb_fs_out_pe.v
+++ b/common/usb_fs_out_pe.v
@@ -154,6 +154,8 @@ module usb_fs_out_pe #(
     for (ep_num = 0; ep_num < NUM_OUT_EPS; ep_num = ep_num + 1) begin
       always @* begin
 
+        ep_state_next[ep_num] <= ep_state[ep_num];
+
         if (out_ep_stall[ep_num]) begin
           ep_state_next[ep_num] <= STALL;
 
@@ -272,7 +274,9 @@ module usb_fs_out_pe #(
   ////////////////////////////////////////////////////////////////////////////////
 
   always @* begin
+    out_ep_acked <= 0;
     out_xfr_start <= 0;
+    out_xfr_state_next <= out_xfr_state;
     tx_pkt_start <= 0;
     tx_pid <= 0;
     new_pkt_end <= 0;

(@smunaut here is how you can do that in the future: https://stackoverflow.com/questions/40883421/diff-syntax-highlighting-in-github-markdown )

@smunaut Was this merged into the code at all?

Yup