I need to design an SPI slave peripheral inside an FPGA that shall be used to communicate with a Microcontroller and configure the behaviour of the FPGA design. I have a few questions.
If the FPGA clock frequency is significantly higher than the input SCLK frequency, it is possible to sample the SCLK and detect the rising and falling edges. The design can use this information to shift or latch data. But, (a) What if the SCLK input clock is almost of same order as the FPGA system clock? Does the clock signal connect directly into the FPGA registers? (b) If not then what is the alternative?I am in this situation where the FPGA system clock is not 4 times or more than the SCLK frequency.
If (a) above is true then how do we write the timing constraints?
The SCLK does not need to use global clock routing. Does this mean that any FPGA pin can be used for it?
How should such a slave be designed, and timing constrained and work in reliable way?
Are you using the SPI IP from Quartus tools? You can refer to the SPI IP spec in the doc below:
There are also some design examples available in the link below where you can refer to the connection:
The UG-01085 states:
188.8.131.52. SPI Clock (sclk) Rate
This setting determines the rate of the sclk signal that synchronizes data between
master and slaves. The target clock rate can be specified in units of Hz, kHz or MHz.
The SPI master core uses the Avalon-MM system clock and a clock divisor to generate
The actual frequency of sclk may not exactly match the desired target clock rate.
The achievable clock values are:
<Avalon-MM system clock frequency> / [2, 4, 6, 8, ...]
The actual frequency achieved will not be greater than the specified target value.
It looks like the SPI slave has been designed in the normal way and not where the SCLK clock is used to clock the FPGA registers. There does not seem to be an easy way out of this at all.
It is design dependent whether the the clock signal is to connect to the registers. If SCLK is going to clock network, we shall connect it to clock pin.
I am from IO team and might not be the best person to comment on SPI design and usage. If there is any Avalon specific question, I suggest you to file another question and someone will be able to provide support on it.