Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
PhMa_4608351
Level 2
Level 2
First like received First like given

Hello community,

I'm trying to write to the microSD card as fast as I can. Unfortunately, there seems to be a considerable amount of time between each byte.

Oscilloscope showing the clock emFile.sclk0 clocking out bytes (ignore the upper line).

emFile clock BYTES.jpg

(Apologies for the low quality oscilloscope)

As shown above, the period time between bytes is nearly four times as much as the time it takes to clock out the byte itself. I assumed that emFile is inflexible and a hidden layer of the code, but the amount of time between bytes makes the write time quite long, even though my master clock (MASTER_CLK) is running at 48MHz. Is there any way of increasing the efficiency of writing short of getting a new file system module?

Thanks!

- Phoenix

0 Likes
1 Solution

As I was writing this question to the SEGGER forum, I suddenly realised the cause - which is less technical than it appeared to be.

This graph explains the gaps between the bytes.

IMG_2218.jpg

The top line shows those "clumps" mentioned earlier, and the bottom is a pin I raise high during the sample-timer interrupt.

Since emFile writing is not interrupt-driven, my interrupt that triggers 10000 times a second pauses the writing. I hadn't realised how long is spent in the sample interrupt. Frustratingly, most of that time is spent writing zeros to the ADC so that it can be read (since SPIM is synchronous). Thankfully, sending those zero bytes via DMA makes the interrupt take much less time, and the oscilloscope now looks like this:

IMG_2219.jpg

Much better!

Takeaways:

  • emFile will stop writing for an interrupt of any priority
  • using DMA with the SPI is much faster

Thanks for the replies Len, turns out it was my code that caused the issue - as usual.

- Phoenix

View solution in original post

0 Likes
9 Replies