STM32F4 SDIO f_write() lockup in Timer Callback

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
forrestjon
Posts: 13
Joined: Mon Jun 16, 2014 10:11 pm

STM32F4 SDIO f_write() lockup in Timer Callback

Post 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
Last edited by forrestjon on Tue Jun 24, 2014 6:17 pm, edited 1 time in total.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 SDIO f_write() lockup in Timer Callback

Post 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
forrestjon
Posts: 13
Joined: Mon Jun 16, 2014 10:11 pm

Re: STM32F4 SDIO f_write() lockup in Timer Callback

Post 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)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 SDIO f_write() lockup in Timer Callback

Post 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
forrestjon
Posts: 13
Joined: Mon Jun 16, 2014 10:11 pm

Re: STM32F4 SDIO f_write() lockup in Timer Callback

Post 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
Post Reply