cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to write on SD card over SDMMC1 with STM32L4xx

dhaval
Associate II
Posted on April 15, 2016 at 07:16

Hi,

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.

Scenario:

FatFs, SD card and the peripherals are initialized successfully in the beginning. The peripheral over SPI (Peripheral &sharp1) generates external interrupt at every 4 ms and the peripheral over I2C (Peripheral &sharp2) 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 &sharp1. 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 &sharp2, but currently these data is unused.

External interrupt priority of Peripheral &sharp1 is 4 and of Peripheral &sharp2 is 5. The SDMMC interrupt priority is 6 and SD card DMA channels priority is 7.

Problem:

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.

Thanks,

Dhaval

#stm32l4 #hal #fatfs #microsd
11 REPLIES 11
dhaval
Associate II
Posted on June 22, 2016 at 09:33

Can someone please help me here?

troy1818
Senior
Posted on June 23, 2016 at 14:23

How long time are you in the ISR ?

As you probably know, the ISR should not perform any heavy duty stuff. Reading data from SPI does not sound very good in my ears.