@@ -2128,8 +2128,10 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
21282128
21292129 # Checks/Parameters.
21302130 assert mode in ["1x" , "4x" ]
2131- default_divisor = math .ceil (self .sys_clk_freq / (2 * clk_freq )) - 1
2132- clk_freq = int (self .sys_clk_freq / (2 * (default_divisor + 1 )))
2131+ default_divisor = math .ceil (self .sys_clk_freq / clk_freq )
2132+ if rate == "1:1" :
2133+ default_divisor += default_divisor % 2 # Round up to nearest even number.
2134+ clk_freq = int (self .sys_clk_freq / default_divisor )
21332135
21342136 if "master_with_irq" not in kwargs and self .irq .enabled and name in self .irq .locs .keys ():
21352137 # If IRQ is enabled, use master_with_irq.
@@ -2154,6 +2156,7 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
21542156
21552157 # Constants.
21562158 self .add_constant (f"{ name } _PHY_FREQUENCY" , clk_freq )
2159+ self .add_constant (f"{ name } _PHY_MIN_DIVISOR" , 2 if rate == "1:1" else 1 )
21572160 self .add_constant (f"{ name } _MODULE_NAME" , module .name )
21582161 self .add_constant (f"{ name } _MODULE_TOTAL_SIZE" , module .total_size )
21592162 self .add_constant (f"{ name } _MODULE_PAGE_SIZE" , module .page_size )
@@ -2179,8 +2182,10 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
21792182
21802183 # Checks/Parameters.
21812184 assert mode in ["1x" , "4x" ]
2182- default_divisor = math .ceil (self .sys_clk_freq / (2 * clk_freq )) - 1
2183- clk_freq = int (self .sys_clk_freq / (2 * (default_divisor + 1 )))
2185+ default_divisor = math .ceil (self .sys_clk_freq / clk_freq )
2186+ if rate == "1:1" :
2187+ default_divisor += default_divisor % 2 # Round up to nearest even number.
2188+ clk_freq = int (self .sys_clk_freq / default_divisor )
21842189
21852190 if "master_with_irq" not in kwargs and self .irq .enabled and name in self .irq .locs .keys ():
21862191 # If IRQ is enabled, use master_with_irq.
@@ -2226,6 +2231,7 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
22262231
22272232 # Constants.
22282233 self .add_constant (f"{ name } _PHY_FREQUENCY" , clk_freq )
2234+ self .add_constant (f"{ name } _PHY_MIN_DIVISOR" , 2 if rate == "1:1" else 1 )
22292235 self .add_constant (f"{ name } _MODULE_NAME" , module .name )
22302236 self .add_constant (f"{ name } _MODULE_TOTAL_SIZE" , module .total_size )
22312237 self .add_constant (f"{ name } _MODULE_PAGE_SIZE" , module .page_size )
0 commit comments