From f01d7e5951c62645eca8e30371589a9ad29eade5 Mon Sep 17 00:00:00 2001 From: LBFFilho Date: Mon, 5 Feb 2024 17:18:27 -0300 Subject: [PATCH] SPI Engine: fix early sdi data clear (#1231) * SPI Engine: fix early sdi data clear In case an SPI read was immediately followed by a cs assert, the sdi register was being cleared one cycle too soon, so that the data being passed on was always 'b0. Signed-off-by: Laez Barbosa --- .../spi_engine_execution.v | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/library/spi_engine/spi_engine_execution/spi_engine_execution.v b/library/spi_engine/spi_engine_execution/spi_engine_execution.v index a95994d12..0fc7c3ef6 100644 --- a/library/spi_engine/spi_engine_execution/spi_engine_execution.v +++ b/library/spi_engine/spi_engine_execution/spi_engine_execution.v @@ -159,6 +159,7 @@ module spi_engine_execution #( wire cs_sleep_counter_compare; wire cs_sleep_early_exit; reg cs_sleep_repeat; + reg cs_active; wire io_ready1; wire io_ready2; @@ -420,7 +421,14 @@ module spi_engine_execution #( // used to latch the MISO lines, improving the overall timing margin of the // interface. - wire cs_active_s = (inst_d1 == CMD_CHIPSELECT) & ~(&cmd_d1[NUM_OF_CS-1:0]); + always @(posedge clk) begin + if (!resetn) begin // set cs_active during reset for a cycle to clear shift reg + cs_active <= 1; + end else begin + cs_active <= ~(&cmd_d1[NUM_OF_CS-1:0]) & cs_gen; + end + end + genvar i; // NOTE: SPI configuration (CPOL/PHA) is only hardware configurable at this point @@ -438,8 +446,8 @@ module spi_engine_execution #( for (i=0; i