@@ -2181,8 +2181,10 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
21812181
21822182 # Checks/Parameters.
21832183 assert mode in ["1x" , "4x" ]
2184- default_divisor = math .ceil (self .sys_clk_freq / (2 * clk_freq )) - 1
2185- clk_freq = int (self .sys_clk_freq / (2 * (default_divisor + 1 )))
2184+ default_divisor = math .ceil (self .sys_clk_freq / clk_freq )
2185+ if rate == "1:1" :
2186+ default_divisor += default_divisor % 2 # Round up to nearest even number.
2187+ clk_freq = int (self .sys_clk_freq / default_divisor )
21862188
21872189 if "master_with_irq" not in kwargs and self .irq .enabled and name in self .irq .locs .keys ():
21882190 # If IRQ is enabled, use master_with_irq.
@@ -2210,6 +2212,7 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
22102212 # Constants.
22112213 self .add_constant (f"{ name } _PHY_FREQUENCY" , clk_freq )
22122214 if module is not None :
2215+ self .add_constant (f"{ name } _PHY_MIN_DIVISOR" , 2 if rate == "1:1" else 1 )
22132216 self .add_constant (f"{ name } _MODULE_NAME" , module .name )
22142217 self .add_constant (f"{ name } _MODULE_TOTAL_SIZE" , module .total_size )
22152218 self .add_constant (f"{ name } _MODULE_PAGE_SIZE" , module .page_size )
@@ -2235,8 +2238,10 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
22352238
22362239 # Checks/Parameters.
22372240 assert mode in ["1x" , "4x" ]
2238- default_divisor = math .ceil (self .sys_clk_freq / (2 * clk_freq )) - 1
2239- clk_freq = int (self .sys_clk_freq / (2 * (default_divisor + 1 )))
2241+ default_divisor = math .ceil (self .sys_clk_freq / clk_freq )
2242+ if rate == "1:1" :
2243+ default_divisor += default_divisor % 2 # Round up to nearest even number.
2244+ clk_freq = int (self .sys_clk_freq / default_divisor )
22402245
22412246 if "master_with_irq" not in kwargs and self .irq .enabled and name in self .irq .locs .keys ():
22422247 # If IRQ is enabled, use master_with_irq.
@@ -2282,6 +2287,7 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
22822287
22832288 # Constants.
22842289 self .add_constant (f"{ name } _PHY_FREQUENCY" , clk_freq )
2290+ self .add_constant (f"{ name } _PHY_MIN_DIVISOR" , 2 if rate == "1:1" else 1 )
22852291 self .add_constant (f"{ name } _MODULE_NAME" , module .name )
22862292 self .add_constant (f"{ name } _MODULE_TOTAL_SIZE" , module .total_size )
22872293 self .add_constant (f"{ name } _MODULE_PAGE_SIZE" , module .page_size )
0 commit comments