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

QSPI: Busy flag sdio_busy is unreliable #763

Closed
Tracked by #782
0xa000 opened this issue Dec 28, 2023 · 6 comments
Closed
Tracked by #782

QSPI: Busy flag sdio_busy is unreliable #763

0xa000 opened this issue Dec 28, 2023 · 6 comments
Assignees
Labels
bug Confirmed bug.

Comments

@0xa000
Copy link
Contributor

0xa000 commented Dec 28, 2023

Test Environment (required)

  • Platform: QMTECH Wukong Board
  • Core Commit: 93e2eb8
  • ROM Release: N/A

Describe the bug
The flag that indicates (amongst other things) if a hardware assisted QSPI operation is being executed is unreliable, that is, it can be set to '0' (false) even though a QSPI operation is in fact being executed.

Although all relevant QSPI hardware assisted operations update the sd_state signal and assign '1' to the sdio_busy signal, these changes only take effect after the VHDL process ends. Often, the value of sd_state at the time a hardware assisted operation is started is Idle.

The state machine that handles sd_state is part of the same VHDL process that handles starting QSPI hardware assisted operations. The handler for sd_state equal to Idle assigns '0' to the sdio_busy signal. Since this VHDL code comes after the code that assigns '1' to the sdio_busy signal in the same process, the first assignment is effectively lost.

To Reproduce
Create a test application that executes a long running QSPI operation (for example, a 64K sector erase) and observe that the sdio_busy flag is never set to 1. The busy flag can be observed by PEEK-ing $D680, bit 0.

Expected behavior
The value of the busy flag should be equal to '1' as long as a QSPI hardware assisted operation is being executed.

Additional context
In sdcardio.vhdl, there is another piece of code that could reset the value of the sdcard_busy signal to '0'. At the moment I'm not certain if it will ever pose a problem, though. It's on lines 3791 -- 3795:

if last_sd_error /= x"0000" then
    sdio_error <= '1';
    sdio_busy <= '0';
    sd_state <= Idle;
end if;
@0xa000 0xa000 added the new New report, not classified yet label Dec 28, 2023
@lydon42 lydon42 added bug Confirmed bug. and removed new New report, not classified yet labels Jan 28, 2024
@gardners
Copy link
Contributor

Consider addressing together with work on #766

@lydon42 lydon42 self-assigned this May 30, 2024
@lydon42
Copy link
Member

lydon42 commented May 30, 2024

The fix should be quite simple:

  • remove setting sdio_busy in the fastio_write switch
  • add set sdio_busy to all initial qspi stages in the state machine

lydon42 added a commit that referenced this issue May 30, 2024
instead of doing it in fastio_write block (which will get reset in Idle state)
@lydon42
Copy link
Member

lydon42 commented May 30, 2024

Handling in 782-mflash-lowlevel, as we need this for MEGAFLASH refactoring.

@lydon42
Copy link
Member

lydon42 commented May 30, 2024

Test with mflash.prg, replacing the delay loop in erase_sector with a sdio_busy wait loop, now results in a stable flash (r6, with attic cache).

@gardners
Copy link
Contributor

Let me know when done, so I can merge the change into my sdcard cache work on #766 as well. Thanks for tackling this.

@lydon42
Copy link
Member

lydon42 commented Jun 29, 2024

I deem this fixed.

@lydon42 lydon42 closed this as completed Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug.
Projects
None yet
Development

No branches or pull requests

3 participants