iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
😼

【Practical FPGA Design】 Two-Stage Flip-Flop Fails for Multi-Bit Signals – Pitfalls of Bus Synchronization

に公開

Introduction

In the previous article, I explained that a two-stage flip-flop is a mechanism to "probabilistically suppress metastability" and is not absolutely safe.

👉 If you want to start from the basics, see here:

Now, are you thinking like this?

"But if I use a two-stage FF, it's safe enough, right?"

To be clear, that only applies to 1-bit signals.

For multi-bit signals (buses), a two-stage FF easily breaks down.

In this article, I'll explain why and show you how it actually fails in practice.


Common Mistake: Synchronizing a Bus Directly

Consider an example where an 8-bit data signal is received from a different clock domain.

process(clk)  
begin  
  if rising_edge(clk) then  
    data_sync1 <= data_async;  
    data_sync2 <= data_sync1;  
  end if;  
end process;

At first glance, this looks safe because each bit goes through two flip-flops.

However, this is a dangerous design.


What Happens: Bit-by-Bit "Skew"

The key points are:

  • Each bit can independently enter metastability.
  • Each bit recovers at a different time.

What's important here is:

  • Each bit is captured by an independent FF.
  • Setup/hold violations occur independently per bit.
  • Whether a bit enters metastability is also independent.
  • Recovery time is also independent.

In other words, the bus as a whole does not become "one value," but rather a "collection of bits that settle individually."

For example:

Original data: 10110011
Received data: 10100011 ← only some bits flip

This creates an "impossible" value.

This is not just a bit error; it's the generation of a "non-existent state."


Another Real-World Failure Example

For instance, when synchronizing a counter value:

Expected transition:
00001111 → 00010000

But due to synchronization skew:

00011111

This can create a "non-existent" value.

👉 Counter jumps
👉 State machine conditions break
👉 Address values distort

These lead to critical bugs in practice.


Why Isn't This a Problem for 1 Bit?

For a 1-bit signal,

  • It eventually settles to 0 or 1.

So the issue is only "a one-clock delay."

More importantly,

👉 After recovering from metastability, it necessarily converges to either 0 or 1, so
👉 There is no concept of "value consistency" in the first place.

However, for multi-bit signals,

  • Consistency between bits breaks down.

That's the essential difference.


Why Valid Synchronization Doesn't Prevent This

A common countermeasure is to add a "Valid signal."

data[7:0] + valid

However,

  • data is a bus
  • valid is also asynchronous

Hence, the following situation can occur:

  • valid is synchronized correctly
  • data is partially old

A common misconception here is:

"If I synchronize valid and then read the data, it's safe, right?"

But the key point is:

  • valid_sync is a synchronized signal
  • data_async is still an asynchronous signal

There is no causal relationship between the two.

Furthermore,

👉 valid_sync does NOT guarantee that "the data is stable"; it only indicates that
👉 "the valid signal has been synchronized."

In other words:

  • When valid_sync asserts, you read the data
  • But there is no guarantee of which timing that data corresponds to

👉 There is no guarantee that "valid asserted means correct data"


Typical Bugs That Occur in Practice

This problem manifests in the following ways:

  • Occurs only sporadically
  • Cannot be reproduced in simulation
  • Difficult to reproduce with a logic analyzer

And the worst part is:

"It breaks sometimes, but I can't figure out why."

What makes this issue particularly nasty is:

👉 It cannot be reproduced in simulation.

This is because:

  • Simulation has no concept of setup/hold violations
  • Metastability cannot be modeled in HDL

Therefore:

👉 The failure mode itself is not reproducible.


Correct Approach (Direction Only)

So what should we do?

Typical methods include:

① Handshake (req/ack)

  • Keep the data held during transfer
  • Do not change it until the receiver acknowledges

② FIFO (Asynchronous FIFO)

  • Safely bridge clock domains
  • Most commonly used in practice

③ Gray Code Encoding (for counters)

  • Ensure only one bit changes at a time

Summary So Far

  • Two-stage FF is a "stabilization method for 1-bit signals"
  • Multi-bit signals suffer from consistency breakdown
  • A Valid signal does not solve the problem

👉 "Synchronizing correctly" is not about "aligning values," but about "aligning meanings."


Going Beyond This

At this point, we've covered:

  • Why bus synchronization is dangerous
  • Why a Valid signal is insufficient

Now the next question arises:

"So, how do we transfer data safely?"

This article focused on the principles and pitfalls, but for the "design decisions" part—

  • How to actually design a safe transfer
  • How much countermeasure is enough

I have organized these details in a Zenn Book.

■ If You Want a Full Overview

👉 I have prepared a "complete navigation" page.

Refer to it if you want to organize your understanding as a whole structure rather than in fragments.

Discussion