Page 1 of 1

STM32F4 SDIO f_write() lockup in Timer Callback

Posted: Tue Jun 24, 2014 5:27 pm
by forrestjon
Hello,

I am toubleshooting an issue involving writing to an SD card with f_write().
My platform is as follows:
Hardware: STM32F4Discovery Board
Compiler : IAR 7.10.3
ChibiOS : 2.6.4

I am able to write full sectors(512 Bytes) to to the SD card without issue within main().

However, calling the same f_write() function from within a timer callback function results in an "_unhandled_exception".

The timer callback function is fired every 50ms.
Each time it is called a single sector(512 Bytes) of data is written to the SD card.
I timed the successful sector writes in main() and they were just over 8ms.
Therefore, there should be plenty of time to write 1 sector every 50ms.

Here is what I have tried thus far:
Suspecting some hidden DMA conflict, I changed the default DMA to DMA2 stream6 (from DMA2 stream3).
The hardware timer being used is TIMER14 which had no DMA capability however, I was just being careful.
- This had no effect.

I am about to dive into the DMA and IRQ priorities next.

As a fairly inexperience ARM firmware guy I could use a little advice here.

Thank You,

Forrest

Re: STM32F4 SDIO f_write() lockup in Timer Callback

Posted: Tue Jun 24, 2014 5:32 pm
by Giovanni
Hi,

f_write is a blocking call, it waits until the data has been written. Callbacks are called from ISR context, "waiting" in an ISR makes no sense this is why you got that error.

If you enable the "state checker" in chconf.h this kind of errors are caught immediately.

In general from ISRs you can call only i-class functions, see "kernel concepts" chapter in the documentation.

Giovanni

Re: STM32F4 SDIO f_write() lockup in Timer Callback

Posted: Tue Jun 24, 2014 5:35 pm
by forrestjon
A little more info:
1) Increasing PORT IDLE STACK SIZE from 16 to 32 has no effect
2) I am using high optimization(for speed)

Re: STM32F4 SDIO f_write() lockup in Timer Callback

Posted: Tue Jun 24, 2014 5:40 pm
by Giovanni
It doesn't matter, you cannot do blocking calls from ISRs :)

You may use a periodic thread instead of a timer there.

Giovanni

Re: STM32F4 SDIO f_write() lockup in Timer Callback

Posted: Tue Jun 24, 2014 6:22 pm
by forrestjon
Hi Giovanni,

I understand. I posted my last message before seeing this one from you.
Thanks for the clarification on the "blocking" issue.

This unfortunately complicates my algorithm which needs to run every 5ms and write data to the SD card.
I slowed my timer callback down to 50ms to isolate what I thought was a timing issue.

I'll look at rewriting my code to split it up.

Thanks,

Forrest