AnsweredAssumed Answered

Failed to write on SD card over SDMMC1 with STM32L4xx

Question asked by dhavalv on Apr 15, 2016
Latest reply on Jun 23, 2016 by Rygel.Troy1818

I am using STM32L4xx MCU to interface micro SD card of 2GB over SDMMC1 interface. The FatFs and FreeRTOS is also integrated with the firmware. There are other peripherals interfaced over SPI and I2C.


FatFs, SD card and the peripherals are initialized successfully in the beginning. The peripheral over SPI (Peripheral #1) generates external interrupt at every 4 ms and the peripheral over I2C (Peripheral #2) generates external interrupt at every 10ms. I am using DMA to write data on SD card.

Now, firmware reads 11 bytes of data and put it into the circular buffer in the ISR of Peripheral #1. There is a thread, which reads these data from the circular buffer and writes it on the SD card. The thread creates new file at every 30 seconds. Firmware reads 12 bytes of data at every 10ms in the ISR of Peripheral #2, but currently these data is unused.

External interrupt priority of Peripheral #1 is 4 and of Peripheral #2 is 5. The SDMMC interrupt priority is 6 and SD card DMA channels priority is 7.


The f_open() and f_write() function calls fail randomly and once it goes into this state it never comes out of it. This thing works perfectly fine when the peripheral interrupts are disabled during the SD card operation in the thread!! But I can't keep the interrupts disabled, as it'll leads to data loss and I can't afford to lose the data.

I also tried to keep the interrupt priority equal to the priority of SDMMC interrupt, but that didn't work.

Please help me to resolve this issue.
Appreciate your quick help.