Skip to main content
Visitor II
June 15, 2021
Question

I am using a STM32H743 to access a SD card using the ST micro driver code. I m NOT using interrupts for the MMC however if an interrupt occurs during a file access the code sometimes crashes. By crashes I mean the read routine times out.

  • June 15, 2021
  • 6 replies
  • 2024 views

Why isn't the SDMMC code tolerant to interrupts?

    This topic has been closed for replies.

    6 replies

    Super User
    June 15, 2021

    > Why isn't the SDMMC code tolerant to interrupts?

    Because the hardware needs to be fed data (or have data read) with strict timing requirements to avoid overrun/underrun of the hardware buffer.

    Disable interrupts during access or use DMA based accessing to avoid.

    Graduate II
    June 15, 2021

    The FIFO adds some tolerance, but you can't go wandering off in the middle of the data transfer phase, the cards just don't have a mid-transfer abort protocol..

    Figure you're interrupt routines are very tardy, or you're task switching to some completely alternate universe.

    Use DMA, polled is very fragile, as I think I've expressed here multiple times.

    BBertAuthor
    Visitor II
    June 15, 2021

    Hi TDK,

    Thanks for the quick reply. I have disabled interrupts during the read access which, as you said, solved the problem. However it raised a new problem. If the interrupts are disabled then the timeout, which uses the systick interrupt, no longer works :( I have not used DMA so far but I'm willing to try it. Do you have any examples showing how to use DMA with the SDMMC?

    Thanks...

    Graduate II
    June 15, 2021

    There should be example diskio drivers in the FatFs Middleware directories.

    H7 going to want to be conscious of the memory being utilized, the alignment and cache coherency.

    BBertAuthor
    Visitor II
    June 15, 2021

    Hi Tesla,

    I have searched all of the FatFs directories (including Middleware) for an example using DMA but I cannot find a single one :(

    Super User
    June 17, 2021

    Hi Bert,

    i was searching also (about 4 minutes) and see: sd_diskio_dma.c

    (in STM32CubeH7-master\Projects\STM32H747I-EVAL\Applications\FatFs\FatFs_Dual_Instance\CM7\Src ) .

    Maybe this is what you want.

    ;)

    BBertAuthor
    Visitor II
    June 17, 2021

    Hi AScha.3,

    Thanks for the reply :)

    The example you mentioned is for a dual-core STM32H7 device but it may work for my needs. I'll give it a try as time permits.