Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: phy: restore operation at lower (50MHz) sys-clk-freq #33

Merged
merged 1 commit into from
May 28, 2024

Conversation

gsomlo
Copy link
Contributor

@gsomlo gsomlo commented May 19, 2024

Following commit 15bc2db, LiteSDCard no longer works properly at the low end of system clock speeds (e.g., 50MHz). Reverting the way self.ce and self.clk are generated to comb instead of sync, allows LiteSDCard to operate at the full previous range of system clock speeds.

Fixes: 15bc2db

tested on nexys_video with vexriscv at 50 and 100 MHz, and with rocket at 50MHz on the nexys_video and ecpix5.

Following commit 15bc2db, LiteSDCard no longer works properly at
the low end of system clock speeds (e.g., 50MHz). Reverting the
way `self.ce` and `self.clk` are generated to `comb` instead of
`sync`, allows LiteSDCard to operate at the full previous range
of system clock speeds.

Fixes: 15bc2db
Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>

# Ensure we don't get short pulses on the SDCard Clk.
ce_delayed = Signal()
ce_latched = Signal()
self.sync += If(clk_d, ce_delayed.eq(self.clk_en))
self.comb += If(clk_d, ce_latched.eq(self.clk_en)).Else(ce_latched.eq(ce_delayed))
self.sync += self.clk.eq(~clk & ce_latched)
self.comb += self.clk.eq(~clk & ce_latched)
Copy link
Contributor Author

@gsomlo gsomlo May 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enjoy-digital : I've understood and agree with all the rest of the changes in commits 1a3d474 and 15bc2db, but not sure why self.ce and self.clk were switched to sync from the original comb. It is the reason sdcard breaks at lower (50MHz) system clock frequencies.

To be honest, though, I also don't get why this change breaks sdcard at low speeds :)

@gsomlo
Copy link
Contributor Author

gsomlo commented May 27, 2024

@enjoy-digital : ping?

@enjoy-digital
Copy link
Owner

Hi @gsomlo,

sorry for the delay and thanks for investigating. The reason for the change was to improve the timings (enjoy-digital/litex#1814). I'll have a closer look at this.

@enjoy-digital
Copy link
Owner

Thanks @gsomlo, that's merged. I'll take the time to understand. Just for info @Dolu1990, this will probably degrade the timings for your SoC -> I'll also redo some test and will try to find a proper fix.

@enjoy-digital enjoy-digital merged commit a053251 into enjoy-digital:master May 28, 2024
1 check failed
@gsomlo
Copy link
Contributor Author

gsomlo commented May 28, 2024

I'll also redo some test and will try to find a proper fix.

The weird thing is that if one switches s/comb/sync/ only one of https://github.com/enjoy-digital/litesdcard/blob/master/litesdcard/phy.py#L65 or https://github.com/enjoy-digital/litesdcard/blob/master/litesdcard/phy.py#L65 sdcard still works at 50MHz sysclock. It only stops working if both of those lines are switched to sync !!!

@gsomlo gsomlo deleted the gls-fix-at-50MHz branch May 28, 2024 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants