@@ -2140,8 +2140,10 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
21402140
21412141 # Checks/Parameters.
21422142 assert mode in ["1x" , "4x" ]
2143- default_divisor = math .ceil (self .sys_clk_freq / (2 * clk_freq )) - 1
2144- clk_freq = int (self .sys_clk_freq / (2 * (default_divisor + 1 )))
2143+ default_divisor = math .ceil (self .sys_clk_freq / clk_freq )
2144+ if rate == "1:1" :
2145+ default_divisor += default_divisor % 2 # Round up to nearest even number.
2146+ clk_freq = int (self .sys_clk_freq / default_divisor )
21452147
21462148 if "master_with_irq" not in kwargs and self .irq .enabled and name in self .irq .locs .keys ():
21472149 # If IRQ is enabled, use master_with_irq.
@@ -2166,6 +2168,7 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
21662168
21672169 # Constants.
21682170 self .add_constant (f"{ name } _PHY_FREQUENCY" , clk_freq )
2171+ self .add_constant (f"{ name } _PHY_MIN_DIVISOR" , 2 if rate == "1:1" else 1 )
21692172 self .add_constant (f"{ name } _MODULE_NAME" , module .name )
21702173 self .add_constant (f"{ name } _MODULE_TOTAL_SIZE" , module .total_size )
21712174 self .add_constant (f"{ name } _MODULE_PAGE_SIZE" , module .page_size )
@@ -2191,8 +2194,10 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
21912194
21922195 # Checks/Parameters.
21932196 assert mode in ["1x" , "4x" ]
2194- default_divisor = math .ceil (self .sys_clk_freq / (2 * clk_freq )) - 1
2195- clk_freq = int (self .sys_clk_freq / (2 * (default_divisor + 1 )))
2197+ default_divisor = math .ceil (self .sys_clk_freq / clk_freq )
2198+ if rate == "1:1" :
2199+ default_divisor += default_divisor % 2 # Round up to nearest even number.
2200+ clk_freq = int (self .sys_clk_freq / default_divisor )
21962201
21972202 if "master_with_irq" not in kwargs and self .irq .enabled and name in self .irq .locs .keys ():
21982203 # If IRQ is enabled, use master_with_irq.
@@ -2238,6 +2243,7 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
22382243
22392244 # Constants.
22402245 self .add_constant (f"{ name } _PHY_FREQUENCY" , clk_freq )
2246+ self .add_constant (f"{ name } _PHY_MIN_DIVISOR" , 2 if rate == "1:1" else 1 )
22412247 self .add_constant (f"{ name } _MODULE_NAME" , module .name )
22422248 self .add_constant (f"{ name } _MODULE_TOTAL_SIZE" , module .total_size )
22432249 self .add_constant (f"{ name } _MODULE_PAGE_SIZE" , module .page_size )
0 commit comments