SDMMC command Time outs

Discussion created by greenwood.greg on Apr 25, 2018
Latest reply on Apr 26, 2018 by greenwood.greg

I having trouble with the SDMMC on the STM32H743i-Eval board.  The problem is that it does not always complete the test write - read example code which is writing a file with some simple text in it and reading the text back.  The failures are either error opening or error writing typically with FR_INT_ERR as a result.  The problem is intermittent.  It will most frequently appear when resetting the board but will also occur after removing and replacing the card.  Most of the time, once the file operations succeed, removing the card and inserting will be repeat the file operation successfully. 

I was wondering if the there is a timing problem and wondered how timeouts are accomplished in the low level code.  There I was surprised to find that the timeouts are performed by software loop in the STM32Cube_FW_H7_V1.2.0 code.  Specifically the loop timing is calculated with:(in stm32h7xx_ll_sdmmc.c )

/* 8 is the number of required instructions cycles for the below loop statement.
  The SDMMC_CMDTIMEOUT is expressed in ms */

register uint32_t count = SDMMC_CMDTIMEOUT * (SystemCoreClock / 8 /1000);


This assumes that the instructions once compiled will always produce the same code.  Bad Assumption!  It can be as little as 6 or as much as 11 depending on optimization and that is with one compiler (eabi in this case).  I know we just need 2 ms but still could be done with the tick unless the assumption is that use of the low level driver must be independent of the tick interrupt.