cancel
Showing results for 
Search instead for 
Did you mean: 

Using SDMMC/SDIO and FATfs for reading SD Card for STM32L471VGT6

morris
Associate II

MCU: STM32L471VGT6

I am trying to get an SD Card to work for my system. I am using a custom board and I cant share any drawings. However, what I am using for the SD Card:

Sd card adapter: https://learn.adafruit.com/adafruit-microsd-spi-sdio

Sd card: SDHC 32 GIG micro sd card.

The wiring is okay, I checked so many times.

The sd card and adapter works for spi, tried it on arduino.

What I have tried in STM32CubeMX:

Enable SDMMC1 (Tried both SD 1 bit and wide 4 bit)

- Formatted it on windows to FAT32

- Interrrupt on

- DMA on

- Pullup on every pin except CK

- Put sdmmc clock to 48 MHz

- DMA template enabled on FATFS

I have tried different PCB, tried different sd adapter, tried different sd card

What My code is crashing on is the f_mount. It returns 

FR_DISK_ERR after a while.
14 REPLIES 14
morris
Associate II

My new problem is not I cant use the sd Card after the stm32 processor have been in sleep mode. The sd card refuse to open a file or make a volume, mouting is fine. I have tried many differemt pf init/deint but nothing seems to work. Any ideas?

 

Note: The cards works before sleep mode

Do you power-down the card while the STM32 is asleep?

What do you do with the SDIO lines while the STM32 is asleep?

It goes into Stop mode 2:

"

Enter Stop 2 mode.
  * @note  In Stop 2 mode, only low power voltage regulator is ON.
  * @note  In Stop 2 mode, all I/O pins keep the same state as in Run mode.
  * @note  All clocks in the VCORE domain are stopped, the PLL, the MSI,
  *        the HSI and the HSE oscillators are disabled. Some peripherals with wakeup capability
  *        (LCD, LPTIM1, I2C3 and LPUART) can switch on the HSI to receive a frame, and switch off the HSI after
  *        receiving the frame if it is not a wakeup frame. In this case the HSI clock is propagated only
  *        to the peripheral requesting it.
  *        SRAM1, SRAM2 and register contents are preserved.
  *        SRAM3 content is preserved depending on RRSTP bit setting (not available on all devices).
  *        The BOR is available.
  *        The voltage regulator is set in low-power mode but LPR bit must be cleared to enter stop 2 mode.
  *        Otherwise, Stop 1 mode is entered.
  * @note  When exiting Stop 2 mode by issuing an interrupt or a wakeup event,
  *         the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register
  *         is set; the MSI oscillator is selected if STOPWUCK is cleared.
  * @PAram STOPEntry  specifies if Stop mode in entered with WFI or WFE instruction.
  *          This parameter can be one of the following values:
  *            @arg @ref PWR_STOPENTRY_WFI  Enter Stop mode with WFI instruction
  *            @arg @ref PWR_STOPENTRY_WFE  Enter Stop mode with WFE instruction"
All sdio lines reamin at 3V under Stop mode, I just checked with multimeter. Can it have someting to do with the clock?

@morris wrote:
Can it have someting to do with the clock?

Quite possibly - you'll have to re-run your SystemClock_Config() to get your clocks back to how they were before sleep.

What happens to the SDIO peripheral during sleep? Does it need to be reconfigured after?

I don't think you answered whether you have a logic analyser to see what's happening on the wires? That should show up if the timings all gone wrong ...

I found it, I had to run 

PeriphCommonClock_Config() after exited my sleep mode becuase the sdmmc runs on a clock that doesnt get started by  SystemClock_Config().