3939module sdspi #(
4040 parameter integer CLK_FREQ_HZ = 27_000_000,
4141 parameter integer SPI_CLK_DIV = 2 , // fast clock: 27 MHz / (2*2) = 6.75 MHz
42- parameter integer SPI_CLK_DIV_INIT = 68 // init clock: 27 MHz / (2*68) ≈ 198 kHz
42+ parameter integer SPI_CLK_DIV_INIT = 68 , // init clock: 27 MHz / (2*68) ≈ 198 kHz
43+ parameter integer ACMD41_RETRIES = 2000 // max ACMD41 polls before error
4344) (
4445 input wire i_clk,
4546 input wire i_rst_n,
@@ -313,7 +314,6 @@ module sdspi #(
313314 wire [7 :0 ] r1 = resp[0 ];
314315
315316 // Retry counter for ACMD41.
316- localparam ACMD41_RETRIES = 16'd2000 ;
317317 reg [15 :0 ] retry_cnt;
318318
319319 // CRC dummy bytes (SPI mode ignores CRC except CMD0/CMD8).
@@ -915,8 +915,9 @@ module sdspi #(
915915 end
916916
917917 // SPI byte engine: once spi_active is set, it must stay set until spi_done.
918+ // Guard with $past(i_rst_n) so reset clearing spi_active doesn't falsely fire.
918919 always @(posedge i_clk) begin
919- if (f_past_valid && i_rst_n) begin
920+ if (f_past_valid && i_rst_n && $past(i_rst_n) ) begin
920921 if ($past(spi_active) && ! $past(spi_done))
921922 assert (spi_active || spi_done);
922923 end
@@ -931,10 +932,16 @@ module sdspi #(
931932 end
932933
933934 // Reachability covers.
934- always @(* ) cover (f_past_valid && state == S_IDLE);
935- always @(* ) cover (f_past_valid && state == S_ERROR);
935+ // S_INIT_CLOCKS and spi_done are reachable within a small depth.
936936 always @(* ) cover (f_past_valid && state == S_INIT_CLOCKS);
937937 always @(* ) cover (f_past_valid && spi_done);
938+ // S_IDLE and S_ERROR require the full init sequence (~961 cycles minimum
939+ // even with SPI_CLK_DIV=1 and ACMD41_RETRIES=0). Guard with
940+ // FORMAL_COVER_DEEP so the default sby run stays tractable.
941+ `ifdef FORMAL_COVER_DEEP
942+ always @(* ) cover (f_past_valid && state == S_IDLE);
943+ always @(* ) cover (f_past_valid && state == S_ERROR);
944+ `endif
938945`endif // FORMAL
939946
940947endmodule // sdspi
0 commit comments