@@ -2146,8 +2146,10 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
21462146
21472147 # Checks/Parameters.
21482148 assert mode in ["1x" , "4x" ]
2149- default_divisor = math .ceil (self .sys_clk_freq / (2 * clk_freq )) - 1
2150- clk_freq = int (self .sys_clk_freq / (2 * (default_divisor + 1 )))
2149+ default_divisor = math .ceil (self .sys_clk_freq / clk_freq )
2150+ if rate == "1:1" :
2151+ default_divisor += default_divisor % 2 # Round up to nearest even number.
2152+ clk_freq = int (self .sys_clk_freq / default_divisor )
21512153
21522154 if "master_with_irq" not in kwargs and self .irq .enabled and name in self .irq .locs .keys ():
21532155 # If IRQ is enabled, use master_with_irq.
@@ -2172,6 +2174,7 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
21722174
21732175 # Constants.
21742176 self .add_constant (f"{ name } _PHY_FREQUENCY" , clk_freq )
2177+ self .add_constant (f"{ name } _PHY_MIN_DIVISOR" , 2 if rate == "1:1" else 1 )
21752178 self .add_constant (f"{ name } _MODULE_NAME" , module .name )
21762179 self .add_constant (f"{ name } _MODULE_TOTAL_SIZE" , module .total_size )
21772180 self .add_constant (f"{ name } _MODULE_PAGE_SIZE" , module .page_size )
@@ -2197,8 +2200,10 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
21972200
21982201 # Checks/Parameters.
21992202 assert mode in ["1x" , "4x" ]
2200- default_divisor = math .ceil (self .sys_clk_freq / (2 * clk_freq )) - 1
2201- clk_freq = int (self .sys_clk_freq / (2 * (default_divisor + 1 )))
2203+ default_divisor = math .ceil (self .sys_clk_freq / clk_freq )
2204+ if rate == "1:1" :
2205+ default_divisor += default_divisor % 2 # Round up to nearest even number.
2206+ clk_freq = int (self .sys_clk_freq / default_divisor )
22022207
22032208 if "master_with_irq" not in kwargs and self .irq .enabled and name in self .irq .locs .keys ():
22042209 # If IRQ is enabled, use master_with_irq.
@@ -2244,6 +2249,7 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
22442249
22452250 # Constants.
22462251 self .add_constant (f"{ name } _PHY_FREQUENCY" , clk_freq )
2252+ self .add_constant (f"{ name } _PHY_MIN_DIVISOR" , 2 if rate == "1:1" else 1 )
22472253 self .add_constant (f"{ name } _MODULE_NAME" , module .name )
22482254 self .add_constant (f"{ name } _MODULE_TOTAL_SIZE" , module .total_size )
22492255 self .add_constant (f"{ name } _MODULE_PAGE_SIZE" , module .page_size )
0 commit comments