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

Hangup, and 'no SD card detected' after reset #7

Open
sergev opened this issue Dec 6, 2014 · 8 comments
Open

Hangup, and 'no SD card detected' after reset #7

sergev opened this issue Dec 6, 2014 · 8 comments

Comments

@sergev
Copy link
Owner

sergev commented Dec 6, 2014

Sometimes the system hangs up, and when restarted using Reset button, the kernel fails to boot up with message:

sd0: no SD card detected

Seems like a bug in sd driver. Wrong timing or something.

@majenkotech
Copy link
Collaborator

Certainly something is locking up in the driver which is leaving the card in a broken state.

When the system hangs it does so with the SD card LED turned on, so it must be doing something to the SD card at the time. Whether it's actually the driver for the SD, or the driver for the SPI, or even something else like the swapper that's causing it, I have no clue.

@sergev
Copy link
Owner Author

sergev commented Dec 6, 2014

It can be a timer interrupt in the middle of block transfer. I'm not sure the card tolerates this kind of intrusion. In perspective, it makes sense to modify sd driver to use DMA for block transfer, with interrupt on completion. It will free cpu resources for user tasks and network packet processing. It could solve this issue as well.

@majenkotech
Copy link
Collaborator

Should the DMA transfer be implemented in the SD driver, or in the SPI driver? I'd vote for the SPI driver, so it could be used for other things besides the SD card.

@sergev
Copy link
Owner Author

sergev commented Dec 7, 2014

Seems like the initiation of a transfer belongs to SPI side. But the interrupt processing should be done in SD driver. So SD driver need to provide the DMA channel number to SPI, as it should match the IRQ number.

@majenkotech
Copy link
Collaborator

Either that or the SD driver provides a function pointer to the SPI library as an interrupt callback routine? That way the SPI library could allocate a DMA channel (or better still the DMA driver could allocate a channel to the SPI device).

@sergev
Copy link
Owner Author

sergev commented Dec 7, 2014

I don't think we need too much dynamics here. The DMA channel can be assigned statically at configuration/compile time, like dma0 - for sd0, dma1 - for sd1 (when on separate SPI port) etc. It would simplify the switch in sys/mips/pic32/trap.c:

    case PIC32_IRQ_DMA0:
        sdintr(0);
        break;

@majenkotech
Copy link
Collaborator

True enough. I do tend to overthink these things :)

@majenkotech
Copy link
Collaborator

Just for fun I just wrapped all the SPI bulk transfers in global disable/enable interrupts. It's solid as a rock. Not had a crash yet, and been making that SD LED flash like crazy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants